Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/gtest/gc/g1/test_g1RegionMap.cpp
41152 views
1
/*
2
* Copyright (c) 2020, 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/g1/g1CommittedRegionMap.inline.hpp"
27
#include "runtime/os.hpp"
28
#include "unittest.hpp"
29
30
class G1CommittedRegionMapSerial : public G1CommittedRegionMap {
31
public:
32
static const uint TestRegions = 512;
33
34
void verify_counts() {
35
verify_active_count(0, TestRegions, num_active());
36
verify_inactive_count(0, TestRegions, num_inactive());
37
}
38
39
protected:
40
void guarantee_mt_safety_active() const { }
41
void guarantee_mt_safety_inactive() const { }
42
};
43
44
static bool mutate() {
45
return os::random() % 2 == 0;
46
}
47
48
static void generate_random_map(G1CommittedRegionMap* map) {
49
for (uint i = 0; i < G1CommittedRegionMapSerial::TestRegions; i++) {
50
if (mutate()) {
51
map->activate(i, i+1);
52
}
53
}
54
55
if (map->num_active() == 0) {
56
// If we randomly activated 0 regions, activate the first half
57
// to have some regions to test.
58
map->activate(0, G1CommittedRegionMapSerial::TestRegions / 2);
59
}
60
}
61
62
static void random_deactivate(G1CommittedRegionMap* map) {
63
uint current_offset = 0;
64
do {
65
HeapRegionRange current = map->next_active_range(current_offset);
66
if (mutate()) {
67
if (current.length() < 5) {
68
// For short ranges, deactivate whole.
69
map->deactivate(current.start(), current.end());
70
} else {
71
// For larger ranges, deactivate half.
72
map->deactivate(current.start(), current.end() - (current.length() / 2));
73
}
74
}
75
current_offset = current.end();
76
} while (current_offset != G1CommittedRegionMapSerial::TestRegions);
77
}
78
79
static void random_uncommit_or_reactive(G1CommittedRegionMap* map) {
80
uint current_offset = 0;
81
do {
82
HeapRegionRange current = map->next_inactive_range(current_offset);
83
// Randomly either reactivate or uncommit
84
if (mutate()) {
85
map->reactivate(current.start(), current.end());
86
} else {
87
map->uncommit(current.start(), current.end());
88
}
89
90
current_offset = current.end();
91
} while (current_offset != G1CommittedRegionMapSerial::TestRegions);
92
}
93
94
static void random_activate_free(G1CommittedRegionMap* map) {
95
uint current_offset = 0;
96
do {
97
HeapRegionRange current = map->next_committable_range(current_offset);
98
// Randomly either reactivate or uncommit
99
if (mutate()) {
100
if (current.length() < 5) {
101
// For short ranges, deactivate whole.
102
map->activate(current.start(), current.end());
103
} else {
104
// For larger ranges, deactivate half.
105
map->activate(current.start(), current.end() - (current.length() / 2));
106
}
107
}
108
109
current_offset = current.end();
110
} while (current_offset != G1CommittedRegionMapSerial::TestRegions);
111
}
112
113
TEST(G1CommittedRegionMapTest, serial) {
114
G1CommittedRegionMapSerial serial_map;
115
serial_map.initialize(G1CommittedRegionMapSerial::TestRegions);
116
117
// Activate some regions
118
generate_random_map(&serial_map);
119
120
// Work through the map and mutate it
121
for (int i = 0; i < 500; i++) {
122
random_deactivate(&serial_map);
123
serial_map.verify_counts();
124
random_uncommit_or_reactive(&serial_map);
125
serial_map.verify_counts();
126
random_activate_free(&serial_map);
127
serial_map.verify_counts();
128
ASSERT_EQ(serial_map.num_inactive(), 0u);
129
}
130
}
131