Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/compiler/codecache/jmx/InitialAndMaxUsageTest.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 InitialAndMaxUsageTest
26
* @summary testing of initial and max usage
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:-UseCodeCacheFlushing
34
* -XX:-MethodFlushing -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI
35
* -XX:CompileCommand=compileonly,null::* -XX:-UseLargePages
36
* -XX:+SegmentedCodeCache
37
* compiler.codecache.jmx.InitialAndMaxUsageTest
38
* @run main/othervm -Xbootclasspath/a:. -XX:-UseCodeCacheFlushing
39
* -XX:-MethodFlushing -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI
40
* -XX:CompileCommand=compileonly,null::* -XX:-UseLargePages
41
* -XX:-SegmentedCodeCache
42
* compiler.codecache.jmx.InitialAndMaxUsageTest
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.ArrayList;
52
import java.util.List;
53
54
public class InitialAndMaxUsageTest {
55
56
private static final double CACHE_USAGE_COEF = 0.95d;
57
private final BlobType btype;
58
private final boolean lowerBoundIsZero;
59
private final long maxSize;
60
61
public InitialAndMaxUsageTest(BlobType btype) {
62
this.btype = btype;
63
this.maxSize = btype.getSize();
64
/* Only profiled code cache initial size should be 0, because of
65
-XX:CompileCommand=compileonly,null::* non-methods might be not empty,
66
as well as non-profiled methods, because it's used as fallback in
67
case non-methods is full */
68
lowerBoundIsZero = btype == BlobType.MethodProfiled;
69
}
70
71
public static void main(String[] args) {
72
for (BlobType btype : BlobType.getAvailable()) {
73
new InitialAndMaxUsageTest(btype).runTest();
74
}
75
}
76
77
private boolean canAllocate(double size, long maxSize, MemoryPoolMXBean bean) {
78
// Don't fill too much to have space for adapters. So, stop after crossing 95% and
79
// don't allocate in case we'll cross 97% on next allocation.
80
double used = bean.getUsage().getUsed();
81
return (used <= CACHE_USAGE_COEF * maxSize) &&
82
(used + size <= (CACHE_USAGE_COEF + 0.02d) * maxSize);
83
}
84
85
protected void runTest() {
86
long headerSize = CodeCacheUtils.getHeaderSize(btype);
87
MemoryPoolMXBean bean = btype.getMemoryPool();
88
long initialUsage = btype.getMemoryPool().getUsage().getUsed();
89
System.out.printf("INFO: trying to test %s of max size %d and initial"
90
+ " usage %d%n", bean.getName(), maxSize, initialUsage);
91
Asserts.assertLT(initialUsage + headerSize + 1L, maxSize,
92
"Initial usage is close to total size for " + bean.getName());
93
if (lowerBoundIsZero) {
94
Asserts.assertEQ(initialUsage, 0L, "Unexpected initial usage");
95
}
96
ArrayList<Long> blobs = new ArrayList<>();
97
long minAllocationUnit = Math.max(1, CodeCacheUtils.MIN_ALLOCATION - headerSize);
98
/* now filling code cache with large-sized allocation first, since
99
lots of small allocations takes too much time, so, just a small
100
optimization */
101
try {
102
for (long size = 100_000 * minAllocationUnit; size > 0; size /= 10) {
103
long blob = 0;
104
while (canAllocate(size, maxSize, bean) &&
105
(blob = CodeCacheUtils.WB.allocateCodeBlob(size, btype.id)) != 0) {
106
blobs.add(blob);
107
}
108
}
109
Asserts.assertGT((double) bean.getUsage().getUsed(),
110
CACHE_USAGE_COEF * maxSize, String.format("Unable to fill "
111
+ "more than %f of %s. Reported usage is %d ",
112
CACHE_USAGE_COEF, bean.getName(),
113
bean.getUsage().getUsed()));
114
} finally {
115
for (long entry : blobs) {
116
CodeCacheUtils.WB.freeCodeBlob(entry);
117
}
118
}
119
System.out.printf("INFO: Scenario finished successfully for %s%n",
120
bean.getName());
121
}
122
123
}
124
125