25 /* 26 * @test 27 * @bug 8136421 28 * @requires (os.simpleArch == "x64" | os.simpleArch == "sparcv9") & os.arch != "aarch64" 29 * @library /testlibrary /../../test/lib / 30 * @compile ../common/CompilerToVMHelper.java 31 * @build compiler.jvmci.compilerToVM.ResolveConstantInPoolTest 32 * @run main ClassFileInstaller jdk.vm.ci.hotspot.CompilerToVMHelper 33 * @run main/othervm -Xbootclasspath/a:. 34 * -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI 35 * compiler.jvmci.compilerToVM.ResolveConstantInPoolTest 36 */ 37 38 package compiler.jvmci.compilerToVM; 39 40 import java.lang.invoke.MethodHandle; 41 import java.lang.invoke.MethodType; 42 import java.util.HashMap; 43 import java.util.Map; 44 import jdk.vm.ci.hotspot.CompilerToVMHelper; 45 import jdk.vm.ci.hotspot.HotSpotConstantPool; 46 import jdk.test.lib.Asserts; 47 import sun.reflect.ConstantPool; 48 49 /** 50 * Test for {@code compiler.jvmci.CompilerToVM.resolveConstantInPool} method 51 */ 52 public class ResolveConstantInPoolTest { 53 54 public static void main(String[] args) throws Exception { 55 Map<ConstantPoolTestsHelper.ConstantTypes, 56 ConstantPoolTestCase.Validator> typeTests = new HashMap<>(2); 57 typeTests.put(ConstantPoolTestsHelper.ConstantTypes.CONSTANT_METHODHANDLE, 58 ResolveConstantInPoolTest::validateMethodHandle); 59 typeTests.put(ConstantPoolTestsHelper.ConstantTypes.CONSTANT_METHODTYPE, 60 ResolveConstantInPoolTest::validateMethodType); 61 ConstantPoolTestCase testCase = new ConstantPoolTestCase(typeTests); 62 testCase.test(); 63 } 64 65 private static void validateMethodHandle(HotSpotConstantPool constantPoolCTVM, 66 ConstantPool constantPoolSS, 67 ConstantPoolTestsHelper.DummyClasses dummyClass, int index) { 68 Object constantInPool = CompilerToVMHelper 69 .resolveConstantInPool(constantPoolCTVM, index); 70 if (!(constantInPool instanceof MethodHandle)) { 71 String msg = String.format( 72 "Wrong constant pool entry accessed by index" 73 + " %d: %s, but should be subclass of %s", 74 index + 1, constantInPool.getClass(), 75 MethodHandle.class.getName()); 76 throw new AssertionError(msg); 77 } 78 } 79 80 private static void validateMethodType(HotSpotConstantPool constantPoolCTVM, 81 ConstantPool constantPoolSS, 82 ConstantPoolTestsHelper.DummyClasses dummyClass, int index) { 83 Object constantInPool = CompilerToVMHelper 84 .resolveConstantInPool(constantPoolCTVM, index); 85 Class mtToVerify = constantInPool.getClass(); 86 Class mtToRefer = MethodType.class; 87 String msg = String.format("Wrong %s accessed by constant pool index" 88 + " %d: %s, but should be %s", "method type class", 89 index, mtToVerify, mtToRefer); 90 Asserts.assertEQ(mtToRefer, mtToVerify, msg); 91 } 92 } | 25 /* 26 * @test 27 * @bug 8136421 28 * @requires (os.simpleArch == "x64" | os.simpleArch == "sparcv9") & os.arch != "aarch64" 29 * @library /testlibrary /../../test/lib / 30 * @compile ../common/CompilerToVMHelper.java 31 * @build compiler.jvmci.compilerToVM.ResolveConstantInPoolTest 32 * @run main ClassFileInstaller jdk.vm.ci.hotspot.CompilerToVMHelper 33 * @run main/othervm -Xbootclasspath/a:. 34 * -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI 35 * compiler.jvmci.compilerToVM.ResolveConstantInPoolTest 36 */ 37 38 package compiler.jvmci.compilerToVM; 39 40 import java.lang.invoke.MethodHandle; 41 import java.lang.invoke.MethodType; 42 import java.util.HashMap; 43 import java.util.Map; 44 import jdk.vm.ci.hotspot.CompilerToVMHelper; 45 import jdk.test.lib.Asserts; 46 import sun.reflect.ConstantPool; 47 48 /** 49 * Test for {@code compiler.jvmci.CompilerToVM.resolveConstantInPool} method 50 */ 51 public class ResolveConstantInPoolTest { 52 53 public static void main(String[] args) throws Exception { 54 Map<ConstantPoolTestsHelper.ConstantTypes, 55 ConstantPoolTestCase.Validator> typeTests = new HashMap<>(2); 56 typeTests.put(ConstantPoolTestsHelper.ConstantTypes.CONSTANT_METHODHANDLE, 57 ResolveConstantInPoolTest::validateMethodHandle); 58 typeTests.put(ConstantPoolTestsHelper.ConstantTypes.CONSTANT_METHODTYPE, 59 ResolveConstantInPoolTest::validateMethodType); 60 ConstantPoolTestCase testCase = new ConstantPoolTestCase(typeTests); 61 testCase.test(); 62 } 63 64 private static void validateMethodHandle( 65 jdk.vm.ci.meta.ConstantPool constantPoolCTVM, 66 ConstantPool constantPoolSS, 67 ConstantPoolTestsHelper.DummyClasses dummyClass, int index) { 68 Object constantInPool = CompilerToVMHelper 69 .resolveConstantInPool(constantPoolCTVM, index); 70 if (!(constantInPool instanceof MethodHandle)) { 71 String msg = String.format( 72 "Wrong constant pool entry accessed by index" 73 + " %d: %s, but should be subclass of %s", 74 index + 1, constantInPool.getClass(), 75 MethodHandle.class.getName()); 76 throw new AssertionError(msg); 77 } 78 } 79 80 private static void validateMethodType( 81 jdk.vm.ci.meta.ConstantPool constantPoolCTVM, 82 ConstantPool constantPoolSS, 83 ConstantPoolTestsHelper.DummyClasses dummyClass, int index) { 84 Object constantInPool = CompilerToVMHelper 85 .resolveConstantInPool(constantPoolCTVM, index); 86 Class mtToVerify = constantInPool.getClass(); 87 Class mtToRefer = MethodType.class; 88 String msg = String.format("Wrong %s accessed by constant pool index" 89 + " %d: %s, but should be %s", "method type class", 90 index, mtToVerify, mtToRefer); 91 Asserts.assertEQ(mtToRefer, mtToVerify, msg); 92 } 93 } |