--- old/src/share/vm/prims/jvmtiTagMap.cpp 2017-04-25 16:45:42.307172848 +0200 +++ new/src/share/vm/prims/jvmtiTagMap.cpp 2017-04-25 16:45:42.159172853 +0200 @@ -34,11 +34,13 @@ #include "oops/objArrayKlass.hpp" #include "oops/objArrayOop.inline.hpp" #include "oops/oop.inline.hpp" +#include "oops/typeArrayOop.inline.hpp" #include "prims/jvmtiEventController.hpp" #include "prims/jvmtiEventController.inline.hpp" #include "prims/jvmtiExport.hpp" #include "prims/jvmtiImpl.hpp" #include "prims/jvmtiTagMap.hpp" +#include "runtime/access.inline.hpp" #include "runtime/biasedLocking.hpp" #include "runtime/javaCalls.hpp" #include "runtime/jniHandles.hpp" @@ -50,10 +52,6 @@ #include "runtime/vm_operations.hpp" #include "services/serviceUtil.hpp" #include "utilities/macros.hpp" -#if INCLUDE_ALL_GCS -#include "gc/g1/g1SATBCardTableModRefBS.hpp" -#include "gc/parallel/parallelScavengeHeap.hpp" -#endif // INCLUDE_ALL_GCS // JvmtiTagHashmapEntry // @@ -81,15 +79,21 @@ public: // accessor methods - inline oop object() const { return _object; } - inline oop* object_addr() { return &_object; } - inline jlong tag() const { return _tag; } + inline oop* object_addr() { return &_object; } + inline oop object() { return RootAccess::oop_load(object_addr()); } + // Load the object weakly. The returned object is not allowed to be seen by the GC. + inline oop load_object_weakly() { return RootAccess::oop_load(object_addr()); } + inline jlong tag() const { return _tag; } inline void set_tag(jlong tag) { assert(tag != 0, "can't be zero"); _tag = tag; } + inline bool equals(oop object) { + return object == load_object_weakly(); + } + inline JvmtiTagHashmapEntry* next() const { return _next; } inline void set_next(JvmtiTagHashmapEntry* next) { _next = next; } }; @@ -209,7 +213,7 @@ JvmtiTagHashmapEntry* entry = _table[i]; while (entry != NULL) { JvmtiTagHashmapEntry* next = entry->next(); - oop key = entry->object(); + oop key = entry->load_object_weakly(); assert(key != NULL, "jni weak reference cleared!!"); unsigned int h = hash(key, new_size); JvmtiTagHashmapEntry* anchor = new_table[h]; @@ -302,7 +306,7 @@ unsigned int h = hash(key); JvmtiTagHashmapEntry* entry = _table[h]; while (entry != NULL) { - if (entry->object() == key) { + if (entry->equals(key)) { return entry; } entry = entry->next(); @@ -1533,16 +1537,12 @@ void do_entry(JvmtiTagHashmapEntry* entry) { for (int i=0; i<_tag_count; i++) { if (_tags[i] == entry->tag()) { - oop o = entry->object(); + oop* p = entry->object_addr(); + // The reference in this tag map could be the only (implicitly weak) + // reference to that object. If we hand it out, we need to keep it live wrt + // SATB marking similar to other j.l.ref.Reference referents. + oop o = RootAccess::oop_load(p); assert(o != NULL && Universe::heap()->is_in_reserved(o), "sanity check"); -#if INCLUDE_ALL_GCS - if (UseG1GC) { - // The reference in this tag map could be the only (implicitly weak) - // reference to that object. If we hand it out, we need to keep it live wrt - // SATB marking similar to other j.l.ref.Reference referents. - G1SATBCardTableModRefBS::enqueue(o); - } -#endif jobject ref = JNIHandles::make_local(JavaThread::current(), o); _object_results->append(ref); _tag_results->append((uint64_t)entry->tag()); @@ -3362,10 +3362,8 @@ while (entry != NULL) { JvmtiTagHashmapEntry* next = entry->next(); - oop* obj = entry->object_addr(); - // has object been GC'ed - if (!is_alive->do_object_b(entry->object())) { + if (!is_alive->do_object_b(entry->load_object_weakly())) { // grab the tag jlong tag = entry->tag(); guarantee(tag != 0, "checking"); @@ -3383,7 +3381,7 @@ ++freed; } else { f->do_oop(entry->object_addr()); - oop new_oop = entry->object(); + oop new_oop = entry->load_object_weakly(); // if the object has moved then re-hash it and move its // entry to its new location. @@ -3417,7 +3415,7 @@ // Re-add all the entries which were kept aside while (delayed_add != NULL) { JvmtiTagHashmapEntry* next = delayed_add->next(); - unsigned int pos = JvmtiTagHashmap::hash(delayed_add->object(), size); + unsigned int pos = JvmtiTagHashmap::hash(delayed_add->load_object_weakly(), size); delayed_add->set_next(table[pos]); table[pos] = delayed_add; delayed_add = next;