author | kvn |
Fri, 07 Jun 2019 13:57:08 -0700 | |
changeset 55295 | 14283f280695 |
parent 51792 | d0dfb9775c08 |
permissions | -rw-r--r-- |
33160 | 1 |
/* |
40631
ed82623d7831
8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents:
40059
diff
changeset
|
2 |
* Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved. |
33160 | 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 |
*/ |
|
41705
332239c052cc
8165687: Fix license and copyright headers in jd9 under hotspot/test
stsmirno
parents:
40631
diff
changeset
|
23 |
|
33160 | 24 |
/** |
25 |
* @test |
|
26 |
* @bug 8136421 |
|
42607
acd91f1875d4
8170227: use vm.jvmci property in compiler/jvmci tests
iignatyev
parents:
41705
diff
changeset
|
27 |
* @requires vm.jvmci |
40631
ed82623d7831
8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents:
40059
diff
changeset
|
28 |
* @library /test/lib / |
36508 | 29 |
* @library ../common/patches |
38152
80e5da81fb2c
8154258: [TESTBUG] Various serviceability tests fail compilation
dsamersoff
parents:
36508
diff
changeset
|
30 |
* @modules java.base/jdk.internal.misc |
36508 | 31 |
* @modules java.base/jdk.internal.org.objectweb.asm |
32 |
* java.base/jdk.internal.org.objectweb.asm.tree |
|
43972 | 33 |
* jdk.internal.vm.ci/jdk.vm.ci.hotspot |
34 |
* jdk.internal.vm.ci/jdk.vm.ci.code |
|
40053
b3617982544e
8160657: Compiler HotSpot tests should use the "run driver" directive where applicable
iignatyev
parents:
39291
diff
changeset
|
35 |
* |
51792
d0dfb9775c08
8210793: [JVMCI] AllocateCompileIdTest.java failed to find DiagnosticCommand.class
dnsimon
parents:
51420
diff
changeset
|
36 |
* @build jdk.internal.vm.ci/jdk.vm.ci.hotspot.CompilerToVMHelper |
d0dfb9775c08
8210793: [JVMCI] AllocateCompileIdTest.java failed to find DiagnosticCommand.class
dnsimon
parents:
51420
diff
changeset
|
37 |
* sun.hotspot.WhiteBox sun.hotspot.parser.DiagnosticCommand |
40053
b3617982544e
8160657: Compiler HotSpot tests should use the "run driver" directive where applicable
iignatyev
parents:
39291
diff
changeset
|
38 |
* @run driver ClassFileInstaller sun.hotspot.WhiteBox |
51420
6bb7b8d0da76
8209535: [JVMCI] Do not swallow NoClassDefFoundError when converting JVMCI methods and fields to reflection objects
dnsimon
parents:
47216
diff
changeset
|
39 |
* sun.hotspot.parser.DiagnosticCommand |
40053
b3617982544e
8160657: Compiler HotSpot tests should use the "run driver" directive where applicable
iignatyev
parents:
39291
diff
changeset
|
40 |
* sun.hotspot.WhiteBox$WhiteBoxPermission |
36508 | 41 |
* @run main/othervm -Xbootclasspath/a:. |
42 |
* -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI |
|
43 |
* -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI |
|
44 |
* -XX:-BackgroundCompilation |
|
45 |
* compiler.jvmci.compilerToVM.AllocateCompileIdTest |
|
33160 | 46 |
*/ |
47 |
||
48 |
package compiler.jvmci.compilerToVM; |
|
49 |
||
50 |
import compiler.jvmci.common.CTVMUtilities; |
|
40059 | 51 |
import jdk.test.lib.Asserts; |
40631
ed82623d7831
8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents:
40059
diff
changeset
|
52 |
import jdk.test.lib.util.Pair; |
40059 | 53 |
import jdk.test.lib.Utils; |
54 |
import jdk.vm.ci.hotspot.CompilerToVMHelper; |
|
55 |
import jdk.vm.ci.hotspot.HotSpotResolvedJavaMethod; |
|
56 |
import sun.hotspot.code.NMethod; |
|
33160 | 57 |
|
58 |
import java.lang.reflect.Executable; |
|
59 |
import java.lang.reflect.Method; |
|
60 |
import java.util.ArrayList; |
|
40059 | 61 |
import java.util.HashSet; |
33160 | 62 |
import java.util.List; |
34171
84f04836ec54
8138810: rework tests for CompilerToVM::allocateCompiledId
tpivovarova
parents:
33632
diff
changeset
|
63 |
import java.util.stream.Collectors; |
84f04836ec54
8138810: rework tests for CompilerToVM::allocateCompiledId
tpivovarova
parents:
33632
diff
changeset
|
64 |
import java.util.stream.Stream; |
33160 | 65 |
|
66 |
public class AllocateCompileIdTest { |
|
67 |
||
34171
84f04836ec54
8138810: rework tests for CompilerToVM::allocateCompiledId
tpivovarova
parents:
33632
diff
changeset
|
68 |
private static final int SOME_REPEAT_VALUE = 5; |
33160 | 69 |
private final HashSet<Integer> ids = new HashSet<>(); |
70 |
||
71 |
public static void main(String[] args) { |
|
72 |
AllocateCompileIdTest test = new AllocateCompileIdTest(); |
|
73 |
createTestCasesCorrectBci().forEach(test::runSanityCorrectTest); |
|
74 |
createTestCasesIncorrectBci().forEach(test::runSanityIncorrectTest); |
|
75 |
} |
|
76 |
||
77 |
private static List<CompileCodeTestCase> createTestCasesCorrectBci() { |
|
78 |
List<CompileCodeTestCase> result = new ArrayList<>(); |
|
79 |
try { |
|
80 |
Class<?> aClass = DummyClass.class; |
|
81 |
Method method = aClass.getMethod("withLoop"); |
|
33632 | 82 |
Object receiver = new DummyClass(); |
83 |
result.add(new CompileCodeTestCase(receiver, method, 17)); |
|
84 |
result.add(new CompileCodeTestCase(receiver, method, -1)); |
|
33160 | 85 |
} catch (NoSuchMethodException e) { |
86 |
throw new Error("TEST BUG : " + e, e); |
|
87 |
} |
|
88 |
return result; |
|
89 |
} |
|
90 |
||
91 |
private static List<Pair<CompileCodeTestCase, Class<? extends Throwable>>> |
|
92 |
createTestCasesIncorrectBci() { |
|
93 |
List<Pair<CompileCodeTestCase, Class<? extends Throwable>>> result |
|
94 |
= new ArrayList<>(); |
|
95 |
try { |
|
96 |
Class<?> aClass = DummyClass.class; |
|
33632 | 97 |
Object receiver = new DummyClass(); |
33160 | 98 |
Method method = aClass.getMethod("dummyInstanceFunction"); |
99 |
// greater than bytecode.length |
|
34171
84f04836ec54
8138810: rework tests for CompilerToVM::allocateCompiledId
tpivovarova
parents:
33632
diff
changeset
|
100 |
byte[] bytecode = CompilerToVMHelper.getBytecode(CTVMUtilities |
84f04836ec54
8138810: rework tests for CompilerToVM::allocateCompiledId
tpivovarova
parents:
33632
diff
changeset
|
101 |
.getResolvedMethod(method)); |
84f04836ec54
8138810: rework tests for CompilerToVM::allocateCompiledId
tpivovarova
parents:
33632
diff
changeset
|
102 |
Stream.of( |
84f04836ec54
8138810: rework tests for CompilerToVM::allocateCompiledId
tpivovarova
parents:
33632
diff
changeset
|
103 |
// greater than bytecode.length |
84f04836ec54
8138810: rework tests for CompilerToVM::allocateCompiledId
tpivovarova
parents:
33632
diff
changeset
|
104 |
bytecode.length + 4, |
84f04836ec54
8138810: rework tests for CompilerToVM::allocateCompiledId
tpivovarova
parents:
33632
diff
changeset
|
105 |
bytecode.length + 50, |
84f04836ec54
8138810: rework tests for CompilerToVM::allocateCompiledId
tpivovarova
parents:
33632
diff
changeset
|
106 |
bytecode.length + 200, |
84f04836ec54
8138810: rework tests for CompilerToVM::allocateCompiledId
tpivovarova
parents:
33632
diff
changeset
|
107 |
// negative cases |
84f04836ec54
8138810: rework tests for CompilerToVM::allocateCompiledId
tpivovarova
parents:
33632
diff
changeset
|
108 |
-4, -50, -200) |
84f04836ec54
8138810: rework tests for CompilerToVM::allocateCompiledId
tpivovarova
parents:
33632
diff
changeset
|
109 |
.map(bci -> new Pair<CompileCodeTestCase, |
84f04836ec54
8138810: rework tests for CompilerToVM::allocateCompiledId
tpivovarova
parents:
33632
diff
changeset
|
110 |
Class<? extends Throwable>>( |
84f04836ec54
8138810: rework tests for CompilerToVM::allocateCompiledId
tpivovarova
parents:
33632
diff
changeset
|
111 |
new CompileCodeTestCase(receiver, method, bci), |
84f04836ec54
8138810: rework tests for CompilerToVM::allocateCompiledId
tpivovarova
parents:
33632
diff
changeset
|
112 |
IllegalArgumentException.class)) |
84f04836ec54
8138810: rework tests for CompilerToVM::allocateCompiledId
tpivovarova
parents:
33632
diff
changeset
|
113 |
.collect(Collectors.toList()); |
33160 | 114 |
} catch (NoSuchMethodException e) { |
115 |
throw new Error("TEST BUG : " + e.getMessage(), e); |
|
116 |
} |
|
117 |
return result; |
|
118 |
} |
|
119 |
||
120 |
private void runSanityCorrectTest(CompileCodeTestCase testCase) { |
|
121 |
System.out.println(testCase); |
|
122 |
Executable aMethod = testCase.executable; |
|
33632 | 123 |
// to generate ciTypeFlow |
34171
84f04836ec54
8138810: rework tests for CompilerToVM::allocateCompiledId
tpivovarova
parents:
33632
diff
changeset
|
124 |
testCase.invoke(Utils.getNullValues(aMethod.getParameterTypes())); |
33160 | 125 |
int bci = testCase.bci; |
33632 | 126 |
HotSpotResolvedJavaMethod method = CTVMUtilities |
33160 | 127 |
.getResolvedMethod(aMethod); |
34171
84f04836ec54
8138810: rework tests for CompilerToVM::allocateCompiledId
tpivovarova
parents:
33632
diff
changeset
|
128 |
for (int i = 0; i < SOME_REPEAT_VALUE; ++i) { |
84f04836ec54
8138810: rework tests for CompilerToVM::allocateCompiledId
tpivovarova
parents:
33632
diff
changeset
|
129 |
int wbCompileID = getWBCompileID(testCase); |
84f04836ec54
8138810: rework tests for CompilerToVM::allocateCompiledId
tpivovarova
parents:
33632
diff
changeset
|
130 |
int id = CompilerToVMHelper.allocateCompileId(method, bci); |
84f04836ec54
8138810: rework tests for CompilerToVM::allocateCompiledId
tpivovarova
parents:
33632
diff
changeset
|
131 |
Asserts.assertNE(id, 0, testCase + " : zero compile id"); |
33160 | 132 |
Asserts.assertGT(id, wbCompileID, testCase |
133 |
+ " : allocated 'compile id' not greater than existed"); |
|
34171
84f04836ec54
8138810: rework tests for CompilerToVM::allocateCompiledId
tpivovarova
parents:
33632
diff
changeset
|
134 |
Asserts.assertTrue(ids.add(wbCompileID), testCase |
84f04836ec54
8138810: rework tests for CompilerToVM::allocateCompiledId
tpivovarova
parents:
33632
diff
changeset
|
135 |
+ " : vm compilation allocated existing id " + id); |
84f04836ec54
8138810: rework tests for CompilerToVM::allocateCompiledId
tpivovarova
parents:
33632
diff
changeset
|
136 |
Asserts.assertTrue(ids.add(id), testCase |
84f04836ec54
8138810: rework tests for CompilerToVM::allocateCompiledId
tpivovarova
parents:
33632
diff
changeset
|
137 |
+ " : allocateCompileId returned existing id " + id); |
33160 | 138 |
} |
139 |
} |
|
140 |
||
141 |
private void runSanityIncorrectTest( |
|
142 |
Pair<CompileCodeTestCase, Class<? extends Throwable>> testCase) { |
|
143 |
System.out.println(testCase); |
|
144 |
Class<? extends Throwable> exception = testCase.second; |
|
145 |
Executable aMethod = testCase.first.executable; |
|
146 |
int bci = testCase.first.bci; |
|
33632 | 147 |
HotSpotResolvedJavaMethod method = CTVMUtilities |
33160 | 148 |
.getResolvedMethod(aMethod); |
149 |
Utils.runAndCheckException( |
|
150 |
() -> CompilerToVMHelper.allocateCompileId(method, bci), |
|
151 |
exception); |
|
152 |
} |
|
153 |
||
154 |
private int getWBCompileID(CompileCodeTestCase testCase) { |
|
155 |
NMethod nm = testCase.deoptimizeAndCompile(); |
|
34171
84f04836ec54
8138810: rework tests for CompilerToVM::allocateCompiledId
tpivovarova
parents:
33632
diff
changeset
|
156 |
if (nm == null || nm.compile_id <= 0) { |
84f04836ec54
8138810: rework tests for CompilerToVM::allocateCompiledId
tpivovarova
parents:
33632
diff
changeset
|
157 |
throw new Error("TEST BUG : cannot compile method " + testCase); |
33160 | 158 |
} |
159 |
return nm.compile_id; |
|
160 |
} |
|
161 |
} |