Skip to content

Commit c96a914

Browse files
committed
8255662: ZGC: Unify nmethod closures in the heap iterator
Reviewed-by: eosterlund, pliden
1 parent aa2862a commit c96a914

File tree

3 files changed

+24
-21
lines changed

3 files changed

+24
-21
lines changed

src/hotspot/share/gc/z/zHeapIterator.cpp

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -250,9 +250,7 @@ class ZHeapIteratorNMethodClosure : public NMethodClosure {
250250
_bs_nm(BarrierSet::barrier_set()->barrier_set_nmethod()) {}
251251

252252
virtual void do_nmethod(nmethod* nm) {
253-
assert(!ClassUnloading, "Only used if class unloading is turned off");
254-
255-
// ClassUnloading is turned off, all nmethods are considered strong,
253+
// If ClassUnloading is turned off, all nmethods are considered strong,
256254
// not only those on the call stacks. The heap iteration might happen
257255
// before the concurrent processign of the code cache, make sure that
258256
// all nmethods have been processed before visiting the oops.
@@ -264,35 +262,24 @@ class ZHeapIteratorNMethodClosure : public NMethodClosure {
264262

265263
class ZHeapIteratorThreadClosure : public ThreadClosure {
266264
private:
267-
OopClosure* const _cl;
268-
269-
class NMethodVisitor : public CodeBlobToOopClosure {
270-
public:
271-
NMethodVisitor(OopClosure* cl) :
272-
CodeBlobToOopClosure(cl, false /* fix_oop_relocations */) {}
273-
274-
void do_code_blob(CodeBlob* cb) {
275-
assert(!cb->is_nmethod() || !ZNMethod::is_armed(cb->as_nmethod()),
276-
"NMethods on stack should have been fixed and disarmed");
277-
278-
CodeBlobToOopClosure::do_code_blob(cb);
279-
}
280-
};
265+
OopClosure* const _cl;
266+
CodeBlobToNMethodClosure _cb_cl;
281267

282268
public:
283-
ZHeapIteratorThreadClosure(OopClosure* cl) : _cl(cl) {}
269+
ZHeapIteratorThreadClosure(OopClosure* cl, NMethodClosure* nm_cl) :
270+
_cl(cl),
271+
_cb_cl(nm_cl) {}
284272

285273
void do_thread(Thread* thread) {
286-
NMethodVisitor code_cl(_cl);
287-
thread->oops_do(_cl, &code_cl);
274+
thread->oops_do(_cl, &_cb_cl);
288275
}
289276
};
290277

291278
void ZHeapIterator::push_strong_roots(const ZHeapIteratorContext& context) {
292279
ZHeapIteratorRootOopClosure<false /* Weak */> cl(context);
293280
ZHeapIteratorCLDCLosure cld_cl(&cl);
294281
ZHeapIteratorNMethodClosure nm_cl(&cl);
295-
ZHeapIteratorThreadClosure thread_cl(&cl);
282+
ZHeapIteratorThreadClosure thread_cl(&cl, &nm_cl);
296283

297284
_concurrent_roots.apply(&cl,
298285
&cld_cl,

src/hotspot/share/memory/iterator.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,10 @@ void MarkingCodeBlobClosure::do_code_blob(CodeBlob* cb) {
6464
do_nmethod(nm);
6565
}
6666
}
67+
68+
void CodeBlobToNMethodClosure::do_code_blob(CodeBlob* cb) {
69+
nmethod* nm = cb->as_nmethod_or_null();
70+
if (nm != NULL) {
71+
_nm_cl->do_nmethod(nm);
72+
}
73+
}

src/hotspot/share/memory/iterator.hpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,15 @@ class NMethodClosure : public Closure {
261261
virtual void do_nmethod(nmethod* n) = 0;
262262
};
263263

264+
class CodeBlobToNMethodClosure : public CodeBlobClosure {
265+
NMethodClosure* const _nm_cl;
266+
267+
public:
268+
CodeBlobToNMethodClosure(NMethodClosure* nm_cl) : _nm_cl(nm_cl) {}
269+
270+
virtual void do_code_blob(CodeBlob* cb);
271+
};
272+
264273
// MonitorClosure is used for iterating over monitors in the monitors cache
265274

266275
class ObjectMonitor;

0 commit comments

Comments
 (0)