8266426: ZHeapIteratorOopClosure does not handle native access properly

Co-authored-by: Per Liden <pliden@openjdk.org>
Co-authored-by: Erik Österlund <eosterlund@openjdk.org>
Co-authored-by: Stefan Karlsson <stefank@openjdk.org>
Reviewed-by: stefank, pliden
This commit is contained in:
Albert Mingkun Yang 2021-05-06 12:52:34 +00:00
parent 2438498a3f
commit 47d4438e75

View File

@ -27,6 +27,7 @@
#include "gc/shared/gc_globals.hpp"
#include "gc/shared/taskqueue.inline.hpp"
#include "gc/z/zAddress.inline.hpp"
#include "gc/z/zCollectedHeap.hpp"
#include "gc/z/zGlobals.hpp"
#include "gc/z/zGranuleMap.inline.hpp"
#include "gc/z/zHeapIterator.hpp"
@ -123,12 +124,14 @@ public:
};
template <bool VisitReferents>
class ZHeapIteratorOopClosure : public ClaimMetadataVisitingOopIterateClosure {
class ZHeapIteratorOopClosure : public OopIterateClosure {
private:
const ZHeapIteratorContext& _context;
const oop _base;
oop load_oop(oop* p) {
assert(ZCollectedHeap::heap()->is_in(p), "Should be in heap");
if (VisitReferents) {
return HeapAccess<AS_NO_KEEPALIVE | ON_UNKNOWN_OOP_REF>::oop_load_at(_base, _base->field_offset(p));
}
@ -138,7 +141,7 @@ private:
public:
ZHeapIteratorOopClosure(const ZHeapIteratorContext& context, oop base) :
ClaimMetadataVisitingOopIterateClosure(ClassLoaderData::_claim_other),
OopIterateClosure(),
_context(context),
_base(base) {}
@ -154,6 +157,39 @@ public:
virtual void do_oop(narrowOop* p) {
ShouldNotReachHere();
}
virtual bool do_metadata() {
return true;
}
virtual void do_klass(Klass* k) {
ClassLoaderData* const cld = k->class_loader_data();
ZHeapIteratorOopClosure::do_cld(cld);
}
virtual void do_cld(ClassLoaderData* cld) {
class NativeAccessClosure : public OopClosure {
private:
const ZHeapIteratorContext& _context;
public:
explicit NativeAccessClosure(const ZHeapIteratorContext& context) :
_context(context) {}
virtual void do_oop(oop* p) {
assert(!ZCollectedHeap::heap()->is_in(p), "Should not be in heap");
const oop obj = NativeAccess<AS_NO_KEEPALIVE>::oop_load(p);
_context.mark_and_push(obj);
}
virtual void do_oop(narrowOop* p) {
ShouldNotReachHere();
}
};
NativeAccessClosure cl(_context);
cld->oops_do(&cl, ClassLoaderData::_claim_other);
}
};
ZHeapIterator::ZHeapIterator(uint nworkers, bool visit_weaks) :