Skip to content

Commit ecfaf35

Browse files
committed
8356083: ZGC: Duplicate ZTestEntry symbols in gtests
Reviewed-by: aboldtch, tschatzl
1 parent 1eee15e commit ecfaf35

File tree

1 file changed

+52
-52
lines changed

1 file changed

+52
-52
lines changed

test/hotspot/gtest/gc/z/test_zIntrusiveRBTree.cpp

Lines changed: 52 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -32,49 +32,49 @@
3232

3333
#include <limits>
3434

35-
struct ZTestEntryCompare {
35+
struct ZRBTestEntryCompare {
3636
int operator()(const ZIntrusiveRBTreeNode* a, const ZIntrusiveRBTreeNode* b);
3737
int operator()(int key, const ZIntrusiveRBTreeNode* entry);
3838
};
3939

40-
class ZTestEntry : public ArenaObj {
41-
friend class ZIntrusiveRBTree<int, ZTestEntryCompare>;
40+
class ZRBTestEntry : public ArenaObj {
41+
friend class ZIntrusiveRBTree<int, ZRBTestEntryCompare>;
4242

4343
public:
44-
using ZTree = ZIntrusiveRBTree<int, ZTestEntryCompare>;
44+
using ZTree = ZIntrusiveRBTree<int, ZRBTestEntryCompare>;
4545
private:
4646
const int _id;
4747
ZIntrusiveRBTreeNode _node;
4848

4949
public:
50-
ZTestEntry(int id)
50+
ZRBTestEntry(int id)
5151
: _id(id),
5252
_node() {}
5353

5454
int id() const {
5555
return _id;
5656
}
5757

58-
static ZIntrusiveRBTreeNode* cast_to_inner(ZTestEntry* element) {
58+
static ZIntrusiveRBTreeNode* cast_to_inner(ZRBTestEntry* element) {
5959
return &element->_node;
6060
}
61-
static const ZTestEntry* cast_to_outer(const ZIntrusiveRBTreeNode* node) {
62-
return (ZTestEntry*)((uintptr_t)node - offset_of(ZTestEntry, _node));
61+
static const ZRBTestEntry* cast_to_outer(const ZIntrusiveRBTreeNode* node) {
62+
return (ZRBTestEntry*)((uintptr_t)node - offset_of(ZRBTestEntry, _node));
6363
}
6464

6565
};
6666

67-
int ZTestEntryCompare::operator()(const ZIntrusiveRBTreeNode* a, const ZIntrusiveRBTreeNode* b) {
68-
return ZTestEntry::cast_to_outer(a)->id() - ZTestEntry::cast_to_outer(b)->id();
67+
int ZRBTestEntryCompare::operator()(const ZIntrusiveRBTreeNode* a, const ZIntrusiveRBTreeNode* b) {
68+
return ZRBTestEntry::cast_to_outer(a)->id() - ZRBTestEntry::cast_to_outer(b)->id();
6969
}
70-
int ZTestEntryCompare::operator()(int key, const ZIntrusiveRBTreeNode* entry) {
71-
return key - ZTestEntry::cast_to_outer(entry)->id();
70+
int ZRBTestEntryCompare::operator()(int key, const ZIntrusiveRBTreeNode* entry) {
71+
return key - ZRBTestEntry::cast_to_outer(entry)->id();
7272
}
7373

7474
class ZTreeTest : public ZTest {
7575
public:
76-
void shuffle_array(ZTestEntry** beg, ZTestEntry** end);
77-
void reverse_array(ZTestEntry** beg, ZTestEntry** end);
76+
void shuffle_array(ZRBTestEntry** beg, ZRBTestEntry** end);
77+
void reverse_array(ZRBTestEntry** beg, ZRBTestEntry** end);
7878
};
7979

8080
class ResettableArena : public Arena {
@@ -96,10 +96,10 @@ TEST_F(ZTreeTest, test_random) {
9696
constexpr size_t sizes[] = {1, 2, 4, 8, 16, 1024, 1024 * 1024};
9797
constexpr size_t num_sizes = ARRAY_SIZE(sizes);
9898
constexpr size_t iterations_multiplier = 4;
99-
constexpr size_t max_allocation_size = sizes[num_sizes - 1] * iterations_multiplier * sizeof(ZTestEntry);
99+
constexpr size_t max_allocation_size = sizes[num_sizes - 1] * iterations_multiplier * sizeof(ZRBTestEntry);
100100
ResettableArena arena{MemTag::mtTest, Arena::Tag::tag_other, max_allocation_size};
101101
for (size_t s : sizes) {
102-
ZTestEntry::ZTree tree;
102+
ZRBTestEntry::ZTree tree;
103103
const size_t num_iterations = s * iterations_multiplier;
104104
for (size_t i = 0; i < num_iterations; i++) {
105105
if (i % s == 0) {
@@ -113,7 +113,7 @@ TEST_F(ZTreeTest, test_random) {
113113
// Replace
114114
if (i % 4 == 0) {
115115
// Replace with new
116-
tree.replace(ZTestEntry::cast_to_inner(new (&arena) ZTestEntry(id)), cursor);
116+
tree.replace(ZRBTestEntry::cast_to_inner(new (&arena) ZRBTestEntry(id)), cursor);
117117
} else {
118118
// Replace with same
119119
tree.replace(cursor.node(), cursor);
@@ -124,34 +124,34 @@ TEST_F(ZTreeTest, test_random) {
124124
}
125125
} else {
126126
// Insert
127-
tree.insert(ZTestEntry::cast_to_inner(new (&arena) ZTestEntry(id)), cursor);
127+
tree.insert(ZRBTestEntry::cast_to_inner(new (&arena) ZRBTestEntry(id)), cursor);
128128
}
129129
}
130130
tree.verify_tree();
131131
arena.reset_arena();
132132
}
133133
}
134134

135-
void ZTreeTest::reverse_array(ZTestEntry** beg, ZTestEntry** end) {
135+
void ZTreeTest::reverse_array(ZRBTestEntry** beg, ZRBTestEntry** end) {
136136
if (beg == end) {
137137
return;
138138
}
139139

140-
ZTestEntry** first = beg;
141-
ZTestEntry** last = end - 1;
140+
ZRBTestEntry** first = beg;
141+
ZRBTestEntry** last = end - 1;
142142
while (first < last) {
143143
::swap(*first, *last);
144144
first++;
145145
last--;
146146
}
147147
}
148148

149-
void ZTreeTest::shuffle_array(ZTestEntry** beg, ZTestEntry** end) {
149+
void ZTreeTest::shuffle_array(ZRBTestEntry** beg, ZRBTestEntry** end) {
150150
if (beg == end) {
151151
return;
152152
}
153153

154-
for (ZTestEntry** first = beg + 1; first != end; first++) {
154+
for (ZRBTestEntry** first = beg + 1; first != end; first++) {
155155
const ptrdiff_t distance = first - beg;
156156
ASSERT_GE(distance, 0);
157157
const ptrdiff_t random_index = random() % (distance + 1);
@@ -162,51 +162,51 @@ void ZTreeTest::shuffle_array(ZTestEntry** beg, ZTestEntry** end) {
162162
TEST_F(ZTreeTest, test_insert) {
163163
Arena arena(MemTag::mtTest);
164164
constexpr size_t num_entries = 1024;
165-
ZTestEntry* forward[num_entries]{};
166-
ZTestEntry* reverse[num_entries]{};
167-
ZTestEntry* shuffle[num_entries]{};
165+
ZRBTestEntry* forward[num_entries]{};
166+
ZRBTestEntry* reverse[num_entries]{};
167+
ZRBTestEntry* shuffle[num_entries]{};
168168
for (size_t i = 0; i < num_entries; i++) {
169169
const int id = static_cast<int>(i);
170-
forward[i] = new (&arena) ZTestEntry(id);
171-
reverse[i] = new (&arena) ZTestEntry(id);
172-
shuffle[i] = new (&arena) ZTestEntry(id);
170+
forward[i] = new (&arena) ZRBTestEntry(id);
171+
reverse[i] = new (&arena) ZRBTestEntry(id);
172+
shuffle[i] = new (&arena) ZRBTestEntry(id);
173173
}
174174
reverse_array(reverse, reverse + num_entries);
175175
shuffle_array(shuffle, shuffle + num_entries);
176176

177-
ZTestEntry::ZTree forward_tree;
177+
ZRBTestEntry::ZTree forward_tree;
178178
auto cursor = forward_tree.root_cursor();
179179
for (size_t i = 0; i < num_entries; i++) {
180180
ASSERT_TRUE(cursor.is_valid());
181181
ASSERT_FALSE(cursor.found());
182-
ZIntrusiveRBTreeNode* const new_node = ZTestEntry::cast_to_inner(forward[i]);
182+
ZIntrusiveRBTreeNode* const new_node = ZRBTestEntry::cast_to_inner(forward[i]);
183183
forward_tree.insert(new_node, cursor);
184184
cursor = forward_tree.next_cursor(new_node);
185185
}
186186
forward_tree.verify_tree();
187187

188-
ZTestEntry::ZTree reverse_tree;
188+
ZRBTestEntry::ZTree reverse_tree;
189189
cursor = reverse_tree.root_cursor();
190190
for (size_t i = 0; i < num_entries; i++) {
191191
ASSERT_TRUE(cursor.is_valid());
192192
ASSERT_FALSE(cursor.found());
193-
ZIntrusiveRBTreeNode* const new_node = ZTestEntry::cast_to_inner(reverse[i]);
193+
ZIntrusiveRBTreeNode* const new_node = ZRBTestEntry::cast_to_inner(reverse[i]);
194194
reverse_tree.insert(new_node, cursor);
195195
cursor = reverse_tree.prev_cursor(new_node);
196196
}
197197
reverse_tree.verify_tree();
198198

199-
ZTestEntry::ZTree shuffle_tree;
199+
ZRBTestEntry::ZTree shuffle_tree;
200200
for (size_t i = 0; i < num_entries; i++) {
201201
cursor = shuffle_tree.find(reverse[i]->id());
202202
ASSERT_TRUE(cursor.is_valid());
203203
ASSERT_FALSE(cursor.found());
204-
ZIntrusiveRBTreeNode* const new_node = ZTestEntry::cast_to_inner(reverse[i]);
204+
ZIntrusiveRBTreeNode* const new_node = ZRBTestEntry::cast_to_inner(reverse[i]);
205205
shuffle_tree.insert(new_node, cursor);
206206
}
207207
shuffle_tree.verify_tree();
208208

209-
ZTestEntryCompare compare_fn;
209+
ZRBTestEntryCompare compare_fn;
210210
const ZIntrusiveRBTreeNode* forward_node = forward_tree.first();
211211
const ZIntrusiveRBTreeNode* reverse_node = reverse_tree.first();
212212
const ZIntrusiveRBTreeNode* shuffle_node = shuffle_tree.first();
@@ -240,13 +240,13 @@ TEST_F(ZTreeTest, test_insert) {
240240
TEST_F(ZTreeTest, test_replace) {
241241
Arena arena(MemTag::mtTest);
242242
constexpr size_t num_entries = 1024;
243-
ZTestEntry::ZTree tree;
243+
ZRBTestEntry::ZTree tree;
244244
auto cursor = tree.root_cursor();
245245
for (size_t i = 0; i < num_entries; i++) {
246246
ASSERT_TRUE(cursor.is_valid());
247247
ASSERT_FALSE(cursor.found());
248248
const int id = static_cast<int>(i) * 2 + 1;
249-
ZIntrusiveRBTreeNode* const new_node = ZTestEntry::cast_to_inner(new (&arena) ZTestEntry(id));
249+
ZIntrusiveRBTreeNode* const new_node = ZRBTestEntry::cast_to_inner(new (&arena) ZRBTestEntry(id));
250250
tree.insert(new_node, cursor);
251251
cursor = tree.next_cursor(new_node);
252252
}
@@ -261,14 +261,14 @@ TEST_F(ZTreeTest, test_replace) {
261261
switch (i++ % 4) {
262262
case 0: {
263263
// Decrement
264-
ZTestEntry* new_entry = new (&arena) ZTestEntry(ZTestEntry::cast_to_outer(&node)->id() - 1);
265-
it.replace(ZTestEntry::cast_to_inner(new_entry));
264+
ZRBTestEntry* new_entry = new (&arena) ZRBTestEntry(ZRBTestEntry::cast_to_outer(&node)->id() - 1);
265+
it.replace(ZRBTestEntry::cast_to_inner(new_entry));
266266
} break;
267267
case 1: break;
268268
case 2: {
269269
// Increment
270-
ZTestEntry* new_entry = new (&arena) ZTestEntry(ZTestEntry::cast_to_outer(&node)->id() + 1);
271-
it.replace(ZTestEntry::cast_to_inner(new_entry));
270+
ZRBTestEntry* new_entry = new (&arena) ZRBTestEntry(ZRBTestEntry::cast_to_outer(&node)->id() + 1);
271+
it.replace(ZRBTestEntry::cast_to_inner(new_entry));
272272
} break;
273273
case 3: break;
274274
default:
@@ -279,39 +279,39 @@ TEST_F(ZTreeTest, test_replace) {
279279

280280
int last_id = std::numeric_limits<int>::min();
281281
for (auto& node : tree) {
282-
int id = ZTestEntry::cast_to_outer(&node)->id();
282+
int id = ZRBTestEntry::cast_to_outer(&node)->id();
283283
ASSERT_LT(last_id, id);
284284
last_id = id;
285285
}
286286
tree.verify_tree();
287287

288288
last_id = std::numeric_limits<int>::min();
289289
for (auto it = tree.begin(), end = tree.end(); it != end; ++it) {
290-
int id = ZTestEntry::cast_to_outer(&*it)->id();
290+
int id = ZRBTestEntry::cast_to_outer(&*it)->id();
291291
ASSERT_LT(last_id, id);
292292
last_id = id;
293293
}
294294
tree.verify_tree();
295295

296296
last_id = std::numeric_limits<int>::min();
297297
for (auto it = tree.cbegin(), end = tree.cend(); it != end; ++it) {
298-
int id = ZTestEntry::cast_to_outer(&*it)->id();
298+
int id = ZRBTestEntry::cast_to_outer(&*it)->id();
299299
ASSERT_LT(last_id, id);
300300
last_id = id;
301301
}
302302
tree.verify_tree();
303303

304304
last_id = std::numeric_limits<int>::max();
305305
for (auto it = tree.rbegin(), end = tree.rend(); it != end; ++it) {
306-
int id = ZTestEntry::cast_to_outer(&*it)->id();
306+
int id = ZRBTestEntry::cast_to_outer(&*it)->id();
307307
ASSERT_GT(last_id, id);
308308
last_id = id;
309309
}
310310
tree.verify_tree();
311311

312312
last_id = std::numeric_limits<int>::max();
313313
for (auto it = tree.crbegin(), end = tree.crend(); it != end; ++it) {
314-
int id = ZTestEntry::cast_to_outer(&*it)->id();
314+
int id = ZRBTestEntry::cast_to_outer(&*it)->id();
315315
ASSERT_GT(last_id, id);
316316
last_id = id;
317317
}
@@ -321,19 +321,19 @@ TEST_F(ZTreeTest, test_replace) {
321321
TEST_F(ZTreeTest, test_remove) {
322322
Arena arena(MemTag::mtTest);
323323
constexpr int num_entries = 1024;
324-
ZTestEntry::ZTree tree;
324+
ZRBTestEntry::ZTree tree;
325325
int id = 0;
326-
tree.insert(ZTestEntry::cast_to_inner(new (&arena) ZTestEntry(++id)), tree.root_cursor());
326+
tree.insert(ZRBTestEntry::cast_to_inner(new (&arena) ZRBTestEntry(++id)), tree.root_cursor());
327327
for (auto& node : tree) {
328-
if (ZTestEntry::cast_to_outer(&node)->id() == num_entries) {
328+
if (ZRBTestEntry::cast_to_outer(&node)->id() == num_entries) {
329329
break;
330330
}
331331
auto cursor = tree.next_cursor(&node);
332-
ZIntrusiveRBTreeNode* const new_node = ZTestEntry::cast_to_inner(new (&arena) ZTestEntry(++id));
332+
ZIntrusiveRBTreeNode* const new_node = ZRBTestEntry::cast_to_inner(new (&arena) ZRBTestEntry(++id));
333333
tree.insert(new_node, cursor);
334334
}
335335
tree.verify_tree();
336-
ASSERT_EQ(ZTestEntry::cast_to_outer(tree.last())->id(), num_entries);
336+
ASSERT_EQ(ZRBTestEntry::cast_to_outer(tree.last())->id(), num_entries);
337337

338338
int i = 0;
339339
int removed = 0;

0 commit comments

Comments
 (0)