Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/compiler/codecache/jmx/GetUsageTest.java
41153 views
1
/*
2
* Copyright (c) 2014, 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
* @test GetUsageTest
26
* @summary testing of getUsage() for segmented code cache
27
* @modules java.base/jdk.internal.misc
28
* java.management
29
* @library /test/lib /
30
*
31
* @build sun.hotspot.WhiteBox
32
* @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox
33
* @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions
34
* -XX:+WhiteBoxAPI -XX:CompileCommand=compileonly,null::*
35
* -XX:-UseCodeCacheFlushing -XX:-MethodFlushing
36
* -XX:+SegmentedCodeCache
37
* compiler.codecache.jmx.GetUsageTest
38
* @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions
39
* -XX:+WhiteBoxAPI -XX:CompileCommand=compileonly,null::*
40
* -XX:-UseCodeCacheFlushing -XX:-MethodFlushing
41
* -XX:-SegmentedCodeCache
42
* compiler.codecache.jmx.GetUsageTest
43
*/
44
45
package compiler.codecache.jmx;
46
47
import jdk.test.lib.Asserts;
48
import sun.hotspot.code.BlobType;
49
50
import java.lang.management.MemoryPoolMXBean;
51
import java.util.HashMap;
52
import java.util.Map;
53
54
public class GetUsageTest {
55
56
private final BlobType btype;
57
private final int allocateSize;
58
59
public GetUsageTest(BlobType btype, int allocSize) {
60
this.btype = btype;
61
this.allocateSize = allocSize;
62
}
63
64
public static void main(String[] args) throws Exception {
65
for (BlobType btype : BlobType.getAvailable()) {
66
for (int allocSize = 10; allocSize < 100000; allocSize *= 10) {
67
new GetUsageTest(btype, allocSize).runTest();
68
}
69
}
70
}
71
72
protected final Map<MemoryPoolMXBean, Long> getBeanUsages() {
73
Map<MemoryPoolMXBean, Long> beanUsages = new HashMap<>();
74
for (BlobType bt : BlobType.getAvailable()) {
75
beanUsages.put(bt.getMemoryPool(),
76
bt.getMemoryPool().getUsage().getUsed());
77
}
78
return beanUsages;
79
}
80
81
protected void runTest() {
82
MemoryPoolMXBean[] predictableBeans = BlobType.getAvailable().stream()
83
.filter(CodeCacheUtils::isCodeHeapPredictable)
84
.map(BlobType::getMemoryPool)
85
.toArray(MemoryPoolMXBean[]::new);
86
Map<MemoryPoolMXBean, Long> initial = getBeanUsages();
87
long addr = 0;
88
try {
89
addr = CodeCacheUtils.WB.allocateCodeBlob(allocateSize, btype.id);
90
Map<MemoryPoolMXBean, Long> current = getBeanUsages();
91
long blockCount = Math.floorDiv(allocateSize
92
+ CodeCacheUtils.getHeaderSize(btype)
93
+ CodeCacheUtils.SEGMENT_SIZE - 1, CodeCacheUtils.SEGMENT_SIZE);
94
long usageUpperEstimate = Math.max(blockCount,
95
CodeCacheUtils.MIN_BLOCK_LENGTH) * CodeCacheUtils.SEGMENT_SIZE;
96
for (MemoryPoolMXBean entry : predictableBeans) {
97
long diff = current.get(entry) - initial.get(entry);
98
if (entry.equals(btype.getMemoryPool())) {
99
if (CodeCacheUtils.isCodeHeapPredictable(btype)) {
100
Asserts.assertFalse(diff <= 0L || diff > usageUpperEstimate,
101
String.format("Pool %s usage increase was reported "
102
+ "unexpectedly as increased by %d using "
103
+ "allocation size %d", entry.getName(),
104
diff, allocateSize));
105
}
106
} else {
107
CodeCacheUtils.assertEQorGTE(btype, diff, 0L,
108
String.format("Pool %s usage changed unexpectedly while"
109
+ " trying to increase: %s using allocation "
110
+ "size %d", entry.getName(),
111
btype.getMemoryPool().getName(), allocateSize));
112
}
113
}
114
} finally {
115
if (addr != 0) {
116
CodeCacheUtils.WB.freeCodeBlob(addr);
117
}
118
}
119
System.out.printf("INFO: Scenario finished successfully for %s%n",
120
btype.getMemoryPool().getName());
121
}
122
}
123
124