comparison jvmci/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/HotSpotMetaAccessProvider.java @ 23749:d6bd0b9cd0b6

remove uses of setAccessible (JDK-8165434)
author Doug Simon <doug.simon@oracle.com>
date Wed, 07 Sep 2016 15:17:13 +0200
parents 1d4ce2d19e52
children
comparison
equal deleted inserted replaced
23748:3e551611f1fc 23749:d6bd0b9cd0b6
26 import static jdk.vm.ci.hotspot.HotSpotJVMCIRuntimeProvider.getArrayIndexScale; 26 import static jdk.vm.ci.hotspot.HotSpotJVMCIRuntimeProvider.getArrayIndexScale;
27 import static jdk.vm.ci.hotspot.HotSpotResolvedObjectTypeImpl.fromObjectClass; 27 import static jdk.vm.ci.hotspot.HotSpotResolvedObjectTypeImpl.fromObjectClass;
28 import static jdk.vm.ci.hotspot.UnsafeAccess.UNSAFE; 28 import static jdk.vm.ci.hotspot.UnsafeAccess.UNSAFE;
29 29
30 import java.lang.reflect.Array; 30 import java.lang.reflect.Array;
31 import java.lang.reflect.Constructor;
32 import java.lang.reflect.Executable; 31 import java.lang.reflect.Executable;
33 import java.lang.reflect.Field; 32 import java.lang.reflect.Field;
34 import java.lang.reflect.Method;
35 import java.lang.reflect.Modifier; 33 import java.lang.reflect.Modifier;
34 import java.util.Objects;
36 35
37 import jdk.vm.ci.code.CodeUtil; 36 import jdk.vm.ci.code.CodeUtil;
38 import jdk.vm.ci.code.TargetDescription; 37 import jdk.vm.ci.code.TargetDescription;
39 import jdk.vm.ci.common.JVMCIError; 38 import jdk.vm.ci.common.JVMCIError;
40 import jdk.vm.ci.meta.DeoptimizationAction; 39 import jdk.vm.ci.meta.DeoptimizationAction;
76 75
77 public Signature parseMethodDescriptor(String signature) { 76 public Signature parseMethodDescriptor(String signature) {
78 return new HotSpotSignature(runtime, signature); 77 return new HotSpotSignature(runtime, signature);
79 } 78 }
80 79
81 /**
82 * {@link Field} object of {@link Method#slot}.
83 */
84 private Field reflectionMethodSlot = getReflectionSlotField(Method.class);
85
86 /**
87 * {@link Field} object of {@link Constructor#slot}.
88 */
89 private Field reflectionConstructorSlot = getReflectionSlotField(Constructor.class);
90
91 private static Field getReflectionSlotField(Class<?> reflectionClass) {
92 try {
93 Field field = reflectionClass.getDeclaredField("slot");
94 field.setAccessible(true);
95 return field;
96 } catch (NoSuchFieldException | SecurityException e) {
97 throw new JVMCIError(e);
98 }
99 }
100
101 public ResolvedJavaMethod lookupJavaMethod(Executable reflectionMethod) { 80 public ResolvedJavaMethod lookupJavaMethod(Executable reflectionMethod) {
102 try { 81 return runtime.getCompilerToVM().asResolvedJavaMethod(Objects.requireNonNull(reflectionMethod));
103 Class<?> holder = reflectionMethod.getDeclaringClass();
104 Field slotField = reflectionMethod instanceof Constructor ? reflectionConstructorSlot : reflectionMethodSlot;
105 final int slot = slotField.getInt(reflectionMethod);
106 return runtime.getCompilerToVM().getResolvedJavaMethodAtSlot(holder, slot);
107 } catch (IllegalArgumentException | IllegalAccessException e) {
108 throw new JVMCIError(e);
109 }
110 } 82 }
111 83
112 public ResolvedJavaField lookupJavaField(Field reflectionField) { 84 public ResolvedJavaField lookupJavaField(Field reflectionField) {
113 Class<?> fieldHolder = reflectionField.getDeclaringClass(); 85 Class<?> fieldHolder = reflectionField.getDeclaringClass();
114 86