417 // We should deallocate the Annotations instance |
417 // We should deallocate the Annotations instance |
418 MetadataFactory::free_metadata(loader_data, annotations()); |
418 MetadataFactory::free_metadata(loader_data, annotations()); |
419 set_annotations(NULL); |
419 set_annotations(NULL); |
420 } |
420 } |
421 |
421 |
422 volatile oop InstanceKlass::init_lock() const { |
|
423 volatile oop lock = _init_lock; // read once |
|
424 assert((oop)lock != NULL || !is_not_initialized(), // initialized or in_error state |
|
425 "only fully initialized state can have a null lock"); |
|
426 return lock; |
|
427 } |
|
428 |
|
429 // Set the initialization lock to null so the object can be GC'ed. Any racing |
|
430 // threads to get this lock will see a null lock and will not lock. |
|
431 // That's okay because they all check for initialized state after getting |
|
432 // the lock and return. |
|
433 void InstanceKlass::fence_and_clear_init_lock() { |
|
434 // make sure previous stores are all done, notably the init_state. |
|
435 OrderAccess::storestore(); |
|
436 klass_oop_store(&_init_lock, NULL); |
|
437 assert(!is_not_initialized(), "class must be initialized now"); |
|
438 } |
|
439 |
|
440 |
|
441 bool InstanceKlass::should_be_initialized() const { |
422 bool InstanceKlass::should_be_initialized() const { |
442 return !is_initialized(); |
423 return !is_initialized(); |
443 } |
424 } |
444 |
425 |
445 klassVtable* InstanceKlass::vtable() const { |
426 klassVtable* InstanceKlass::vtable() const { |
472 |
453 |
473 |
454 |
474 void InstanceKlass::eager_initialize_impl(instanceKlassHandle this_oop) { |
455 void InstanceKlass::eager_initialize_impl(instanceKlassHandle this_oop) { |
475 EXCEPTION_MARK; |
456 EXCEPTION_MARK; |
476 volatile oop init_lock = this_oop->init_lock(); |
457 volatile oop init_lock = this_oop->init_lock(); |
477 ObjectLocker ol(init_lock, THREAD, init_lock != NULL); |
458 ObjectLocker ol(init_lock, THREAD); |
478 |
459 |
479 // abort if someone beat us to the initialization |
460 // abort if someone beat us to the initialization |
480 if (!this_oop->is_not_initialized()) return; // note: not equivalent to is_initialized() |
461 if (!this_oop->is_not_initialized()) return; // note: not equivalent to is_initialized() |
481 |
462 |
482 ClassState old_state = this_oop->init_state(); |
463 ClassState old_state = this_oop->init_state(); |
491 if( old_state != this_oop->_init_state ) |
472 if( old_state != this_oop->_init_state ) |
492 this_oop->set_init_state (old_state); |
473 this_oop->set_init_state (old_state); |
493 } else { |
474 } else { |
494 // linking successfull, mark class as initialized |
475 // linking successfull, mark class as initialized |
495 this_oop->set_init_state (fully_initialized); |
476 this_oop->set_init_state (fully_initialized); |
496 this_oop->fence_and_clear_init_lock(); |
|
497 // trace |
477 // trace |
498 if (TraceClassInitialization) { |
478 if (TraceClassInitialization) { |
499 ResourceMark rm(THREAD); |
479 ResourceMark rm(THREAD); |
500 tty->print_cr("[Initialized %s without side effects]", this_oop->external_name()); |
480 tty->print_cr("[Initialized %s without side effects]", this_oop->external_name()); |
501 } |
481 } |
618 PerfClassTraceTime::CLASS_LINK); |
598 PerfClassTraceTime::CLASS_LINK); |
619 |
599 |
620 // verification & rewriting |
600 // verification & rewriting |
621 { |
601 { |
622 volatile oop init_lock = this_oop->init_lock(); |
602 volatile oop init_lock = this_oop->init_lock(); |
623 ObjectLocker ol(init_lock, THREAD, init_lock != NULL); |
603 ObjectLocker ol(init_lock, THREAD); |
624 // rewritten will have been set if loader constraint error found |
604 // rewritten will have been set if loader constraint error found |
625 // on an earlier link attempt |
605 // on an earlier link attempt |
626 // don't verify or rewrite if already rewritten |
606 // don't verify or rewrite if already rewritten |
627 |
607 |
628 if (!this_oop->is_linked()) { |
608 if (!this_oop->is_linked()) { |
741 |
721 |
742 // refer to the JVM book page 47 for description of steps |
722 // refer to the JVM book page 47 for description of steps |
743 // Step 1 |
723 // Step 1 |
744 { |
724 { |
745 volatile oop init_lock = this_oop->init_lock(); |
725 volatile oop init_lock = this_oop->init_lock(); |
746 ObjectLocker ol(init_lock, THREAD, init_lock != NULL); |
726 ObjectLocker ol(init_lock, THREAD); |
747 |
727 |
748 Thread *self = THREAD; // it's passed the current thread |
728 Thread *self = THREAD; // it's passed the current thread |
749 |
729 |
750 // Step 2 |
730 // Step 2 |
751 // If we were to use wait() instead of waitInterruptibly() then |
731 // If we were to use wait() instead of waitInterruptibly() then |
889 set_initialization_state_and_notify_impl(kh, state, CHECK); |
869 set_initialization_state_and_notify_impl(kh, state, CHECK); |
890 } |
870 } |
891 |
871 |
892 void InstanceKlass::set_initialization_state_and_notify_impl(instanceKlassHandle this_oop, ClassState state, TRAPS) { |
872 void InstanceKlass::set_initialization_state_and_notify_impl(instanceKlassHandle this_oop, ClassState state, TRAPS) { |
893 volatile oop init_lock = this_oop->init_lock(); |
873 volatile oop init_lock = this_oop->init_lock(); |
894 ObjectLocker ol(init_lock, THREAD, init_lock != NULL); |
874 ObjectLocker ol(init_lock, THREAD); |
895 this_oop->set_init_state(state); |
875 this_oop->set_init_state(state); |
896 this_oop->fence_and_clear_init_lock(); |
|
897 ol.notify_all(CHECK); |
876 ol.notify_all(CHECK); |
898 } |
877 } |
899 |
878 |
900 // The embedded _implementor field can only record one implementor. |
879 // The embedded _implementor field can only record one implementor. |
901 // When there are more than one implementors, the _implementor field |
880 // When there are more than one implementors, the _implementor field |
2858 st->cr(); |
2837 st->cr(); |
2859 } |
2838 } |
2860 st->print(BULLET"protection domain: "); ((InstanceKlass*)this)->protection_domain()->print_value_on(st); st->cr(); |
2839 st->print(BULLET"protection domain: "); ((InstanceKlass*)this)->protection_domain()->print_value_on(st); st->cr(); |
2861 st->print(BULLET"host class: "); host_klass()->print_value_on_maybe_null(st); st->cr(); |
2840 st->print(BULLET"host class: "); host_klass()->print_value_on_maybe_null(st); st->cr(); |
2862 st->print(BULLET"signers: "); signers()->print_value_on(st); st->cr(); |
2841 st->print(BULLET"signers: "); signers()->print_value_on(st); st->cr(); |
2863 st->print(BULLET"init_lock: "); ((oop)_init_lock)->print_value_on(st); st->cr(); |
2842 st->print(BULLET"init_lock: "); ((oop)_init_lock)->print_value_on(st); st->cr(); |
2864 if (source_file_name() != NULL) { |
2843 if (source_file_name() != NULL) { |
2865 st->print(BULLET"source file: "); |
2844 st->print(BULLET"source file: "); |
2866 source_file_name()->print_value_on(st); |
2845 source_file_name()->print_value_on(st); |
2867 st->cr(); |
2846 st->cr(); |
2868 } |
2847 } |