< prev index next >

src/hotspot/share/runtime/reflection.cpp

Print this page
rev 55090 : secret-sfac


 826   if (type != T_OBJECT && type != T_VALUETYPE) {
 827     return Handle(THREAD, Universe::java_mirror(type));
 828   }
 829 
 830   Klass* result =
 831     SystemDictionary::resolve_or_fail(signature,
 832                                       Handle(THREAD, k->class_loader()),
 833                                       Handle(THREAD, k->protection_domain()),
 834                                       true, CHECK_(Handle()));
 835 
 836   if (log_is_enabled(Debug, class, resolve)) {
 837     trace_class_resolution(result);
 838   }
 839   oop nt = java_mirror(result, type == T_VALUETYPE);
 840   return Handle(THREAD, nt);
 841 }
 842 
 843 
 844 oop Reflection::new_method(const methodHandle& method, bool for_constant_pool_access, TRAPS) {
 845   // Allow sun.reflect.ConstantPool to refer to <clinit> methods as java.lang.reflect.Methods.
 846   assert(!method()->is_initializer() ||
 847          (for_constant_pool_access && method()->is_static()),
 848          "should call new_constructor instead");
 849   InstanceKlass* holder = method->method_holder();
 850   int slot = method->method_idnum();
 851 
 852   Symbol*  signature  = method->signature();
 853   int parameter_count = ArgumentCount(signature).size();
 854   oop return_type_oop = NULL;
 855   objArrayHandle parameter_types = get_parameter_types(method, parameter_count, &return_type_oop, CHECK_NULL);
 856   if (parameter_types.is_null() || return_type_oop == NULL) return NULL;
 857 
 858   Handle return_type(THREAD, return_type_oop);
 859 
 860   objArrayHandle exception_types = get_exception_types(method, CHECK_NULL);
 861 
 862   if (exception_types.is_null()) return NULL;
 863 
 864   Symbol*  method_name = method->name();
 865   oop name_oop = StringTable::intern(method_name, CHECK_NULL);
 866   Handle name = Handle(THREAD, name_oop);
 867   if (name == NULL) return NULL;


 877   java_lang_reflect_Method::set_parameter_types(mh(), parameter_types());
 878   java_lang_reflect_Method::set_exception_types(mh(), exception_types());
 879   java_lang_reflect_Method::set_modifiers(mh(), modifiers);
 880   java_lang_reflect_Method::set_override(mh(), false);
 881   if (method->generic_signature() != NULL) {
 882     Symbol*  gs = method->generic_signature();
 883     Handle sig = java_lang_String::create_from_symbol(gs, CHECK_NULL);
 884     java_lang_reflect_Method::set_signature(mh(), sig());
 885   }
 886   typeArrayOop an_oop = Annotations::make_java_array(method->annotations(), CHECK_NULL);
 887   java_lang_reflect_Method::set_annotations(mh(), an_oop);
 888   an_oop = Annotations::make_java_array(method->parameter_annotations(), CHECK_NULL);
 889   java_lang_reflect_Method::set_parameter_annotations(mh(), an_oop);
 890   an_oop = Annotations::make_java_array(method->annotation_default(), CHECK_NULL);
 891   java_lang_reflect_Method::set_annotation_default(mh(), an_oop);
 892   return mh();
 893 }
 894 
 895 
 896 oop Reflection::new_constructor(const methodHandle& method, TRAPS) {
 897   assert(method()->is_initializer(), "should call new_method instead");


 898 
 899   InstanceKlass* holder = method->method_holder();
 900   int slot = method->method_idnum();
 901 
 902   Symbol*  signature  = method->signature();
 903   int parameter_count = ArgumentCount(signature).size();
 904   objArrayHandle parameter_types = get_parameter_types(method, parameter_count, NULL, CHECK_NULL);
 905   if (parameter_types.is_null()) return NULL;
 906 
 907   objArrayHandle exception_types = get_exception_types(method, CHECK_NULL);
 908   if (exception_types.is_null()) return NULL;
 909 
 910   const int modifiers = method->access_flags().as_int() & JVM_RECOGNIZED_METHOD_MODIFIERS;
 911 
 912   Handle ch = java_lang_reflect_Constructor::create(CHECK_NULL);
 913 
 914   java_lang_reflect_Constructor::set_clazz(ch(), holder->java_mirror());
 915   java_lang_reflect_Constructor::set_slot(ch(), slot);
 916   java_lang_reflect_Constructor::set_parameter_types(ch(), parameter_types());
 917   java_lang_reflect_Constructor::set_exception_types(ch(), exception_types());


1245 
1246 oop Reflection::invoke_constructor(oop constructor_mirror, objArrayHandle args, TRAPS) {
1247   oop mirror             = java_lang_reflect_Constructor::clazz(constructor_mirror);
1248   int slot               = java_lang_reflect_Constructor::slot(constructor_mirror);
1249   bool override          = java_lang_reflect_Constructor::override(constructor_mirror) != 0;
1250   objArrayHandle ptypes(THREAD, objArrayOop(java_lang_reflect_Constructor::parameter_types(constructor_mirror)));
1251 
1252   InstanceKlass* klass = InstanceKlass::cast(java_lang_Class::as_Klass(mirror));
1253   Method* m = klass->method_with_idnum(slot);
1254   if (m == NULL) {
1255     THROW_MSG_0(vmSymbols::java_lang_InternalError(), "invoke");
1256   }
1257   methodHandle method(THREAD, m);
1258   assert(method->name() == vmSymbols::object_initializer_name(), "invalid constructor");
1259 
1260   // Make sure klass gets initialize
1261   klass->initialize(CHECK_NULL);
1262 
1263   // Create new instance (the receiver)
1264   klass->check_valid_for_instantiation(false, CHECK_NULL);










1265   Handle receiver = klass->allocate_instance_handle(CHECK_NULL);
1266 
1267   // Ignore result from call and return receiver
1268   invoke(klass, method, receiver, override, ptypes, T_VOID, args, false, CHECK_NULL);
1269   return receiver();
1270 }


 826   if (type != T_OBJECT && type != T_VALUETYPE) {
 827     return Handle(THREAD, Universe::java_mirror(type));
 828   }
 829 
 830   Klass* result =
 831     SystemDictionary::resolve_or_fail(signature,
 832                                       Handle(THREAD, k->class_loader()),
 833                                       Handle(THREAD, k->protection_domain()),
 834                                       true, CHECK_(Handle()));
 835 
 836   if (log_is_enabled(Debug, class, resolve)) {
 837     trace_class_resolution(result);
 838   }
 839   oop nt = java_mirror(result, type == T_VALUETYPE);
 840   return Handle(THREAD, nt);
 841 }
 842 
 843 
 844 oop Reflection::new_method(const methodHandle& method, bool for_constant_pool_access, TRAPS) {
 845   // Allow sun.reflect.ConstantPool to refer to <clinit> methods as java.lang.reflect.Methods.
 846   assert(!method()->name()->starts_with('<') || for_constant_pool_access,

 847          "should call new_constructor instead");
 848   InstanceKlass* holder = method->method_holder();
 849   int slot = method->method_idnum();
 850 
 851   Symbol*  signature  = method->signature();
 852   int parameter_count = ArgumentCount(signature).size();
 853   oop return_type_oop = NULL;
 854   objArrayHandle parameter_types = get_parameter_types(method, parameter_count, &return_type_oop, CHECK_NULL);
 855   if (parameter_types.is_null() || return_type_oop == NULL) return NULL;
 856 
 857   Handle return_type(THREAD, return_type_oop);
 858 
 859   objArrayHandle exception_types = get_exception_types(method, CHECK_NULL);
 860 
 861   if (exception_types.is_null()) return NULL;
 862 
 863   Symbol*  method_name = method->name();
 864   oop name_oop = StringTable::intern(method_name, CHECK_NULL);
 865   Handle name = Handle(THREAD, name_oop);
 866   if (name == NULL) return NULL;


 876   java_lang_reflect_Method::set_parameter_types(mh(), parameter_types());
 877   java_lang_reflect_Method::set_exception_types(mh(), exception_types());
 878   java_lang_reflect_Method::set_modifiers(mh(), modifiers);
 879   java_lang_reflect_Method::set_override(mh(), false);
 880   if (method->generic_signature() != NULL) {
 881     Symbol*  gs = method->generic_signature();
 882     Handle sig = java_lang_String::create_from_symbol(gs, CHECK_NULL);
 883     java_lang_reflect_Method::set_signature(mh(), sig());
 884   }
 885   typeArrayOop an_oop = Annotations::make_java_array(method->annotations(), CHECK_NULL);
 886   java_lang_reflect_Method::set_annotations(mh(), an_oop);
 887   an_oop = Annotations::make_java_array(method->parameter_annotations(), CHECK_NULL);
 888   java_lang_reflect_Method::set_parameter_annotations(mh(), an_oop);
 889   an_oop = Annotations::make_java_array(method->annotation_default(), CHECK_NULL);
 890   java_lang_reflect_Method::set_annotation_default(mh(), an_oop);
 891   return mh();
 892 }
 893 
 894 
 895 oop Reflection::new_constructor(const methodHandle& method, TRAPS) {
 896   assert(method()->is_object_constructor() ||
 897          method()->is_static_init_factory(),
 898          "should call new_method instead");
 899 
 900   InstanceKlass* holder = method->method_holder();
 901   int slot = method->method_idnum();
 902 
 903   Symbol*  signature  = method->signature();
 904   int parameter_count = ArgumentCount(signature).size();
 905   objArrayHandle parameter_types = get_parameter_types(method, parameter_count, NULL, CHECK_NULL);
 906   if (parameter_types.is_null()) return NULL;
 907 
 908   objArrayHandle exception_types = get_exception_types(method, CHECK_NULL);
 909   if (exception_types.is_null()) return NULL;
 910 
 911   const int modifiers = method->access_flags().as_int() & JVM_RECOGNIZED_METHOD_MODIFIERS;
 912 
 913   Handle ch = java_lang_reflect_Constructor::create(CHECK_NULL);
 914 
 915   java_lang_reflect_Constructor::set_clazz(ch(), holder->java_mirror());
 916   java_lang_reflect_Constructor::set_slot(ch(), slot);
 917   java_lang_reflect_Constructor::set_parameter_types(ch(), parameter_types());
 918   java_lang_reflect_Constructor::set_exception_types(ch(), exception_types());


1246 
1247 oop Reflection::invoke_constructor(oop constructor_mirror, objArrayHandle args, TRAPS) {
1248   oop mirror             = java_lang_reflect_Constructor::clazz(constructor_mirror);
1249   int slot               = java_lang_reflect_Constructor::slot(constructor_mirror);
1250   bool override          = java_lang_reflect_Constructor::override(constructor_mirror) != 0;
1251   objArrayHandle ptypes(THREAD, objArrayOop(java_lang_reflect_Constructor::parameter_types(constructor_mirror)));
1252 
1253   InstanceKlass* klass = InstanceKlass::cast(java_lang_Class::as_Klass(mirror));
1254   Method* m = klass->method_with_idnum(slot);
1255   if (m == NULL) {
1256     THROW_MSG_0(vmSymbols::java_lang_InternalError(), "invoke");
1257   }
1258   methodHandle method(THREAD, m);
1259   assert(method->name() == vmSymbols::object_initializer_name(), "invalid constructor");
1260 
1261   // Make sure klass gets initialize
1262   klass->initialize(CHECK_NULL);
1263 
1264   // Create new instance (the receiver)
1265   klass->check_valid_for_instantiation(false, CHECK_NULL);
1266 
1267   // Special case for factory methods
1268   if (!method->signature()->is_void_method_signature()) {
1269     assert(klass->is_value(), "inline classes must use factory methods");
1270     Handle no_receiver; // null instead of receiver
1271     return invoke(klass, method, no_receiver, override, ptypes, T_OBJECT, args, false, CHECK_NULL);
1272   }
1273 
1274   // main branch of code creates a non-inline object:
1275   assert(!klass->is_value(), "classic constructors are only for non-inline classes");
1276   Handle receiver = klass->allocate_instance_handle(CHECK_NULL);
1277 
1278   // Ignore result from call and return receiver
1279   invoke(klass, method, receiver, override, ptypes, T_VOID, args, false, CHECK_NULL);
1280   return receiver();
1281 }
< prev index next >