27 * @bug 8136421 |
27 * @bug 8136421 |
28 * @requires (os.simpleArch == "x64" | os.simpleArch == "sparcv9" | os.simpleArch == "aarch64") |
28 * @requires (os.simpleArch == "x64" | os.simpleArch == "sparcv9" | os.simpleArch == "aarch64") |
29 * @summary Testing compiler.jvmci.CompilerToVM.resolveTypeInPool method |
29 * @summary Testing compiler.jvmci.CompilerToVM.resolveTypeInPool method |
30 * @library /testlibrary /test/lib / |
30 * @library /testlibrary /test/lib / |
31 * @compile ../common/CompilerToVMHelper.java |
31 * @compile ../common/CompilerToVMHelper.java |
32 * @build compiler.jvmci.common.testcases.MultipleImplementersInterface |
32 * @build sun.hotspot.WhiteBox |
33 * compiler.jvmci.common.testcases.MultipleImplementer2 |
|
34 * compiler.jvmci.compilerToVM.ConstantPoolTestsHelper |
|
35 * compiler.jvmci.compilerToVM.ConstantPoolTestCase |
|
36 * compiler.jvmci.compilerToVM.ResolveTypeInPoolTest |
33 * compiler.jvmci.compilerToVM.ResolveTypeInPoolTest |
37 * @run main ClassFileInstaller jdk.vm.ci.hotspot.CompilerToVMHelper |
34 * @run main ClassFileInstaller sun.hotspot.WhiteBox |
38 * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockExperimentalVMOptions |
35 * sun.hotspot.WhiteBox$WhiteBoxPermission |
|
36 * jdk.vm.ci.hotspot.CompilerToVMHelper |
|
37 * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions |
|
38 * -XX:+WhiteBoxAPI -XX:+UnlockExperimentalVMOptions |
39 * -XX:+EnableJVMCI compiler.jvmci.compilerToVM.ResolveTypeInPoolTest |
39 * -XX:+EnableJVMCI compiler.jvmci.compilerToVM.ResolveTypeInPoolTest |
40 */ |
40 */ |
41 |
41 |
42 package compiler.jvmci.compilerToVM; |
42 package compiler.jvmci.compilerToVM; |
43 |
43 |
|
44 import compiler.jvmci.compilerToVM.ConstantPoolTestsHelper.DummyClasses; |
|
45 import compiler.jvmci.compilerToVM.ConstantPoolTestCase.ConstantTypes; |
|
46 import static compiler.jvmci.compilerToVM.ConstantPoolTestCase.ConstantTypes.*; |
|
47 import compiler.jvmci.compilerToVM.ConstantPoolTestCase.TestedCPEntry; |
|
48 import compiler.jvmci.compilerToVM.ConstantPoolTestCase.Validator; |
44 import java.util.HashMap; |
49 import java.util.HashMap; |
45 import java.util.Map; |
50 import java.util.Map; |
46 import jdk.vm.ci.hotspot.CompilerToVMHelper; |
51 import jdk.vm.ci.hotspot.CompilerToVMHelper; |
47 import jdk.vm.ci.hotspot.HotSpotResolvedObjectType; |
52 import jdk.vm.ci.hotspot.HotSpotResolvedObjectType; |
48 import sun.reflect.ConstantPool; |
53 import jdk.vm.ci.meta.ConstantPool; |
49 |
54 |
50 /** |
55 /** |
51 * Test for {@code compiler.jvmci.CompilerToVM.resolveTypeInPool} method |
56 * Test for {@code jdk.vm.ci.hotspot.CompilerToVM.resolveTypeInPool} method |
52 */ |
57 */ |
53 public class ResolveTypeInPoolTest { |
58 public class ResolveTypeInPoolTest { |
54 |
59 |
55 public static void main(String[] args) throws Exception { |
60 public static void main(String[] args) throws Exception { |
56 Map<ConstantPoolTestsHelper.ConstantTypes, |
61 Map<ConstantTypes, Validator> typeTests = new HashMap<>(); |
57 ConstantPoolTestCase.Validator> typeTests = new HashMap<>(1); |
62 typeTests.put(CONSTANT_CLASS, ResolveTypeInPoolTest::validate); |
58 typeTests.put(ConstantPoolTestsHelper.ConstantTypes.CONSTANT_CLASS, |
|
59 ResolveTypeInPoolTest::validate); |
|
60 ConstantPoolTestCase testCase = new ConstantPoolTestCase(typeTests); |
63 ConstantPoolTestCase testCase = new ConstantPoolTestCase(typeTests); |
|
64 testCase.test(); |
|
65 // The next "Class.forName" and repeating "testCase.test()" |
|
66 // are here for the following reason. |
|
67 // The first test run is without dummy class initialization, |
|
68 // which means no constant pool cache exists. |
|
69 // The second run is with initialized class (with constant pool cache available). |
|
70 // Some CompilerToVM methods require different input |
|
71 // depending on whether CP cache exists or not. |
|
72 for (DummyClasses dummy : DummyClasses.values()) { |
|
73 Class.forName(dummy.klass.getName()); |
|
74 } |
61 testCase.test(); |
75 testCase.test(); |
62 } |
76 } |
63 |
77 |
64 public static void validate( |
78 public static void validate(ConstantPool constantPoolCTVM, |
65 jdk.vm.ci.meta.ConstantPool constantPoolCTVM, |
79 ConstantTypes cpType, |
66 ConstantPool constantPoolSS, |
80 DummyClasses dummyClass, |
67 ConstantPoolTestsHelper.DummyClasses dummyClass, int i) { |
81 int i) { |
68 HotSpotResolvedObjectType typeToVerify = CompilerToVMHelper |
82 TestedCPEntry entry = cpType.getTestedCPEntry(dummyClass, i); |
69 .resolveTypeInPool(constantPoolCTVM, i); |
83 if (entry == null) { |
70 int classNameIndex = (int) dummyClass.cp.get(i).value; |
84 return; |
71 String classNameToRefer = constantPoolSS.getUTF8At(classNameIndex); |
85 } |
|
86 HotSpotResolvedObjectType typeToVerify = CompilerToVMHelper.resolveTypeInPool(constantPoolCTVM, i); |
|
87 String classNameToRefer = entry.klass; |
72 String outputToVerify = typeToVerify.toString(); |
88 String outputToVerify = typeToVerify.toString(); |
73 if (!outputToVerify.contains(classNameToRefer)) { |
89 if (!outputToVerify.contains(classNameToRefer)) { |
74 String msg = String.format("Wrong class accessed by constant" |
90 String msg = String.format("Wrong class accessed by constant" |
75 + " pool index %d: %s, but should be %s", |
91 + " pool index %d: %s, but should be %s", |
76 i, outputToVerify, classNameToRefer); |
92 i, |
|
93 outputToVerify, |
|
94 classNameToRefer); |
77 throw new AssertionError(msg); |
95 throw new AssertionError(msg); |
78 } |
96 } |
79 } |
97 } |
80 } |
98 } |