< 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;

 748     }
 749     if (!ss.at_return_type()) {
 750       mirrors->obj_at_put(index++, mirror);
 751     } else if (return_type != nullptr) {
 752       // Collect return type as well
 753       assert(ss.at_return_type(), "return type should be present");
 754       *return_type = mirror;
 755     }
 756   }
 757   assert(index == parameter_count, "invalid parameter count");
 758   return mirrors;
 759 }
 760 
 761 static objArrayHandle get_exception_types(const methodHandle& method, TRAPS) {
 762   return method->resolved_checked_exceptions(THREAD);
 763 }
 764 
 765 static Handle new_type(Symbol* signature, Klass* k, TRAPS) {
 766   ResolvingSignatureStream ss(signature, k, false);
 767   oop nt = ss.as_java_mirror(SignatureStream::NCDFError, CHECK_NH);
 768   if (log_is_enabled(Debug, class, resolve)) {
 769     trace_class_resolution(nt);
 770   }
 771   return Handle(THREAD, nt);
 772 }
 773 
 774 oop Reflection::new_method(const methodHandle& method, bool for_constant_pool_access, TRAPS) {
 775   // Allow sun.reflect.ConstantPool to refer to <clinit> methods as java.lang.reflect.Methods.
 776   assert(!method()->is_initializer() ||
 777          (for_constant_pool_access && method()->is_static()),
 778          "should call new_constructor instead");
 779   InstanceKlass* holder = method->method_holder();
 780   int slot = method->method_idnum();
 781 
 782   Symbol*  signature  = method->signature();
 783   int parameter_count = ArgumentCount(signature).size();
 784   oop return_type_oop = nullptr;
 785   objArrayHandle parameter_types = get_parameter_types(method, parameter_count, &return_type_oop, CHECK_NULL);
 786   if (parameter_types.is_null() || return_type_oop == nullptr) return nullptr;
 787 
 788   Handle return_type(THREAD, return_type_oop);
 789 
 790   objArrayHandle exception_types = get_exception_types(method, CHECK_NULL);
 791   assert(!exception_types.is_null(), "cannot return null");
 792 
 793   Symbol*  method_name = method->name();
 794   oop name_oop = StringTable::intern(method_name, CHECK_NULL);
 795   Handle name = Handle(THREAD, name_oop);
 796   if (name == nullptr) return nullptr;
 797 

 806   java_lang_reflect_Method::set_parameter_types(mh(), parameter_types());
 807   java_lang_reflect_Method::set_exception_types(mh(), exception_types());
 808   java_lang_reflect_Method::set_modifiers(mh(), modifiers);
 809   java_lang_reflect_Method::set_override(mh(), false);
 810   if (method->generic_signature() != nullptr) {
 811     Symbol*  gs = method->generic_signature();
 812     Handle sig = java_lang_String::create_from_symbol(gs, CHECK_NULL);
 813     java_lang_reflect_Method::set_signature(mh(), sig());
 814   }
 815   typeArrayOop an_oop = Annotations::make_java_array(method->annotations(), CHECK_NULL);
 816   java_lang_reflect_Method::set_annotations(mh(), an_oop);
 817   an_oop = Annotations::make_java_array(method->parameter_annotations(), CHECK_NULL);
 818   java_lang_reflect_Method::set_parameter_annotations(mh(), an_oop);
 819   an_oop = Annotations::make_java_array(method->annotation_default(), CHECK_NULL);
 820   java_lang_reflect_Method::set_annotation_default(mh(), an_oop);
 821   return mh();
 822 }
 823 
 824 
 825 oop Reflection::new_constructor(const methodHandle& method, TRAPS) {
 826   assert(method()->is_initializer(), "should call new_method instead");

 827 
 828   InstanceKlass* holder = method->method_holder();
 829   int slot = method->method_idnum();
 830 
 831   Symbol*  signature  = method->signature();
 832   int parameter_count = ArgumentCount(signature).size();
 833   objArrayHandle parameter_types = get_parameter_types(method, parameter_count, nullptr, CHECK_NULL);
 834   if (parameter_types.is_null()) return nullptr;
 835 
 836   objArrayHandle exception_types = get_exception_types(method, CHECK_NULL);
 837   assert(!exception_types.is_null(), "cannot return null");
 838 
 839   const int modifiers = method->access_flags().as_int() & JVM_RECOGNIZED_METHOD_MODIFIERS;
 840 
 841   Handle ch = java_lang_reflect_Constructor::create(CHECK_NULL);
 842 
 843   java_lang_reflect_Constructor::set_clazz(ch(), holder->java_mirror());
 844   java_lang_reflect_Constructor::set_slot(ch(), slot);
 845   java_lang_reflect_Constructor::set_parameter_types(ch(), parameter_types());
 846   java_lang_reflect_Constructor::set_exception_types(ch(), exception_types());

 855   java_lang_reflect_Constructor::set_annotations(ch(), an_oop);
 856   an_oop = Annotations::make_java_array(method->parameter_annotations(), CHECK_NULL);
 857   java_lang_reflect_Constructor::set_parameter_annotations(ch(), an_oop);
 858   return ch();
 859 }
 860 
 861 
 862 oop Reflection::new_field(fieldDescriptor* fd, TRAPS) {
 863   Symbol*  field_name = fd->name();
 864   oop name_oop = StringTable::intern(field_name, CHECK_NULL);
 865   Handle name = Handle(THREAD, name_oop);
 866   Symbol*  signature  = fd->signature();
 867   InstanceKlass* holder = fd->field_holder();
 868   Handle type = new_type(signature, holder, CHECK_NULL);
 869   Handle rh  = java_lang_reflect_Field::create(CHECK_NULL);
 870 
 871   java_lang_reflect_Field::set_clazz(rh(), fd->field_holder()->java_mirror());
 872   java_lang_reflect_Field::set_slot(rh(), fd->index());
 873   java_lang_reflect_Field::set_name(rh(), name());
 874   java_lang_reflect_Field::set_type(rh(), type());


 875   if (fd->is_trusted_final()) {
 876     java_lang_reflect_Field::set_trusted_final(rh());



 877   }


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

 880   java_lang_reflect_Field::set_override(rh(), false);
 881   if (fd->has_generic_signature()) {
 882     Symbol*  gs = fd->generic_signature();
 883     Handle sig = java_lang_String::create_from_symbol(gs, CHECK_NULL);
 884     java_lang_reflect_Field::set_signature(rh(), sig());
 885   }
 886   typeArrayOop an_oop = Annotations::make_java_array(fd->annotations(), CHECK_NULL);
 887   java_lang_reflect_Field::set_annotations(rh(), an_oop);
 888   return rh();
 889 }
 890 
 891 oop Reflection::new_parameter(Handle method, int index, Symbol* sym,
 892                               int flags, TRAPS) {
 893 
 894   Handle rh = java_lang_reflect_Parameter::create(CHECK_NULL);
 895 
 896   if(nullptr != sym) {
 897     Handle name = java_lang_String::create_from_symbol(sym, CHECK_NULL);
 898     java_lang_reflect_Parameter::set_name(rh(), name());
 899   } else {

 975   // Ensure klass is initialized
 976   klass->initialize(CHECK_NULL);
 977 
 978   bool is_static = reflected_method->is_static();
 979   if (is_static) {
 980     // ignore receiver argument
 981     method = reflected_method;
 982     target_klass = klass;
 983   } else {
 984     // check for null receiver
 985     if (receiver.is_null()) {
 986       THROW_0(vmSymbols::java_lang_NullPointerException());
 987     }
 988     // Check class of receiver against class declaring method
 989     if (!receiver->is_a(klass)) {
 990       THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "object is not an instance of declaring class");
 991     }
 992     // target klass is receiver's klass
 993     target_klass = receiver->klass();
 994     // no need to resolve if method is private or <init>
 995     if (reflected_method->is_private() || reflected_method->name() == vmSymbols::object_initializer_name()) {

 996       method = reflected_method;
 997     } else {
 998       // resolve based on the receiver
 999       if (reflected_method->method_holder()->is_interface()) {
1000         // resolve interface call
1001         //
1002         // Match resolution errors with those thrown due to reflection inlining
1003         // Linktime resolution & IllegalAccessCheck already done by Class.getMethod()
1004         method = resolve_interface_call(klass, reflected_method, target_klass, receiver, THREAD);
1005         if (HAS_PENDING_EXCEPTION) {
1006           // Method resolution threw an exception; wrap it in an InvocationTargetException
1007           oop resolution_exception = PENDING_EXCEPTION;
1008           CLEAR_PENDING_EXCEPTION;
1009           // JVMTI has already reported the pending exception
1010           // JVMTI internal flag reset is needed in order to report InvocationTargetException
1011           JvmtiExport::clear_detected_exception(THREAD);
1012           JavaCallArguments args(Handle(THREAD, resolution_exception));
1013           THROW_ARG_0(vmSymbols::java_lang_reflect_InvocationTargetException(),
1014                       vmSymbols::throwable_void_signature(),
1015                       &args);

1157     THROW_MSG_0(vmSymbols::java_lang_InternalError(), "invoke");
1158   }
1159   methodHandle method(THREAD, m);
1160 
1161   return invoke(klass, method, receiver, override, ptypes, rtype, args, true, THREAD);
1162 }
1163 
1164 
1165 oop Reflection::invoke_constructor(oop constructor_mirror, objArrayHandle args, TRAPS) {
1166   oop mirror             = java_lang_reflect_Constructor::clazz(constructor_mirror);
1167   int slot               = java_lang_reflect_Constructor::slot(constructor_mirror);
1168   bool override          = java_lang_reflect_Constructor::override(constructor_mirror) != 0;
1169   objArrayHandle ptypes(THREAD, objArrayOop(java_lang_reflect_Constructor::parameter_types(constructor_mirror)));
1170 
1171   InstanceKlass* klass = InstanceKlass::cast(java_lang_Class::as_Klass(mirror));
1172   Method* m = klass->method_with_idnum(slot);
1173   if (m == nullptr) {
1174     THROW_MSG_0(vmSymbols::java_lang_InternalError(), "invoke");
1175   }
1176   methodHandle method(THREAD, m);
1177   assert(method->name() == vmSymbols::object_initializer_name(), "invalid constructor");
1178 
1179   // Make sure klass gets initialize
1180   klass->initialize(CHECK_NULL);
1181 
1182   // Create new instance (the receiver)
1183   klass->check_valid_for_instantiation(false, CHECK_NULL);
1184   Handle receiver = klass->allocate_instance_handle(CHECK_NULL);
1185 
1186   // Ignore result from call and return receiver
1187   invoke(klass, method, receiver, override, ptypes, T_VOID, args, false, CHECK_NULL);
1188   return receiver();
1189 }

  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;

 755     }
 756     if (!ss.at_return_type()) {
 757       mirrors->obj_at_put(index++, mirror);
 758     } else if (return_type != nullptr) {
 759       // Collect return type as well
 760       assert(ss.at_return_type(), "return type should be present");
 761       *return_type = mirror;
 762     }
 763   }
 764   assert(index == parameter_count, "invalid parameter count");
 765   return mirrors;
 766 }
 767 
 768 static objArrayHandle get_exception_types(const methodHandle& method, TRAPS) {
 769   return method->resolved_checked_exceptions(THREAD);
 770 }
 771 
 772 static Handle new_type(Symbol* signature, Klass* k, TRAPS) {
 773   ResolvingSignatureStream ss(signature, k, false);
 774   oop nt = ss.as_java_mirror(SignatureStream::NCDFError, CHECK_NH);



 775   return Handle(THREAD, nt);
 776 }
 777 
 778 oop Reflection::new_method(const methodHandle& method, bool for_constant_pool_access, TRAPS) {
 779   // Allow sun.reflect.ConstantPool to refer to <clinit> methods as java.lang.reflect.Methods.
 780   assert(!method()->name()->starts_with('<') || for_constant_pool_access,

 781          "should call new_constructor instead");
 782   InstanceKlass* holder = method->method_holder();
 783   int slot = method->method_idnum();
 784 
 785   Symbol*  signature  = method->signature();
 786   int parameter_count = ArgumentCount(signature).size();
 787   oop return_type_oop = nullptr;
 788   objArrayHandle parameter_types = get_parameter_types(method, parameter_count, &return_type_oop, CHECK_NULL);
 789   if (parameter_types.is_null() || return_type_oop == nullptr) return nullptr;
 790 
 791   Handle return_type(THREAD, return_type_oop);
 792 
 793   objArrayHandle exception_types = get_exception_types(method, CHECK_NULL);
 794   assert(!exception_types.is_null(), "cannot return null");
 795 
 796   Symbol*  method_name = method->name();
 797   oop name_oop = StringTable::intern(method_name, CHECK_NULL);
 798   Handle name = Handle(THREAD, name_oop);
 799   if (name == nullptr) return nullptr;
 800 

 809   java_lang_reflect_Method::set_parameter_types(mh(), parameter_types());
 810   java_lang_reflect_Method::set_exception_types(mh(), exception_types());
 811   java_lang_reflect_Method::set_modifiers(mh(), modifiers);
 812   java_lang_reflect_Method::set_override(mh(), false);
 813   if (method->generic_signature() != nullptr) {
 814     Symbol*  gs = method->generic_signature();
 815     Handle sig = java_lang_String::create_from_symbol(gs, CHECK_NULL);
 816     java_lang_reflect_Method::set_signature(mh(), sig());
 817   }
 818   typeArrayOop an_oop = Annotations::make_java_array(method->annotations(), CHECK_NULL);
 819   java_lang_reflect_Method::set_annotations(mh(), an_oop);
 820   an_oop = Annotations::make_java_array(method->parameter_annotations(), CHECK_NULL);
 821   java_lang_reflect_Method::set_parameter_annotations(mh(), an_oop);
 822   an_oop = Annotations::make_java_array(method->annotation_default(), CHECK_NULL);
 823   java_lang_reflect_Method::set_annotation_default(mh(), an_oop);
 824   return mh();
 825 }
 826 
 827 
 828 oop Reflection::new_constructor(const methodHandle& method, TRAPS) {
 829   assert(method()->is_object_constructor(),
 830          "should call new_method instead");
 831 
 832   InstanceKlass* holder = method->method_holder();
 833   int slot = method->method_idnum();
 834 
 835   Symbol*  signature  = method->signature();
 836   int parameter_count = ArgumentCount(signature).size();
 837   objArrayHandle parameter_types = get_parameter_types(method, parameter_count, nullptr, CHECK_NULL);
 838   if (parameter_types.is_null()) return nullptr;
 839 
 840   objArrayHandle exception_types = get_exception_types(method, CHECK_NULL);
 841   assert(!exception_types.is_null(), "cannot return null");
 842 
 843   const int modifiers = method->access_flags().as_int() & JVM_RECOGNIZED_METHOD_MODIFIERS;
 844 
 845   Handle ch = java_lang_reflect_Constructor::create(CHECK_NULL);
 846 
 847   java_lang_reflect_Constructor::set_clazz(ch(), holder->java_mirror());
 848   java_lang_reflect_Constructor::set_slot(ch(), slot);
 849   java_lang_reflect_Constructor::set_parameter_types(ch(), parameter_types());
 850   java_lang_reflect_Constructor::set_exception_types(ch(), exception_types());

 859   java_lang_reflect_Constructor::set_annotations(ch(), an_oop);
 860   an_oop = Annotations::make_java_array(method->parameter_annotations(), CHECK_NULL);
 861   java_lang_reflect_Constructor::set_parameter_annotations(ch(), an_oop);
 862   return ch();
 863 }
 864 
 865 
 866 oop Reflection::new_field(fieldDescriptor* fd, TRAPS) {
 867   Symbol*  field_name = fd->name();
 868   oop name_oop = StringTable::intern(field_name, CHECK_NULL);
 869   Handle name = Handle(THREAD, name_oop);
 870   Symbol*  signature  = fd->signature();
 871   InstanceKlass* holder = fd->field_holder();
 872   Handle type = new_type(signature, holder, CHECK_NULL);
 873   Handle rh  = java_lang_reflect_Field::create(CHECK_NULL);
 874 
 875   java_lang_reflect_Field::set_clazz(rh(), fd->field_holder()->java_mirror());
 876   java_lang_reflect_Field::set_slot(rh(), fd->index());
 877   java_lang_reflect_Field::set_name(rh(), name());
 878   java_lang_reflect_Field::set_type(rh(), type());
 879 
 880   int flags = 0;
 881   if (fd->is_trusted_final()) {
 882     flags |= TRUSTED_FINAL;
 883   }
 884   if (fd->is_null_free_inline_type()) {
 885     flags |= NULL_RESTRICTED;
 886   }
 887   java_lang_reflect_Field::set_flags(rh(), flags);
 888 
 889   // Note the ACC_ANNOTATION bit, which is a per-class access flag, is never set here.
 890   int modifiers = fd->access_flags().as_int();
 891   java_lang_reflect_Field::set_modifiers(rh(), modifiers);
 892   java_lang_reflect_Field::set_override(rh(), false);
 893   if (fd->has_generic_signature()) {
 894     Symbol*  gs = fd->generic_signature();
 895     Handle sig = java_lang_String::create_from_symbol(gs, CHECK_NULL);
 896     java_lang_reflect_Field::set_signature(rh(), sig());
 897   }
 898   typeArrayOop an_oop = Annotations::make_java_array(fd->annotations(), CHECK_NULL);
 899   java_lang_reflect_Field::set_annotations(rh(), an_oop);
 900   return rh();
 901 }
 902 
 903 oop Reflection::new_parameter(Handle method, int index, Symbol* sym,
 904                               int flags, TRAPS) {
 905 
 906   Handle rh = java_lang_reflect_Parameter::create(CHECK_NULL);
 907 
 908   if(nullptr != sym) {
 909     Handle name = java_lang_String::create_from_symbol(sym, CHECK_NULL);
 910     java_lang_reflect_Parameter::set_name(rh(), name());
 911   } else {

 987   // Ensure klass is initialized
 988   klass->initialize(CHECK_NULL);
 989 
 990   bool is_static = reflected_method->is_static();
 991   if (is_static) {
 992     // ignore receiver argument
 993     method = reflected_method;
 994     target_klass = klass;
 995   } else {
 996     // check for null receiver
 997     if (receiver.is_null()) {
 998       THROW_0(vmSymbols::java_lang_NullPointerException());
 999     }
1000     // Check class of receiver against class declaring method
1001     if (!receiver->is_a(klass)) {
1002       THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "object is not an instance of declaring class");
1003     }
1004     // target klass is receiver's klass
1005     target_klass = receiver->klass();
1006     // no need to resolve if method is private or <init>
1007     if (reflected_method->is_private() ||
1008         reflected_method->name() == vmSymbols::object_initializer_name()) {
1009       method = reflected_method;
1010     } else {
1011       // resolve based on the receiver
1012       if (reflected_method->method_holder()->is_interface()) {
1013         // resolve interface call
1014         //
1015         // Match resolution errors with those thrown due to reflection inlining
1016         // Linktime resolution & IllegalAccessCheck already done by Class.getMethod()
1017         method = resolve_interface_call(klass, reflected_method, target_klass, receiver, THREAD);
1018         if (HAS_PENDING_EXCEPTION) {
1019           // Method resolution threw an exception; wrap it in an InvocationTargetException
1020           oop resolution_exception = PENDING_EXCEPTION;
1021           CLEAR_PENDING_EXCEPTION;
1022           // JVMTI has already reported the pending exception
1023           // JVMTI internal flag reset is needed in order to report InvocationTargetException
1024           JvmtiExport::clear_detected_exception(THREAD);
1025           JavaCallArguments args(Handle(THREAD, resolution_exception));
1026           THROW_ARG_0(vmSymbols::java_lang_reflect_InvocationTargetException(),
1027                       vmSymbols::throwable_void_signature(),
1028                       &args);

1170     THROW_MSG_0(vmSymbols::java_lang_InternalError(), "invoke");
1171   }
1172   methodHandle method(THREAD, m);
1173 
1174   return invoke(klass, method, receiver, override, ptypes, rtype, args, true, THREAD);
1175 }
1176 
1177 
1178 oop Reflection::invoke_constructor(oop constructor_mirror, objArrayHandle args, TRAPS) {
1179   oop mirror             = java_lang_reflect_Constructor::clazz(constructor_mirror);
1180   int slot               = java_lang_reflect_Constructor::slot(constructor_mirror);
1181   bool override          = java_lang_reflect_Constructor::override(constructor_mirror) != 0;
1182   objArrayHandle ptypes(THREAD, objArrayOop(java_lang_reflect_Constructor::parameter_types(constructor_mirror)));
1183 
1184   InstanceKlass* klass = InstanceKlass::cast(java_lang_Class::as_Klass(mirror));
1185   Method* m = klass->method_with_idnum(slot);
1186   if (m == nullptr) {
1187     THROW_MSG_0(vmSymbols::java_lang_InternalError(), "invoke");
1188   }
1189   methodHandle method(THREAD, m);

1190 
1191   // Make sure klass gets initialize
1192   klass->initialize(CHECK_NULL);
1193 
1194   // Create new instance (the receiver)
1195   klass->check_valid_for_instantiation(false, CHECK_NULL);
1196   Handle receiver = klass->allocate_instance_handle(CHECK_NULL);
1197 
1198   // Ignore result from call and return receiver
1199   invoke(klass, method, receiver, override, ptypes, T_VOID, args, false, CHECK_NULL);
1200   return receiver();
1201 }
< prev index next >