コード例 #1
0
  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);

    HotSpotResolvedObjectType holder = fromObjectClass(fieldHolder);
    JavaType type = runtime.fromClass(fieldType);

    if (offset != -1) {
      HotSpotResolvedObjectType resolved = holder;
      return resolved.createField(name, type, offset, modifiers);
    } else {
      throw new JVMCIError("unresolved field %s", reflectionField);
    }
  }
コード例 #2
0
  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);
    }
  }