121 ptr - ptr / 2L); 122 } 123 }, 124 CONSTANT_POOL_BASE_ZERO { 125 @Override 126 ConstantPool getConstantPool() { 127 long ptr = getPtrToCpAddress(); 128 ConstantPool cpInst; 129 try { 130 cpInst = CompilerToVMHelper.getConstantPool(null, ptr); 131 Field field = CompilerToVMHelper.HotSpotConstantPoolClass() 132 .getDeclaredField("metaspaceConstantPool"); 133 field.setAccessible(true); 134 field.set(cpInst, 0L); 135 } catch (ReflectiveOperationException e) { 136 throw new Error("TESTBUG : " + e.getMessage(), e); 137 } 138 return CompilerToVMHelper.getConstantPool(cpInst, ptr); 139 } 140 }, 141 OBJECT_TYPE_BASE { 142 @Override 143 ConstantPool getConstantPool() { 144 HotSpotResolvedObjectType type 145 = HotSpotResolvedObjectType.fromObjectClass( 146 OBJECT_TYPE_BASE.getClass()); 147 long ptrToClass = UNSAFE.getKlassPointer(OBJECT_TYPE_BASE); 148 return CompilerToVMHelper.getConstantPool(type, 149 getPtrToCpAddress() - ptrToClass); 150 } 151 }, 152 ; 153 abstract ConstantPool getConstantPool(); 154 } 155 156 private static final WhiteBox WB = WhiteBox.getWhiteBox(); 157 private static final Unsafe UNSAFE = Utils.getUnsafe(); 158 159 private static final Class TEST_CLASS = GetConstantPoolTest.class; 160 private static final long CP_ADDRESS 161 = WB.getConstantPool(GetConstantPoolTest.class); 162 163 public void test(TestCase testCase) { 164 System.out.println(testCase.name()); 165 ConstantPool cp = testCase.getConstantPool(); 166 String cpStringRep = cp.toString(); 167 String cpClassSimpleName 168 = CompilerToVMHelper.HotSpotConstantPoolClass().getSimpleName(); 169 if (!cpStringRep.contains(cpClassSimpleName) 170 || !cpStringRep.contains(TEST_CLASS.getName())) { 171 String msg = String.format("%s : " | 121 ptr - ptr / 2L); 122 } 123 }, 124 CONSTANT_POOL_BASE_ZERO { 125 @Override 126 ConstantPool getConstantPool() { 127 long ptr = getPtrToCpAddress(); 128 ConstantPool cpInst; 129 try { 130 cpInst = CompilerToVMHelper.getConstantPool(null, ptr); 131 Field field = CompilerToVMHelper.HotSpotConstantPoolClass() 132 .getDeclaredField("metaspaceConstantPool"); 133 field.setAccessible(true); 134 field.set(cpInst, 0L); 135 } catch (ReflectiveOperationException e) { 136 throw new Error("TESTBUG : " + e.getMessage(), e); 137 } 138 return CompilerToVMHelper.getConstantPool(cpInst, ptr); 139 } 140 }, 141 ; 142 abstract ConstantPool getConstantPool(); 143 } 144 145 private static final WhiteBox WB = WhiteBox.getWhiteBox(); 146 private static final Unsafe UNSAFE = Utils.getUnsafe(); 147 148 private static final Class TEST_CLASS = GetConstantPoolTest.class; 149 private static final long CP_ADDRESS 150 = WB.getConstantPool(GetConstantPoolTest.class); 151 152 public void test(TestCase testCase) { 153 System.out.println(testCase.name()); 154 ConstantPool cp = testCase.getConstantPool(); 155 String cpStringRep = cp.toString(); 156 String cpClassSimpleName 157 = CompilerToVMHelper.HotSpotConstantPoolClass().getSimpleName(); 158 if (!cpStringRep.contains(cpClassSimpleName) 159 || !cpStringRep.contains(TEST_CLASS.getName())) { 160 String msg = String.format("%s : " |