8008962: NPG: Memory regression: One extra Monitor per ConstantPool

Re-use InstanceKlass::_init_lock locking ConstantPool as well.

Reviewed-by: dholmes, coleenp, acorn
This commit is contained in:
Ioi Lam 2013-04-25 12:55:49 -07:00
parent 333cf9a756
commit 4e19360f89
7 changed files with 61 additions and 51 deletions

View file

@ -419,25 +419,6 @@ void InstanceKlass::deallocate_contents(ClassLoaderData* loader_data) {
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();
}
@ -474,7 +455,7 @@ void InstanceKlass::eager_initialize(Thread *thread) {
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);
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()
@ -493,7 +474,6 @@ void InstanceKlass::eager_initialize_impl(instanceKlassHandle this_oop) {
} 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);
@ -620,7 +600,7 @@ bool InstanceKlass::link_class_impl(
// verification & rewriting
{
volatile oop init_lock = this_oop->init_lock();
ObjectLocker ol(init_lock, THREAD, init_lock != NULL);
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
@ -743,7 +723,7 @@ void InstanceKlass::initialize_impl(instanceKlassHandle this_oop, TRAPS) {
// Step 1
{
volatile oop init_lock = this_oop->init_lock();
ObjectLocker ol(init_lock, THREAD, init_lock != NULL);
ObjectLocker ol(init_lock, THREAD);
Thread *self = THREAD; // it's passed the current thread
@ -891,9 +871,8 @@ void InstanceKlass::set_initialization_state_and_notify(ClassState state, TRAPS)
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);
ObjectLocker ol(init_lock, THREAD);
this_oop->set_init_state(state);
this_oop->fence_and_clear_init_lock();
ol.notify_all(CHECK);
}
@ -2860,7 +2839,7 @@ void InstanceKlass::print_on(outputStream* st) const {
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();
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);