Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/jdk17u
Path: blob/master/test/hotspot/jtreg/compiler/codecache/OverflowCodeCacheTest.java
64474 views
1
/*
2
* Copyright (c) 2014, 2022, 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 OverflowCodeCacheTest
26
* @bug 8059550 8279356
27
* @summary testing of code cache segments overflow
28
* @library /test/lib
29
* @modules java.base/jdk.internal.misc
30
* java.management
31
*
32
* @build sun.hotspot.WhiteBox
33
* @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox
34
* @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions
35
* -XX:+WhiteBoxAPI -XX:CompileCommand=compileonly,null::*
36
* -XX:-SegmentedCodeCache -Xmixed
37
* compiler.codecache.OverflowCodeCacheTest CompilationDisabled
38
* @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions
39
* -XX:+WhiteBoxAPI -XX:CompileCommand=compileonly,null::*
40
* -XX:+SegmentedCodeCache -Xmixed
41
* compiler.codecache.OverflowCodeCacheTest CompilationDisabled
42
* @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions
43
* -XX:+WhiteBoxAPI -XX:-SegmentedCodeCache -Xmixed
44
* compiler.codecache.OverflowCodeCacheTest
45
*/
46
47
package compiler.codecache;
48
49
import jdk.test.lib.Asserts;
50
import sun.hotspot.WhiteBox;
51
import sun.hotspot.code.BlobType;
52
import sun.hotspot.code.CodeBlob;
53
54
import java.lang.management.MemoryPoolMXBean;
55
import java.lang.reflect.Method;
56
import java.util.ArrayList;
57
import java.util.EnumSet;
58
59
class Helper {
60
// Uncommon signature to prevent sharing and force creation of a new adapter
61
public void method(float a, float b, float c, Object o) { }
62
}
63
64
public class OverflowCodeCacheTest {
65
private static final WhiteBox WHITE_BOX = WhiteBox.getWhiteBox();
66
private static boolean COMPILATION_DISABLED = false;
67
68
public static void main(String[] args) {
69
COMPILATION_DISABLED = args.length > 0;
70
EnumSet<BlobType> blobTypes = BlobType.getAvailable();
71
for (BlobType type : blobTypes) {
72
new OverflowCodeCacheTest(type).test();
73
}
74
}
75
76
private final BlobType type;
77
private final MemoryPoolMXBean bean;
78
private OverflowCodeCacheTest(BlobType type) {
79
this.type = type;
80
this.bean = type.getMemoryPool();
81
}
82
83
private void test() {
84
System.out.printf("type %s%n", type);
85
System.out.println("allocating till possible...");
86
ArrayList<Long> blobs = new ArrayList<>();
87
int compilationActivityMode = -1;
88
// Lock compilation to be able to better control code cache space
89
WHITE_BOX.lockCompilation();
90
try {
91
long addr;
92
int size = (int) (getHeapSize() >> 7);
93
while ((addr = WHITE_BOX.allocateCodeBlob(size, type.id)) != 0) {
94
blobs.add(addr);
95
96
BlobType actualType = CodeBlob.getCodeBlob(addr).code_blob_type;
97
if (actualType != type) {
98
// check we got allowed overflow handling
99
Asserts.assertTrue(type.allowTypeWhenOverflow(actualType),
100
type + " doesn't allow using " + actualType + " when overflow");
101
}
102
}
103
/* now, remember compilationActivityMode to check it later, after freeing, since we
104
possibly have no free cache for further work */
105
compilationActivityMode = WHITE_BOX.getCompilationActivityMode();
106
107
// Use smallest allocation size to make sure all of the available space
108
// is filled up. Don't free these below to put some pressure on the sweeper.
109
while ((addr = WHITE_BOX.allocateCodeBlob(1, type.id)) != 0) { }
110
} finally {
111
try {
112
// Trigger creation of a new adapter for Helper::method
113
// which will fail because we are out of code cache space.
114
Helper helper = new Helper();
115
} catch (VirtualMachineError e) {
116
// Expected
117
}
118
// Free code cache space
119
for (Long blob : blobs) {
120
WHITE_BOX.freeCodeBlob(blob);
121
}
122
123
// Convert some nmethods to zombie and then free them to re-enable compilation
124
WHITE_BOX.unlockCompilation();
125
WHITE_BOX.forceNMethodSweep();
126
WHITE_BOX.forceNMethodSweep();
127
128
// Trigger compilation of Helper::method which will hit an assert because
129
// adapter creation failed above due to a lack of code cache space.
130
Helper helper = new Helper();
131
for (int i = 0; i < 100_000; i++) {
132
helper.method(0, 0, 0, null);
133
}
134
}
135
// Only check this if compilation is disabled, otherwise the sweeper might have
136
// freed enough nmethods to allow for re-enabling compilation.
137
if (COMPILATION_DISABLED) {
138
Asserts.assertNotEquals(compilationActivityMode, 1 /* run_compilation*/,
139
"Compilation must be disabled when CodeCache(CodeHeap) overflows");
140
}
141
}
142
143
private long getHeapSize() {
144
return bean.getUsage().getMax();
145
}
146
147
}
148
149