Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/compiler/codecache/jmx/PeakUsageTest.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 PeakUsageTest
26
* @library /test/lib /
27
* @modules java.base/jdk.internal.misc
28
* java.management
29
*
30
* @build sun.hotspot.WhiteBox
31
* @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox
32
* @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions
33
* -XX:+WhiteBoxAPI -XX:CompileCommand=compileonly,null::*
34
* -XX:+SegmentedCodeCache
35
* compiler.codecache.jmx.PeakUsageTest
36
* @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions
37
* -XX:+WhiteBoxAPI -XX:CompileCommand=compileonly,null::*
38
* -XX:-SegmentedCodeCache
39
* compiler.codecache.jmx.PeakUsageTest
40
* @summary testing of getPeakUsage() and resetPeakUsage for
41
* segmented code cache
42
*/
43
44
package compiler.codecache.jmx;
45
46
import sun.hotspot.code.BlobType;
47
48
import java.lang.management.MemoryPoolMXBean;
49
50
51
public class PeakUsageTest {
52
53
private final BlobType btype;
54
55
public PeakUsageTest(BlobType btype) {
56
this.btype = btype;
57
}
58
59
public static void main(String[] args) {
60
for (BlobType btype : BlobType.getAvailable()) {
61
new PeakUsageTest(btype).runTest();
62
}
63
}
64
65
protected void runTest() {
66
MemoryPoolMXBean bean = btype.getMemoryPool();
67
bean.resetPeakUsage();
68
long addr = CodeCacheUtils.WB.allocateCodeBlob(
69
CodeCacheUtils.ALLOCATION_SIZE, btype.id);
70
71
try {
72
/*
73
Always save peakUsage after saving currentUsage. Reversing the order
74
can lead to inconsistent results (currentUsage > peakUsage) because
75
of intermediate allocations.
76
*/
77
long currUsage = bean.getUsage().getUsed();
78
long peakUsage = bean.getPeakUsage().getUsed();
79
CodeCacheUtils.assertEQorLTE(btype, currUsage,
80
peakUsage,
81
"Peak usage does not match usage after allocation for "
82
+ bean.getName());
83
} finally {
84
if (addr != 0) {
85
CodeCacheUtils.WB.freeCodeBlob(addr);
86
}
87
}
88
bean.resetPeakUsage();
89
long currUsage = bean.getUsage().getUsed();
90
long peakUsage = bean.getPeakUsage().getUsed();
91
CodeCacheUtils.assertEQorLTE(btype, currUsage,
92
peakUsage,
93
"Code cache peak usage is not equal to usage after reset for "
94
+ bean.getName());
95
long addr2 = CodeCacheUtils.WB.allocateCodeBlob(
96
CodeCacheUtils.ALLOCATION_SIZE, btype.id);
97
try {
98
currUsage = bean.getUsage().getUsed();
99
peakUsage = bean.getPeakUsage().getUsed();
100
101
CodeCacheUtils.assertEQorLTE(btype, currUsage,
102
peakUsage,
103
"Code cache peak usage is not equal to usage after fresh "
104
+ "allocation for " + bean.getName());
105
} finally {
106
if (addr2 != 0) {
107
CodeCacheUtils.WB.freeCodeBlob(addr2);
108
}
109
}
110
System.out.printf("INFO: Scenario finished successfully for %s%n",
111
bean.getName());
112
}
113
}
114
115