< prev index next >

src/hotspot/share/runtime/reflection.cpp

Print this page
*** 34,10 ***
--- 34,11 ---
  #include "jvm.h"
  #include "logging/log.hpp"
  #include "memory/oopFactory.hpp"
  #include "memory/resourceArea.hpp"
  #include "memory/universe.hpp"
+ #include "oops/inlineKlass.inline.hpp"
  #include "oops/instanceKlass.inline.hpp"
  #include "oops/klass.inline.hpp"
  #include "oops/objArrayKlass.hpp"
  #include "oops/objArrayOop.inline.hpp"
  #include "oops/oop.inline.hpp"

*** 49,10 ***
--- 50,11 ---
  #include "runtime/javaThread.hpp"
  #include "runtime/reflection.hpp"
  #include "runtime/signature.hpp"
  #include "runtime/vframe.inline.hpp"
  #include "utilities/formatBuffer.hpp"
+ #include "utilities/globalDefinitions.hpp"
  
  static void trace_class_resolution(oop mirror) {
    if (mirror == nullptr || java_lang_Class::is_primitive(mirror)) {
      return;
    }

*** 226,11 ***
  BasicType Reflection::array_get(jvalue* value, arrayOop a, int index, TRAPS) {
    if (!a->is_within_bounds(index)) {
      THROW_(vmSymbols::java_lang_ArrayIndexOutOfBoundsException(), T_ILLEGAL);
    }
    if (a->is_objArray()) {
!     value->l = cast_from_oop<jobject>(objArrayOop(a)->obj_at(index));
      return T_OBJECT;
    } else {
      assert(a->is_typeArray(), "just checking");
      BasicType type = TypeArrayKlass::cast(a->klass())->element_type();
      switch (type) {
--- 228,12 ---
  BasicType Reflection::array_get(jvalue* value, arrayOop a, int index, TRAPS) {
    if (!a->is_within_bounds(index)) {
      THROW_(vmSymbols::java_lang_ArrayIndexOutOfBoundsException(), T_ILLEGAL);
    }
    if (a->is_objArray()) {
!     oop o = objArrayOop(a)->obj_at(index, CHECK_(T_ILLEGAL)); // reading from a flat array can throw an OOM
+     value->l = cast_from_oop<jobject>(o);
      return T_OBJECT;
    } else {
      assert(a->is_typeArray(), "just checking");
      BasicType type = TypeArrayKlass::cast(a->klass())->element_type();
      switch (type) {

*** 268,13 ***
--- 271,18 ---
  
  void Reflection::array_set(jvalue* value, arrayOop a, int index, BasicType value_type, TRAPS) {
    if (!a->is_within_bounds(index)) {
      THROW(vmSymbols::java_lang_ArrayIndexOutOfBoundsException());
    }
+ 
    if (a->is_objArray()) {
      if (value_type == T_OBJECT) {
        oop obj = cast_to_oop(value->l);
+       if (a->is_null_free_array() && obj == nullptr) {
+          THROW_MSG(vmSymbols::java_lang_NullPointerException(), "null-restricted array");
+       }
+ 
        if (obj != nullptr) {
          Klass* element_klass = ObjArrayKlass::cast(a->klass())->element_klass();
          if (!obj->is_a(element_klass)) {
            THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), "array element type mismatch");
          }

*** 755,21 ***
  }
  
  static Handle new_type(Symbol* signature, Klass* k, TRAPS) {
    ResolvingSignatureStream ss(signature, k, false);
    oop nt = ss.as_java_mirror(SignatureStream::NCDFError, CHECK_NH);
-   if (log_is_enabled(Debug, class, resolve)) {
-     trace_class_resolution(nt);
-   }
    return Handle(THREAD, nt);
  }
  
  oop Reflection::new_method(const methodHandle& method, bool for_constant_pool_access, TRAPS) {
    // Allow jdk.internal.reflect.ConstantPool to refer to <clinit> methods as java.lang.reflect.Methods.
!   assert(!method()->is_object_initializer() &&
!          (for_constant_pool_access || !method()->is_static_initializer()),
-          "Should not be the initializer");
    InstanceKlass* holder = method->method_holder();
    int slot = method->method_idnum();
  
    Symbol*  signature  = method->signature();
    int parameter_count = ArgumentCount(signature).size();
--- 763,17 ---
  }
  
  static Handle new_type(Symbol* signature, Klass* k, TRAPS) {
    ResolvingSignatureStream ss(signature, k, false);
    oop nt = ss.as_java_mirror(SignatureStream::NCDFError, CHECK_NH);
    return Handle(THREAD, nt);
  }
  
  oop Reflection::new_method(const methodHandle& method, bool for_constant_pool_access, TRAPS) {
    // Allow jdk.internal.reflect.ConstantPool to refer to <clinit> methods as java.lang.reflect.Methods.
!   assert(!method()->name()->starts_with('<') || for_constant_pool_access,
!          "should call new_constructor instead");
    InstanceKlass* holder = method->method_holder();
    int slot = method->method_idnum();
  
    Symbol*  signature  = method->signature();
    int parameter_count = ArgumentCount(signature).size();

*** 813,11 ***
    return mh();
  }
  
  
  oop Reflection::new_constructor(const methodHandle& method, TRAPS) {
!   assert(method()->is_object_initializer(), "Should be the initializer");
  
    InstanceKlass* holder = method->method_holder();
    int slot = method->method_idnum();
  
    Symbol*  signature  = method->signature();
--- 817,12 ---
    return mh();
  }
  
  
  oop Reflection::new_constructor(const methodHandle& method, TRAPS) {
!   assert(method()->is_object_constructor(),
+          "should call new_method instead");
  
    InstanceKlass* holder = method->method_holder();
    int slot = method->method_idnum();
  
    Symbol*  signature  = method->signature();

*** 862,13 ***
  
    java_lang_reflect_Field::set_clazz(rh(), fd->field_holder()->java_mirror());
    java_lang_reflect_Field::set_slot(rh(), fd->index());
    java_lang_reflect_Field::set_name(rh(), name());
    java_lang_reflect_Field::set_type(rh(), type());
    if (fd->is_trusted_final()) {
!     java_lang_reflect_Field::set_trusted_final(rh());
    }
    // Note the ACC_ANNOTATION bit, which is a per-class access flag, is never set here.
    java_lang_reflect_Field::set_modifiers(rh(), fd->access_flags().as_field_flags());
    java_lang_reflect_Field::set_override(rh(), false);
    if (fd->has_generic_signature()) {
      Symbol*  gs = fd->generic_signature();
--- 867,20 ---
  
    java_lang_reflect_Field::set_clazz(rh(), fd->field_holder()->java_mirror());
    java_lang_reflect_Field::set_slot(rh(), fd->index());
    java_lang_reflect_Field::set_name(rh(), name());
    java_lang_reflect_Field::set_type(rh(), type());
+ 
+   int flags = 0;
    if (fd->is_trusted_final()) {
!     flags |= TRUSTED_FINAL;
+   }
+   if (fd->is_null_free_inline_type()) {
+     flags |= NULL_RESTRICTED;
    }
+   java_lang_reflect_Field::set_flags(rh(), flags);
+ 
    // Note the ACC_ANNOTATION bit, which is a per-class access flag, is never set here.
    java_lang_reflect_Field::set_modifiers(rh(), fd->access_flags().as_field_flags());
    java_lang_reflect_Field::set_override(rh(), false);
    if (fd->has_generic_signature()) {
      Symbol*  gs = fd->generic_signature();

*** 975,11 ***
        THROW_MSG_NULL(vmSymbols::java_lang_IllegalArgumentException(), "object is not an instance of declaring class");
      }
      // target klass is receiver's klass
      target_klass = receiver->klass();
      // no need to resolve if method is private or <init>
!     if (reflected_method->is_private() || reflected_method->name() == vmSymbols::object_initializer_name()) {
        method = reflected_method;
      } else {
        // resolve based on the receiver
        if (reflected_method->method_holder()->is_interface()) {
          // resolve interface call
--- 987,12 ---
        THROW_MSG_NULL(vmSymbols::java_lang_IllegalArgumentException(), "object is not an instance of declaring class");
      }
      // target klass is receiver's klass
      target_klass = receiver->klass();
      // no need to resolve if method is private or <init>
!     if (reflected_method->is_private() ||
+         reflected_method->name() == vmSymbols::object_initializer_name()) {
        method = reflected_method;
      } else {
        // resolve based on the receiver
        if (reflected_method->method_holder()->is_interface()) {
          // resolve interface call

*** 1055,12 ***
    if (!is_static) {
      java_args.push_oop(receiver);
    }
  
    for (int i = 0; i < args_len; i++) {
!     oop type_mirror = ptypes->obj_at(i);
!     oop arg = args->obj_at(i);
      if (java_lang_Class::is_primitive(type_mirror)) {
        jvalue value;
        BasicType ptype = basic_type_mirror_to_basic_type(type_mirror);
        BasicType atype = Reflection::unbox_for_primitive(arg, &value, CHECK_NULL);
        if (ptype != atype) {
--- 1068,12 ---
    if (!is_static) {
      java_args.push_oop(receiver);
    }
  
    for (int i = 0; i < args_len; i++) {
!     oop type_mirror = ptypes->obj_at(i, CHECK_NULL);
!     oop arg = args->obj_at(i, CHECK_NULL);
      if (java_lang_Class::is_primitive(type_mirror)) {
        jvalue value;
        BasicType ptype = basic_type_mirror_to_basic_type(type_mirror);
        BasicType atype = Reflection::unbox_for_primitive(arg, &value, CHECK_NULL);
        if (ptype != atype) {

*** 1157,11 ***
    Method* m = klass->method_with_idnum(slot);
    if (m == nullptr) {
      THROW_MSG_NULL(vmSymbols::java_lang_InternalError(), "invoke");
    }
    methodHandle method(THREAD, m);
-   assert(method->name() == vmSymbols::object_initializer_name(), "invalid constructor");
  
    // Make sure klass gets initialize
    klass->initialize(CHECK_NULL);
  
    // Create new instance (the receiver)
--- 1170,10 ---
< prev index next >