1 /* |
1 /* |
2 * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. |
7 * published by the Free Software Foundation. |
44 #include "runtime/signature.hpp" |
44 #include "runtime/signature.hpp" |
45 #include "runtime/vframe.hpp" |
45 #include "runtime/vframe.hpp" |
46 |
46 |
47 #define JAVA_1_5_VERSION 49 |
47 #define JAVA_1_5_VERSION 49 |
48 |
48 |
49 static void trace_class_resolution(klassOop to_class) { |
49 static void trace_class_resolution(Klass* to_class) { |
50 ResourceMark rm; |
50 ResourceMark rm; |
51 int line_number = -1; |
51 int line_number = -1; |
52 const char * source_file = NULL; |
52 const char * source_file = NULL; |
53 klassOop caller = NULL; |
53 Klass* caller = NULL; |
54 JavaThread* jthread = JavaThread::current(); |
54 JavaThread* jthread = JavaThread::current(); |
55 if (jthread->has_last_Java_frame()) { |
55 if (jthread->has_last_Java_frame()) { |
56 vframeStream vfst(jthread); |
56 vframeStream vfst(jthread); |
57 // skip over any frames belonging to java.lang.Class |
57 // skip over any frames belonging to java.lang.Class |
58 while (!vfst.at_end() && |
58 while (!vfst.at_end() && |
59 instanceKlass::cast(vfst.method()->method_holder())->name() == vmSymbols::java_lang_Class()) { |
59 InstanceKlass::cast(vfst.method()->method_holder())->name() == vmSymbols::java_lang_Class()) { |
60 vfst.next(); |
60 vfst.next(); |
61 } |
61 } |
62 if (!vfst.at_end()) { |
62 if (!vfst.at_end()) { |
63 // this frame is a likely suspect |
63 // this frame is a likely suspect |
64 caller = vfst.method()->method_holder(); |
64 caller = vfst.method()->method_holder(); |
65 line_number = vfst.method()->line_number_from_bci(vfst.bci()); |
65 line_number = vfst.method()->line_number_from_bci(vfst.bci()); |
66 Symbol* s = instanceKlass::cast(vfst.method()->method_holder())->source_file_name(); |
66 Symbol* s = InstanceKlass::cast(vfst.method()->method_holder())->source_file_name(); |
67 if (s != NULL) { |
67 if (s != NULL) { |
68 source_file = s->as_C_string(); |
68 source_file = s->as_C_string(); |
69 } |
69 } |
70 } |
70 } |
71 } |
71 } |
252 } |
252 } |
253 if (a->is_objArray()) { |
253 if (a->is_objArray()) { |
254 if (value_type == T_OBJECT) { |
254 if (value_type == T_OBJECT) { |
255 oop obj = (oop) value->l; |
255 oop obj = (oop) value->l; |
256 if (obj != NULL) { |
256 if (obj != NULL) { |
257 klassOop element_klass = objArrayKlass::cast(a->klass())->element_klass(); |
257 Klass* element_klass = objArrayKlass::cast(a->klass())->element_klass(); |
258 if (!obj->is_a(element_klass)) { |
258 if (!obj->is_a(element_klass)) { |
259 THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), "array element type mismatch"); |
259 THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), "array element type mismatch"); |
260 } |
260 } |
261 } |
261 } |
262 objArrayOop(a)->obj_at_put(index, obj); |
262 objArrayOop(a)->obj_at_put(index, obj); |
299 } |
299 } |
300 } |
300 } |
301 } |
301 } |
302 |
302 |
303 |
303 |
304 klassOop Reflection::basic_type_mirror_to_arrayklass(oop basic_type_mirror, TRAPS) { |
304 Klass* Reflection::basic_type_mirror_to_arrayklass(oop basic_type_mirror, TRAPS) { |
305 assert(java_lang_Class::is_primitive(basic_type_mirror), "just checking"); |
305 assert(java_lang_Class::is_primitive(basic_type_mirror), "just checking"); |
306 BasicType type = java_lang_Class::primitive_type(basic_type_mirror); |
306 BasicType type = java_lang_Class::primitive_type(basic_type_mirror); |
307 if (type == T_VOID) { |
307 if (type == T_VOID) { |
308 THROW_0(vmSymbols::java_lang_IllegalArgumentException()); |
308 THROW_0(vmSymbols::java_lang_IllegalArgumentException()); |
309 } else { |
309 } else { |
310 return Universe::typeArrayKlassObj(type); |
310 return Universe::typeArrayKlassObj(type); |
311 } |
311 } |
312 } |
312 } |
313 |
313 |
314 |
314 |
315 oop Reflection:: basic_type_arrayklass_to_mirror(klassOop basic_type_arrayklass, TRAPS) { |
315 oop Reflection:: basic_type_arrayklass_to_mirror(Klass* basic_type_arrayklass, TRAPS) { |
316 BasicType type = typeArrayKlass::cast(basic_type_arrayklass)->element_type(); |
316 BasicType type = typeArrayKlass::cast(basic_type_arrayklass)->element_type(); |
317 return Universe::java_mirror(type); |
317 return Universe::java_mirror(type); |
318 } |
318 } |
319 |
319 |
320 |
320 |
324 } |
324 } |
325 if (length < 0) { |
325 if (length < 0) { |
326 THROW_0(vmSymbols::java_lang_NegativeArraySizeException()); |
326 THROW_0(vmSymbols::java_lang_NegativeArraySizeException()); |
327 } |
327 } |
328 if (java_lang_Class::is_primitive(element_mirror)) { |
328 if (java_lang_Class::is_primitive(element_mirror)) { |
329 klassOop tak = basic_type_mirror_to_arrayklass(element_mirror, CHECK_NULL); |
329 Klass* tak = basic_type_mirror_to_arrayklass(element_mirror, CHECK_NULL); |
330 return typeArrayKlass::cast(tak)->allocate(length, THREAD); |
330 return typeArrayKlass::cast(tak)->allocate(length, THREAD); |
331 } else { |
331 } else { |
332 klassOop k = java_lang_Class::as_klassOop(element_mirror); |
332 Klass* k = java_lang_Class::as_Klass(element_mirror); |
333 if (Klass::cast(k)->oop_is_array() && arrayKlass::cast(k)->dimension() >= MAX_DIM) { |
333 if (Klass::cast(k)->oop_is_array() && arrayKlass::cast(k)->dimension() >= MAX_DIM) { |
334 THROW_0(vmSymbols::java_lang_IllegalArgumentException()); |
334 THROW_0(vmSymbols::java_lang_IllegalArgumentException()); |
335 } |
335 } |
336 return oopFactory::new_objArray(k, length, THREAD); |
336 return oopFactory::new_objArray(k, length, THREAD); |
337 } |
337 } |
358 THROW_0(vmSymbols::java_lang_NegativeArraySizeException()); |
358 THROW_0(vmSymbols::java_lang_NegativeArraySizeException()); |
359 } |
359 } |
360 dimensions[i] = d; |
360 dimensions[i] = d; |
361 } |
361 } |
362 |
362 |
363 klassOop klass; |
363 Klass* klass; |
364 int dim = len; |
364 int dim = len; |
365 if (java_lang_Class::is_primitive(element_mirror)) { |
365 if (java_lang_Class::is_primitive(element_mirror)) { |
366 klass = basic_type_mirror_to_arrayklass(element_mirror, CHECK_NULL); |
366 klass = basic_type_mirror_to_arrayklass(element_mirror, CHECK_NULL); |
367 } else { |
367 } else { |
368 klass = java_lang_Class::as_klassOop(element_mirror); |
368 klass = java_lang_Class::as_Klass(element_mirror); |
369 if (Klass::cast(klass)->oop_is_array()) { |
369 if (Klass::cast(klass)->oop_is_array()) { |
370 int k_dim = arrayKlass::cast(klass)->dimension(); |
370 int k_dim = arrayKlass::cast(klass)->dimension(); |
371 if (k_dim + len > MAX_DIM) { |
371 if (k_dim + len > MAX_DIM) { |
372 THROW_0(vmSymbols::java_lang_IllegalArgumentException()); |
372 THROW_0(vmSymbols::java_lang_IllegalArgumentException()); |
373 } |
373 } |
399 result2 = basic_type_arrayklass_to_mirror(klass, CHECK_NULL); |
399 result2 = basic_type_arrayklass_to_mirror(klass, CHECK_NULL); |
400 } else { |
400 } else { |
401 result2 = Klass::cast(objArrayKlass::cast(klass)->element_klass())->java_mirror(); |
401 result2 = Klass::cast(objArrayKlass::cast(klass)->element_klass())->java_mirror(); |
402 } |
402 } |
403 } else { |
403 } else { |
404 klassOop lower_dim = arrayKlass::cast(klass)->lower_dimension(); |
404 Klass* lower_dim = arrayKlass::cast(klass)->lower_dimension(); |
405 assert(Klass::cast(lower_dim)->oop_is_array(), "just checking"); |
405 assert(Klass::cast(lower_dim)->oop_is_array(), "just checking"); |
406 result2 = Klass::cast(lower_dim)->java_mirror(); |
406 result2 = Klass::cast(lower_dim)->java_mirror(); |
407 } |
407 } |
408 assert(result == result2, "results must be consistent"); |
408 assert(result == result2, "results must be consistent"); |
409 #endif //ASSERT |
409 #endif //ASSERT |
410 return result; |
410 return result; |
411 } |
411 } |
412 |
412 |
413 |
413 |
414 bool Reflection::reflect_check_access(klassOop field_class, AccessFlags acc, klassOop target_class, bool is_method_invoke, TRAPS) { |
414 bool Reflection::reflect_check_access(Klass* field_class, AccessFlags acc, Klass* target_class, bool is_method_invoke, TRAPS) { |
415 // field_class : declaring class |
415 // field_class : declaring class |
416 // acc : declared field access |
416 // acc : declared field access |
417 // target_class : for protected |
417 // target_class : for protected |
418 |
418 |
419 // Check if field or method is accessible to client. Throw an |
419 // Check if field or method is accessible to client. Throw an |
422 // The "client" is the class associated with the nearest real frame |
422 // The "client" is the class associated with the nearest real frame |
423 // getCallerClass already skips Method.invoke frames, so pass 0 in |
423 // getCallerClass already skips Method.invoke frames, so pass 0 in |
424 // that case (same as classic). |
424 // that case (same as classic). |
425 ResourceMark rm(THREAD); |
425 ResourceMark rm(THREAD); |
426 assert(THREAD->is_Java_thread(), "sanity check"); |
426 assert(THREAD->is_Java_thread(), "sanity check"); |
427 klassOop client_class = ((JavaThread *)THREAD)->security_get_caller_class(is_method_invoke ? 0 : 1); |
427 Klass* client_class = ((JavaThread *)THREAD)->security_get_caller_class(is_method_invoke ? 0 : 1); |
428 |
428 |
429 if (client_class != field_class) { |
429 if (client_class != field_class) { |
430 if (!verify_class_access(client_class, field_class, false) |
430 if (!verify_class_access(client_class, field_class, false) |
431 || !verify_field_access(client_class, |
431 || !verify_field_access(client_class, |
432 field_class, |
432 field_class, |
452 // Passed all tests |
452 // Passed all tests |
453 return true; |
453 return true; |
454 } |
454 } |
455 |
455 |
456 |
456 |
457 bool Reflection::verify_class_access(klassOop current_class, klassOop new_class, bool classloader_only) { |
457 bool Reflection::verify_class_access(Klass* current_class, Klass* new_class, bool classloader_only) { |
458 // Verify that current_class can access new_class. If the classloader_only |
458 // Verify that current_class can access new_class. If the classloader_only |
459 // flag is set, we automatically allow any accesses in which current_class |
459 // flag is set, we automatically allow any accesses in which current_class |
460 // doesn't have a classloader. |
460 // doesn't have a classloader. |
461 if ((current_class == NULL) || |
461 if ((current_class == NULL) || |
462 (current_class == new_class) || |
462 (current_class == new_class) || |
463 (instanceKlass::cast(new_class)->is_public()) || |
463 (InstanceKlass::cast(new_class)->is_public()) || |
464 is_same_class_package(current_class, new_class)) { |
464 is_same_class_package(current_class, new_class)) { |
465 return true; |
465 return true; |
466 } |
466 } |
467 // New (1.4) reflection implementation. Allow all accesses from |
467 // New (1.4) reflection implementation. Allow all accesses from |
468 // sun/reflect/MagicAccessorImpl subclasses to succeed trivially. |
468 // sun/reflect/MagicAccessorImpl subclasses to succeed trivially. |
473 } |
473 } |
474 |
474 |
475 return can_relax_access_check_for(current_class, new_class, classloader_only); |
475 return can_relax_access_check_for(current_class, new_class, classloader_only); |
476 } |
476 } |
477 |
477 |
478 static bool under_host_klass(instanceKlass* ik, klassOop host_klass) { |
478 static bool under_host_klass(InstanceKlass* ik, Klass* host_klass) { |
479 DEBUG_ONLY(int inf_loop_check = 1000 * 1000 * 1000); |
479 DEBUG_ONLY(int inf_loop_check = 1000 * 1000 * 1000); |
480 for (;;) { |
480 for (;;) { |
481 klassOop hc = (klassOop) ik->host_klass(); |
481 Klass* hc = (Klass*) ik->host_klass(); |
482 if (hc == NULL) return false; |
482 if (hc == NULL) return false; |
483 if (hc == host_klass) return true; |
483 if (hc == host_klass) return true; |
484 ik = instanceKlass::cast(hc); |
484 ik = InstanceKlass::cast(hc); |
485 |
485 |
486 // There's no way to make a host class loop short of patching memory. |
486 // There's no way to make a host class loop short of patching memory. |
487 // Therefore there cannot be a loop here unles there's another bug. |
487 // Therefore there cannot be a loop here unles there's another bug. |
488 // Still, let's check for it. |
488 // Still, let's check for it. |
489 assert(--inf_loop_check > 0, "no host_klass loop"); |
489 assert(--inf_loop_check > 0, "no host_klass loop"); |
490 } |
490 } |
491 } |
491 } |
492 |
492 |
493 bool Reflection::can_relax_access_check_for( |
493 bool Reflection::can_relax_access_check_for( |
494 klassOop accessor, klassOop accessee, bool classloader_only) { |
494 Klass* accessor, Klass* accessee, bool classloader_only) { |
495 instanceKlass* accessor_ik = instanceKlass::cast(accessor); |
495 InstanceKlass* accessor_ik = InstanceKlass::cast(accessor); |
496 instanceKlass* accessee_ik = instanceKlass::cast(accessee); |
496 InstanceKlass* accessee_ik = InstanceKlass::cast(accessee); |
497 |
497 |
498 // If either is on the other's host_klass chain, access is OK, |
498 // If either is on the other's host_klass chain, access is OK, |
499 // because one is inside the other. |
499 // because one is inside the other. |
500 if (under_host_klass(accessor_ik, accessee) || |
500 if (under_host_klass(accessor_ik, accessee) || |
501 under_host_klass(accessee_ik, accessor)) |
501 under_host_klass(accessee_ik, accessor)) |
511 } else { |
511 } else { |
512 return false; |
512 return false; |
513 } |
513 } |
514 } |
514 } |
515 |
515 |
516 bool Reflection::verify_field_access(klassOop current_class, |
516 bool Reflection::verify_field_access(Klass* current_class, |
517 klassOop resolved_class, |
517 Klass* resolved_class, |
518 klassOop field_class, |
518 Klass* field_class, |
519 AccessFlags access, |
519 AccessFlags access, |
520 bool classloader_only, |
520 bool classloader_only, |
521 bool protected_restriction) { |
521 bool protected_restriction) { |
522 // Verify that current_class can access a field of field_class, where that |
522 // Verify that current_class can access a field of field_class, where that |
523 // field's access bits are "access". We assume that we've already verified |
523 // field's access bits are "access". We assume that we've already verified |
567 return can_relax_access_check_for( |
567 return can_relax_access_check_for( |
568 current_class, field_class, classloader_only); |
568 current_class, field_class, classloader_only); |
569 } |
569 } |
570 |
570 |
571 |
571 |
572 bool Reflection::is_same_class_package(klassOop class1, klassOop class2) { |
572 bool Reflection::is_same_class_package(Klass* class1, Klass* class2) { |
573 return instanceKlass::cast(class1)->is_same_class_package(class2); |
573 return InstanceKlass::cast(class1)->is_same_class_package(class2); |
574 } |
574 } |
575 |
575 |
576 bool Reflection::is_same_package_member(klassOop class1, klassOop class2, TRAPS) { |
576 bool Reflection::is_same_package_member(Klass* class1, Klass* class2, TRAPS) { |
577 return instanceKlass::cast(class1)->is_same_package_member(class2, THREAD); |
577 return InstanceKlass::cast(class1)->is_same_package_member(class2, THREAD); |
578 } |
578 } |
579 |
579 |
580 |
580 |
581 // Checks that the 'outer' klass has declared 'inner' as being an inner klass. If not, |
581 // Checks that the 'outer' klass has declared 'inner' as being an inner klass. If not, |
582 // throw an incompatible class change exception |
582 // throw an incompatible class change exception |
590 for (; !iter.done(); iter.next()) { |
590 for (; !iter.done(); iter.next()) { |
591 int ioff = iter.inner_class_info_index(); |
591 int ioff = iter.inner_class_info_index(); |
592 int ooff = iter.outer_class_info_index(); |
592 int ooff = iter.outer_class_info_index(); |
593 |
593 |
594 if (inner_is_member && ioff != 0 && ooff != 0) { |
594 if (inner_is_member && ioff != 0 && ooff != 0) { |
595 klassOop o = cp->klass_at(ooff, CHECK); |
595 Klass* o = cp->klass_at(ooff, CHECK); |
596 if (o == outer()) { |
596 if (o == outer()) { |
597 klassOop i = cp->klass_at(ioff, CHECK); |
597 Klass* i = cp->klass_at(ioff, CHECK); |
598 if (i == inner()) { |
598 if (i == inner()) { |
599 return; |
599 return; |
600 } |
600 } |
601 } |
601 } |
602 } |
602 } |
603 if (!inner_is_member && ioff != 0 && ooff == 0 && |
603 if (!inner_is_member && ioff != 0 && ooff == 0 && |
604 cp->klass_name_at_matches(inner, ioff)) { |
604 cp->klass_name_at_matches(inner, ioff)) { |
605 klassOop i = cp->klass_at(ioff, CHECK); |
605 Klass* i = cp->klass_at(ioff, CHECK); |
606 if (i == inner()) { |
606 if (i == inner()) { |
607 return; |
607 return; |
608 } |
608 } |
609 } |
609 } |
610 } |
610 } |
628 assert(ss->type() != T_VOID || ss->at_return_type(), "T_VOID should only appear as return type"); |
628 assert(ss->type() != T_VOID || ss->at_return_type(), "T_VOID should only appear as return type"); |
629 return java_lang_Class::primitive_mirror(ss->type()); |
629 return java_lang_Class::primitive_mirror(ss->type()); |
630 case T_OBJECT: |
630 case T_OBJECT: |
631 case T_ARRAY: |
631 case T_ARRAY: |
632 Symbol* name = ss->as_symbol(CHECK_NULL); |
632 Symbol* name = ss->as_symbol(CHECK_NULL); |
633 oop loader = instanceKlass::cast(method->method_holder())->class_loader(); |
633 oop loader = InstanceKlass::cast(method->method_holder())->class_loader(); |
634 oop protection_domain = instanceKlass::cast(method->method_holder())->protection_domain(); |
634 oop protection_domain = InstanceKlass::cast(method->method_holder())->protection_domain(); |
635 klassOop k = SystemDictionary::resolve_or_fail( |
635 Klass* k = SystemDictionary::resolve_or_fail( |
636 name, |
636 name, |
637 Handle(THREAD, loader), |
637 Handle(THREAD, loader), |
638 Handle(THREAD, protection_domain), |
638 Handle(THREAD, protection_domain), |
639 true, CHECK_NULL); |
639 true, CHECK_NULL); |
640 if (TraceClassResolution) { |
640 if (TraceClassResolution) { |
678 BasicType type = vmSymbols::signature_type(signature); |
678 BasicType type = vmSymbols::signature_type(signature); |
679 if (type != T_OBJECT) { |
679 if (type != T_OBJECT) { |
680 return Handle(THREAD, Universe::java_mirror(type)); |
680 return Handle(THREAD, Universe::java_mirror(type)); |
681 } |
681 } |
682 |
682 |
683 oop loader = instanceKlass::cast(k())->class_loader(); |
683 oop loader = InstanceKlass::cast(k())->class_loader(); |
684 oop protection_domain = Klass::cast(k())->protection_domain(); |
684 oop protection_domain = Klass::cast(k())->protection_domain(); |
685 klassOop result = SystemDictionary::resolve_or_fail(signature, |
685 Klass* result = SystemDictionary::resolve_or_fail(signature, |
686 Handle(THREAD, loader), |
686 Handle(THREAD, loader), |
687 Handle(THREAD, protection_domain), |
687 Handle(THREAD, protection_domain), |
688 true, CHECK_(Handle())); |
688 true, CHECK_(Handle())); |
689 |
689 |
690 if (TraceClassResolution) { |
690 if (TraceClassResolution) { |
746 Symbol* gs = method->generic_signature(); |
746 Symbol* gs = method->generic_signature(); |
747 Handle sig = java_lang_String::create_from_symbol(gs, CHECK_NULL); |
747 Handle sig = java_lang_String::create_from_symbol(gs, CHECK_NULL); |
748 java_lang_reflect_Method::set_signature(mh(), sig()); |
748 java_lang_reflect_Method::set_signature(mh(), sig()); |
749 } |
749 } |
750 if (java_lang_reflect_Method::has_annotations_field()) { |
750 if (java_lang_reflect_Method::has_annotations_field()) { |
751 java_lang_reflect_Method::set_annotations(mh(), method->annotations()); |
751 typeArrayOop an_oop = Annotations::make_java_array(method->annotations(), CHECK_NULL); |
|
752 java_lang_reflect_Method::set_annotations(mh(), an_oop); |
752 } |
753 } |
753 if (java_lang_reflect_Method::has_parameter_annotations_field()) { |
754 if (java_lang_reflect_Method::has_parameter_annotations_field()) { |
754 java_lang_reflect_Method::set_parameter_annotations(mh(), method->parameter_annotations()); |
755 typeArrayOop an_oop = Annotations::make_java_array(method->parameter_annotations(), CHECK_NULL); |
|
756 java_lang_reflect_Method::set_parameter_annotations(mh(), an_oop); |
755 } |
757 } |
756 if (java_lang_reflect_Method::has_annotation_default_field()) { |
758 if (java_lang_reflect_Method::has_annotation_default_field()) { |
757 java_lang_reflect_Method::set_annotation_default(mh(), method->annotation_default()); |
759 typeArrayOop an_oop = Annotations::make_java_array(method->annotation_default(), CHECK_NULL); |
|
760 java_lang_reflect_Method::set_annotation_default(mh(), an_oop); |
758 } |
761 } |
759 return mh(); |
762 return mh(); |
760 } |
763 } |
761 |
764 |
762 |
765 |
789 Symbol* gs = method->generic_signature(); |
792 Symbol* gs = method->generic_signature(); |
790 Handle sig = java_lang_String::create_from_symbol(gs, CHECK_NULL); |
793 Handle sig = java_lang_String::create_from_symbol(gs, CHECK_NULL); |
791 java_lang_reflect_Constructor::set_signature(ch(), sig()); |
794 java_lang_reflect_Constructor::set_signature(ch(), sig()); |
792 } |
795 } |
793 if (java_lang_reflect_Constructor::has_annotations_field()) { |
796 if (java_lang_reflect_Constructor::has_annotations_field()) { |
794 java_lang_reflect_Constructor::set_annotations(ch(), method->annotations()); |
797 typeArrayOop an_oop = Annotations::make_java_array(method->annotations(), CHECK_NULL); |
|
798 java_lang_reflect_Constructor::set_annotations(ch(), an_oop); |
795 } |
799 } |
796 if (java_lang_reflect_Constructor::has_parameter_annotations_field()) { |
800 if (java_lang_reflect_Constructor::has_parameter_annotations_field()) { |
797 java_lang_reflect_Constructor::set_parameter_annotations(ch(), method->parameter_annotations()); |
801 typeArrayOop an_oop = Annotations::make_java_array(method->parameter_annotations(), CHECK_NULL); |
|
802 java_lang_reflect_Constructor::set_parameter_annotations(ch(), an_oop); |
798 } |
803 } |
799 return ch(); |
804 return ch(); |
800 } |
805 } |
801 |
806 |
802 |
807 |
809 name = Handle(THREAD, name_oop); |
814 name = Handle(THREAD, name_oop); |
810 } else { |
815 } else { |
811 name = java_lang_String::create_from_symbol(field_name, CHECK_NULL); |
816 name = java_lang_String::create_from_symbol(field_name, CHECK_NULL); |
812 } |
817 } |
813 Symbol* signature = fd->signature(); |
818 Symbol* signature = fd->signature(); |
814 KlassHandle holder (THREAD, fd->field_holder()); |
819 instanceKlassHandle holder (THREAD, fd->field_holder()); |
815 Handle type = new_type(signature, holder, CHECK_NULL); |
820 Handle type = new_type(signature, holder, CHECK_NULL); |
816 Handle rh = java_lang_reflect_Field::create(CHECK_NULL); |
821 Handle rh = java_lang_reflect_Field::create(CHECK_NULL); |
817 |
822 |
818 java_lang_reflect_Field::set_clazz(rh(), Klass::cast(fd->field_holder())->java_mirror()); |
823 java_lang_reflect_Field::set_clazz(rh(), Klass::cast(fd->field_holder())->java_mirror()); |
819 java_lang_reflect_Field::set_slot(rh(), fd->index()); |
824 java_lang_reflect_Field::set_slot(rh(), fd->index()); |
827 Symbol* gs = fd->generic_signature(); |
832 Symbol* gs = fd->generic_signature(); |
828 Handle sig = java_lang_String::create_from_symbol(gs, CHECK_NULL); |
833 Handle sig = java_lang_String::create_from_symbol(gs, CHECK_NULL); |
829 java_lang_reflect_Field::set_signature(rh(), sig()); |
834 java_lang_reflect_Field::set_signature(rh(), sig()); |
830 } |
835 } |
831 if (java_lang_reflect_Field::has_annotations_field()) { |
836 if (java_lang_reflect_Field::has_annotations_field()) { |
832 java_lang_reflect_Field::set_annotations(rh(), fd->annotations()); |
837 typeArrayOop an_oop = Annotations::make_java_array(fd->annotations(), CHECK_NULL); |
|
838 java_lang_reflect_Field::set_annotations(rh(), an_oop); |
833 } |
839 } |
834 return rh(); |
840 return rh(); |
835 } |
841 } |
836 |
842 |
837 |
843 |
880 // no need to resolve if method is private or <init> |
886 // no need to resolve if method is private or <init> |
881 if (reflected_method->is_private() || reflected_method->name() == vmSymbols::object_initializer_name()) { |
887 if (reflected_method->is_private() || reflected_method->name() == vmSymbols::object_initializer_name()) { |
882 method = reflected_method; |
888 method = reflected_method; |
883 } else { |
889 } else { |
884 // resolve based on the receiver |
890 // resolve based on the receiver |
885 if (instanceKlass::cast(reflected_method->method_holder())->is_interface()) { |
891 if (InstanceKlass::cast(reflected_method->method_holder())->is_interface()) { |
886 // resolve interface call |
892 // resolve interface call |
887 if (ReflectionWrapResolutionErrors) { |
893 if (ReflectionWrapResolutionErrors) { |
888 // new default: 6531596 |
894 // new default: 6531596 |
889 // Match resolution errors with those thrown due to reflection inlining |
895 // Match resolution errors with those thrown due to reflection inlining |
890 // Linktime resolution & IllegalAccessCheck already done by Class.getMethod() |
896 // Linktime resolution & IllegalAccessCheck already done by Class.getMethod() |
903 } |
909 } |
904 } else { |
910 } else { |
905 // if the method can be overridden, we resolve using the vtable index. |
911 // if the method can be overridden, we resolve using the vtable index. |
906 int index = reflected_method->vtable_index(); |
912 int index = reflected_method->vtable_index(); |
907 method = reflected_method; |
913 method = reflected_method; |
908 if (index != methodOopDesc::nonvirtual_vtable_index) { |
914 if (index != Method::nonvirtual_vtable_index) { |
909 // target_klass might be an arrayKlassOop but all vtables start at |
915 // target_klass might be an arrayKlassOop but all vtables start at |
910 // the same place. The cast is to avoid virtual call and assertion. |
916 // the same place. The cast is to avoid virtual call and assertion. |
911 instanceKlass* inst = (instanceKlass*)target_klass()->klass_part(); |
917 InstanceKlass* inst = (InstanceKlass*)target_klass(); |
912 method = methodHandle(THREAD, inst->method_at_vtable(index)); |
918 method = methodHandle(THREAD, inst->method_at_vtable(index)); |
913 } |
919 } |
914 if (!method.is_null()) { |
920 if (!method.is_null()) { |
915 // Check for abstract methods as well |
921 // Check for abstract methods as well |
916 if (method->is_abstract()) { |
922 if (method->is_abstract()) { |
917 // new default: 6531596 |
923 // new default: 6531596 |
918 if (ReflectionWrapResolutionErrors) { |
924 if (ReflectionWrapResolutionErrors) { |
919 ResourceMark rm(THREAD); |
925 ResourceMark rm(THREAD); |
920 Handle h_origexception = Exceptions::new_exception(THREAD, |
926 Handle h_origexception = Exceptions::new_exception(THREAD, |
921 vmSymbols::java_lang_AbstractMethodError(), |
927 vmSymbols::java_lang_AbstractMethodError(), |
922 methodOopDesc::name_and_sig_as_C_string(Klass::cast(target_klass()), |
928 Method::name_and_sig_as_C_string(Klass::cast(target_klass()), |
923 method->name(), |
929 method->name(), |
924 method->signature())); |
930 method->signature())); |
925 JavaCallArguments args(h_origexception); |
931 JavaCallArguments args(h_origexception); |
926 THROW_ARG_0(vmSymbols::java_lang_reflect_InvocationTargetException(), |
932 THROW_ARG_0(vmSymbols::java_lang_reflect_InvocationTargetException(), |
927 vmSymbols::throwable_void_signature(), |
933 vmSymbols::throwable_void_signature(), |
928 &args); |
934 &args); |
929 } else { |
935 } else { |
930 ResourceMark rm(THREAD); |
936 ResourceMark rm(THREAD); |
931 THROW_MSG_0(vmSymbols::java_lang_AbstractMethodError(), |
937 THROW_MSG_0(vmSymbols::java_lang_AbstractMethodError(), |
932 methodOopDesc::name_and_sig_as_C_string(Klass::cast(target_klass()), |
938 Method::name_and_sig_as_C_string(Klass::cast(target_klass()), |
933 method->name(), |
939 method->name(), |
934 method->signature())); |
940 method->signature())); |
935 } |
941 } |
936 } |
942 } |
937 } |
943 } |
942 // I believe this is a ShouldNotGetHere case which requires |
948 // I believe this is a ShouldNotGetHere case which requires |
943 // an internal vtable bug. If you ever get this please let Karen know. |
949 // an internal vtable bug. If you ever get this please let Karen know. |
944 if (method.is_null()) { |
950 if (method.is_null()) { |
945 ResourceMark rm(THREAD); |
951 ResourceMark rm(THREAD); |
946 THROW_MSG_0(vmSymbols::java_lang_NoSuchMethodError(), |
952 THROW_MSG_0(vmSymbols::java_lang_NoSuchMethodError(), |
947 methodOopDesc::name_and_sig_as_C_string(Klass::cast(klass()), |
953 Method::name_and_sig_as_C_string(Klass::cast(klass()), |
948 reflected_method->name(), |
954 reflected_method->name(), |
949 reflected_method->signature())); |
955 reflected_method->signature())); |
950 } |
956 } |
951 |
957 |
952 // In the JDK 1.4 reflection implementation, the security check is |
958 // In the JDK 1.4 reflection implementation, the security check is |
1001 default: |
1007 default: |
1002 THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "argument type mismatch"); |
1008 THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "argument type mismatch"); |
1003 } |
1009 } |
1004 } else { |
1010 } else { |
1005 if (arg != NULL) { |
1011 if (arg != NULL) { |
1006 klassOop k = java_lang_Class::as_klassOop(type_mirror); |
1012 Klass* k = java_lang_Class::as_Klass(type_mirror); |
1007 if (!arg->is_a(k)) { |
1013 if (!arg->is_a(k)) { |
1008 THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "argument type mismatch"); |
1014 THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "argument type mismatch"); |
1009 } |
1015 } |
1010 } |
1016 } |
1011 Handle arg_handle(THREAD, arg); // Create handle for argument |
1017 Handle arg_handle(THREAD, arg); // Create handle for argument |
1077 rtype = basic_type_mirror_to_basic_type(return_type_mirror, CHECK_NULL); |
1083 rtype = basic_type_mirror_to_basic_type(return_type_mirror, CHECK_NULL); |
1078 } else { |
1084 } else { |
1079 rtype = T_OBJECT; |
1085 rtype = T_OBJECT; |
1080 } |
1086 } |
1081 |
1087 |
1082 instanceKlassHandle klass(THREAD, java_lang_Class::as_klassOop(mirror)); |
1088 instanceKlassHandle klass(THREAD, java_lang_Class::as_Klass(mirror)); |
1083 methodOop m = klass->method_with_idnum(slot); |
1089 Method* m = klass->method_with_idnum(slot); |
1084 if (m == NULL) { |
1090 if (m == NULL) { |
1085 THROW_MSG_0(vmSymbols::java_lang_InternalError(), "invoke"); |
1091 THROW_MSG_0(vmSymbols::java_lang_InternalError(), "invoke"); |
1086 } |
1092 } |
1087 methodHandle method(THREAD, m); |
1093 methodHandle method(THREAD, m); |
1088 |
1094 |
1094 oop mirror = java_lang_reflect_Constructor::clazz(constructor_mirror); |
1100 oop mirror = java_lang_reflect_Constructor::clazz(constructor_mirror); |
1095 int slot = java_lang_reflect_Constructor::slot(constructor_mirror); |
1101 int slot = java_lang_reflect_Constructor::slot(constructor_mirror); |
1096 bool override = java_lang_reflect_Constructor::override(constructor_mirror) != 0; |
1102 bool override = java_lang_reflect_Constructor::override(constructor_mirror) != 0; |
1097 objArrayHandle ptypes(THREAD, objArrayOop(java_lang_reflect_Constructor::parameter_types(constructor_mirror))); |
1103 objArrayHandle ptypes(THREAD, objArrayOop(java_lang_reflect_Constructor::parameter_types(constructor_mirror))); |
1098 |
1104 |
1099 instanceKlassHandle klass(THREAD, java_lang_Class::as_klassOop(mirror)); |
1105 instanceKlassHandle klass(THREAD, java_lang_Class::as_Klass(mirror)); |
1100 methodOop m = klass->method_with_idnum(slot); |
1106 Method* m = klass->method_with_idnum(slot); |
1101 if (m == NULL) { |
1107 if (m == NULL) { |
1102 THROW_MSG_0(vmSymbols::java_lang_InternalError(), "invoke"); |
1108 THROW_MSG_0(vmSymbols::java_lang_InternalError(), "invoke"); |
1103 } |
1109 } |
1104 methodHandle method(THREAD, m); |
1110 methodHandle method(THREAD, m); |
1105 assert(method->name() == vmSymbols::object_initializer_name(), "invalid constructor"); |
1111 assert(method->name() == vmSymbols::object_initializer_name(), "invalid constructor"); |