# HG changeset patch # Parent 5b84039ca7399dbc4ae8b1467fe6048b4e33f93b 8023037: Race between ciEnv::register_method and nmethod::make_not_entrant_or_zombie Reviewed-by: ? diff --git a/src/share/vm/ci/ciEnv.cpp b/src/share/vm/ci/ciEnv.cpp --- a/src/share/vm/ci/ciEnv.cpp +++ b/src/share/vm/ci/ciEnv.cpp @@ -1020,48 +1020,54 @@ CompileBroker::handle_full_code_cache(); } } else { + // Need to coordinate method registration with the sweeper thread. + nmethodLocker nml(nm); + nm->set_has_unsafe_access(has_unsafe_access); nm->set_has_wide_vectors(has_wide_vectors); - // Record successful registration. - // (Put nm into the task handle *before* publishing to the Java heap.) - if (task() != NULL) task()->set_code(nm); + // nmethod could be marked as non-entrant by the sweeper already. + // Don't install it then. + if (nm->is_in_use()) { + // Record successful registration. + // (Put nm into the task handle *before* publishing to the Java heap.) + if (task() != NULL) task()->set_code(nm); - if (entry_bci == InvocationEntryBci) { - if (TieredCompilation) { - // If there is an old version we're done with it - nmethod* old = method->code(); - if (TraceMethodReplacement && old != NULL) { + if (entry_bci == InvocationEntryBci) { + if (TieredCompilation) { + // If there is an old version we're done with it + nmethod* old = method->code(); + if (TraceMethodReplacement && old != NULL) { + ResourceMark rm; + char *method_name = method->name_and_sig_as_C_string(); + tty->print_cr("Replacing method %s", method_name); + } + if (old != NULL ) { + old->make_not_entrant(); + } + } + if (TraceNMethodInstalls) { ResourceMark rm; char *method_name = method->name_and_sig_as_C_string(); - tty->print_cr("Replacing method %s", method_name); + ttyLocker ttyl; + tty->print_cr("Installing method (%d) %s ", + comp_level, + method_name); } - if (old != NULL ) { - old->make_not_entrant(); + // Allow the code to be executed + method->set_code(method, nm); + } else { + if (TraceNMethodInstalls ) { + ResourceMark rm; + char *method_name = method->name_and_sig_as_C_string(); + ttyLocker ttyl; + tty->print_cr("Installing osr method (%d) %s @ %d", + comp_level, + method_name, + entry_bci); } + method->method_holder()->add_osr_nmethod(nm); } - if (TraceNMethodInstalls ) { - ResourceMark rm; - char *method_name = method->name_and_sig_as_C_string(); - ttyLocker ttyl; - tty->print_cr("Installing method (%d) %s ", - comp_level, - method_name); - } - // Allow the code to be executed - method->set_code(method, nm); - } else { - if (TraceNMethodInstalls ) { - ResourceMark rm; - char *method_name = method->name_and_sig_as_C_string(); - ttyLocker ttyl; - tty->print_cr("Installing osr method (%d) %s @ %d", - comp_level, - method_name, - entry_bci); - } - method->method_holder()->add_osr_nmethod(nm); - } } } @@ -1069,7 +1075,6 @@ if (nm != NULL) { nm->post_compiled_method_load_event(); } - }