Skip to content

Commit 3460bce

Browse files
committed
8229451: ZGC: Make some roots invisible to the heap iterator
Reviewed-by: eosterlund
1 parent 403475d commit 3460bce

File tree

8 files changed

+65
-20
lines changed

8 files changed

+65
-20
lines changed

src/hotspot/share/gc/shared/gcThreadLocalData.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,6 @@
4040
// should consider placing frequently accessed fields first in
4141
// T, so that field offsets relative to Thread are small, which
4242
// often allows for a more compact instruction encoding.
43-
typedef uint64_t GCThreadLocalData[18]; // 144 bytes
43+
typedef uint64_t GCThreadLocalData[19]; // 152 bytes
4444

4545
#endif // SHARE_GC_SHARED_GCTHREADLOCALDATA_HPP

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ void ZHeapIterator::objects_do(ObjectClosure* cl) {
193193
ZStatTimerDisable disable;
194194

195195
// Push roots to visit
196-
push_roots<ZRootsIterator, false /* Concurrent */, false /* Weak */>();
196+
push_roots<ZRootsIteratorNoInvisible, false /* Concurrent */, false /* Weak */>();
197197
push_roots<ZConcurrentRootsIteratorClaimOther, true /* Concurrent */, false /* Weak */>();
198198
if (VisitWeaks) {
199199
push_roots<ZWeakRootsIterator, false /* Concurrent */, true /* Weak */>();

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ class ZMarkRootsTask : public ZTask {
156156
ZMarkRootsTask(ZMark* mark) :
157157
ZTask("ZMarkRootsTask"),
158158
_mark(mark),
159-
_roots() {}
159+
_roots(true /* visit_invisible */, false /* visit_jvmti_weak_export */) {}
160160

161161
virtual void work() {
162162
_roots.oops_do(&_cl);

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

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
*/
2323

2424
#include "precompiled.hpp"
25+
#include "gc/z/zThreadLocalData.hpp"
2526
#include "gc/z/zObjArrayAllocator.hpp"
2627
#include "gc/z/zUtils.inline.hpp"
2728
#include "memory/universe.hpp"
@@ -57,8 +58,12 @@ ZObjArrayAllocator::ZObjArrayAllocator(Klass* klass, size_t word_size, int lengt
5758
_final_klass(klass) {}
5859

5960
oop ZObjArrayAllocator::finish(HeapWord* mem) const {
60-
HandleMark hm;
61-
Handle array(_thread, ObjArrayAllocator::finish(mem));
61+
// Set mark word and initial klass pointer
62+
ObjArrayAllocator::finish(mem);
63+
64+
// Keep the array alive across safepoints, but make it invisible
65+
// to the heap itarator until the final klass pointer has been set
66+
ZThreadLocalData::set_invisible_root(_thread, (oop*)&mem);
6267

6368
const size_t segment_max = ZUtils::bytes_to_words(64 * K);
6469
const size_t skip = arrayOopDesc::header_size(ArrayKlass::cast(_klass)->element_type());
@@ -67,7 +72,7 @@ oop ZObjArrayAllocator::finish(HeapWord* mem) const {
6772
while (remaining > 0) {
6873
// Clear segment
6974
const size_t segment = MIN2(remaining, segment_max);
70-
Copy::zero_to_words((HeapWord*)array() + (_word_size - remaining), segment);
75+
Copy::zero_to_words(mem + (_word_size - remaining), segment);
7176
remaining -= segment;
7277

7378
if (remaining > 0) {
@@ -77,9 +82,12 @@ oop ZObjArrayAllocator::finish(HeapWord* mem) const {
7782
}
7883

7984
if (_klass != _final_klass) {
80-
// Set final klass
81-
oopDesc::release_set_klass((HeapWord*)array(), _final_klass);
85+
// Set final klass pointer
86+
oopDesc::release_set_klass(mem, _final_klass);
8287
}
8388

84-
return array();
89+
// Make the array visible to the heap iterator
90+
ZThreadLocalData::clear_invisible_root(_thread);
91+
92+
return oop(mem);
8593
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,12 @@ class ZRelocateRootsTask : public ZTask {
6969
public:
7070
ZRelocateRootsTask() :
7171
ZTask("ZRelocateRootsTask"),
72-
_roots() {}
72+
_roots(true /* visit_invisible */, true /* visit_jvmti_weak_export */) {}
7373

7474
virtual void work() {
7575
// During relocation we need to visit the JVMTI
7676
// export weak roots to rehash the JVMTI tag map
77-
_roots.oops_do(&_cl, true /* visit_jvmti_weak_export */);
77+
_roots.oops_do(&_cl);
7878
}
7979
};
8080

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

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -159,19 +159,26 @@ class ZRootsIteratorCodeBlobClosure : public CodeBlobToOopClosure {
159159
class ZRootsIteratorThreadClosure : public ThreadClosure {
160160
private:
161161
ZRootsIteratorClosure* _cl;
162+
const bool _visit_invisible;
162163

163164
public:
164-
ZRootsIteratorThreadClosure(ZRootsIteratorClosure* cl) :
165-
_cl(cl) {}
165+
ZRootsIteratorThreadClosure(ZRootsIteratorClosure* cl, bool visit_invisible) :
166+
_cl(cl),
167+
_visit_invisible(visit_invisible) {}
166168

167169
virtual void do_thread(Thread* thread) {
168170
ZRootsIteratorCodeBlobClosure code_cl(_cl);
169171
thread->oops_do(_cl, ClassUnloading ? &code_cl : NULL);
170172
_cl->do_thread(thread);
173+
if (_visit_invisible && ZThreadLocalData::has_invisible_root(thread)) {
174+
_cl->do_oop(ZThreadLocalData::invisible_root(thread));
175+
}
171176
}
172177
};
173178

174-
ZRootsIterator::ZRootsIterator() :
179+
ZRootsIterator::ZRootsIterator(bool visit_invisible, bool visit_jvmti_weak_export) :
180+
_visit_invisible(visit_invisible),
181+
_visit_jvmti_weak_export(visit_jvmti_weak_export),
175182
_universe(this),
176183
_object_synchronizer(this),
177184
_management(this),
@@ -239,7 +246,7 @@ void ZRootsIterator::do_system_dictionary(ZRootsIteratorClosure* cl) {
239246
void ZRootsIterator::do_threads(ZRootsIteratorClosure* cl) {
240247
ZStatTimer timer(ZSubPhasePauseRootsThreads);
241248
ResourceMark rm;
242-
ZRootsIteratorThreadClosure thread_cl(cl);
249+
ZRootsIteratorThreadClosure thread_cl(cl, _visit_invisible);
243250
Threads::possibly_parallel_threads_do(true, &thread_cl);
244251
}
245252

@@ -248,7 +255,7 @@ void ZRootsIterator::do_code_cache(ZRootsIteratorClosure* cl) {
248255
ZNMethod::oops_do(cl);
249256
}
250257

251-
void ZRootsIterator::oops_do(ZRootsIteratorClosure* cl, bool visit_jvmti_weak_export) {
258+
void ZRootsIterator::oops_do(ZRootsIteratorClosure* cl) {
252259
ZStatTimer timer(ZSubPhasePauseRoots);
253260
_universe.oops_do(cl);
254261
_object_synchronizer.oops_do(cl);
@@ -259,7 +266,7 @@ void ZRootsIterator::oops_do(ZRootsIteratorClosure* cl, bool visit_jvmti_weak_ex
259266
if (!ClassUnloading) {
260267
_code_cache.oops_do(cl);
261268
}
262-
if (visit_jvmti_weak_export) {
269+
if (_visit_jvmti_weak_export) {
263270
_jvmti_weak_export.oops_do(cl);
264271
}
265272
}

src/hotspot/share/gc/z/zRootsIterator.hpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@ class ZParallelWeakOopsDo {
8484

8585
class ZRootsIterator {
8686
private:
87+
bool _visit_invisible;
88+
bool _visit_jvmti_weak_export;
89+
8790
void do_universe(ZRootsIteratorClosure* cl);
8891
void do_object_synchronizer(ZRootsIteratorClosure* cl);
8992
void do_management(ZRootsIteratorClosure* cl);
@@ -103,10 +106,16 @@ class ZRootsIterator {
103106
ZParallelOopsDo<ZRootsIterator, &ZRootsIterator::do_code_cache> _code_cache;
104107

105108
public:
106-
ZRootsIterator();
109+
ZRootsIterator(bool visit_invisible = true, bool visit_jvmti_weak_export = false);
107110
~ZRootsIterator();
108111

109-
void oops_do(ZRootsIteratorClosure* cl, bool visit_jvmti_weak_export = false);
112+
void oops_do(ZRootsIteratorClosure* cl);
113+
};
114+
115+
class ZRootsIteratorNoInvisible : public ZRootsIterator {
116+
public:
117+
ZRootsIteratorNoInvisible() :
118+
ZRootsIterator(false /* visit_invisible */, false /* visit_jvmti_weak_export */) {}
110119
};
111120

112121
class ZConcurrentRootsIterator {

src/hotspot/share/gc/z/zThreadLocalData.hpp

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,12 @@ class ZThreadLocalData {
3434
private:
3535
uintptr_t _address_bad_mask;
3636
ZMarkThreadLocalStacks _stacks;
37+
oop* _invisible_root;
3738

3839
ZThreadLocalData() :
3940
_address_bad_mask(0),
40-
_stacks() {}
41+
_stacks(),
42+
_invisible_root(NULL) {}
4143

4244
static ZThreadLocalData* data(Thread* thread) {
4345
return thread->gc_data<ZThreadLocalData>();
@@ -60,6 +62,25 @@ class ZThreadLocalData {
6062
return &data(thread)->_stacks;
6163
}
6264

65+
static void set_invisible_root(Thread* thread, oop* root) {
66+
assert(!has_invisible_root(thread), "Already set");
67+
data(thread)->_invisible_root = root;
68+
}
69+
70+
static void clear_invisible_root(Thread* thread) {
71+
assert(has_invisible_root(thread), "Should be set");
72+
data(thread)->_invisible_root = NULL;
73+
}
74+
75+
static bool has_invisible_root(Thread* thread) {
76+
return data(thread)->_invisible_root != NULL;
77+
}
78+
79+
static oop* invisible_root(Thread* thread) {
80+
assert(has_invisible_root(thread), "Should be set");
81+
return data(thread)->_invisible_root;
82+
}
83+
6384
static ByteSize address_bad_mask_offset() {
6485
return Thread::gc_data_offset() + byte_offset_of(ZThreadLocalData, _address_bad_mask);
6586
}

0 commit comments

Comments
 (0)