@@ -62,10 +62,23 @@ class VirtualSpaceSummary;
6262class WorkGang ;
6363class nmethod ;
6464
65- class ParallelObjectIterator : public CHeapObj <mtGC> {
65+ class ParallelObjectIteratorImpl : public CHeapObj <mtGC> {
6666public:
67+ virtual ~ParallelObjectIteratorImpl () {}
6768 virtual void object_iterate (ObjectClosure* cl, uint worker_id) = 0;
68- virtual ~ParallelObjectIterator () {}
69+ };
70+
71+ // User facing parallel object iterator. This is a StackObj, which ensures that
72+ // the _impl is allocated and deleted in the scope of this object. This ensures
73+ // the life cycle of the implementation is as required by ThreadsListHandle,
74+ // which is sometimes used by the root iterators.
75+ class ParallelObjectIterator : public StackObj {
76+ ParallelObjectIteratorImpl* _impl;
77+
78+ public:
79+ ParallelObjectIterator (uint thread_num);
80+ ~ParallelObjectIterator ();
81+ void object_iterate (ObjectClosure* cl, uint worker_id);
6982};
7083
7184//
@@ -82,6 +95,7 @@ class CollectedHeap : public CHeapObj<mtGC> {
8295 friend class JVMCIVMStructs ;
8396 friend class IsGCActiveMark ; // Block structured external access to _is_gc_active
8497 friend class MemAllocator ;
98+ friend class ParallelObjectIterator ;
8599
86100 private:
87101 GCHeapLog* _gc_heap_log;
@@ -382,10 +396,12 @@ class CollectedHeap : public CHeapObj<mtGC> {
382396 // Iterate over all objects, calling "cl.do_object" on each.
383397 virtual void object_iterate (ObjectClosure* cl) = 0;
384398
385- virtual ParallelObjectIterator* parallel_object_iterator (uint thread_num) {
399+ protected:
400+ virtual ParallelObjectIteratorImpl* parallel_object_iterator (uint thread_num) {
386401 return NULL ;
387402 }
388403
404+ public:
389405 // Keep alive an object that was loaded with AS_NO_KEEPALIVE.
390406 virtual void keep_alive (oop obj) {}
391407
0 commit comments