--- old/src/share/vm/code/codeCache.cpp 2016-03-06 20:43:07.550199613 -0500 +++ new/src/share/vm/code/codeCache.cpp 2016-03-06 20:43:07.430198906 -0500 @@ -637,16 +637,19 @@ } // Walk the list of methods which might contain non-perm oops. -void CodeCache::scavenge_root_nmethods_do(CodeBlobClosure* f) { +void CodeCache::scavenge_root_nmethods_do(CodeBlobToOopClosure* f) { assert_locked_or_safepoint(CodeCache_lock); if (UseG1GC) { return; } + const bool fix_relocations = f->fix_relocations(); debug_only(mark_scavenge_root_nmethods()); - for (nmethod* cur = scavenge_root_nmethods(); cur != NULL; cur = cur->scavenge_root_link()) { + nmethod* prev = NULL; + nmethod* cur = scavenge_root_nmethods(); + while (cur != NULL) { debug_only(cur->clear_scavenge_root_marked()); assert(cur->scavenge_root_not_marked(), ""); assert(cur->on_scavenge_root_list(), "else shouldn't be on this list"); @@ -659,6 +662,18 @@ // Perform cur->oops_do(f), maybe just once per nmethod. f->do_code_blob(cur); } + nmethod* const next = cur->scavenge_root_link(); + // The scavengable nmethod list must contain all methods with scavengable + // oops. It is safe to include more nmethod on the list, but we do not + // expect any live non-scavengable nmethods on the list. + if (fix_relocations) { + if (!is_live || !cur->detect_scavenge_root_oops()) { + unlink_scavenge_root_nmethod(cur, prev); + } else { + prev = cur; + } + } + cur = next; } // Check for stray marks. @@ -678,6 +693,24 @@ print_trace("add_scavenge_root", nm); } +void CodeCache::unlink_scavenge_root_nmethod(nmethod* nm, nmethod* prev) { + assert_locked_or_safepoint(CodeCache_lock); + + assert((prev == NULL && scavenge_root_nmethods() == nm) || + (prev != NULL && prev->scavenge_root_link() == nm), "precondition"); + + assert(!UseG1GC, "G1 does not use the scavenge_root_nmethods list"); + + print_trace("unlink_scavenge_root", nm); + if (prev == NULL) { + set_scavenge_root_nmethods(nm->scavenge_root_link()); + } else { + prev->set_scavenge_root_link(nm->scavenge_root_link()); + } + nm->set_scavenge_root_link(NULL); + nm->clear_on_scavenge_root_list(); +} + void CodeCache::drop_scavenge_root_nmethod(nmethod* nm) { assert_locked_or_safepoint(CodeCache_lock); @@ -686,20 +719,13 @@ } print_trace("drop_scavenge_root", nm); - nmethod* last = NULL; - nmethod* cur = scavenge_root_nmethods(); - while (cur != NULL) { - nmethod* next = cur->scavenge_root_link(); + nmethod* prev = NULL; + for (nmethod* cur = scavenge_root_nmethods(); cur != NULL; cur = cur->scavenge_root_link()) { if (cur == nm) { - if (last != NULL) - last->set_scavenge_root_link(next); - else set_scavenge_root_nmethods(next); - nm->set_scavenge_root_link(NULL); - nm->clear_on_scavenge_root_list(); + unlink_scavenge_root_nmethod(cur, prev); return; } - last = cur; - cur = next; + prev = cur; } assert(false, "should have been on list"); } @@ -728,11 +754,7 @@ } else { // Prune it from the list, so we don't have to look at it any more. print_trace("prune_scavenge_root", cur); - cur->set_scavenge_root_link(NULL); - cur->clear_on_scavenge_root_list(); - if (last != NULL) - last->set_scavenge_root_link(next); - else set_scavenge_root_nmethods(next); + unlink_scavenge_root_nmethod(cur, last); } cur = next; }