Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/gtest/gc/shared/test_oopStorageSet.cpp
41149 views
1
/*
2
* Copyright (c) 2019, 2021, 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
25
#include "precompiled.hpp"
26
#include "gc/shared/oopStorage.hpp"
27
#include "gc/shared/oopStorageSet.hpp"
28
#include "memory/allocation.inline.hpp"
29
#include "utilities/debug.hpp"
30
#include "utilities/enumIterator.hpp"
31
#include "utilities/globalDefinitions.hpp"
32
#include "utilities/macros.hpp"
33
#include "unittest.hpp"
34
35
class OopStorageSetTest : public ::testing::Test {
36
protected:
37
// Returns index of s in storages, or size if not found.
38
template <uint count>
39
static size_t find_storage(OopStorage* s, OopStorage* storages[count]) {
40
for (uint i = 0; i < count; ++i) {
41
if (s == storages[i]) {
42
return i;
43
}
44
}
45
return count;
46
}
47
48
template <uint count, typename Range>
49
static void check_iteration(Range range, OopStorage* storages[count]) {
50
ASSERT_EQ(range.size(), count);
51
for (auto id : range) {
52
OopStorage* storage = OopStorageSet::storage(id);
53
size_t index = find_storage<count>(storage, storages);
54
ASSERT_LT(index, count);
55
storages[index] = nullptr;
56
}
57
for (uint i = 0; i < count; ++i) {
58
ASSERT_EQ(nullptr /* null_storage */, storages[i]);
59
}
60
}
61
62
template<uint count, typename Range>
63
static void test_iteration(Range range, void (*fill)(OopStorage*[count])) {
64
OopStorage* storages[count];
65
fill(storages);
66
check_iteration<count>(range, storages);
67
}
68
69
static void test_strong_iteration() {
70
test_iteration<OopStorageSet::strong_count>(
71
EnumRange<OopStorageSet::StrongId>(),
72
&OopStorageSet::fill_strong);
73
74
}
75
static void test_weak_iteration() {
76
test_iteration<OopStorageSet::weak_count>(
77
EnumRange<OopStorageSet::WeakId>(),
78
&OopStorageSet::fill_weak);
79
80
}
81
static void test_all_iteration() {
82
test_iteration<OopStorageSet::all_count>(
83
EnumRange<OopStorageSet::Id>(),
84
&OopStorageSet::fill_all);
85
}
86
};
87
88
TEST_VM_F(OopStorageSetTest, strong_iteration) {
89
test_strong_iteration();
90
}
91
92
TEST_VM_F(OopStorageSetTest, weak_iteration) {
93
test_weak_iteration();
94
}
95
96
TEST_VM_F(OopStorageSetTest, all_iteration) {
97
test_all_iteration();
98
}
99
100