diff --git a/src/hotspot/share/gc/z/zRootsIterator.cpp b/src/hotspot/share/gc/z/zRootsIterator.cpp index 58493c2..35ba43f 100644 --- a/src/hotspot/share/gc/z/zRootsIterator.cpp +++ b/src/hotspot/share/gc/z/zRootsIterator.cpp @@ -29,6 +29,7 @@ #include "compiler/oopMap.hpp" #include "gc/shared/oopStorageParState.inline.hpp" #include "gc/z/zGlobals.hpp" +#include "gc/z/zNMethodBarrier.hpp" #include "gc/z/zNMethodTable.hpp" #include "gc/z/zOopClosures.inline.hpp" #include "gc/z/zRootsIterator.hpp" @@ -134,7 +135,8 @@ void ZParallelWeakOopsDo::weak_oops_do(BoolObjectClosure* is_alive, OopClo } } -ZRootsIterator::ZRootsIterator() : +ZRootsIterator::ZRootsIterator(bool strong_only) : + _strong_only(strong_only), _vm_weak_handles_iter(SystemDictionary::vm_weak_oop_storage()), _jni_handles_iter(JNIHandles::global_handles()), _jni_weak_handles_iter(JNIHandles::weak_global_handles()), @@ -150,6 +152,7 @@ ZRootsIterator::ZRootsIterator() : _jni_handles(this), _jni_weak_handles(this), _class_loader_data_graph(this), + _class_loader_data_graph_strong_only(this), _threads(this), _code_cache(this), _string_table(this) { @@ -158,16 +161,19 @@ ZRootsIterator::ZRootsIterator() : Threads::change_thread_claim_parity(); ClassLoaderDataGraph::clear_claimed_marks(); COMPILER2_PRESENT(DerivedPointerTable::clear()); - CodeCache::gc_prologue(); - ZNMethodTable::gc_prologue(); + if (!ClassUnloading) { + ZNMethodTable::gc_prologue(); + } } ZRootsIterator::~ZRootsIterator() { ZStatTimer timer(ZSubPhasePauseRootsTeardown); ResourceMark rm; - ZNMethodTable::gc_epilogue(); - CodeCache::gc_epilogue(); + if (!ClassUnloading) { + ZNMethodTable::gc_epilogue(); + } JvmtiExport::gc_epilogue(); + COMPILER2_PRESENT(DerivedPointerTable::update_pointers()); Threads::assert_all_threads_claimed(); } @@ -232,13 +238,32 @@ void ZRootsIterator::do_class_loader_data_graph(OopClosure* cl) { ClassLoaderDataGraph::cld_do(&cld_cl); } +void ZRootsIterator::do_class_loader_data_graph_strong_only(OopClosure* cl) { + ZStatTimer timer(ZSubPhasePauseRootsClassLoaderDataGraph); + ClassLoaderDataGraph::always_strong_oops_do(cl, /* must_claim */ true); +} + +class ZCodeBlobClosure : public CodeBlobToOopClosure { +public: + ZCodeBlobClosure(OopClosure* cl) : CodeBlobToOopClosure(cl, true) {} + virtual void do_code_blob(CodeBlob* cb) { + CodeBlobToOopClosure::do_code_blob(cb); + if (cb->is_nmethod()) { + nmethod* nm = (nmethod*) cb; + nm->disarm_barrier(); + } + } +}; + class ZRootsIteratorThreadClosure : public ThreadClosure { private: OopClosure* const _cl; + CodeBlobClosure* const _code_cl; public: - ZRootsIteratorThreadClosure(OopClosure* cl) : - _cl(cl) {} + ZRootsIteratorThreadClosure(OopClosure* cl, CodeBlobClosure* code_cl) : + _cl(cl), + _code_cl(code_cl) {} virtual void do_thread(Thread* thread) { if (thread->is_Java_thread()) { @@ -247,14 +272,16 @@ public: } // Process thread oops - thread->oops_do(_cl, NULL); + thread->oops_do(_cl, _code_cl); } }; void ZRootsIterator::do_threads(OopClosure* cl) { ZStatTimer timer(ZSubPhasePauseRootsThreads); ResourceMark rm; - ZRootsIteratorThreadClosure thread_cl(cl); + + ZCodeBlobClosure code_cl(cl); + ZRootsIteratorThreadClosure thread_cl(cl, ClassUnloading ? &code_cl : NULL); Threads::possibly_parallel_threads_do(true, &thread_cl); } @@ -276,9 +303,18 @@ void ZRootsIterator::oops_do(OopClosure* cl, bool visit_jvmti_weak_export) { _jvmti_export.oops_do(cl); _system_dictionary.oops_do(cl); _jni_handles.oops_do(cl); - _class_loader_data_graph.oops_do(cl); _threads.oops_do(cl); - _code_cache.oops_do(cl); + + if (!ClassUnloading) { + _code_cache.oops_do(cl); + } + + if (!ClassUnloading || !ZWeakRoots || !_strong_only) { + _class_loader_data_graph.oops_do(cl); + } else { + _class_loader_data_graph_strong_only.oops_do(cl); + } + if (!ZWeakRoots) { _jvmti_weak_export.oops_do(cl); _jfr_weak.oops_do(cl); @@ -304,6 +340,7 @@ ZWeakRootsIterator::ZWeakRootsIterator() : assert(SafepointSynchronize::is_at_safepoint(), "Should be at safepoint"); ZStatTimer timer(ZSubPhasePauseWeakRootsSetup); StringTable::reset_dead_counter(); + ClassLoaderDataGraph::clear_claimed_marks(); } ZWeakRootsIterator::~ZWeakRootsIterator() {