./src/share/vm/oops/instanceKlass.cpp

Print this page
rev 4331 : review #1

*** 276,286 **** set_static_oop_field_count(0); set_nonstatic_field_size(0); set_is_marked_dependent(false); set_init_state(InstanceKlass::allocated); set_init_thread(NULL); ! set_init_lock(NULL); set_reference_type(rt); set_oop_map_cache(NULL); set_jni_ids(NULL); set_osr_nmethods_head(NULL); set_breakpoints(NULL); --- 276,286 ---- set_static_oop_field_count(0); set_nonstatic_field_size(0); set_is_marked_dependent(false); set_init_state(InstanceKlass::allocated); set_init_thread(NULL); ! set_per_class_lock(NULL); set_reference_type(rt); set_oop_map_cache(NULL); set_jni_ids(NULL); set_osr_nmethods_head(NULL); set_breakpoints(NULL);
*** 409,444 **** // Null out Java heap objects, although these won't be walked to keep // alive once this InstanceKlass is deallocated. set_protection_domain(NULL); set_signers(NULL); ! set_init_lock(NULL); // We should deallocate the Annotations instance MetadataFactory::free_metadata(loader_data, annotations()); set_annotations(NULL); } - volatile oop InstanceKlass::init_lock() const { - volatile oop lock = _init_lock; // read once - assert((oop)lock != NULL || !is_not_initialized(), // initialized or in_error state - "only fully initialized state can have a null lock"); - return lock; - } - - // Set the initialization lock to null so the object can be GC'ed. Any racing - // threads to get this lock will see a null lock and will not lock. - // That's okay because they all check for initialized state after getting - // the lock and return. - void InstanceKlass::fence_and_clear_init_lock() { - // make sure previous stores are all done, notably the init_state. - OrderAccess::storestore(); - klass_oop_store(&_init_lock, NULL); - assert(!is_not_initialized(), "class must be initialized now"); - } - - bool InstanceKlass::should_be_initialized() const { return !is_initialized(); } klassVtable* InstanceKlass::vtable() const { --- 409,425 ---- // Null out Java heap objects, although these won't be walked to keep // alive once this InstanceKlass is deallocated. set_protection_domain(NULL); set_signers(NULL); ! set_per_class_lock(NULL); // We should deallocate the Annotations instance MetadataFactory::free_metadata(loader_data, annotations()); set_annotations(NULL); } bool InstanceKlass::should_be_initialized() const { return !is_initialized(); } klassVtable* InstanceKlass::vtable() const {
*** 471,481 **** void InstanceKlass::eager_initialize_impl(instanceKlassHandle this_oop) { EXCEPTION_MARK; volatile oop init_lock = this_oop->init_lock(); ! ObjectLocker ol(init_lock, THREAD, init_lock != NULL); // abort if someone beat us to the initialization if (!this_oop->is_not_initialized()) return; // note: not equivalent to is_initialized() ClassState old_state = this_oop->init_state(); --- 452,462 ---- void InstanceKlass::eager_initialize_impl(instanceKlassHandle this_oop) { EXCEPTION_MARK; volatile oop init_lock = this_oop->init_lock(); ! ObjectLocker ol(init_lock, THREAD); // abort if someone beat us to the initialization if (!this_oop->is_not_initialized()) return; // note: not equivalent to is_initialized() ClassState old_state = this_oop->init_state();
*** 490,500 **** if( old_state != this_oop->_init_state ) this_oop->set_init_state (old_state); } else { // linking successfull, mark class as initialized this_oop->set_init_state (fully_initialized); - this_oop->fence_and_clear_init_lock(); // trace if (TraceClassInitialization) { ResourceMark rm(THREAD); tty->print_cr("[Initialized %s without side effects]", this_oop->external_name()); } --- 471,480 ----
*** 617,627 **** PerfClassTraceTime::CLASS_LINK); // verification & rewriting { volatile oop init_lock = this_oop->init_lock(); ! ObjectLocker ol(init_lock, THREAD, init_lock != NULL); // rewritten will have been set if loader constraint error found // on an earlier link attempt // don't verify or rewrite if already rewritten if (!this_oop->is_linked()) { --- 597,607 ---- PerfClassTraceTime::CLASS_LINK); // verification & rewriting { volatile oop init_lock = this_oop->init_lock(); ! ObjectLocker ol(init_lock, THREAD); // rewritten will have been set if loader constraint error found // on an earlier link attempt // don't verify or rewrite if already rewritten if (!this_oop->is_linked()) {
*** 740,750 **** // refer to the JVM book page 47 for description of steps // Step 1 { volatile oop init_lock = this_oop->init_lock(); ! ObjectLocker ol(init_lock, THREAD, init_lock != NULL); Thread *self = THREAD; // it's passed the current thread // Step 2 // If we were to use wait() instead of waitInterruptibly() then --- 720,730 ---- // refer to the JVM book page 47 for description of steps // Step 1 { volatile oop init_lock = this_oop->init_lock(); ! ObjectLocker ol(init_lock, THREAD); Thread *self = THREAD; // it's passed the current thread // Step 2 // If we were to use wait() instead of waitInterruptibly() then
*** 888,900 **** set_initialization_state_and_notify_impl(kh, state, CHECK); } void InstanceKlass::set_initialization_state_and_notify_impl(instanceKlassHandle this_oop, ClassState state, TRAPS) { volatile oop init_lock = this_oop->init_lock(); ! ObjectLocker ol(init_lock, THREAD, init_lock != NULL); this_oop->set_init_state(state); - this_oop->fence_and_clear_init_lock(); ol.notify_all(CHECK); } // The embedded _implementor field can only record one implementor. // When there are more than one implementors, the _implementor field --- 868,879 ---- set_initialization_state_and_notify_impl(kh, state, CHECK); } void InstanceKlass::set_initialization_state_and_notify_impl(instanceKlassHandle this_oop, ClassState state, TRAPS) { volatile oop init_lock = this_oop->init_lock(); ! ObjectLocker ol(init_lock, THREAD); this_oop->set_init_state(state); ol.notify_all(CHECK); } // The embedded _implementor field can only record one implementor. // When there are more than one implementors, the _implementor field
*** 1906,1916 **** void InstanceKlass::oops_do(OopClosure* cl) { Klass::oops_do(cl); cl->do_oop(adr_protection_domain()); cl->do_oop(adr_signers()); ! cl->do_oop(adr_init_lock()); // Don't walk the arrays since they are walked from the ClassLoaderData objects. } #ifdef ASSERT --- 1885,1895 ---- void InstanceKlass::oops_do(OopClosure* cl) { Klass::oops_do(cl); cl->do_oop(adr_protection_domain()); cl->do_oop(adr_signers()); ! cl->do_oop(adr_per_class_lock()); // Don't walk the arrays since they are walked from the ClassLoaderData objects. } #ifdef ASSERT
*** 2271,2281 **** Method* m = methods()->at(i); m->remove_unshareable_info(); } // Need to reinstate when reading back the class. ! set_init_lock(NULL); // do array classes also. array_klasses_do(remove_unshareable_in_class); } --- 2250,2260 ---- Method* m = methods()->at(i); m->remove_unshareable_info(); } // Need to reinstate when reading back the class. ! set_per_class_lock(NULL); // do array classes also. array_klasses_do(remove_unshareable_in_class); }
*** 2309,2319 **** // Allocate a simple java object for a lock. // This needs to be a java object because during class initialization // it can be held across a java call. typeArrayOop r = oopFactory::new_typeArray(T_INT, 0, CHECK); Handle h(THREAD, (oop)r); ! ik->set_init_lock(h()); // restore constant pool resolved references ik->constants()->restore_unshareable_info(CHECK); ik->array_klasses_do(restore_unshareable_in_class, CHECK); --- 2288,2298 ---- // Allocate a simple java object for a lock. // This needs to be a java object because during class initialization // it can be held across a java call. typeArrayOop r = oopFactory::new_typeArray(T_INT, 0, CHECK); Handle h(THREAD, (oop)r); ! ik->set_per_class_lock(h()); // restore constant pool resolved references ik->constants()->restore_unshareable_info(CHECK); ik->array_klasses_do(restore_unshareable_in_class, CHECK);
*** 2829,2839 **** st->cr(); } st->print(BULLET"protection domain: "); ((InstanceKlass*)this)->protection_domain()->print_value_on(st); st->cr(); st->print(BULLET"host class: "); host_klass()->print_value_on_maybe_null(st); st->cr(); st->print(BULLET"signers: "); signers()->print_value_on(st); st->cr(); ! st->print(BULLET"init_lock: "); ((oop)_init_lock)->print_value_on(st); st->cr(); if (source_file_name() != NULL) { st->print(BULLET"source file: "); source_file_name()->print_value_on(st); st->cr(); } --- 2808,2818 ---- st->cr(); } st->print(BULLET"protection domain: "); ((InstanceKlass*)this)->protection_domain()->print_value_on(st); st->cr(); st->print(BULLET"host class: "); host_klass()->print_value_on_maybe_null(st); st->cr(); st->print(BULLET"signers: "); signers()->print_value_on(st); st->cr(); ! st->print(BULLET"per_class_lock: "); ((oop)_per_class_lock)->print_value_on(st); st->cr(); if (source_file_name() != NULL) { st->print(BULLET"source file: "); source_file_name()->print_value_on(st); st->cr(); }