jdk

Форк
0
/z
/
test_zPhysicalMemory.cpp 
219 строк · 6.9 Кб
1
/*
2
 * Copyright (c) 2016, 2023, Oracle and/or its affiliates. All rights reserved.
3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
 *
5
 * This code is free software; you can redistribute it and/or modify it
6
 * under the terms of the GNU General Public License version 2 only, as
7
 * published by the Free Software Foundation.
8
 *
9
 * This code is distributed in the hope that it will be useful, but WITHOUT
10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12
 * version 2 for more details (a copy is included in the LICENSE file that
13
 * accompanied this code).
14
 *
15
 * You should have received a copy of the GNU General Public License version
16
 * 2 along with this work; if not, write to the Free Software Foundation,
17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
 *
19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
 * or visit www.oracle.com if you need additional information or have any
21
 * questions.
22
 */
23

24
#include "precompiled.hpp"
25
#include "gc/z/zPhysicalMemory.inline.hpp"
26
#include "unittest.hpp"
27

28
class ZAddressOffsetMaxSetter {
29
private:
30
  const size_t _old_max;
31
  const size_t _old_mask;
32

33
public:
34
  ZAddressOffsetMaxSetter()
35
    : _old_max(ZAddressOffsetMax),
36
      _old_mask(ZAddressOffsetMask) {
37
    ZAddressOffsetMax = size_t(16) * G * 1024;
38
    ZAddressOffsetMask = ZAddressOffsetMax - 1;
39
  }
40
  ~ZAddressOffsetMaxSetter() {
41
    ZAddressOffsetMax = _old_max;
42
    ZAddressOffsetMask = _old_mask;
43
  }
44
};
45

46
TEST(ZPhysicalMemoryTest, copy) {
47
  ZAddressOffsetMaxSetter setter;
48

49
  const ZPhysicalMemorySegment seg0(zoffset(0), 100, true);
50
  const ZPhysicalMemorySegment seg1(zoffset(200), 100, true);
51

52
  ZPhysicalMemory pmem0;
53
  pmem0.add_segment(seg0);
54
  EXPECT_EQ(pmem0.nsegments(), 1);
55
  EXPECT_EQ(pmem0.segment(0).size(), 100u);
56

57
  ZPhysicalMemory pmem1;
58
  pmem1.add_segment(seg0);
59
  pmem1.add_segment(seg1);
60
  EXPECT_EQ(pmem1.nsegments(), 2);
61
  EXPECT_EQ(pmem1.segment(0).size(), 100u);
62
  EXPECT_EQ(pmem1.segment(1).size(), 100u);
63

64
  ZPhysicalMemory pmem2(pmem0);
65
  EXPECT_EQ(pmem2.nsegments(), 1);
66
  EXPECT_EQ(pmem2.segment(0).size(), 100u);
67

68
  pmem2 = pmem1;
69
  EXPECT_EQ(pmem2.nsegments(), 2);
70
  EXPECT_EQ(pmem2.segment(0).size(), 100u);
71
  EXPECT_EQ(pmem2.segment(1).size(), 100u);
72
}
73

74
TEST(ZPhysicalMemoryTest, add) {
75
  ZAddressOffsetMaxSetter setter;
76

77
  const ZPhysicalMemorySegment seg0(zoffset(0), 1, true);
78
  const ZPhysicalMemorySegment seg1(zoffset(1), 1, true);
79
  const ZPhysicalMemorySegment seg2(zoffset(2), 1, true);
80
  const ZPhysicalMemorySegment seg3(zoffset(3), 1, true);
81
  const ZPhysicalMemorySegment seg4(zoffset(4), 1, true);
82
  const ZPhysicalMemorySegment seg5(zoffset(5), 1, true);
83
  const ZPhysicalMemorySegment seg6(zoffset(6), 1, true);
84

85
  ZPhysicalMemory pmem0;
86
  EXPECT_EQ(pmem0.nsegments(), 0);
87
  EXPECT_EQ(pmem0.is_null(), true);
88

89
  ZPhysicalMemory pmem1;
90
  pmem1.add_segment(seg0);
91
  pmem1.add_segment(seg1);
92
  pmem1.add_segment(seg2);
93
  pmem1.add_segment(seg3);
94
  pmem1.add_segment(seg4);
95
  pmem1.add_segment(seg5);
96
  pmem1.add_segment(seg6);
97
  EXPECT_EQ(pmem1.nsegments(), 1);
98
  EXPECT_EQ(pmem1.segment(0).size(), 7u);
99
  EXPECT_EQ(pmem1.is_null(), false);
100

101
  ZPhysicalMemory pmem2;
102
  pmem2.add_segment(seg0);
103
  pmem2.add_segment(seg1);
104
  pmem2.add_segment(seg2);
105
  pmem2.add_segment(seg4);
106
  pmem2.add_segment(seg5);
107
  pmem2.add_segment(seg6);
108
  EXPECT_EQ(pmem2.nsegments(), 2);
109
  EXPECT_EQ(pmem2.segment(0).size(), 3u);
110
  EXPECT_EQ(pmem2.segment(1).size(), 3u);
111
  EXPECT_EQ(pmem2.is_null(), false);
112

113
  ZPhysicalMemory pmem3;
114
  pmem3.add_segment(seg0);
115
  pmem3.add_segment(seg2);
116
  pmem3.add_segment(seg3);
117
  pmem3.add_segment(seg4);
118
  pmem3.add_segment(seg6);
119
  EXPECT_EQ(pmem3.nsegments(), 3);
120
  EXPECT_EQ(pmem3.segment(0).size(), 1u);
121
  EXPECT_EQ(pmem3.segment(1).size(), 3u);
122
  EXPECT_EQ(pmem3.segment(2).size(), 1u);
123
  EXPECT_EQ(pmem3.is_null(), false);
124

125
  ZPhysicalMemory pmem4;
126
  pmem4.add_segment(seg0);
127
  pmem4.add_segment(seg2);
128
  pmem4.add_segment(seg4);
129
  pmem4.add_segment(seg6);
130
  EXPECT_EQ(pmem4.nsegments(), 4);
131
  EXPECT_EQ(pmem4.segment(0).size(), 1u);
132
  EXPECT_EQ(pmem4.segment(1).size(), 1u);
133
  EXPECT_EQ(pmem4.segment(2).size(), 1u);
134
  EXPECT_EQ(pmem4.segment(3).size(), 1u);
135
  EXPECT_EQ(pmem4.is_null(), false);
136
}
137

138
TEST(ZPhysicalMemoryTest, remove) {
139
  ZAddressOffsetMaxSetter setter;
140

141
  ZPhysicalMemory pmem;
142

143
  pmem.add_segment(ZPhysicalMemorySegment(zoffset(10), 10, true));
144
  pmem.add_segment(ZPhysicalMemorySegment(zoffset(30), 10, true));
145
  pmem.add_segment(ZPhysicalMemorySegment(zoffset(50), 10, true));
146
  EXPECT_EQ(pmem.nsegments(), 3);
147
  EXPECT_EQ(pmem.size(), 30u);
148
  EXPECT_FALSE(pmem.is_null());
149

150
  pmem.remove_segments();
151
  EXPECT_EQ(pmem.nsegments(), 0);
152
  EXPECT_EQ(pmem.size(), 0u);
153
  EXPECT_TRUE(pmem.is_null());
154
}
155

156
TEST(ZPhysicalMemoryTest, split) {
157
  ZAddressOffsetMaxSetter setter;
158

159
  ZPhysicalMemory pmem;
160

161
  pmem.add_segment(ZPhysicalMemorySegment(zoffset(0), 10, true));
162
  pmem.add_segment(ZPhysicalMemorySegment(zoffset(10), 10, true));
163
  pmem.add_segment(ZPhysicalMemorySegment(zoffset(30), 10, true));
164
  EXPECT_EQ(pmem.nsegments(), 2);
165
  EXPECT_EQ(pmem.size(), 30u);
166

167
  ZPhysicalMemory pmem0 = pmem.split(1);
168
  EXPECT_EQ(pmem0.nsegments(), 1);
169
  EXPECT_EQ(pmem0.size(), 1u);
170
  EXPECT_EQ(pmem.nsegments(), 2);
171
  EXPECT_EQ(pmem.size(), 29u);
172

173
  ZPhysicalMemory pmem1 = pmem.split(25);
174
  EXPECT_EQ(pmem1.nsegments(), 2);
175
  EXPECT_EQ(pmem1.size(), 25u);
176
  EXPECT_EQ(pmem.nsegments(), 1);
177
  EXPECT_EQ(pmem.size(), 4u);
178

179
  ZPhysicalMemory pmem2 = pmem.split(4);
180
  EXPECT_EQ(pmem2.nsegments(), 1);
181
  EXPECT_EQ(pmem2.size(), 4u);
182
  EXPECT_EQ(pmem.nsegments(), 0);
183
  EXPECT_EQ(pmem.size(), 0u);
184
}
185

186
TEST(ZPhysicalMemoryTest, split_committed) {
187
  ZAddressOffsetMaxSetter setter;
188

189
  ZPhysicalMemory pmem0;
190
  pmem0.add_segment(ZPhysicalMemorySegment(zoffset(0), 10, true));
191
  pmem0.add_segment(ZPhysicalMemorySegment(zoffset(10), 10, false));
192
  pmem0.add_segment(ZPhysicalMemorySegment(zoffset(20), 10, true));
193
  pmem0.add_segment(ZPhysicalMemorySegment(zoffset(30), 10, false));
194
  EXPECT_EQ(pmem0.nsegments(), 4);
195
  EXPECT_EQ(pmem0.size(), 40u);
196

197
  ZPhysicalMemory pmem1 = pmem0.split_committed();
198
  EXPECT_EQ(pmem0.nsegments(), 2);
199
  EXPECT_EQ(pmem0.size(), 20u);
200
  EXPECT_EQ(pmem1.nsegments(), 2);
201
  EXPECT_EQ(pmem1.size(), 20u);
202
}
203

204
TEST(ZPhysicalMemoryTest, limits) {
205
  ZAddressOffsetMaxSetter setter;
206

207
  const size_t HalfZAddressOffsetMax = ZAddressOffsetMax >> 1;
208
  ZPhysicalMemory pmem0;
209
  pmem0.add_segment(ZPhysicalMemorySegment(zoffset(0), HalfZAddressOffsetMax, true));
210
  pmem0.add_segment(ZPhysicalMemorySegment(zoffset(HalfZAddressOffsetMax), HalfZAddressOffsetMax, false));
211
  EXPECT_EQ(pmem0.nsegments(), 2);
212
  EXPECT_EQ(pmem0.size(), ZAddressOffsetMax);
213

214
  ZPhysicalMemory pmem1 = pmem0.split_committed();
215
  EXPECT_EQ(pmem0.nsegments(), 1);
216
  EXPECT_EQ(pmem0.size(), HalfZAddressOffsetMax);
217
  EXPECT_EQ(pmem1.nsegments(), 1);
218
  EXPECT_EQ(pmem1.size(), HalfZAddressOffsetMax);
219
}
220

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.