Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/gtest/gc/g1/test_stressCommitUncommit.cpp
41149 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/g1BlockOffsetTable.hpp"
27
#include "gc/g1/g1RegionToSpaceMapper.hpp"
28
#include "memory/virtualspace.hpp"
29
#include "gc/shared/workgroup.hpp"
30
#include "runtime/atomic.hpp"
31
#include "runtime/os.hpp"
32
#include "unittest.hpp"
33
34
class G1MapperWorkers : AllStatic {
35
static WorkGang* _work_gang;
36
static WorkGang* work_gang() {
37
if (_work_gang == NULL) {
38
_work_gang = new WorkGang("G1 Small Workers", MaxWorkers, false, false);
39
_work_gang->initialize_workers();
40
_work_gang->update_active_workers(MaxWorkers);
41
}
42
return _work_gang;
43
}
44
45
public:
46
static const uint MaxWorkers = 4;
47
static void run_task(AbstractGangTask* task) {
48
work_gang()->run_task(task);
49
}
50
};
51
WorkGang* G1MapperWorkers::_work_gang = NULL;
52
53
class G1TestCommitUncommit : public AbstractGangTask {
54
G1RegionToSpaceMapper* _mapper;
55
uint _claim_id;
56
public:
57
G1TestCommitUncommit(G1RegionToSpaceMapper* mapper) :
58
AbstractGangTask("Stress mapper"),
59
_mapper(mapper),
60
_claim_id(0) { }
61
62
void work(uint worker_id) {
63
uint index = Atomic::fetch_and_add(&_claim_id, 1u);
64
65
for (int i = 0; i < 100000; i++) {
66
// Stress commit and uncommit of a single region. The same
67
// will be done for multiple adjacent region to make sure
68
// we properly handle bitmap updates as well as updates for
69
// regions sharing the same underlying OS page.
70
_mapper->commit_regions(index);
71
_mapper->uncommit_regions(index);
72
}
73
}
74
};
75
76
TEST_VM(G1RegionToSpaceMapper, smallStressAdjacent) {
77
// Fake a heap with 1m regions and create a BOT like mapper. This
78
// will give a G1RegionsSmallerThanCommitSizeMapper to stress.
79
uint num_regions = G1MapperWorkers::MaxWorkers;
80
size_t region_size = 1*M;
81
size_t size = G1BlockOffsetTable::compute_size(num_regions * region_size / HeapWordSize);
82
size_t page_size = os::vm_page_size();
83
84
ReservedSpace rs(size, os::vm_page_size());
85
86
G1RegionToSpaceMapper* small_mapper =
87
G1RegionToSpaceMapper::create_mapper(rs,
88
size,
89
page_size,
90
region_size,
91
G1BlockOffsetTable::heap_map_factor(),
92
mtGC);
93
94
95
96
G1TestCommitUncommit task(small_mapper);
97
G1MapperWorkers::run_task(&task);
98
}
99
100
TEST_VM(G1RegionToSpaceMapper, largeStressAdjacent) {
101
// Fake a heap with 2m regions and create a BOT like mapper. This
102
// will give a G1RegionsLargerThanCommitSizeMapper to stress.
103
uint num_regions = G1MapperWorkers::MaxWorkers;
104
size_t region_size = 2*M;
105
size_t size = G1BlockOffsetTable::compute_size(num_regions * region_size / HeapWordSize);
106
size_t page_size = os::vm_page_size();
107
108
ReservedSpace rs(size, page_size);
109
110
G1RegionToSpaceMapper* large_mapper =
111
G1RegionToSpaceMapper::create_mapper(rs,
112
size,
113
page_size,
114
region_size,
115
G1BlockOffsetTable::heap_map_factor(),
116
mtGC);
117
118
G1TestCommitUncommit task(large_mapper);
119
G1MapperWorkers::run_task(&task);
120
}
121