< prev index next >

src/hotspot/share/runtime/reflection.cpp

Print this page
*** 35,10 ***
--- 35,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"

*** 51,10 ***
--- 52,11 ---
  #include "runtime/reflection.hpp"
  #include "runtime/reflectionUtils.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;
    }

*** 270,13 ***
--- 272,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");
          }

*** 764,20 ***
  }
  
  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 sun.reflect.ConstantPool to refer to <clinit> methods as java.lang.reflect.Methods.
!   assert(!method()->is_initializer() ||
-          (for_constant_pool_access && method()->is_static()),
           "should call new_constructor instead");
    InstanceKlass* holder = method->method_holder();
    int slot = method->method_idnum();
  
    Symbol*  signature  = method->signature();
--- 771,16 ---
  }
  
  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 sun.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();

*** 822,11 ***
    return mh();
  }
  
  
  oop Reflection::new_constructor(const methodHandle& method, TRAPS) {
!   assert(method()->is_initializer(), "should call new_method instead");
  
    InstanceKlass* holder = method->method_holder();
    int slot = method->method_idnum();
  
    Symbol*  signature  = method->signature();
--- 825,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();

*** 871,15 ***
  
    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_int() & JVM_RECOGNIZED_FIELD_MODIFIERS);
    java_lang_reflect_Field::set_override(rh(), false);
    if (fd->has_generic_signature()) {
      Symbol*  gs = fd->generic_signature();
      Handle sig = java_lang_String::create_from_symbol(gs, CHECK_NULL);
      java_lang_reflect_Field::set_signature(rh(), sig());
--- 875,23 ---
  
    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.
!   int modifiers = fd->access_flags().as_int();
+   java_lang_reflect_Field::set_modifiers(rh(), modifiers);
    java_lang_reflect_Field::set_override(rh(), false);
    if (fd->has_generic_signature()) {
      Symbol*  gs = fd->generic_signature();
      Handle sig = java_lang_String::create_from_symbol(gs, CHECK_NULL);
      java_lang_reflect_Field::set_signature(rh(), sig());

*** 991,11 ***
        THROW_MSG_0(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
--- 1003,12 ---
        THROW_MSG_0(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

*** 1173,11 ***
    Method* m = klass->method_with_idnum(slot);
    if (m == nullptr) {
      THROW_MSG_0(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)
--- 1186,10 ---
< prev index next >