430 OrderAccess::storestore(); |
429 OrderAccess::storestore(); |
431 java_lang_Class::set_init_lock(java_mirror(), NULL); |
430 java_lang_Class::set_init_lock(java_mirror(), NULL); |
432 assert(!is_not_initialized(), "class must be initialized now"); |
431 assert(!is_not_initialized(), "class must be initialized now"); |
433 } |
432 } |
434 |
433 |
435 void InstanceKlass::eager_initialize_impl(instanceKlassHandle this_k) { |
434 void InstanceKlass::eager_initialize_impl(InstanceKlass* this_k) { |
436 EXCEPTION_MARK; |
435 EXCEPTION_MARK; |
437 HandleMark hm(THREAD); |
436 HandleMark hm(THREAD); |
438 Handle init_lock(THREAD, this_k->init_lock()); |
437 Handle init_lock(THREAD, this_k->init_lock()); |
439 ObjectLocker ol(init_lock, THREAD, init_lock() != NULL); |
438 ObjectLocker ol(init_lock, THREAD, init_lock() != NULL); |
440 |
439 |
468 // See "The Virtual Machine Specification" section 2.16.5 for a detailed explanation of the class initialization |
467 // See "The Virtual Machine Specification" section 2.16.5 for a detailed explanation of the class initialization |
469 // process. The step comments refers to the procedure described in that section. |
468 // process. The step comments refers to the procedure described in that section. |
470 // Note: implementation moved to static method to expose the this pointer. |
469 // Note: implementation moved to static method to expose the this pointer. |
471 void InstanceKlass::initialize(TRAPS) { |
470 void InstanceKlass::initialize(TRAPS) { |
472 if (this->should_be_initialized()) { |
471 if (this->should_be_initialized()) { |
473 instanceKlassHandle this_k(THREAD, this); |
472 initialize_impl(this, CHECK); |
474 initialize_impl(this_k, CHECK); |
|
475 // Note: at this point the class may be initialized |
473 // Note: at this point the class may be initialized |
476 // OR it may be in the state of being initialized |
474 // OR it may be in the state of being initialized |
477 // in case of recursive initialization! |
475 // in case of recursive initialization! |
478 } else { |
476 } else { |
479 assert(is_initialized(), "sanity check"); |
477 assert(is_initialized(), "sanity check"); |
480 } |
478 } |
481 } |
479 } |
482 |
480 |
483 |
481 |
484 bool InstanceKlass::verify_code( |
482 bool InstanceKlass::verify_code( |
485 instanceKlassHandle this_k, bool throw_verifyerror, TRAPS) { |
483 InstanceKlass* this_k, bool throw_verifyerror, TRAPS) { |
486 // 1) Verify the bytecodes |
484 // 1) Verify the bytecodes |
487 Verifier::Mode mode = |
485 Verifier::Mode mode = |
488 throw_verifyerror ? Verifier::ThrowException : Verifier::NoException; |
486 throw_verifyerror ? Verifier::ThrowException : Verifier::NoException; |
489 return Verifier::verify(this_k, mode, this_k->should_verify_class(), THREAD); |
487 return Verifier::verify(this_k, mode, this_k->should_verify_class(), THREAD); |
490 } |
488 } |
499 } |
497 } |
500 |
498 |
501 void InstanceKlass::link_class(TRAPS) { |
499 void InstanceKlass::link_class(TRAPS) { |
502 assert(is_loaded(), "must be loaded"); |
500 assert(is_loaded(), "must be loaded"); |
503 if (!is_linked()) { |
501 if (!is_linked()) { |
504 instanceKlassHandle this_k(THREAD, this); |
502 link_class_impl(this, true, CHECK); |
505 link_class_impl(this_k, true, CHECK); |
|
506 } |
503 } |
507 } |
504 } |
508 |
505 |
509 // Called to verify that a class can link during initialization, without |
506 // Called to verify that a class can link during initialization, without |
510 // throwing a VerifyError. |
507 // throwing a VerifyError. |
511 bool InstanceKlass::link_class_or_fail(TRAPS) { |
508 bool InstanceKlass::link_class_or_fail(TRAPS) { |
512 assert(is_loaded(), "must be loaded"); |
509 assert(is_loaded(), "must be loaded"); |
513 if (!is_linked()) { |
510 if (!is_linked()) { |
514 instanceKlassHandle this_k(THREAD, this); |
511 link_class_impl(this, false, CHECK_false); |
515 link_class_impl(this_k, false, CHECK_false); |
|
516 } |
512 } |
517 return is_linked(); |
513 return is_linked(); |
518 } |
514 } |
519 |
515 |
520 bool InstanceKlass::link_class_impl( |
516 bool InstanceKlass::link_class_impl( |
521 instanceKlassHandle this_k, bool throw_verifyerror, TRAPS) { |
517 InstanceKlass* this_k, bool throw_verifyerror, TRAPS) { |
522 if (DumpSharedSpaces && this_k->is_in_error_state()) { |
518 if (DumpSharedSpaces && this_k->is_in_error_state()) { |
523 // This is for CDS dumping phase only -- we use the in_error_state to indicate that |
519 // This is for CDS dumping phase only -- we use the in_error_state to indicate that |
524 // the class has failed verification. Throwing the NoClassDefFoundError here is just |
520 // the class has failed verification. Throwing the NoClassDefFoundError here is just |
525 // a convenient way to stop repeat attempts to verify the same (bad) class. |
521 // a convenient way to stop repeat attempts to verify the same (bad) class. |
526 // |
522 // |
540 // timer handles recursion |
536 // timer handles recursion |
541 assert(THREAD->is_Java_thread(), "non-JavaThread in link_class_impl"); |
537 assert(THREAD->is_Java_thread(), "non-JavaThread in link_class_impl"); |
542 JavaThread* jt = (JavaThread*)THREAD; |
538 JavaThread* jt = (JavaThread*)THREAD; |
543 |
539 |
544 // link super class before linking this class |
540 // link super class before linking this class |
545 instanceKlassHandle super(THREAD, this_k->super()); |
541 Klass* super = this_k->super(); |
546 if (super.not_null()) { |
542 if (super != NULL) { |
547 if (super->is_interface()) { // check if super class is an interface |
543 if (super->is_interface()) { // check if super class is an interface |
548 ResourceMark rm(THREAD); |
544 ResourceMark rm(THREAD); |
549 Exceptions::fthrow( |
545 Exceptions::fthrow( |
550 THREAD_AND_LOCATION, |
546 THREAD_AND_LOCATION, |
551 vmSymbols::java_lang_IncompatibleClassChangeError(), |
547 vmSymbols::java_lang_IncompatibleClassChangeError(), |
554 super->external_name() |
550 super->external_name() |
555 ); |
551 ); |
556 return false; |
552 return false; |
557 } |
553 } |
558 |
554 |
559 link_class_impl(super, throw_verifyerror, CHECK_false); |
555 InstanceKlass* ik_super = InstanceKlass::cast(super); |
|
556 link_class_impl(ik_super, throw_verifyerror, CHECK_false); |
560 } |
557 } |
561 |
558 |
562 // link all interfaces implemented by this class before linking this class |
559 // link all interfaces implemented by this class before linking this class |
563 Array<Klass*>* interfaces = this_k->local_interfaces(); |
560 Array<Klass*>* interfaces = this_k->local_interfaces(); |
564 int num_interfaces = interfaces->length(); |
561 int num_interfaces = interfaces->length(); |
565 for (int index = 0; index < num_interfaces; index++) { |
562 for (int index = 0; index < num_interfaces; index++) { |
566 instanceKlassHandle ih(THREAD, interfaces->at(index)); |
563 InstanceKlass* interk = InstanceKlass::cast(interfaces->at(index)); |
567 link_class_impl(ih, throw_verifyerror, CHECK_false); |
564 link_class_impl(interk, throw_verifyerror, CHECK_false); |
568 } |
565 } |
569 |
566 |
570 // in case the class is linked in the process of linking its superclasses |
567 // in case the class is linked in the process of linking its superclasses |
571 if (this_k->is_linked()) { |
568 if (this_k->is_linked()) { |
572 return true; |
569 return true; |
653 // Rewrite the byte codes of all of the methods of a class. |
650 // Rewrite the byte codes of all of the methods of a class. |
654 // The rewriter must be called exactly once. Rewriting must happen after |
651 // The rewriter must be called exactly once. Rewriting must happen after |
655 // verification but before the first method of the class is executed. |
652 // verification but before the first method of the class is executed. |
656 void InstanceKlass::rewrite_class(TRAPS) { |
653 void InstanceKlass::rewrite_class(TRAPS) { |
657 assert(is_loaded(), "must be loaded"); |
654 assert(is_loaded(), "must be loaded"); |
658 instanceKlassHandle this_k(THREAD, this); |
655 if (is_rewritten()) { |
659 if (this_k->is_rewritten()) { |
656 assert(is_shared(), "rewriting an unshared class?"); |
660 assert(this_k()->is_shared(), "rewriting an unshared class?"); |
|
661 return; |
657 return; |
662 } |
658 } |
663 Rewriter::rewrite(this_k, CHECK); |
659 Rewriter::rewrite(this, CHECK); |
664 this_k->set_rewritten(); |
660 set_rewritten(); |
665 } |
661 } |
666 |
662 |
667 // Now relocate and link method entry points after class is rewritten. |
663 // Now relocate and link method entry points after class is rewritten. |
668 // This is outside is_rewritten flag. In case of an exception, it can be |
664 // This is outside is_rewritten flag. In case of an exception, it can be |
669 // executed more than once. |
665 // executed more than once. |
676 m->link_method(m, CHECK); |
672 m->link_method(m, CHECK); |
677 } |
673 } |
678 } |
674 } |
679 |
675 |
680 // Eagerly initialize superinterfaces that declare default methods (concrete instance: any access) |
676 // Eagerly initialize superinterfaces that declare default methods (concrete instance: any access) |
681 void InstanceKlass::initialize_super_interfaces(instanceKlassHandle this_k, TRAPS) { |
677 void InstanceKlass::initialize_super_interfaces(InstanceKlass* this_k, TRAPS) { |
682 assert (this_k->has_nonstatic_concrete_methods(), "caller should have checked this"); |
678 assert (this_k->has_nonstatic_concrete_methods(), "caller should have checked this"); |
683 for (int i = 0; i < this_k->local_interfaces()->length(); ++i) { |
679 for (int i = 0; i < this_k->local_interfaces()->length(); ++i) { |
684 Klass* iface = this_k->local_interfaces()->at(i); |
680 Klass* iface = this_k->local_interfaces()->at(i); |
685 InstanceKlass* ik = InstanceKlass::cast(iface); |
681 InstanceKlass* ik = InstanceKlass::cast(iface); |
686 |
682 |
696 ik->initialize(CHECK); |
692 ik->initialize(CHECK); |
697 } |
693 } |
698 } |
694 } |
699 } |
695 } |
700 |
696 |
701 void InstanceKlass::initialize_impl(instanceKlassHandle this_k, TRAPS) { |
697 void InstanceKlass::initialize_impl(InstanceKlass* this_k, TRAPS) { |
702 HandleMark hm(THREAD); |
698 HandleMark hm(THREAD); |
703 |
699 |
704 // Make sure klass is linked (verified) before initialization |
700 // Make sure klass is linked (verified) before initialization |
705 // A class could already be verified, since it has been reflected upon. |
701 // A class could already be verified, since it has been reflected upon. |
706 this_k->link_class(CHECK); |
702 this_k->link_class(CHECK); |
707 |
703 |
708 DTRACE_CLASSINIT_PROBE(required, this_k(), -1); |
704 DTRACE_CLASSINIT_PROBE(required, this_k, -1); |
709 |
705 |
710 bool wait = false; |
706 bool wait = false; |
711 |
707 |
712 // refer to the JVM book page 47 for description of steps |
708 // refer to the JVM book page 47 for description of steps |
713 // Step 1 |
709 // Step 1 |
726 ol.waitUninterruptibly(CHECK); |
722 ol.waitUninterruptibly(CHECK); |
727 } |
723 } |
728 |
724 |
729 // Step 3 |
725 // Step 3 |
730 if (this_k->is_being_initialized() && this_k->is_reentrant_initialization(self)) { |
726 if (this_k->is_being_initialized() && this_k->is_reentrant_initialization(self)) { |
731 DTRACE_CLASSINIT_PROBE_WAIT(recursive, this_k(), -1,wait); |
727 DTRACE_CLASSINIT_PROBE_WAIT(recursive, this_k, -1,wait); |
732 return; |
728 return; |
733 } |
729 } |
734 |
730 |
735 // Step 4 |
731 // Step 4 |
736 if (this_k->is_initialized()) { |
732 if (this_k->is_initialized()) { |
737 DTRACE_CLASSINIT_PROBE_WAIT(concurrent, this_k(), -1,wait); |
733 DTRACE_CLASSINIT_PROBE_WAIT(concurrent, this_k, -1,wait); |
738 return; |
734 return; |
739 } |
735 } |
740 |
736 |
741 // Step 5 |
737 // Step 5 |
742 if (this_k->is_in_error_state()) { |
738 if (this_k->is_in_error_state()) { |
743 DTRACE_CLASSINIT_PROBE_WAIT(erroneous, this_k(), -1,wait); |
739 DTRACE_CLASSINIT_PROBE_WAIT(erroneous, this_k, -1,wait); |
744 ResourceMark rm(THREAD); |
740 ResourceMark rm(THREAD); |
745 const char* desc = "Could not initialize class "; |
741 const char* desc = "Could not initialize class "; |
746 const char* className = this_k->external_name(); |
742 const char* className = this_k->external_name(); |
747 size_t msglen = strlen(desc) + strlen(className) + 1; |
743 size_t msglen = strlen(desc) + strlen(className) + 1; |
748 char* message = NEW_RESOURCE_ARRAY(char, msglen); |
744 char* message = NEW_RESOURCE_ARRAY(char, msglen); |
797 |
793 |
798 // Step 8 |
794 // Step 8 |
799 { |
795 { |
800 assert(THREAD->is_Java_thread(), "non-JavaThread in initialize_impl"); |
796 assert(THREAD->is_Java_thread(), "non-JavaThread in initialize_impl"); |
801 JavaThread* jt = (JavaThread*)THREAD; |
797 JavaThread* jt = (JavaThread*)THREAD; |
802 DTRACE_CLASSINIT_PROBE_WAIT(clinit, this_k(), -1,wait); |
798 DTRACE_CLASSINIT_PROBE_WAIT(clinit, this_k, -1,wait); |
803 // Timer includes any side effects of class initialization (resolution, |
799 // Timer includes any side effects of class initialization (resolution, |
804 // etc), but not recursive entry into call_class_initializer(). |
800 // etc), but not recursive entry into call_class_initializer(). |
805 PerfClassTraceTime timer(ClassLoader::perf_class_init_time(), |
801 PerfClassTraceTime timer(ClassLoader::perf_class_init_time(), |
806 ClassLoader::perf_class_init_selftime(), |
802 ClassLoader::perf_class_init_selftime(), |
807 ClassLoader::perf_classes_inited(), |
803 ClassLoader::perf_classes_inited(), |
831 CLEAR_PENDING_EXCEPTION; // ignore any exception thrown, class initialization error is thrown below |
827 CLEAR_PENDING_EXCEPTION; // ignore any exception thrown, class initialization error is thrown below |
832 // JVMTI has already reported the pending exception |
828 // JVMTI has already reported the pending exception |
833 // JVMTI internal flag reset is needed in order to report ExceptionInInitializerError |
829 // JVMTI internal flag reset is needed in order to report ExceptionInInitializerError |
834 JvmtiExport::clear_detected_exception((JavaThread*)THREAD); |
830 JvmtiExport::clear_detected_exception((JavaThread*)THREAD); |
835 } |
831 } |
836 DTRACE_CLASSINIT_PROBE_WAIT(error, this_k(), -1,wait); |
832 DTRACE_CLASSINIT_PROBE_WAIT(error, this_k, -1,wait); |
837 if (e->is_a(SystemDictionary::Error_klass())) { |
833 if (e->is_a(SystemDictionary::Error_klass())) { |
838 THROW_OOP(e()); |
834 THROW_OOP(e()); |
839 } else { |
835 } else { |
840 JavaCallArguments args(e); |
836 JavaCallArguments args(e); |
841 THROW_ARG(vmSymbols::java_lang_ExceptionInInitializerError(), |
837 THROW_ARG(vmSymbols::java_lang_ExceptionInInitializerError(), |
842 vmSymbols::throwable_void_signature(), |
838 vmSymbols::throwable_void_signature(), |
843 &args); |
839 &args); |
844 } |
840 } |
845 } |
841 } |
846 DTRACE_CLASSINIT_PROBE_WAIT(end, this_k(), -1,wait); |
842 DTRACE_CLASSINIT_PROBE_WAIT(end, this_k, -1,wait); |
847 } |
843 } |
848 |
844 |
849 |
845 |
850 // Note: implementation moved to static method to expose the this pointer. |
846 // Note: implementation moved to static method to expose the this pointer. |
851 void InstanceKlass::set_initialization_state_and_notify(ClassState state, TRAPS) { |
847 void InstanceKlass::set_initialization_state_and_notify(ClassState state, TRAPS) { |
852 instanceKlassHandle kh(THREAD, this); |
848 set_initialization_state_and_notify_impl(this, state, CHECK); |
853 set_initialization_state_and_notify_impl(kh, state, CHECK); |
849 } |
854 } |
850 |
855 |
851 void InstanceKlass::set_initialization_state_and_notify_impl(InstanceKlass* this_k, ClassState state, TRAPS) { |
856 void InstanceKlass::set_initialization_state_and_notify_impl(instanceKlassHandle this_k, ClassState state, TRAPS) { |
|
857 Handle init_lock(THREAD, this_k->init_lock()); |
852 Handle init_lock(THREAD, this_k->init_lock()); |
858 if (init_lock() != NULL) { |
853 if (init_lock() != NULL) { |
859 ObjectLocker ol(init_lock, THREAD); |
854 ObjectLocker ol(init_lock, THREAD); |
860 this_k->set_init_state(state); |
855 this_k->set_init_state(state); |
861 this_k->fence_and_clear_init_lock(); |
856 this_k->fence_and_clear_init_lock(); |
993 JvmtiExport::post_array_size_exhausted(); |
988 JvmtiExport::post_array_size_exhausted(); |
994 THROW_OOP_0(Universe::out_of_memory_error_array_size()); |
989 THROW_OOP_0(Universe::out_of_memory_error_array_size()); |
995 } |
990 } |
996 int size = objArrayOopDesc::object_size(length); |
991 int size = objArrayOopDesc::object_size(length); |
997 Klass* ak = array_klass(n, CHECK_NULL); |
992 Klass* ak = array_klass(n, CHECK_NULL); |
998 KlassHandle h_ak (THREAD, ak); |
|
999 objArrayOop o = |
993 objArrayOop o = |
1000 (objArrayOop)CollectedHeap::array_allocate(h_ak, size, length, CHECK_NULL); |
994 (objArrayOop)CollectedHeap::array_allocate(ak, size, length, CHECK_NULL); |
1001 return o; |
995 return o; |
1002 } |
996 } |
1003 |
997 |
1004 instanceOop InstanceKlass::register_finalizer(instanceOop i, TRAPS) { |
998 instanceOop InstanceKlass::register_finalizer(instanceOop i, TRAPS) { |
1005 if (TraceFinalizerRegistration) { |
999 if (TraceFinalizerRegistration) { |
1043 : vmSymbols::java_lang_IllegalAccessException(), external_name()); |
1035 : vmSymbols::java_lang_IllegalAccessException(), external_name()); |
1044 } |
1036 } |
1045 } |
1037 } |
1046 |
1038 |
1047 Klass* InstanceKlass::array_klass_impl(bool or_null, int n, TRAPS) { |
1039 Klass* InstanceKlass::array_klass_impl(bool or_null, int n, TRAPS) { |
1048 instanceKlassHandle this_k(THREAD, this); |
1040 return array_klass_impl(this, or_null, n, THREAD); |
1049 return array_klass_impl(this_k, or_null, n, THREAD); |
1041 } |
1050 } |
1042 |
1051 |
1043 Klass* InstanceKlass::array_klass_impl(InstanceKlass* this_k, bool or_null, int n, TRAPS) { |
1052 Klass* InstanceKlass::array_klass_impl(instanceKlassHandle this_k, bool or_null, int n, TRAPS) { |
|
1053 // Need load-acquire for lock-free read |
1044 // Need load-acquire for lock-free read |
1054 if (this_k->array_klasses_acquire() == NULL) { |
1045 if (this_k->array_klasses_acquire() == NULL) { |
1055 if (or_null) return NULL; |
1046 if (or_null) return NULL; |
1056 |
1047 |
1057 ResourceMark rm; |
1048 ResourceMark rm; |
1080 Klass* InstanceKlass::array_klass_impl(bool or_null, TRAPS) { |
1071 Klass* InstanceKlass::array_klass_impl(bool or_null, TRAPS) { |
1081 return array_klass_impl(or_null, 1, THREAD); |
1072 return array_klass_impl(or_null, 1, THREAD); |
1082 } |
1073 } |
1083 |
1074 |
1084 void InstanceKlass::call_class_initializer(TRAPS) { |
1075 void InstanceKlass::call_class_initializer(TRAPS) { |
1085 instanceKlassHandle ik (THREAD, this); |
1076 call_class_initializer_impl(this, THREAD); |
1086 call_class_initializer_impl(ik, THREAD); |
|
1087 } |
1077 } |
1088 |
1078 |
1089 static int call_class_initializer_impl_counter = 0; // for debugging |
1079 static int call_class_initializer_impl_counter = 0; // for debugging |
1090 |
1080 |
1091 Method* InstanceKlass::class_initializer() { |
1081 Method* InstanceKlass::class_initializer() const { |
1092 Method* clinit = find_method( |
1082 Method* clinit = find_method( |
1093 vmSymbols::class_initializer_name(), vmSymbols::void_method_signature()); |
1083 vmSymbols::class_initializer_name(), vmSymbols::void_method_signature()); |
1094 if (clinit != NULL && clinit->has_valid_initializer_flags()) { |
1084 if (clinit != NULL && clinit->has_valid_initializer_flags()) { |
1095 return clinit; |
1085 return clinit; |
1096 } |
1086 } |
1097 return NULL; |
1087 return NULL; |
1098 } |
1088 } |
1099 |
1089 |
1100 void InstanceKlass::call_class_initializer_impl(instanceKlassHandle this_k, TRAPS) { |
1090 void InstanceKlass::call_class_initializer_impl(InstanceKlass* this_k, TRAPS) { |
1101 if (ReplayCompiles && |
1091 if (ReplayCompiles && |
1102 (ReplaySuppressInitializers == 1 || |
1092 (ReplaySuppressInitializers == 1 || |
1103 ReplaySuppressInitializers >= 2 && this_k->class_loader() != NULL)) { |
1093 ReplaySuppressInitializers >= 2 && this_k->class_loader() != NULL)) { |
1104 // Hide the existence of the initializer for the purpose of replaying the compile |
1094 // Hide the existence of the initializer for the purpose of replaying the compile |
1105 return; |
1095 return; |
1110 if (log_is_enabled(Info, class, init)) { |
1100 if (log_is_enabled(Info, class, init)) { |
1111 ResourceMark rm; |
1101 ResourceMark rm; |
1112 outputStream* log = Log(class, init)::info_stream(); |
1102 outputStream* log = Log(class, init)::info_stream(); |
1113 log->print("%d Initializing ", call_class_initializer_impl_counter++); |
1103 log->print("%d Initializing ", call_class_initializer_impl_counter++); |
1114 this_k->name()->print_value_on(log); |
1104 this_k->name()->print_value_on(log); |
1115 log->print_cr("%s (" INTPTR_FORMAT ")", h_method() == NULL ? "(no method)" : "", p2i(this_k())); |
1105 log->print_cr("%s (" INTPTR_FORMAT ")", h_method() == NULL ? "(no method)" : "", p2i(this_k)); |
1116 } |
1106 } |
1117 if (h_method() != NULL) { |
1107 if (h_method() != NULL) { |
1118 JavaCallArguments args; // No arguments |
1108 JavaCallArguments args; // No arguments |
1119 JavaValue result(T_VOID); |
1109 JavaValue result(T_VOID); |
1120 JavaCalls::call(&result, h_method, &args, CHECK); // Static call (no args) |
1110 JavaCalls::call(&result, h_method, &args, CHECK); // Static call (no args) |
1261 } |
1251 } |
1262 } |
1252 } |
1263 |
1253 |
1264 |
1254 |
1265 void InstanceKlass::do_local_static_fields(void f(fieldDescriptor*, Handle, TRAPS), Handle mirror, TRAPS) { |
1255 void InstanceKlass::do_local_static_fields(void f(fieldDescriptor*, Handle, TRAPS), Handle mirror, TRAPS) { |
1266 instanceKlassHandle h_this(THREAD, this); |
1256 do_local_static_fields_impl(this, f, mirror, CHECK); |
1267 do_local_static_fields_impl(h_this, f, mirror, CHECK); |
1257 } |
1268 } |
1258 |
1269 |
1259 |
1270 |
1260 void InstanceKlass::do_local_static_fields_impl(InstanceKlass* this_k, |
1271 void InstanceKlass::do_local_static_fields_impl(instanceKlassHandle this_k, |
|
1272 void f(fieldDescriptor* fd, Handle, TRAPS), Handle mirror, TRAPS) { |
1261 void f(fieldDescriptor* fd, Handle, TRAPS), Handle mirror, TRAPS) { |
1273 for (JavaFieldStream fs(this_k()); !fs.done(); fs.next()) { |
1262 for (JavaFieldStream fs(this_k); !fs.done(); fs.next()) { |
1274 if (fs.access_flags().is_static()) { |
1263 if (fs.access_flags().is_static()) { |
1275 fieldDescriptor& fd = fs.field_descriptor(); |
1264 fieldDescriptor& fd = fs.field_descriptor(); |
1276 f(&fd, mirror, CHECK); |
1265 f(&fd, mirror, CHECK); |
1277 } |
1266 } |
1278 } |
1267 } |
1627 } |
1616 } |
1628 return NULL; |
1617 return NULL; |
1629 } |
1618 } |
1630 |
1619 |
1631 /* jni_id_for_impl for jfieldIds only */ |
1620 /* jni_id_for_impl for jfieldIds only */ |
1632 JNIid* InstanceKlass::jni_id_for_impl(instanceKlassHandle this_k, int offset) { |
1621 JNIid* InstanceKlass::jni_id_for_impl(InstanceKlass* this_k, int offset) { |
1633 MutexLocker ml(JfieldIdCreation_lock); |
1622 MutexLocker ml(JfieldIdCreation_lock); |
1634 // Retry lookup after we got the lock |
1623 // Retry lookup after we got the lock |
1635 JNIid* probe = this_k->jni_ids() == NULL ? NULL : this_k->jni_ids()->find(offset); |
1624 JNIid* probe = this_k->jni_ids() == NULL ? NULL : this_k->jni_ids()->find(offset); |
1636 if (probe == NULL) { |
1625 if (probe == NULL) { |
1637 // Slow case, allocate new static field identifier |
1626 // Slow case, allocate new static field identifier |
1638 probe = new JNIid(this_k(), offset, this_k->jni_ids()); |
1627 probe = new JNIid(this_k, offset, this_k->jni_ids()); |
1639 this_k->set_jni_ids(probe); |
1628 this_k->set_jni_ids(probe); |
1640 } |
1629 } |
1641 return probe; |
1630 return probe; |
1642 } |
1631 } |
1643 |
1632 |
1682 // Lookup or create a jmethodID. |
1671 // Lookup or create a jmethodID. |
1683 // This code is called by the VMThread and JavaThreads so the |
1672 // This code is called by the VMThread and JavaThreads so the |
1684 // locking has to be done very carefully to avoid deadlocks |
1673 // locking has to be done very carefully to avoid deadlocks |
1685 // and/or other cache consistency problems. |
1674 // and/or other cache consistency problems. |
1686 // |
1675 // |
1687 jmethodID InstanceKlass::get_jmethod_id(instanceKlassHandle ik_h, const methodHandle& method_h) { |
1676 jmethodID InstanceKlass::get_jmethod_id(InstanceKlass* ik, const methodHandle& method_h) { |
1688 size_t idnum = (size_t)method_h->method_idnum(); |
1677 size_t idnum = (size_t)method_h->method_idnum(); |
1689 jmethodID* jmeths = ik_h->methods_jmethod_ids_acquire(); |
1678 jmethodID* jmeths = ik->methods_jmethod_ids_acquire(); |
1690 size_t length = 0; |
1679 size_t length = 0; |
1691 jmethodID id = NULL; |
1680 jmethodID id = NULL; |
1692 |
1681 |
1693 // We use a double-check locking idiom here because this cache is |
1682 // We use a double-check locking idiom here because this cache is |
1694 // performance sensitive. In the normal system, this cache only |
1683 // performance sensitive. In the normal system, this cache only |
1708 // cache accesses and freeing of the old cache so a lock is generally |
1697 // cache accesses and freeing of the old cache so a lock is generally |
1709 // acquired when the RedefineClasses() API has been used. |
1698 // acquired when the RedefineClasses() API has been used. |
1710 |
1699 |
1711 if (jmeths != NULL) { |
1700 if (jmeths != NULL) { |
1712 // the cache already exists |
1701 // the cache already exists |
1713 if (!ik_h->idnum_can_increment()) { |
1702 if (!ik->idnum_can_increment()) { |
1714 // the cache can't grow so we can just get the current values |
1703 // the cache can't grow so we can just get the current values |
1715 get_jmethod_id_length_value(jmeths, idnum, &length, &id); |
1704 get_jmethod_id_length_value(jmeths, idnum, &length, &id); |
1716 } else { |
1705 } else { |
1717 // cache can grow so we have to be more careful |
1706 // cache can grow so we have to be more careful |
1718 if (Threads::number_of_threads() == 0 || |
1707 if (Threads::number_of_threads() == 0 || |
1742 |
1731 |
1743 // may not allocate new_jmeths or use it if we allocate it |
1732 // may not allocate new_jmeths or use it if we allocate it |
1744 jmethodID* new_jmeths = NULL; |
1733 jmethodID* new_jmeths = NULL; |
1745 if (length <= idnum) { |
1734 if (length <= idnum) { |
1746 // allocate a new cache that might be used |
1735 // allocate a new cache that might be used |
1747 size_t size = MAX2(idnum+1, (size_t)ik_h->idnum_allocated_count()); |
1736 size_t size = MAX2(idnum+1, (size_t)ik->idnum_allocated_count()); |
1748 new_jmeths = NEW_C_HEAP_ARRAY(jmethodID, size+1, mtClass); |
1737 new_jmeths = NEW_C_HEAP_ARRAY(jmethodID, size+1, mtClass); |
1749 memset(new_jmeths, 0, (size+1)*sizeof(jmethodID)); |
1738 memset(new_jmeths, 0, (size+1)*sizeof(jmethodID)); |
1750 // cache size is stored in element[0], other elements offset by one |
1739 // cache size is stored in element[0], other elements offset by one |
1751 new_jmeths[0] = (jmethodID)size; |
1740 new_jmeths[0] = (jmethodID)size; |
1752 } |
1741 } |
1753 |
1742 |
1754 // allocate a new jmethodID that might be used |
1743 // allocate a new jmethodID that might be used |
1755 jmethodID new_id = NULL; |
1744 jmethodID new_id = NULL; |
1756 if (method_h->is_old() && !method_h->is_obsolete()) { |
1745 if (method_h->is_old() && !method_h->is_obsolete()) { |
1757 // The method passed in is old (but not obsolete), we need to use the current version |
1746 // The method passed in is old (but not obsolete), we need to use the current version |
1758 Method* current_method = ik_h->method_with_idnum((int)idnum); |
1747 Method* current_method = ik->method_with_idnum((int)idnum); |
1759 assert(current_method != NULL, "old and but not obsolete, so should exist"); |
1748 assert(current_method != NULL, "old and but not obsolete, so should exist"); |
1760 new_id = Method::make_jmethod_id(ik_h->class_loader_data(), current_method); |
1749 new_id = Method::make_jmethod_id(ik->class_loader_data(), current_method); |
1761 } else { |
1750 } else { |
1762 // It is the current version of the method or an obsolete method, |
1751 // It is the current version of the method or an obsolete method, |
1763 // use the version passed in |
1752 // use the version passed in |
1764 new_id = Method::make_jmethod_id(ik_h->class_loader_data(), method_h()); |
1753 new_id = Method::make_jmethod_id(ik->class_loader_data(), method_h()); |
1765 } |
1754 } |
1766 |
1755 |
1767 if (Threads::number_of_threads() == 0 || |
1756 if (Threads::number_of_threads() == 0 || |
1768 SafepointSynchronize::is_at_safepoint()) { |
1757 SafepointSynchronize::is_at_safepoint()) { |
1769 // we're single threaded or at a safepoint - no locking needed |
1758 // we're single threaded or at a safepoint - no locking needed |
1770 id = get_jmethod_id_fetch_or_update(ik_h, idnum, new_id, new_jmeths, |
1759 id = get_jmethod_id_fetch_or_update(ik, idnum, new_id, new_jmeths, |
1771 &to_dealloc_id, &to_dealloc_jmeths); |
1760 &to_dealloc_id, &to_dealloc_jmeths); |
1772 } else { |
1761 } else { |
1773 MutexLocker ml(JmethodIdCreation_lock); |
1762 MutexLocker ml(JmethodIdCreation_lock); |
1774 id = get_jmethod_id_fetch_or_update(ik_h, idnum, new_id, new_jmeths, |
1763 id = get_jmethod_id_fetch_or_update(ik, idnum, new_id, new_jmeths, |
1775 &to_dealloc_id, &to_dealloc_jmeths); |
1764 &to_dealloc_id, &to_dealloc_jmeths); |
1776 } |
1765 } |
1777 |
1766 |
1778 // The lock has been dropped so we can free resources. |
1767 // The lock has been dropped so we can free resources. |
1779 // Free up either the old cache or the new cache if we allocated one. |
1768 // Free up either the old cache or the new cache if we allocated one. |
1780 if (to_dealloc_jmeths != NULL) { |
1769 if (to_dealloc_jmeths != NULL) { |
1781 FreeHeap(to_dealloc_jmeths); |
1770 FreeHeap(to_dealloc_jmeths); |
1782 } |
1771 } |
1783 // free up the new ID since it wasn't needed |
1772 // free up the new ID since it wasn't needed |
1784 if (to_dealloc_id != NULL) { |
1773 if (to_dealloc_id != NULL) { |
1785 Method::destroy_jmethod_id(ik_h->class_loader_data(), to_dealloc_id); |
1774 Method::destroy_jmethod_id(ik->class_loader_data(), to_dealloc_id); |
1786 } |
1775 } |
1787 } |
1776 } |
1788 return id; |
1777 return id; |
1789 } |
1778 } |
1790 |
1779 |
1812 // cache with the new jmethodID. This function should never do anything |
1801 // cache with the new jmethodID. This function should never do anything |
1813 // that causes the caller to go to a safepoint or we can deadlock with |
1802 // that causes the caller to go to a safepoint or we can deadlock with |
1814 // the VMThread or have cache consistency issues. |
1803 // the VMThread or have cache consistency issues. |
1815 // |
1804 // |
1816 jmethodID InstanceKlass::get_jmethod_id_fetch_or_update( |
1805 jmethodID InstanceKlass::get_jmethod_id_fetch_or_update( |
1817 instanceKlassHandle ik_h, size_t idnum, jmethodID new_id, |
1806 InstanceKlass* ik, size_t idnum, jmethodID new_id, |
1818 jmethodID* new_jmeths, jmethodID* to_dealloc_id_p, |
1807 jmethodID* new_jmeths, jmethodID* to_dealloc_id_p, |
1819 jmethodID** to_dealloc_jmeths_p) { |
1808 jmethodID** to_dealloc_jmeths_p) { |
1820 assert(new_id != NULL, "sanity check"); |
1809 assert(new_id != NULL, "sanity check"); |
1821 assert(to_dealloc_id_p != NULL, "sanity check"); |
1810 assert(to_dealloc_id_p != NULL, "sanity check"); |
1822 assert(to_dealloc_jmeths_p != NULL, "sanity check"); |
1811 assert(to_dealloc_jmeths_p != NULL, "sanity check"); |
1823 assert(Threads::number_of_threads() == 0 || |
1812 assert(Threads::number_of_threads() == 0 || |
1824 SafepointSynchronize::is_at_safepoint() || |
1813 SafepointSynchronize::is_at_safepoint() || |
1825 JmethodIdCreation_lock->owned_by_self(), "sanity check"); |
1814 JmethodIdCreation_lock->owned_by_self(), "sanity check"); |
1826 |
1815 |
1827 // reacquire the cache - we are locked, single threaded or at a safepoint |
1816 // reacquire the cache - we are locked, single threaded or at a safepoint |
1828 jmethodID* jmeths = ik_h->methods_jmethod_ids_acquire(); |
1817 jmethodID* jmeths = ik->methods_jmethod_ids_acquire(); |
1829 jmethodID id = NULL; |
1818 jmethodID id = NULL; |
1830 size_t length = 0; |
1819 size_t length = 0; |
1831 |
1820 |
1832 if (jmeths == NULL || // no cache yet |
1821 if (jmeths == NULL || // no cache yet |
1833 (length = (size_t)jmeths[0]) <= idnum) { // cache is too short |
1822 (length = (size_t)jmeths[0]) <= idnum) { // cache is too short |
2056 // --> see ArrayKlass::complete_create_array_klass() |
2045 // --> see ArrayKlass::complete_create_array_klass() |
2057 k->restore_unshareable_info(ClassLoaderData::the_null_class_loader_data(), Handle(), CHECK); |
2046 k->restore_unshareable_info(ClassLoaderData::the_null_class_loader_data(), Handle(), CHECK); |
2058 } |
2047 } |
2059 |
2048 |
2060 void InstanceKlass::restore_unshareable_info(ClassLoaderData* loader_data, Handle protection_domain, TRAPS) { |
2049 void InstanceKlass::restore_unshareable_info(ClassLoaderData* loader_data, Handle protection_domain, TRAPS) { |
2061 instanceKlassHandle ik(THREAD, this); |
2050 set_package(loader_data, CHECK); |
2062 ik->set_package(loader_data, CHECK); |
|
2063 Klass::restore_unshareable_info(loader_data, protection_domain, CHECK); |
2051 Klass::restore_unshareable_info(loader_data, protection_domain, CHECK); |
2064 |
2052 |
2065 Array<Method*>* methods = ik->methods(); |
2053 Array<Method*>* methods = this->methods(); |
2066 int num_methods = methods->length(); |
2054 int num_methods = methods->length(); |
2067 for (int index2 = 0; index2 < num_methods; ++index2) { |
2055 for (int index2 = 0; index2 < num_methods; ++index2) { |
2068 methodHandle m(THREAD, methods->at(index2)); |
2056 methodHandle m(THREAD, methods->at(index2)); |
2069 m->restore_unshareable_info(CHECK); |
2057 m->restore_unshareable_info(CHECK); |
2070 } |
2058 } |
2073 // entries in this vtable for super classes so the CDS vtable might |
2061 // entries in this vtable for super classes so the CDS vtable might |
2074 // point to old or obsolete entries. RedefineClasses doesn't fix up |
2062 // point to old or obsolete entries. RedefineClasses doesn't fix up |
2075 // vtables in the shared system dictionary, only the main one. |
2063 // vtables in the shared system dictionary, only the main one. |
2076 // It also redefines the itable too so fix that too. |
2064 // It also redefines the itable too so fix that too. |
2077 ResourceMark rm(THREAD); |
2065 ResourceMark rm(THREAD); |
2078 ik->vtable()->initialize_vtable(false, CHECK); |
2066 vtable()->initialize_vtable(false, CHECK); |
2079 ik->itable()->initialize_itable(false, CHECK); |
2067 itable()->initialize_itable(false, CHECK); |
2080 } |
2068 } |
2081 |
2069 |
2082 // restore constant pool resolved references |
2070 // restore constant pool resolved references |
2083 ik->constants()->restore_unshareable_info(CHECK); |
2071 constants()->restore_unshareable_info(CHECK); |
2084 |
2072 |
2085 ik->array_klasses_do(restore_unshareable_in_class, CHECK); |
2073 array_klasses_do(restore_unshareable_in_class, CHECK); |
2086 } |
2074 } |
2087 |
2075 |
2088 // returns true IFF is_in_error_state() has been changed as a result of this call. |
2076 // returns true IFF is_in_error_state() has been changed as a result of this call. |
2089 bool InstanceKlass::check_sharing_error_state() { |
2077 bool InstanceKlass::check_sharing_error_state() { |
2090 assert(DumpSharedSpaces, "should only be called during dumping"); |
2078 assert(DumpSharedSpaces, "should only be called during dumping"); |
2520 // If by this point we have not found an equality between the |
2508 // If by this point we have not found an equality between the |
2521 // two classes, we know they are in separate package members. |
2509 // two classes, we know they are in separate package members. |
2522 return false; |
2510 return false; |
2523 } |
2511 } |
2524 |
2512 |
2525 bool InstanceKlass::find_inner_classes_attr(instanceKlassHandle k, int* ooff, int* noff, TRAPS) { |
2513 bool InstanceKlass::find_inner_classes_attr(const InstanceKlass* k, int* ooff, int* noff, TRAPS) { |
2526 constantPoolHandle i_cp(THREAD, k->constants()); |
2514 constantPoolHandle i_cp(THREAD, k->constants()); |
2527 for (InnerClassesIterator iter(k); !iter.done(); iter.next()) { |
2515 for (InnerClassesIterator iter(k); !iter.done(); iter.next()) { |
2528 int ioff = iter.inner_class_info_index(); |
2516 int ioff = iter.inner_class_info_index(); |
2529 if (ioff != 0) { |
2517 if (ioff != 0) { |
2530 // Check to see if the name matches the class we're looking for |
2518 // Check to see if the name matches the class we're looking for |
2531 // before attempting to find the class. |
2519 // before attempting to find the class. |
2532 if (i_cp->klass_name_at_matches(k, ioff)) { |
2520 if (i_cp->klass_name_at_matches(k, ioff)) { |
2533 Klass* inner_klass = i_cp->klass_at(ioff, CHECK_false); |
2521 Klass* inner_klass = i_cp->klass_at(ioff, CHECK_false); |
2534 if (k() == inner_klass) { |
2522 if (k == inner_klass) { |
2535 *ooff = iter.outer_class_info_index(); |
2523 *ooff = iter.outer_class_info_index(); |
2536 *noff = iter.inner_name_index(); |
2524 *noff = iter.inner_name_index(); |
2537 return true; |
2525 return true; |
2538 } |
2526 } |
2539 } |
2527 } |
2578 |
2566 |
2579 jint InstanceKlass::compute_modifier_flags(TRAPS) const { |
2567 jint InstanceKlass::compute_modifier_flags(TRAPS) const { |
2580 jint access = access_flags().as_int(); |
2568 jint access = access_flags().as_int(); |
2581 |
2569 |
2582 // But check if it happens to be member class. |
2570 // But check if it happens to be member class. |
2583 instanceKlassHandle ik(THREAD, this); |
2571 InnerClassesIterator iter(this); |
2584 InnerClassesIterator iter(ik); |
|
2585 for (; !iter.done(); iter.next()) { |
2572 for (; !iter.done(); iter.next()) { |
2586 int ioff = iter.inner_class_info_index(); |
2573 int ioff = iter.inner_class_info_index(); |
2587 // Inner class attribute can be zero, skip it. |
2574 // Inner class attribute can be zero, skip it. |
2588 // Strange but true: JVM spec. allows null inner class refs. |
2575 // Strange but true: JVM spec. allows null inner class refs. |
2589 if (ioff == 0) continue; |
2576 if (ioff == 0) continue; |
2590 |
2577 |
2591 // only look at classes that are already loaded |
2578 // only look at classes that are already loaded |
2592 // since we are looking for the flags for our self. |
2579 // since we are looking for the flags for our self. |
2593 Symbol* inner_name = ik->constants()->klass_name_at(ioff); |
2580 Symbol* inner_name = constants()->klass_name_at(ioff); |
2594 if ((ik->name() == inner_name)) { |
2581 if (name() == inner_name) { |
2595 // This is really a member class. |
2582 // This is really a member class. |
2596 access = iter.inner_access_flags(); |
2583 access = iter.inner_access_flags(); |
2597 break; |
2584 break; |
2598 } |
2585 } |
2599 } |
2586 } |
3636 ConstantPool* cp_ref = scratch_class->constants(); |
3623 ConstantPool* cp_ref = scratch_class->constants(); |
3637 if (!cp_ref->on_stack()) { |
3624 if (!cp_ref->on_stack()) { |
3638 log_trace(redefine, class, iklass, add)("scratch class not added; no methods are running"); |
3625 log_trace(redefine, class, iklass, add)("scratch class not added; no methods are running"); |
3639 // For debugging purposes. |
3626 // For debugging purposes. |
3640 scratch_class->set_is_scratch_class(); |
3627 scratch_class->set_is_scratch_class(); |
3641 scratch_class->class_loader_data()->add_to_deallocate_list(scratch_class()); |
3628 scratch_class->class_loader_data()->add_to_deallocate_list(scratch_class); |
3642 return; |
3629 return; |
3643 } |
3630 } |
3644 |
3631 |
3645 if (emcp_method_count != 0) { |
3632 if (emcp_method_count != 0) { |
3646 // At least one method is still running, check for EMCP methods |
3633 // At least one method is still running, check for EMCP methods |
3669 // Set has_previous_version flag for processing during class unloading. |
3656 // Set has_previous_version flag for processing during class unloading. |
3670 _has_previous_versions = true; |
3657 _has_previous_versions = true; |
3671 log_trace(redefine, class, iklass, add) ("scratch class added; one of its methods is on_stack."); |
3658 log_trace(redefine, class, iklass, add) ("scratch class added; one of its methods is on_stack."); |
3672 assert(scratch_class->previous_versions() == NULL, "shouldn't have a previous version"); |
3659 assert(scratch_class->previous_versions() == NULL, "shouldn't have a previous version"); |
3673 scratch_class->link_previous_versions(previous_versions()); |
3660 scratch_class->link_previous_versions(previous_versions()); |
3674 link_previous_versions(scratch_class()); |
3661 link_previous_versions(scratch_class); |
3675 } // end add_previous_version() |
3662 } // end add_previous_version() |
3676 |
3663 |
3677 #endif // INCLUDE_JVMTI |
3664 #endif // INCLUDE_JVMTI |
3678 |
3665 |
3679 Method* InstanceKlass::method_with_idnum(int idnum) { |
3666 Method* InstanceKlass::method_with_idnum(int idnum) { |