Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/jdk17u
Path: blob/master/test/hotspot/jtreg/runtime/Metaspace/elastic/MetaspaceTestWithThreads.java
64507 views
1
/*
2
* Copyright (c) 2021 SAP SE. All rights reserved.
3
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
4
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5
*
6
* This code is free software; you can redistribute it and/or modify it
7
* under the terms of the GNU General Public License version 2 only, as
8
* published by the Free Software Foundation.
9
*
10
* This code is distributed in the hope that it will be useful, but WITHOUT
11
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13
* version 2 for more details (a copy is included in the LICENSE file that
14
* accompanied this code).
15
*
16
* You should have received a copy of the GNU General Public License version
17
* 2 along with this work; if not, write to the Free Software Foundation,
18
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19
*
20
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21
* or visit www.oracle.com if you need additional information or have any
22
* questions.
23
*
24
*/
25
26
public class MetaspaceTestWithThreads {
27
28
// The context to use.
29
final MetaspaceTestContext context;
30
31
// Total *word* size we allow for the test to allocation. The test may overshoot this a bit, but should not by much.
32
final long testAllocationCeiling;
33
34
// Number of parallel allocators
35
final int numThreads;
36
37
// Number of seconds for each test
38
final int seconds;
39
40
RandomAllocatorThread threads[];
41
42
public MetaspaceTestWithThreads(MetaspaceTestContext context, long testAllocationCeiling, int numThreads, int seconds) {
43
this.context = context;
44
this.testAllocationCeiling = testAllocationCeiling;
45
this.numThreads = numThreads;
46
this.seconds = seconds;
47
this.threads = new RandomAllocatorThread[numThreads];
48
}
49
50
protected void stopAllThreads() throws InterruptedException {
51
// Stop all threads.
52
for (Thread t: threads) {
53
t.interrupt();
54
}
55
for (Thread t: threads) {
56
t.join();
57
}
58
}
59
60
void destroyArenasAndPurgeSpace() {
61
62
for (RandomAllocatorThread t: threads) {
63
if (t.allocator.arena.isLive()) {
64
context.destroyArena(t.allocator.arena);
65
}
66
}
67
68
context.checkStatistics();
69
70
// After deleting all arenas, we should have no committed space left: all arena chunks have been returned to
71
// the freelist amd should have been maximally merged to a bunch of root chunks, which should be uncommitted
72
// in one go.
73
// Exception: if reclamation policy is none.
74
if (Settings.settings().doesReclaim()) {
75
if (context.committedWords() > 0) {
76
throw new RuntimeException("Expected no committed words after purging empty metaspace context (was: " + context.committedWords() + ")");
77
}
78
}
79
80
context.purge();
81
82
context.checkStatistics();
83
84
// After purging - if all arenas had been deleted before - we should have no committed space left even in
85
// recmalation=none mode:
86
// purging deletes all nodes with only free chunks, and in this case no node should still house in-use chunks,
87
// so all nodes would have been unmapped.
88
// This is independent on reclamation policy. Only one exception: if the area was created with a reserve limit
89
// (mimicking compressed class space), the underlying virtual space list cannot be purged.
90
if (context.reserveLimit == 0) {
91
if (context.committedWords() > 0) {
92
throw new RuntimeException("Expected no committed words after purging empty metaspace context (was: " + context.committedWords() + ")");
93
}
94
}
95
96
}
97
98
@Override
99
public String toString() {
100
return "commitLimit=" + context.commitLimit +
101
", reserveLimit=" + context.reserveLimit +
102
", testAllocationCeiling=" + testAllocationCeiling +
103
", num_allocators=" + numThreads +
104
", seconds=" + seconds;
105
}
106
107
}
108
109