Skip to content

Commit

Permalink
8234654: ZGC: Only disarm NMethods when marking/relocating code roots
Browse files Browse the repository at this point in the history
Reviewed-by: eosterlund, stefank
  • Loading branch information
pliden committed Dec 10, 2019
1 parent c041940 commit 6ad3768
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 20 deletions.
4 changes: 4 additions & 0 deletions src/hotspot/share/gc/z/zMark.cpp
Expand Up @@ -140,6 +140,10 @@ class ZMarkRootsIteratorClosure : public ZRootsIteratorClosure {
ZThreadLocalAllocBuffer::retire(thread);
}

virtual bool should_disarm_nmethods() const {
return true;
}

virtual void do_oop(oop* p) {
ZBarrier::mark_barrier_on_root_oop_field(p);
}
Expand Down
23 changes: 17 additions & 6 deletions src/hotspot/share/gc/z/zNMethod.cpp
Expand Up @@ -163,7 +163,7 @@ void ZNMethod::register_nmethod(nmethod* nm) {
ZNMethodTable::register_nmethod(nm);

// Disarm nmethod entry barrier
disarm_nmethod(nm);
disarm(nm);
}

void ZNMethod::unregister_nmethod(nmethod* nm) {
Expand All @@ -187,7 +187,16 @@ void ZNMethod::flush_nmethod(nmethod* nm) {
delete gc_data(nm);
}

void ZNMethod::disarm_nmethod(nmethod* nm) {
bool ZNMethod::is_armed(nmethod* nm) {
BarrierSetNMethod* const bs = BarrierSet::barrier_set()->barrier_set_nmethod();
if (bs != NULL) {
return bs->is_armed(nm);
}

return false;
}

void ZNMethod::disarm(nmethod* nm) {
BarrierSetNMethod* const bs = BarrierSet::barrier_set()->barrier_set_nmethod();
if (bs != NULL) {
bs->disarm(nm);
Expand Down Expand Up @@ -301,10 +310,12 @@ class ZNMethodUnlinkClosure : public NMethodClosure {

ZLocker<ZReentrantLock> locker(ZNMethod::lock_for_nmethod(nm));

// Heal oops and disarm
ZNMethodOopClosure cl;
ZNMethod::nmethod_oops_do(nm, &cl);
ZNMethod::disarm_nmethod(nm);
if (ZNMethod::is_armed(nm)) {
// Heal oops and disarm
ZNMethodOopClosure cl;
ZNMethod::nmethod_oops_do(nm, &cl);
ZNMethod::disarm(nm);
}

// Clear compiled ICs and exception caches
if (!nm->unload_nmethod_caches(_unloading_occurred)) {
Expand Down
3 changes: 2 additions & 1 deletion src/hotspot/share/gc/z/zNMethod.hpp
Expand Up @@ -43,7 +43,8 @@ class ZNMethod : public AllStatic {
static void unregister_nmethod(nmethod* nm);
static void flush_nmethod(nmethod* nm);

static void disarm_nmethod(nmethod* nm);
static bool is_armed(nmethod* nm);
static void disarm(nmethod* nm);

static void nmethod_oops_do(nmethod* nm, OopClosure* cl);

Expand Down
4 changes: 4 additions & 0 deletions src/hotspot/share/gc/z/zRelocate.cpp
Expand Up @@ -56,6 +56,10 @@ class ZRelocateRootsIteratorClosure : public ZRootsIteratorClosure {
ZThreadLocalAllocBuffer::remap(thread);
}

virtual bool should_disarm_nmethods() const {
return true;
}

virtual void do_oop(oop* p) {
ZBarrier::relocate_barrier_on_root_oop_field(p);
}
Expand Down
20 changes: 12 additions & 8 deletions src/hotspot/share/gc/z/zRootsIterator.cpp
Expand Up @@ -139,27 +139,31 @@ void ZParallelWeakOopsDo<T, F>::weak_oops_do(BoolObjectClosure* is_alive, ZRoots
}
}

class ZRootsIteratorCodeBlobClosure : public CodeBlobToOopClosure {
class ZRootsIteratorCodeBlobClosure : public CodeBlobClosure {
private:
BarrierSetNMethod* _bs;
ZRootsIteratorClosure* const _cl;
const bool _should_disarm_nmethods;

public:
ZRootsIteratorCodeBlobClosure(OopClosure* cl) :
CodeBlobToOopClosure(cl, true /* fix_relocations */),
_bs(BarrierSet::barrier_set()->barrier_set_nmethod()) {}
ZRootsIteratorCodeBlobClosure(ZRootsIteratorClosure* cl) :
_cl(cl),
_should_disarm_nmethods(cl->should_disarm_nmethods()) {}

virtual void do_code_blob(CodeBlob* cb) {
nmethod* const nm = cb->as_nmethod_or_null();
if (nm != NULL && nm->oops_do_try_claim()) {
CodeBlobToOopClosure::do_code_blob(cb);
_bs->disarm(nm);
ZNMethod::nmethod_oops_do(nm, _cl);
assert(ZNMethod::is_armed(nm) == _should_disarm_nmethods, "Invalid state");
if (_should_disarm_nmethods) {
ZNMethod::disarm(nm);
}
}
}
};

class ZRootsIteratorThreadClosure : public ThreadClosure {
private:
ZRootsIteratorClosure* _cl;
ZRootsIteratorClosure* const _cl;

public:
ZRootsIteratorThreadClosure(ZRootsIteratorClosure* cl) :
Expand Down
16 changes: 11 additions & 5 deletions src/hotspot/share/gc/z/zRootsIterator.hpp
Expand Up @@ -31,10 +31,7 @@
#include "runtime/thread.hpp"
#include "utilities/globalDefinitions.hpp"

class ZRootsIteratorClosure : public OopClosure {
public:
virtual void do_thread(Thread* thread) {}
};
class ZRootsIteratorClosure;

typedef OopStorage::ParState<true /* concurrent */, false /* is_const */> ZOopStorageIterator;

Expand Down Expand Up @@ -82,9 +79,18 @@ class ZParallelWeakOopsDo {
void weak_oops_do(BoolObjectClosure* is_alive, ZRootsIteratorClosure* cl);
};

class ZRootsIteratorClosure : public OopClosure {
public:
virtual void do_thread(Thread* thread) {}

virtual bool should_disarm_nmethods() const {
return false;
}
};

class ZRootsIterator {
private:
bool _visit_jvmti_weak_export;
const bool _visit_jvmti_weak_export;

void do_universe(ZRootsIteratorClosure* cl);
void do_object_synchronizer(ZRootsIteratorClosure* cl);
Expand Down

0 comments on commit 6ad3768

Please sign in to comment.