# HG changeset patch # User rkennke # Date 1521037626 -3600 # Wed Mar 14 15:27:06 2018 +0100 # Node ID b1398f4d3be9f98f5b7e565596ef7b338f7122b3 # Parent c382614abe590f693b84a2697bb50a7fef4d5844 8199612: Replace remaining uses of G1BarrierSet::enqueue() with appropriate Access API calls diff --git a/src/hotspot/share/prims/jvmtiGetLoadedClasses.cpp b/src/hotspot/share/prims/jvmtiGetLoadedClasses.cpp --- a/src/hotspot/share/prims/jvmtiGetLoadedClasses.cpp +++ b/src/hotspot/share/prims/jvmtiGetLoadedClasses.cpp @@ -26,13 +26,11 @@ #include "classfile/systemDictionary.hpp" #include "gc/shared/collectedHeap.hpp" #include "memory/universe.hpp" +#include "oops/access.inline.hpp" #include "prims/jvmtiGetLoadedClasses.hpp" #include "runtime/jniHandles.inline.hpp" #include "runtime/thread.hpp" #include "utilities/stack.inline.hpp" -#if INCLUDE_ALL_GCS -#include "gc/g1/g1BarrierSet.hpp" -#endif // The closure for GetLoadedClasses @@ -42,20 +40,6 @@ JvmtiEnv* _env; Thread* _cur_thread; -// Tell the GC to keep this klass alive -static void ensure_klass_alive(oop o) { - // A klass that was previously considered dead can be looked up in the - // CLD/SD, and its _java_mirror or _class_loader can be stored in a root - // or a reachable object making it alive again. The SATB part of G1 needs - // to get notified about this potential resurrection, otherwise the marking - // might not find the object. -#if INCLUDE_ALL_GCS - if (UseG1GC && o != NULL) { - G1BarrierSet::enqueue(o); - } -#endif -} - public: LoadedClassesClosure(Thread* thread, JvmtiEnv* env) : _cur_thread(thread), _env(env) { assert(_cur_thread == Thread::current(), "must be current thread"); @@ -63,8 +47,12 @@ void do_klass(Klass* k) { // Collect all jclasses - _classStack.push((jclass) _env->jni_reference(Handle(_cur_thread, k->java_mirror()))); - ensure_klass_alive(k->java_mirror()); + // A klass that was previously considered dead can be looked up in the + // CLD/SD, and its _java_mirror or _class_loader can be stored in a root + // or a reachable object making it alive again. We must get the mirror via RootAccess, + // with ON_PHANTOM_OOP_REF to ensure that (SATB) GCs mark the mirror alive. + oop mirror = RootAccess::oop_load(k->java_mirror_handle().ptr_raw()); + _classStack.push((jclass) _env->jni_reference(Handle(_cur_thread, mirror))); } int extract(jclass* result_list) { diff --git a/src/hotspot/share/runtime/jniHandles.cpp b/src/hotspot/share/runtime/jniHandles.cpp --- a/src/hotspot/share/runtime/jniHandles.cpp +++ b/src/hotspot/share/runtime/jniHandles.cpp @@ -26,6 +26,7 @@ #include "gc/shared/oopStorage.inline.hpp" #include "logging/log.hpp" #include "memory/iterator.hpp" +#include "oops/access.inline.hpp" #include "oops/oop.inline.hpp" #include "runtime/handles.inline.hpp" #include "runtime/jniHandles.inline.hpp" @@ -34,9 +35,6 @@ #include "trace/traceMacros.hpp" #include "utilities/align.hpp" #include "utilities/debug.hpp" -#if INCLUDE_ALL_GCS -#include "gc/g1/g1BarrierSet.hpp" -#endif OopStorage* JNIHandles::_global_handles = NULL; OopStorage* JNIHandles::_weak_global_handles = NULL; @@ -151,13 +149,9 @@ oop JNIHandles::resolve_jweak(jweak handle) { assert(handle != NULL, "precondition"); assert(is_jweak(handle), "precondition"); - oop result = jweak_ref(handle); -#if INCLUDE_ALL_GCS - if (result != NULL && UseG1GC) { - G1BarrierSet::enqueue(result); - } -#endif // INCLUDE_ALL_GCS - return result; + char* ptr = reinterpret_cast(handle) - weak_tag_value; + oop* oopptr = reinterpret_cast(ptr); + return RootAccess::oop_load(oopptr); } bool JNIHandles::is_global_weak_cleared(jweak handle) {