< prev index next >

src/hotspot/share/runtime/reflection.cpp

Print this page

  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "cds/cdsConfig.hpp"
  27 #include "classfile/javaClasses.inline.hpp"
  28 #include "classfile/moduleEntry.hpp"
  29 #include "classfile/packageEntry.hpp"
  30 #include "classfile/stringTable.hpp"
  31 #include "classfile/verifier.hpp"
  32 #include "classfile/vmClasses.hpp"
  33 #include "classfile/vmSymbols.hpp"
  34 #include "interpreter/linkResolver.hpp"
  35 #include "jvm.h"
  36 #include "logging/log.hpp"
  37 #include "memory/oopFactory.hpp"
  38 #include "memory/resourceArea.hpp"
  39 #include "memory/universe.hpp"

  40 #include "oops/instanceKlass.inline.hpp"
  41 #include "oops/klass.inline.hpp"
  42 #include "oops/objArrayKlass.hpp"
  43 #include "oops/objArrayOop.inline.hpp"
  44 #include "oops/oop.inline.hpp"
  45 #include "oops/typeArrayOop.inline.hpp"
  46 #include "prims/jvmtiExport.hpp"
  47 #include "runtime/fieldDescriptor.inline.hpp"
  48 #include "runtime/handles.inline.hpp"
  49 #include "runtime/javaCalls.hpp"
  50 #include "runtime/javaThread.hpp"
  51 #include "runtime/reflection.hpp"
  52 #include "runtime/signature.hpp"
  53 #include "runtime/vframe.inline.hpp"
  54 #include "utilities/formatBuffer.hpp"

  55 
  56 static void trace_class_resolution(oop mirror) {
  57   if (mirror == nullptr || java_lang_Class::is_primitive(mirror)) {
  58     return;
  59   }
  60   Klass* to_class = java_lang_Class::as_Klass(mirror);
  61   ResourceMark rm;
  62   int line_number = -1;
  63   const char * source_file = nullptr;
  64   Klass* caller = nullptr;
  65   JavaThread* jthread = JavaThread::current();
  66   if (jthread->has_last_Java_frame()) {
  67     vframeStream vfst(jthread);
  68     // skip over any frames belonging to java.lang.Class
  69     while (!vfst.at_end() &&
  70            vfst.method()->method_holder()->name() == vmSymbols::java_lang_Class()) {
  71       vfst.next();
  72     }
  73     if (!vfst.at_end()) {
  74       // this frame is a likely suspect

 254         value->s = typeArrayOop(a)->short_at(index);
 255         break;
 256       case T_INT:
 257         value->i = typeArrayOop(a)->int_at(index);
 258         break;
 259       case T_LONG:
 260         value->j = typeArrayOop(a)->long_at(index);
 261         break;
 262       default:
 263         return T_ILLEGAL;
 264     }
 265     return type;
 266   }
 267 }
 268 
 269 
 270 void Reflection::array_set(jvalue* value, arrayOop a, int index, BasicType value_type, TRAPS) {
 271   if (!a->is_within_bounds(index)) {
 272     THROW(vmSymbols::java_lang_ArrayIndexOutOfBoundsException());
 273   }

 274   if (a->is_objArray()) {
 275     if (value_type == T_OBJECT) {
 276       oop obj = cast_to_oop(value->l);




 277       if (obj != nullptr) {
 278         Klass* element_klass = ObjArrayKlass::cast(a->klass())->element_klass();
 279         if (!obj->is_a(element_klass)) {
 280           THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), "array element type mismatch");
 281         }
 282       }
 283       objArrayOop(a)->obj_at_put(index, obj);
 284     }
 285   } else {
 286     assert(a->is_typeArray(), "just checking");
 287     BasicType array_type = TypeArrayKlass::cast(a->klass())->element_type();
 288     if (array_type != value_type) {
 289       // The widen operation can potentially throw an exception, but cannot block,
 290       // so typeArrayOop a is safe if the call succeeds.
 291       widen(value, value_type, array_type, CHECK);
 292     }
 293     switch (array_type) {
 294       case T_BOOLEAN:
 295         typeArrayOop(a)->bool_at_put(index, value->z);
 296         break;

 730     }
 731     if (!ss.at_return_type()) {
 732       mirrors->obj_at_put(index++, mirror);
 733     } else if (return_type != nullptr) {
 734       // Collect return type as well
 735       assert(ss.at_return_type(), "return type should be present");
 736       *return_type = mirror;
 737     }
 738   }
 739   assert(index == parameter_count, "invalid parameter count");
 740   return mirrors;
 741 }
 742 
 743 static objArrayHandle get_exception_types(const methodHandle& method, TRAPS) {
 744   return method->resolved_checked_exceptions(THREAD);
 745 }
 746 
 747 static Handle new_type(Symbol* signature, Klass* k, TRAPS) {
 748   ResolvingSignatureStream ss(signature, k, false);
 749   oop nt = ss.as_java_mirror(SignatureStream::NCDFError, CHECK_NH);
 750   if (log_is_enabled(Debug, class, resolve)) {
 751     trace_class_resolution(nt);
 752   }
 753   return Handle(THREAD, nt);
 754 }
 755 
 756 oop Reflection::new_method(const methodHandle& method, bool for_constant_pool_access, TRAPS) {
 757   // Allow jdk.internal.reflect.ConstantPool to refer to <clinit> methods as java.lang.reflect.Methods.
 758   assert(!method()->is_object_initializer() &&
 759          (for_constant_pool_access || !method()->is_static_initializer()),
 760          "Should not be the initializer");
 761   InstanceKlass* holder = method->method_holder();
 762   int slot = method->method_idnum();
 763 
 764   Symbol*  signature  = method->signature();
 765   int parameter_count = ArgumentCount(signature).size();
 766   oop return_type_oop = nullptr;
 767   objArrayHandle parameter_types = get_parameter_types(method, parameter_count, &return_type_oop, CHECK_NULL);
 768   if (parameter_types.is_null() || return_type_oop == nullptr) return nullptr;
 769 
 770   Handle return_type(THREAD, return_type_oop);
 771 
 772   objArrayHandle exception_types = get_exception_types(method, CHECK_NULL);
 773   assert(!exception_types.is_null(), "cannot return null");
 774 
 775   Symbol*  method_name = method->name();
 776   oop name_oop = StringTable::intern(method_name, CHECK_NULL);
 777   Handle name = Handle(THREAD, name_oop);
 778   if (name == nullptr) return nullptr;
 779 
 780   const int modifiers = method->access_flags().as_int() & JVM_RECOGNIZED_METHOD_MODIFIERS;

 788   java_lang_reflect_Method::set_parameter_types(mh(), parameter_types());
 789   java_lang_reflect_Method::set_exception_types(mh(), exception_types());
 790   java_lang_reflect_Method::set_modifiers(mh(), modifiers);
 791   java_lang_reflect_Method::set_override(mh(), false);
 792   if (method->generic_signature() != nullptr) {
 793     Symbol*  gs = method->generic_signature();
 794     Handle sig = java_lang_String::create_from_symbol(gs, CHECK_NULL);
 795     java_lang_reflect_Method::set_signature(mh(), sig());
 796   }
 797   typeArrayOop an_oop = Annotations::make_java_array(method->annotations(), CHECK_NULL);
 798   java_lang_reflect_Method::set_annotations(mh(), an_oop);
 799   an_oop = Annotations::make_java_array(method->parameter_annotations(), CHECK_NULL);
 800   java_lang_reflect_Method::set_parameter_annotations(mh(), an_oop);
 801   an_oop = Annotations::make_java_array(method->annotation_default(), CHECK_NULL);
 802   java_lang_reflect_Method::set_annotation_default(mh(), an_oop);
 803   return mh();
 804 }
 805 
 806 
 807 oop Reflection::new_constructor(const methodHandle& method, TRAPS) {
 808   assert(method()->is_object_initializer(), "Should be the initializer");

 809 
 810   InstanceKlass* holder = method->method_holder();
 811   int slot = method->method_idnum();
 812 
 813   Symbol*  signature  = method->signature();
 814   int parameter_count = ArgumentCount(signature).size();
 815   objArrayHandle parameter_types = get_parameter_types(method, parameter_count, nullptr, CHECK_NULL);
 816   if (parameter_types.is_null()) return nullptr;
 817 
 818   objArrayHandle exception_types = get_exception_types(method, CHECK_NULL);
 819   assert(!exception_types.is_null(), "cannot return null");
 820 
 821   const int modifiers = method->access_flags().as_int() & JVM_RECOGNIZED_METHOD_MODIFIERS;
 822 
 823   Handle ch = java_lang_reflect_Constructor::create(CHECK_NULL);
 824 
 825   java_lang_reflect_Constructor::set_clazz(ch(), holder->java_mirror());
 826   java_lang_reflect_Constructor::set_slot(ch(), slot);
 827   java_lang_reflect_Constructor::set_parameter_types(ch(), parameter_types());
 828   java_lang_reflect_Constructor::set_exception_types(ch(), exception_types());

 837   java_lang_reflect_Constructor::set_annotations(ch(), an_oop);
 838   an_oop = Annotations::make_java_array(method->parameter_annotations(), CHECK_NULL);
 839   java_lang_reflect_Constructor::set_parameter_annotations(ch(), an_oop);
 840   return ch();
 841 }
 842 
 843 
 844 oop Reflection::new_field(fieldDescriptor* fd, TRAPS) {
 845   Symbol*  field_name = fd->name();
 846   oop name_oop = StringTable::intern(field_name, CHECK_NULL);
 847   Handle name = Handle(THREAD, name_oop);
 848   Symbol*  signature  = fd->signature();
 849   InstanceKlass* holder = fd->field_holder();
 850   Handle type = new_type(signature, holder, CHECK_NULL);
 851   Handle rh  = java_lang_reflect_Field::create(CHECK_NULL);
 852 
 853   java_lang_reflect_Field::set_clazz(rh(), fd->field_holder()->java_mirror());
 854   java_lang_reflect_Field::set_slot(rh(), fd->index());
 855   java_lang_reflect_Field::set_name(rh(), name());
 856   java_lang_reflect_Field::set_type(rh(), type());


 857   if (fd->is_trusted_final()) {
 858     java_lang_reflect_Field::set_trusted_final(rh());



 859   }


 860   // Note the ACC_ANNOTATION bit, which is a per-class access flag, is never set here.
 861   java_lang_reflect_Field::set_modifiers(rh(), fd->access_flags().as_int() & JVM_RECOGNIZED_FIELD_MODIFIERS);

 862   java_lang_reflect_Field::set_override(rh(), false);
 863   if (fd->has_generic_signature()) {
 864     Symbol*  gs = fd->generic_signature();
 865     Handle sig = java_lang_String::create_from_symbol(gs, CHECK_NULL);
 866     java_lang_reflect_Field::set_signature(rh(), sig());
 867   }
 868   typeArrayOop an_oop = Annotations::make_java_array(fd->annotations(), CHECK_NULL);
 869   java_lang_reflect_Field::set_annotations(rh(), an_oop);
 870   return rh();
 871 }
 872 
 873 oop Reflection::new_parameter(Handle method, int index, Symbol* sym,
 874                               int flags, TRAPS) {
 875 
 876   Handle rh = java_lang_reflect_Parameter::create(CHECK_NULL);
 877 
 878   if(nullptr != sym) {
 879     Handle name = java_lang_String::create_from_symbol(sym, CHECK_NULL);
 880     java_lang_reflect_Parameter::set_name(rh(), name());
 881   } else {

 957   // Ensure klass is initialized
 958   klass->initialize(CHECK_NULL);
 959 
 960   bool is_static = reflected_method->is_static();
 961   if (is_static) {
 962     // ignore receiver argument
 963     method = reflected_method;
 964     target_klass = klass;
 965   } else {
 966     // check for null receiver
 967     if (receiver.is_null()) {
 968       THROW_NULL(vmSymbols::java_lang_NullPointerException());
 969     }
 970     // Check class of receiver against class declaring method
 971     if (!receiver->is_a(klass)) {
 972       THROW_MSG_NULL(vmSymbols::java_lang_IllegalArgumentException(), "object is not an instance of declaring class");
 973     }
 974     // target klass is receiver's klass
 975     target_klass = receiver->klass();
 976     // no need to resolve if method is private or <init>
 977     if (reflected_method->is_private() || reflected_method->name() == vmSymbols::object_initializer_name()) {

 978       method = reflected_method;
 979     } else {
 980       // resolve based on the receiver
 981       if (reflected_method->method_holder()->is_interface()) {
 982         // resolve interface call
 983         //
 984         // Match resolution errors with those thrown due to reflection inlining
 985         // Linktime resolution & IllegalAccessCheck already done by Class.getMethod()
 986         method = resolve_interface_call(klass, reflected_method, target_klass, receiver, THREAD);
 987         if (HAS_PENDING_EXCEPTION) {
 988           // Method resolution threw an exception; wrap it in an InvocationTargetException
 989           oop resolution_exception = PENDING_EXCEPTION;
 990           CLEAR_PENDING_EXCEPTION;
 991           // JVMTI has already reported the pending exception
 992           // JVMTI internal flag reset is needed in order to report InvocationTargetException
 993           JvmtiExport::clear_detected_exception(THREAD);
 994           JavaCallArguments args(Handle(THREAD, resolution_exception));
 995           THROW_ARG_NULL(vmSymbols::java_lang_reflect_InvocationTargetException(),
 996                          vmSymbols::throwable_void_signature(),
 997                          &args);

1139     THROW_MSG_NULL(vmSymbols::java_lang_InternalError(), "invoke");
1140   }
1141   methodHandle method(THREAD, m);
1142 
1143   return invoke(klass, method, receiver, override, ptypes, rtype, args, true, THREAD);
1144 }
1145 
1146 
1147 oop Reflection::invoke_constructor(oop constructor_mirror, objArrayHandle args, TRAPS) {
1148   oop mirror             = java_lang_reflect_Constructor::clazz(constructor_mirror);
1149   int slot               = java_lang_reflect_Constructor::slot(constructor_mirror);
1150   bool override          = java_lang_reflect_Constructor::override(constructor_mirror) != 0;
1151   objArrayHandle ptypes(THREAD, objArrayOop(java_lang_reflect_Constructor::parameter_types(constructor_mirror)));
1152 
1153   InstanceKlass* klass = InstanceKlass::cast(java_lang_Class::as_Klass(mirror));
1154   Method* m = klass->method_with_idnum(slot);
1155   if (m == nullptr) {
1156     THROW_MSG_NULL(vmSymbols::java_lang_InternalError(), "invoke");
1157   }
1158   methodHandle method(THREAD, m);
1159   assert(method->name() == vmSymbols::object_initializer_name(), "invalid constructor");
1160 
1161   // Make sure klass gets initialize
1162   klass->initialize(CHECK_NULL);
1163 
1164   // Create new instance (the receiver)
1165   klass->check_valid_for_instantiation(false, CHECK_NULL);
1166   Handle receiver = klass->allocate_instance_handle(CHECK_NULL);
1167 
1168   // Ignore result from call and return receiver
1169   invoke(klass, method, receiver, override, ptypes, T_VOID, args, false, CHECK_NULL);
1170   return receiver();
1171 }

  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "cds/cdsConfig.hpp"
  27 #include "classfile/javaClasses.inline.hpp"
  28 #include "classfile/moduleEntry.hpp"
  29 #include "classfile/packageEntry.hpp"
  30 #include "classfile/stringTable.hpp"
  31 #include "classfile/verifier.hpp"
  32 #include "classfile/vmClasses.hpp"
  33 #include "classfile/vmSymbols.hpp"
  34 #include "interpreter/linkResolver.hpp"
  35 #include "jvm.h"
  36 #include "logging/log.hpp"
  37 #include "memory/oopFactory.hpp"
  38 #include "memory/resourceArea.hpp"
  39 #include "memory/universe.hpp"
  40 #include "oops/inlineKlass.inline.hpp"
  41 #include "oops/instanceKlass.inline.hpp"
  42 #include "oops/klass.inline.hpp"
  43 #include "oops/objArrayKlass.hpp"
  44 #include "oops/objArrayOop.inline.hpp"
  45 #include "oops/oop.inline.hpp"
  46 #include "oops/typeArrayOop.inline.hpp"
  47 #include "prims/jvmtiExport.hpp"
  48 #include "runtime/fieldDescriptor.inline.hpp"
  49 #include "runtime/handles.inline.hpp"
  50 #include "runtime/javaCalls.hpp"
  51 #include "runtime/javaThread.hpp"
  52 #include "runtime/reflection.hpp"
  53 #include "runtime/signature.hpp"
  54 #include "runtime/vframe.inline.hpp"
  55 #include "utilities/formatBuffer.hpp"
  56 #include "utilities/globalDefinitions.hpp"
  57 
  58 static void trace_class_resolution(oop mirror) {
  59   if (mirror == nullptr || java_lang_Class::is_primitive(mirror)) {
  60     return;
  61   }
  62   Klass* to_class = java_lang_Class::as_Klass(mirror);
  63   ResourceMark rm;
  64   int line_number = -1;
  65   const char * source_file = nullptr;
  66   Klass* caller = nullptr;
  67   JavaThread* jthread = JavaThread::current();
  68   if (jthread->has_last_Java_frame()) {
  69     vframeStream vfst(jthread);
  70     // skip over any frames belonging to java.lang.Class
  71     while (!vfst.at_end() &&
  72            vfst.method()->method_holder()->name() == vmSymbols::java_lang_Class()) {
  73       vfst.next();
  74     }
  75     if (!vfst.at_end()) {
  76       // this frame is a likely suspect

 256         value->s = typeArrayOop(a)->short_at(index);
 257         break;
 258       case T_INT:
 259         value->i = typeArrayOop(a)->int_at(index);
 260         break;
 261       case T_LONG:
 262         value->j = typeArrayOop(a)->long_at(index);
 263         break;
 264       default:
 265         return T_ILLEGAL;
 266     }
 267     return type;
 268   }
 269 }
 270 
 271 
 272 void Reflection::array_set(jvalue* value, arrayOop a, int index, BasicType value_type, TRAPS) {
 273   if (!a->is_within_bounds(index)) {
 274     THROW(vmSymbols::java_lang_ArrayIndexOutOfBoundsException());
 275   }
 276 
 277   if (a->is_objArray()) {
 278     if (value_type == T_OBJECT) {
 279       oop obj = cast_to_oop(value->l);
 280       if (a->is_null_free_array() && obj == nullptr) {
 281          THROW_MSG(vmSymbols::java_lang_NullPointerException(), "null-restricted array");
 282       }
 283 
 284       if (obj != nullptr) {
 285         Klass* element_klass = ObjArrayKlass::cast(a->klass())->element_klass();
 286         if (!obj->is_a(element_klass)) {
 287           THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), "array element type mismatch");
 288         }
 289       }
 290       objArrayOop(a)->obj_at_put(index, obj);
 291     }
 292   } else {
 293     assert(a->is_typeArray(), "just checking");
 294     BasicType array_type = TypeArrayKlass::cast(a->klass())->element_type();
 295     if (array_type != value_type) {
 296       // The widen operation can potentially throw an exception, but cannot block,
 297       // so typeArrayOop a is safe if the call succeeds.
 298       widen(value, value_type, array_type, CHECK);
 299     }
 300     switch (array_type) {
 301       case T_BOOLEAN:
 302         typeArrayOop(a)->bool_at_put(index, value->z);
 303         break;

 737     }
 738     if (!ss.at_return_type()) {
 739       mirrors->obj_at_put(index++, mirror);
 740     } else if (return_type != nullptr) {
 741       // Collect return type as well
 742       assert(ss.at_return_type(), "return type should be present");
 743       *return_type = mirror;
 744     }
 745   }
 746   assert(index == parameter_count, "invalid parameter count");
 747   return mirrors;
 748 }
 749 
 750 static objArrayHandle get_exception_types(const methodHandle& method, TRAPS) {
 751   return method->resolved_checked_exceptions(THREAD);
 752 }
 753 
 754 static Handle new_type(Symbol* signature, Klass* k, TRAPS) {
 755   ResolvingSignatureStream ss(signature, k, false);
 756   oop nt = ss.as_java_mirror(SignatureStream::NCDFError, CHECK_NH);



 757   return Handle(THREAD, nt);
 758 }
 759 
 760 oop Reflection::new_method(const methodHandle& method, bool for_constant_pool_access, TRAPS) {
 761   // Allow jdk.internal.reflect.ConstantPool to refer to <clinit> methods as java.lang.reflect.Methods.
 762   assert(!method()->name()->starts_with('<') || for_constant_pool_access,
 763          "should call new_constructor instead");

 764   InstanceKlass* holder = method->method_holder();
 765   int slot = method->method_idnum();
 766 
 767   Symbol*  signature  = method->signature();
 768   int parameter_count = ArgumentCount(signature).size();
 769   oop return_type_oop = nullptr;
 770   objArrayHandle parameter_types = get_parameter_types(method, parameter_count, &return_type_oop, CHECK_NULL);
 771   if (parameter_types.is_null() || return_type_oop == nullptr) return nullptr;
 772 
 773   Handle return_type(THREAD, return_type_oop);
 774 
 775   objArrayHandle exception_types = get_exception_types(method, CHECK_NULL);
 776   assert(!exception_types.is_null(), "cannot return null");
 777 
 778   Symbol*  method_name = method->name();
 779   oop name_oop = StringTable::intern(method_name, CHECK_NULL);
 780   Handle name = Handle(THREAD, name_oop);
 781   if (name == nullptr) return nullptr;
 782 
 783   const int modifiers = method->access_flags().as_int() & JVM_RECOGNIZED_METHOD_MODIFIERS;

 791   java_lang_reflect_Method::set_parameter_types(mh(), parameter_types());
 792   java_lang_reflect_Method::set_exception_types(mh(), exception_types());
 793   java_lang_reflect_Method::set_modifiers(mh(), modifiers);
 794   java_lang_reflect_Method::set_override(mh(), false);
 795   if (method->generic_signature() != nullptr) {
 796     Symbol*  gs = method->generic_signature();
 797     Handle sig = java_lang_String::create_from_symbol(gs, CHECK_NULL);
 798     java_lang_reflect_Method::set_signature(mh(), sig());
 799   }
 800   typeArrayOop an_oop = Annotations::make_java_array(method->annotations(), CHECK_NULL);
 801   java_lang_reflect_Method::set_annotations(mh(), an_oop);
 802   an_oop = Annotations::make_java_array(method->parameter_annotations(), CHECK_NULL);
 803   java_lang_reflect_Method::set_parameter_annotations(mh(), an_oop);
 804   an_oop = Annotations::make_java_array(method->annotation_default(), CHECK_NULL);
 805   java_lang_reflect_Method::set_annotation_default(mh(), an_oop);
 806   return mh();
 807 }
 808 
 809 
 810 oop Reflection::new_constructor(const methodHandle& method, TRAPS) {
 811   assert(method()->is_object_constructor(),
 812          "should call new_method instead");
 813 
 814   InstanceKlass* holder = method->method_holder();
 815   int slot = method->method_idnum();
 816 
 817   Symbol*  signature  = method->signature();
 818   int parameter_count = ArgumentCount(signature).size();
 819   objArrayHandle parameter_types = get_parameter_types(method, parameter_count, nullptr, CHECK_NULL);
 820   if (parameter_types.is_null()) return nullptr;
 821 
 822   objArrayHandle exception_types = get_exception_types(method, CHECK_NULL);
 823   assert(!exception_types.is_null(), "cannot return null");
 824 
 825   const int modifiers = method->access_flags().as_int() & JVM_RECOGNIZED_METHOD_MODIFIERS;
 826 
 827   Handle ch = java_lang_reflect_Constructor::create(CHECK_NULL);
 828 
 829   java_lang_reflect_Constructor::set_clazz(ch(), holder->java_mirror());
 830   java_lang_reflect_Constructor::set_slot(ch(), slot);
 831   java_lang_reflect_Constructor::set_parameter_types(ch(), parameter_types());
 832   java_lang_reflect_Constructor::set_exception_types(ch(), exception_types());

 841   java_lang_reflect_Constructor::set_annotations(ch(), an_oop);
 842   an_oop = Annotations::make_java_array(method->parameter_annotations(), CHECK_NULL);
 843   java_lang_reflect_Constructor::set_parameter_annotations(ch(), an_oop);
 844   return ch();
 845 }
 846 
 847 
 848 oop Reflection::new_field(fieldDescriptor* fd, TRAPS) {
 849   Symbol*  field_name = fd->name();
 850   oop name_oop = StringTable::intern(field_name, CHECK_NULL);
 851   Handle name = Handle(THREAD, name_oop);
 852   Symbol*  signature  = fd->signature();
 853   InstanceKlass* holder = fd->field_holder();
 854   Handle type = new_type(signature, holder, CHECK_NULL);
 855   Handle rh  = java_lang_reflect_Field::create(CHECK_NULL);
 856 
 857   java_lang_reflect_Field::set_clazz(rh(), fd->field_holder()->java_mirror());
 858   java_lang_reflect_Field::set_slot(rh(), fd->index());
 859   java_lang_reflect_Field::set_name(rh(), name());
 860   java_lang_reflect_Field::set_type(rh(), type());
 861 
 862   int flags = 0;
 863   if (fd->is_trusted_final()) {
 864     flags |= TRUSTED_FINAL;
 865   }
 866   if (fd->is_null_free_inline_type()) {
 867     flags |= NULL_RESTRICTED;
 868   }
 869   java_lang_reflect_Field::set_flags(rh(), flags);
 870 
 871   // Note the ACC_ANNOTATION bit, which is a per-class access flag, is never set here.
 872   int modifiers = fd->access_flags().as_int();
 873   java_lang_reflect_Field::set_modifiers(rh(), modifiers);
 874   java_lang_reflect_Field::set_override(rh(), false);
 875   if (fd->has_generic_signature()) {
 876     Symbol*  gs = fd->generic_signature();
 877     Handle sig = java_lang_String::create_from_symbol(gs, CHECK_NULL);
 878     java_lang_reflect_Field::set_signature(rh(), sig());
 879   }
 880   typeArrayOop an_oop = Annotations::make_java_array(fd->annotations(), CHECK_NULL);
 881   java_lang_reflect_Field::set_annotations(rh(), an_oop);
 882   return rh();
 883 }
 884 
 885 oop Reflection::new_parameter(Handle method, int index, Symbol* sym,
 886                               int flags, TRAPS) {
 887 
 888   Handle rh = java_lang_reflect_Parameter::create(CHECK_NULL);
 889 
 890   if(nullptr != sym) {
 891     Handle name = java_lang_String::create_from_symbol(sym, CHECK_NULL);
 892     java_lang_reflect_Parameter::set_name(rh(), name());
 893   } else {

 969   // Ensure klass is initialized
 970   klass->initialize(CHECK_NULL);
 971 
 972   bool is_static = reflected_method->is_static();
 973   if (is_static) {
 974     // ignore receiver argument
 975     method = reflected_method;
 976     target_klass = klass;
 977   } else {
 978     // check for null receiver
 979     if (receiver.is_null()) {
 980       THROW_NULL(vmSymbols::java_lang_NullPointerException());
 981     }
 982     // Check class of receiver against class declaring method
 983     if (!receiver->is_a(klass)) {
 984       THROW_MSG_NULL(vmSymbols::java_lang_IllegalArgumentException(), "object is not an instance of declaring class");
 985     }
 986     // target klass is receiver's klass
 987     target_klass = receiver->klass();
 988     // no need to resolve if method is private or <init>
 989     if (reflected_method->is_private() ||
 990         reflected_method->name() == vmSymbols::object_initializer_name()) {
 991       method = reflected_method;
 992     } else {
 993       // resolve based on the receiver
 994       if (reflected_method->method_holder()->is_interface()) {
 995         // resolve interface call
 996         //
 997         // Match resolution errors with those thrown due to reflection inlining
 998         // Linktime resolution & IllegalAccessCheck already done by Class.getMethod()
 999         method = resolve_interface_call(klass, reflected_method, target_klass, receiver, THREAD);
1000         if (HAS_PENDING_EXCEPTION) {
1001           // Method resolution threw an exception; wrap it in an InvocationTargetException
1002           oop resolution_exception = PENDING_EXCEPTION;
1003           CLEAR_PENDING_EXCEPTION;
1004           // JVMTI has already reported the pending exception
1005           // JVMTI internal flag reset is needed in order to report InvocationTargetException
1006           JvmtiExport::clear_detected_exception(THREAD);
1007           JavaCallArguments args(Handle(THREAD, resolution_exception));
1008           THROW_ARG_NULL(vmSymbols::java_lang_reflect_InvocationTargetException(),
1009                          vmSymbols::throwable_void_signature(),
1010                          &args);

1152     THROW_MSG_NULL(vmSymbols::java_lang_InternalError(), "invoke");
1153   }
1154   methodHandle method(THREAD, m);
1155 
1156   return invoke(klass, method, receiver, override, ptypes, rtype, args, true, THREAD);
1157 }
1158 
1159 
1160 oop Reflection::invoke_constructor(oop constructor_mirror, objArrayHandle args, TRAPS) {
1161   oop mirror             = java_lang_reflect_Constructor::clazz(constructor_mirror);
1162   int slot               = java_lang_reflect_Constructor::slot(constructor_mirror);
1163   bool override          = java_lang_reflect_Constructor::override(constructor_mirror) != 0;
1164   objArrayHandle ptypes(THREAD, objArrayOop(java_lang_reflect_Constructor::parameter_types(constructor_mirror)));
1165 
1166   InstanceKlass* klass = InstanceKlass::cast(java_lang_Class::as_Klass(mirror));
1167   Method* m = klass->method_with_idnum(slot);
1168   if (m == nullptr) {
1169     THROW_MSG_NULL(vmSymbols::java_lang_InternalError(), "invoke");
1170   }
1171   methodHandle method(THREAD, m);

1172 
1173   // Make sure klass gets initialize
1174   klass->initialize(CHECK_NULL);
1175 
1176   // Create new instance (the receiver)
1177   klass->check_valid_for_instantiation(false, CHECK_NULL);
1178   Handle receiver = klass->allocate_instance_handle(CHECK_NULL);
1179 
1180   // Ignore result from call and return receiver
1181   invoke(klass, method, receiver, override, ptypes, T_VOID, args, false, CHECK_NULL);
1182   return receiver();
1183 }
< prev index next >