6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 package jdk.vm.ci.hotspot.test; 25 26 import jdk.internal.misc.Unsafe; 27 import jdk.vm.ci.hotspot.HotSpotConstantReflectionProvider; 28 import jdk.vm.ci.hotspot.HotSpotJVMCIRuntimeProvider; 29 import jdk.vm.ci.hotspot.HotSpotResolvedObjectType; 30 import jdk.vm.ci.hotspot.HotSpotVMConfigAccess; 31 import jdk.vm.ci.meta.Constant; 32 import jdk.vm.ci.meta.JavaConstant; 33 import jdk.vm.ci.meta.JavaKind; 34 import jdk.vm.ci.runtime.JVMCI; 35 import org.testng.annotations.DataProvider; 36 37 import java.lang.reflect.Field; 38 39 public class MemoryAccessProviderData { 40 private static final Unsafe UNSAFE = getUnsafe(); 41 private static final HotSpotConstantReflectionProvider CONSTANT_REFLECTION = (HotSpotConstantReflectionProvider) JVMCI.getRuntime().getHostJVMCIBackend().getConstantReflection(); 42 private static final TestClass TEST_OBJECT = new TestClass(); 43 private static final JavaConstant TEST_CONSTANT = CONSTANT_REFLECTION.forObject(TEST_OBJECT); 44 private static final JavaConstant TEST_CLASS_CONSTANT = CONSTANT_REFLECTION.forObject(TestClass.class); 45 46 private static Unsafe getUnsafe() { 47 try { 48 Field f = Unsafe.class.getDeclaredField("theUnsafe"); 49 f.setAccessible(true); 50 return (Unsafe) f.get(null); 51 } catch (NoSuchFieldException | IllegalAccessException e) { 52 throw new RuntimeException("Unable to get Unsafe instance.", e); 53 } 54 } 55 56 @DataProvider(name = "positiveObject") 57 public static Object[][] getPositiveObjectJavaKind() { 58 HotSpotJVMCIRuntimeProvider runtime = (HotSpotJVMCIRuntimeProvider) JVMCI.getRuntime(); 59 int offset = new HotSpotVMConfigAccess(runtime.getConfigStore()).getFieldOffset("Klass::_java_mirror", Integer.class, "oop"); 60 Constant wrappedKlassPointer = ((HotSpotResolvedObjectType) runtime.fromClass(TestClass.class)).klass(); 61 return new Object[][]{new Object[]{JavaKind.Object, wrappedKlassPointer, (long) offset, TEST_CLASS_CONSTANT, 0}}; 62 } 63 64 @DataProvider(name = "positivePrimitive") 65 public static Object[][] getPositivePrimitiveJavaKinds() { 66 Field booleanField; 67 Field byteField; 68 Field shortField; 69 Field intField; 70 Field longField; 71 Field floatField; 72 Field doubleField; 73 Field charField; 74 try { 75 booleanField = MemoryAccessProviderData.TestClass.class.getDeclaredField("booleanField"); | 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 package jdk.vm.ci.hotspot.test; 25 26 import java.lang.reflect.Field; 27 28 import org.testng.annotations.DataProvider; 29 30 import jdk.internal.misc.Unsafe; 31 import jdk.vm.ci.hotspot.HotSpotConstantReflectionProvider; 32 import jdk.vm.ci.hotspot.HotSpotJVMCIRuntimeProvider; 33 import jdk.vm.ci.hotspot.HotSpotResolvedObjectType; 34 import jdk.vm.ci.hotspot.HotSpotVMConfigAccess; 35 import jdk.vm.ci.meta.Constant; 36 import jdk.vm.ci.meta.JavaConstant; 37 import jdk.vm.ci.meta.JavaKind; 38 import jdk.vm.ci.runtime.JVMCI; 39 40 public class MemoryAccessProviderData { 41 private static final Unsafe UNSAFE = Unsafe.getUnsafe(); 42 private static final HotSpotConstantReflectionProvider CONSTANT_REFLECTION = (HotSpotConstantReflectionProvider) JVMCI.getRuntime().getHostJVMCIBackend().getConstantReflection(); 43 private static final TestClass TEST_OBJECT = new TestClass(); 44 private static final JavaConstant TEST_CONSTANT = CONSTANT_REFLECTION.forObject(TEST_OBJECT); 45 private static final JavaConstant TEST_CLASS_CONSTANT = CONSTANT_REFLECTION.forObject(TestClass.class); 46 47 @DataProvider(name = "positiveObject") 48 public static Object[][] getPositiveObjectJavaKind() { 49 HotSpotJVMCIRuntimeProvider runtime = (HotSpotJVMCIRuntimeProvider) JVMCI.getRuntime(); 50 int offset = new HotSpotVMConfigAccess(runtime.getConfigStore()).getFieldOffset("Klass::_java_mirror", Integer.class, "oop"); 51 Constant wrappedKlassPointer = ((HotSpotResolvedObjectType) runtime.fromClass(TestClass.class)).klass(); 52 return new Object[][]{new Object[]{JavaKind.Object, wrappedKlassPointer, (long) offset, TEST_CLASS_CONSTANT, 0}}; 53 } 54 55 @DataProvider(name = "positivePrimitive") 56 public static Object[][] getPositivePrimitiveJavaKinds() { 57 Field booleanField; 58 Field byteField; 59 Field shortField; 60 Field intField; 61 Field longField; 62 Field floatField; 63 Field doubleField; 64 Field charField; 65 try { 66 booleanField = MemoryAccessProviderData.TestClass.class.getDeclaredField("booleanField"); |