author | kvn |
Wed, 01 May 2019 12:31:29 -0700 | |
changeset 54669 | ad45b3802d4e |
parent 52427 | 3c6aa484536c |
child 55206 | 2fe2063fe567 |
permissions | -rw-r--r-- |
36306
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
1 |
/* |
52427
3c6aa484536c
8211122: Reduce the number of internal classes made accessible to jdk.unsupported
mchung
parents:
47216
diff
changeset
|
2 |
* Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved. |
36306
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
4 |
* |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
8 |
* |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
13 |
* accompanied this code). |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
14 |
* |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
18 |
* |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
21 |
* questions. |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
22 |
*/ |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
23 |
|
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
24 |
/* |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
25 |
* @test |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
26 |
* @bug 8138708 |
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 |
52427
3c6aa484536c
8211122: Reduce the number of internal classes made accessible to jdk.unsupported
mchung
parents:
47216
diff
changeset
|
30 |
* @modules java.base/jdk.internal.access |
37301
a936b4e01afb
8137058: Clear out all non-Critical APIs from sun.reflect
chegar
parents:
36508
diff
changeset
|
31 |
* java.base/jdk.internal.reflect |
36508 | 32 |
* java.base/jdk.internal.org.objectweb.asm |
33 |
* java.base/jdk.internal.org.objectweb.asm.tree |
|
43972 | 34 |
* jdk.internal.vm.ci/jdk.vm.ci.hotspot |
35 |
* jdk.internal.vm.ci/jdk.vm.ci.runtime |
|
36 |
* jdk.internal.vm.ci/jdk.vm.ci.meta |
|
40053
b3617982544e
8160657: Compiler HotSpot tests should use the "run driver" directive where applicable
iignatyev
parents:
39450
diff
changeset
|
37 |
* |
43972 | 38 |
* @build jdk.internal.vm.ci/jdk.vm.ci.hotspot.CompilerToVMHelper |
36306
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
39 |
* @build sun.hotspot.WhiteBox |
40053
b3617982544e
8160657: Compiler HotSpot tests should use the "run driver" directive where applicable
iignatyev
parents:
39450
diff
changeset
|
40 |
* @run driver ClassFileInstaller sun.hotspot.WhiteBox |
b3617982544e
8160657: Compiler HotSpot tests should use the "run driver" directive where applicable
iignatyev
parents:
39450
diff
changeset
|
41 |
* sun.hotspot.WhiteBox$WhiteBoxPermission |
36306
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
42 |
* @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
43 |
* -XX:+WhiteBoxAPI -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI |
44836 | 44 |
* -Djvmci.Compiler=null |
36306
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
45 |
* compiler.jvmci.compilerToVM.LookupSignatureInPoolTest |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
46 |
*/ |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
47 |
|
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
48 |
package compiler.jvmci.compilerToVM; |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
49 |
|
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
50 |
import compiler.jvmci.compilerToVM.ConstantPoolTestCase.ConstantTypes; |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
51 |
import compiler.jvmci.compilerToVM.ConstantPoolTestCase.TestedCPEntry; |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
52 |
import compiler.jvmci.compilerToVM.ConstantPoolTestCase.Validator; |
40059 | 53 |
import compiler.jvmci.compilerToVM.ConstantPoolTestsHelper.DummyClasses; |
36306
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
54 |
import jdk.test.lib.Asserts; |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
55 |
import jdk.vm.ci.hotspot.CompilerToVMHelper; |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
56 |
import jdk.vm.ci.meta.ConstantPool; |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
57 |
|
40059 | 58 |
import java.util.HashMap; |
59 |
import java.util.Map; |
|
60 |
||
61 |
import static compiler.jvmci.compilerToVM.ConstantPoolTestCase.ConstantTypes.CONSTANT_FIELDREF; |
|
62 |
import static compiler.jvmci.compilerToVM.ConstantPoolTestCase.ConstantTypes.CONSTANT_INTERFACEMETHODREF; |
|
63 |
import static compiler.jvmci.compilerToVM.ConstantPoolTestCase.ConstantTypes.CONSTANT_INVOKEDYNAMIC; |
|
64 |
import static compiler.jvmci.compilerToVM.ConstantPoolTestCase.ConstantTypes.CONSTANT_METHODREF; |
|
65 |
||
36306
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
66 |
/** |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
67 |
* Test for {@code jdk.vm.ci.hotspot.CompilerToVM.lookupSignatureInPool} method |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
68 |
*/ |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
69 |
public class LookupSignatureInPoolTest { |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
70 |
|
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
71 |
public static void main(String[] args) throws Exception { |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
72 |
Map<ConstantTypes, Validator> typeTests = new HashMap<>(); |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
73 |
typeTests.put(CONSTANT_METHODREF, LookupSignatureInPoolTest::validate); |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
74 |
typeTests.put(CONSTANT_INTERFACEMETHODREF, LookupSignatureInPoolTest::validate); |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
75 |
typeTests.put(CONSTANT_FIELDREF, LookupSignatureInPoolTest::validate); |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
76 |
typeTests.put(CONSTANT_INVOKEDYNAMIC, LookupSignatureInPoolTest::validate); |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
77 |
ConstantPoolTestCase testCase = new ConstantPoolTestCase(typeTests); |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
78 |
testCase.test(); |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
79 |
// The next "Class.forName" and repeating "testCase.test()" |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
80 |
// are here for the following reason. |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
81 |
// The first test run is without dummy class initialization, |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
82 |
// which means no constant pool cache exists. |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
83 |
// The second run is with initialized class (with constant pool cache available). |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
84 |
// Some CompilerToVM methods require different input |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
85 |
// depending on whether CP cache exists or not. |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
86 |
for (DummyClasses dummy : DummyClasses.values()) { |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
87 |
Class.forName(dummy.klass.getName()); |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
88 |
} |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
89 |
testCase.test(); |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
90 |
} |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
91 |
|
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
92 |
private static void validate(ConstantPool constantPoolCTVM, |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
93 |
ConstantTypes cpType, |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
94 |
DummyClasses dummyClass, |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
95 |
int cpi) { |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
96 |
TestedCPEntry entry = cpType.getTestedCPEntry(dummyClass, cpi); |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
97 |
if (entry == null) { |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
98 |
return; |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
99 |
} |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
100 |
int index = cpi; |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
101 |
String cached = ""; |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
102 |
int cpci = dummyClass.getCPCacheIndex(cpi); |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
103 |
if (cpci != ConstantPoolTestsHelper.NO_CP_CACHE_PRESENT) { |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
104 |
index = cpci; |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
105 |
cached = "cached "; |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
106 |
} |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
107 |
String sigToVerify = CompilerToVMHelper.lookupSignatureInPool(constantPoolCTVM, index); |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
108 |
String sigToRefer = entry.type; |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
109 |
String msg = String.format("Wrong signature accessed by %sconstant pool index %d", |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
110 |
cached, |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
111 |
index); |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
112 |
Asserts.assertEQ(sigToVerify, sigToRefer, msg); |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
113 |
} |
9b8ba80e9327
8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff
changeset
|
114 |
} |