< prev index next >
test/compiler/jvmci/compilerToVM/GetConstantPoolTest.java
Print this page
*** 25,52 ****
/*
* @test
* @bug 8136421
* @requires (os.simpleArch == "x64" | os.simpleArch == "sparcv9") & os.arch != "aarch64"
* @library /testlibrary /../../test/lib /
! * @compile ../common/CompilerToVMHelper.java
* @build sun.hotspot.WhiteBox
* compiler.jvmci.compilerToVM.GetConstantPoolTest
* @run main ClassFileInstaller sun.hotspot.WhiteBox
* sun.hotspot.WhiteBox$WhiteBoxPermission
* jdk.vm.ci.hotspot.CompilerToVMHelper
* @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions
* -XX:+WhiteBoxAPI -XX:+UnlockExperimentalVMOptions
* -XX:+EnableJVMCI compiler.jvmci.compilerToVM.GetConstantPoolTest
*/
package compiler.jvmci.compilerToVM;
import java.lang.reflect.Field;
import jdk.vm.ci.hotspot.CompilerToVMHelper;
! import jdk.vm.ci.hotspot.HotSpotConstantPool;
! import jdk.vm.ci.hotspot.HotSpotResolvedJavaMethodImpl;
! import jdk.vm.ci.hotspot.HotSpotResolvedObjectTypeImpl;
! import jdk.vm.ci.hotspot.MetaspaceWrapperObject;
import jdk.test.lib.Utils;
import sun.hotspot.WhiteBox;
import sun.misc.Unsafe;
/**
--- 25,53 ----
/*
* @test
* @bug 8136421
* @requires (os.simpleArch == "x64" | os.simpleArch == "sparcv9") & os.arch != "aarch64"
* @library /testlibrary /../../test/lib /
! * @compile ../common/CompilerToVMHelper.java ../common/PublicMetaspaceWrapperObject.java
* @build sun.hotspot.WhiteBox
* compiler.jvmci.compilerToVM.GetConstantPoolTest
* @run main ClassFileInstaller sun.hotspot.WhiteBox
* sun.hotspot.WhiteBox$WhiteBoxPermission
* jdk.vm.ci.hotspot.CompilerToVMHelper
+ * jdk.vm.ci.hotspot.PublicMetaspaceWrapperObject
* @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions
* -XX:+WhiteBoxAPI -XX:+UnlockExperimentalVMOptions
* -XX:+EnableJVMCI compiler.jvmci.compilerToVM.GetConstantPoolTest
*/
package compiler.jvmci.compilerToVM;
import java.lang.reflect.Field;
+ import jdk.vm.ci.meta.ConstantPool;
import jdk.vm.ci.hotspot.CompilerToVMHelper;
! import jdk.vm.ci.hotspot.HotSpotResolvedJavaMethod;
! import jdk.vm.ci.hotspot.HotSpotResolvedObjectType;
! import jdk.vm.ci.hotspot.PublicMetaspaceWrapperObject;
import jdk.test.lib.Utils;
import sun.hotspot.WhiteBox;
import sun.misc.Unsafe;
/**
*** 54,95 ****
*/
public class GetConstantPoolTest {
private static enum TestCase {
NULL_BASE {
@Override
! HotSpotConstantPool getConstantPool() {
return CompilerToVMHelper.getConstantPool(null,
getPtrToCpAddress());
}
},
JAVA_METHOD_BASE {
@Override
! HotSpotConstantPool getConstantPool() {
! HotSpotResolvedJavaMethodImpl methodInstance
= CompilerToVMHelper.getResolvedJavaMethodAtSlot(
TEST_CLASS, 0);
Field field;
try {
! field = HotSpotResolvedJavaMethodImpl
! .class.getDeclaredField("metaspaceMethod");
field.setAccessible(true);
field.set(methodInstance, getPtrToCpAddress());
} catch (ReflectiveOperationException e) {
! throw new Error("TESTBUG : " + e.getMessage(), e);
}
return CompilerToVMHelper.getConstantPool(methodInstance, 0L);
}
},
CONSTANT_POOL_BASE {
@Override
! HotSpotConstantPool getConstantPool() {
! HotSpotConstantPool cpInst;
try {
cpInst = CompilerToVMHelper.getConstantPool(null,
getPtrToCpAddress());
! Field field = HotSpotConstantPool.class
.getDeclaredField("metaspaceConstantPool");
field.setAccessible(true);
field.set(cpInst, getPtrToCpAddress());
} catch (ReflectiveOperationException e) {
throw new Error("TESTBUG : " + e.getMessage(), e);
--- 55,97 ----
*/
public class GetConstantPoolTest {
private static enum TestCase {
NULL_BASE {
@Override
! ConstantPool getConstantPool() {
return CompilerToVMHelper.getConstantPool(null,
getPtrToCpAddress());
}
},
JAVA_METHOD_BASE {
@Override
! ConstantPool getConstantPool() {
! HotSpotResolvedJavaMethod methodInstance
= CompilerToVMHelper.getResolvedJavaMethodAtSlot(
TEST_CLASS, 0);
Field field;
try {
! // jdk.vm.ci.hotspot.HotSpotResolvedJavaMethodImpl.metaspaceMethod
! field = methodInstance.getClass()
! .getDeclaredField("metaspaceMethod");
field.setAccessible(true);
field.set(methodInstance, getPtrToCpAddress());
} catch (ReflectiveOperationException e) {
! throw new Error("TESTBUG : " + e, e);
}
return CompilerToVMHelper.getConstantPool(methodInstance, 0L);
}
},
CONSTANT_POOL_BASE {
@Override
! ConstantPool getConstantPool() {
! ConstantPool cpInst;
try {
cpInst = CompilerToVMHelper.getConstantPool(null,
getPtrToCpAddress());
! Field field = CompilerToVMHelper.HotSpotConstantPoolClass()
.getDeclaredField("metaspaceConstantPool");
field.setAccessible(true);
field.set(cpInst, getPtrToCpAddress());
} catch (ReflectiveOperationException e) {
throw new Error("TESTBUG : " + e.getMessage(), e);
*** 97,112 ****
return CompilerToVMHelper.getConstantPool(cpInst, 0L);
}
},
CONSTANT_POOL_BASE_IN_TWO {
@Override
! HotSpotConstantPool getConstantPool() {
long ptr = getPtrToCpAddress();
! HotSpotConstantPool cpInst;
try {
cpInst = CompilerToVMHelper.getConstantPool(null, ptr);
! Field field = HotSpotConstantPool.class
.getDeclaredField("metaspaceConstantPool");
field.setAccessible(true);
field.set(cpInst, ptr / 2L);
} catch (ReflectiveOperationException e) {
throw new Error("TESTBUG : " + e.getMessage(), e);
--- 99,114 ----
return CompilerToVMHelper.getConstantPool(cpInst, 0L);
}
},
CONSTANT_POOL_BASE_IN_TWO {
@Override
! ConstantPool getConstantPool() {
long ptr = getPtrToCpAddress();
! ConstantPool cpInst;
try {
cpInst = CompilerToVMHelper.getConstantPool(null, ptr);
! Field field = CompilerToVMHelper.HotSpotConstantPoolClass()
.getDeclaredField("metaspaceConstantPool");
field.setAccessible(true);
field.set(cpInst, ptr / 2L);
} catch (ReflectiveOperationException e) {
throw new Error("TESTBUG : " + e.getMessage(), e);
*** 115,130 ****
ptr - ptr / 2L);
}
},
CONSTANT_POOL_BASE_ZERO {
@Override
! HotSpotConstantPool getConstantPool() {
long ptr = getPtrToCpAddress();
! HotSpotConstantPool cpInst;
try {
cpInst = CompilerToVMHelper.getConstantPool(null, ptr);
! Field field = HotSpotConstantPool.class
.getDeclaredField("metaspaceConstantPool");
field.setAccessible(true);
field.set(cpInst, 0L);
} catch (ReflectiveOperationException e) {
throw new Error("TESTBUG : " + e.getMessage(), e);
--- 117,132 ----
ptr - ptr / 2L);
}
},
CONSTANT_POOL_BASE_ZERO {
@Override
! ConstantPool getConstantPool() {
long ptr = getPtrToCpAddress();
! ConstantPool cpInst;
try {
cpInst = CompilerToVMHelper.getConstantPool(null, ptr);
! Field field = CompilerToVMHelper.HotSpotConstantPoolClass()
.getDeclaredField("metaspaceConstantPool");
field.setAccessible(true);
field.set(cpInst, 0L);
} catch (ReflectiveOperationException e) {
throw new Error("TESTBUG : " + e.getMessage(), e);
*** 132,171 ****
return CompilerToVMHelper.getConstantPool(cpInst, ptr);
}
},
OBJECT_TYPE_BASE {
@Override
! HotSpotConstantPool getConstantPool() {
! HotSpotResolvedObjectTypeImpl type
! = HotSpotResolvedObjectTypeImpl.fromObjectClass(
OBJECT_TYPE_BASE.getClass());
long ptrToClass = UNSAFE.getKlassPointer(OBJECT_TYPE_BASE);
return CompilerToVMHelper.getConstantPool(type,
getPtrToCpAddress() - ptrToClass);
}
},
;
! abstract HotSpotConstantPool getConstantPool();
}
private static final WhiteBox WB = WhiteBox.getWhiteBox();
private static final Unsafe UNSAFE = Utils.getUnsafe();
private static final Class TEST_CLASS = GetConstantPoolTest.class;
private static final long CP_ADDRESS
= WB.getConstantPool(GetConstantPoolTest.class);
public void test(TestCase testCase) {
System.out.println(testCase.name());
! HotSpotConstantPool cp = testCase.getConstantPool();
String cpStringRep = cp.toString();
! if (!cpStringRep.contains(HotSpotConstantPool.class.getSimpleName())
|| !cpStringRep.contains(TEST_CLASS.getName())) {
String msg = String.format("%s : "
+ " Constant pool is not valid."
+ " String representation should contain \"%s\" and \"%s\"",
! testCase.name(),
! HotSpotConstantPool.class.getSimpleName(),
TEST_CLASS.getName());
throw new AssertionError(msg);
}
}
--- 134,175 ----
return CompilerToVMHelper.getConstantPool(cpInst, ptr);
}
},
OBJECT_TYPE_BASE {
@Override
! ConstantPool getConstantPool() {
! HotSpotResolvedObjectType type
! = HotSpotResolvedObjectType.fromObjectClass(
OBJECT_TYPE_BASE.getClass());
long ptrToClass = UNSAFE.getKlassPointer(OBJECT_TYPE_BASE);
return CompilerToVMHelper.getConstantPool(type,
getPtrToCpAddress() - ptrToClass);
}
},
;
! abstract ConstantPool getConstantPool();
}
private static final WhiteBox WB = WhiteBox.getWhiteBox();
private static final Unsafe UNSAFE = Utils.getUnsafe();
+
private static final Class TEST_CLASS = GetConstantPoolTest.class;
private static final long CP_ADDRESS
= WB.getConstantPool(GetConstantPoolTest.class);
public void test(TestCase testCase) {
System.out.println(testCase.name());
! ConstantPool cp = testCase.getConstantPool();
String cpStringRep = cp.toString();
! String cpClassSimpleName
! = CompilerToVMHelper.HotSpotConstantPoolClass().getSimpleName();
! if (!cpStringRep.contains(cpClassSimpleName)
|| !cpStringRep.contains(TEST_CLASS.getName())) {
String msg = String.format("%s : "
+ " Constant pool is not valid."
+ " String representation should contain \"%s\" and \"%s\"",
! testCase.name(), cpClassSimpleName,
TEST_CLASS.getName());
throw new AssertionError(msg);
}
}
*** 178,199 ****
testMetaspaceWrapperBase();
}
private static void testObjectBase() {
try {
! HotSpotConstantPool cp
! = CompilerToVMHelper.getConstantPool(new Object(), 0L);
throw new AssertionError("Test OBJECT_BASE."
+ " Expected IllegalArgumentException has not been caught");
} catch (IllegalArgumentException iae) {
// expected
}
}
private static void testMetaspaceWrapperBase() {
try {
! HotSpotConstantPool cp = CompilerToVMHelper.getConstantPool(
! new MetaspaceWrapperObject() {
@Override
public long getMetaspacePointer() {
return getPtrToCpAddress();
}
}, 0L);
--- 182,202 ----
testMetaspaceWrapperBase();
}
private static void testObjectBase() {
try {
! Object cp = CompilerToVMHelper.getConstantPool(new Object(), 0L);
throw new AssertionError("Test OBJECT_BASE."
+ " Expected IllegalArgumentException has not been caught");
} catch (IllegalArgumentException iae) {
// expected
}
}
private static void testMetaspaceWrapperBase() {
try {
! Object cp = CompilerToVMHelper.getConstantPool(
! new PublicMetaspaceWrapperObject() {
@Override
public long getMetaspacePointer() {
return getPtrToCpAddress();
}
}, 0L);
< prev index next >