private static Field getReflectionSlotField(Class<?> reflectionClass) { try { Field field = reflectionClass.getDeclaredField("slot"); field.setAccessible(true); return field; } catch (NoSuchFieldException | SecurityException e) { throw new GraalInternalError(e); } }
public ResolvedJavaMethod lookupJavaConstructor(Constructor<?> reflectionConstructor) { try { Class<?> holder = reflectionConstructor.getDeclaringClass(); final int slot = reflectionConstructorSlot.getInt(reflectionConstructor); final long metaspaceMethod = runtime.getCompilerToVM().getMetaspaceMethod(holder, slot); return HotSpotResolvedJavaMethod.fromMetaspace(metaspaceMethod); } catch (IllegalArgumentException | IllegalAccessException e) { throw new GraalInternalError(e); } }
public ResolvedJavaField lookupJavaField(Field reflectionField) { String name = reflectionField.getName(); Class<?> fieldHolder = reflectionField.getDeclaringClass(); Class<?> fieldType = reflectionField.getType(); // java.lang.reflect.Field's modifiers should be enough here since VM internal modifier bits // are not used (yet). final int modifiers = reflectionField.getModifiers(); final long offset = Modifier.isStatic(modifiers) ? unsafe.staticFieldOffset(reflectionField) : unsafe.objectFieldOffset(reflectionField); ResolvedJavaType holder = HotSpotResolvedObjectType.fromClass(fieldHolder); ResolvedJavaType type = HotSpotResolvedObjectType.fromClass(fieldType); if (offset != -1) { HotSpotResolvedObjectType resolved = (HotSpotResolvedObjectType) holder; return resolved.createField(name, type, offset, modifiers); } else { throw GraalInternalError.shouldNotReachHere("unresolved field " + reflectionField); } }