Skip to content

Commit 674a97b

Browse files
author
Thomas Schatzl
committedJan 25, 2022
8280396: G1: Full gc mark stack draining should prefer to make work available to other threads
Reviewed-by: sjohanss, ayang
1 parent fe77250 commit 674a97b

File tree

2 files changed

+40
-18
lines changed

2 files changed

+40
-18
lines changed
 

Diff for: ‎src/hotspot/share/gc/g1/g1FullGCMarker.hpp

+9-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2017, 2022, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -71,15 +71,21 @@ class G1FullGCMarker : public CHeapObj<mtGC> {
7171
G1RegionMarkStatsCache _mark_stats_cache;
7272

7373
inline bool is_empty();
74-
inline bool pop_object(oop& obj);
75-
inline bool pop_objarray(ObjArrayTask& array);
7674
inline void push_objarray(oop obj, size_t index);
7775
inline bool mark_object(oop obj);
7876

7977
// Marking helpers
8078
inline void follow_object(oop obj);
8179
inline void follow_array(objArrayOop array);
8280
inline void follow_array_chunk(objArrayOop array, int index);
81+
82+
inline void drain_oop_stack();
83+
// Transfer contents from the objArray task queue overflow stack to the shared
84+
// objArray stack.
85+
// Returns true and a valid task if there has not been enough space in the shared
86+
// objArray stack, otherwise the task is invalid.
87+
inline bool transfer_objArray_overflow_stack(ObjArrayTask& task);
88+
8389
public:
8490
G1FullGCMarker(G1FullCollector* collector,
8591
uint worker_id,

Diff for: ‎src/hotspot/share/gc/g1/g1FullGCMarker.inline.hpp

+31-15
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2017, 2022, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -91,20 +91,12 @@ inline bool G1FullGCMarker::is_empty() {
9191
return _oop_stack.is_empty() && _objarray_stack.is_empty();
9292
}
9393

94-
inline bool G1FullGCMarker::pop_object(oop& oop) {
95-
return _oop_stack.pop_overflow(oop) || _oop_stack.pop_local(oop);
96-
}
97-
9894
inline void G1FullGCMarker::push_objarray(oop obj, size_t index) {
9995
ObjArrayTask task(obj, index);
10096
assert(task.is_valid(), "bad ObjArrayTask");
10197
_objarray_stack.push(task);
10298
}
10399

104-
inline bool G1FullGCMarker::pop_objarray(ObjArrayTask& arr) {
105-
return _objarray_stack.pop_overflow(arr) || _objarray_stack.pop_local(arr);
106-
}
107-
108100
inline void G1FullGCMarker::follow_array(objArrayOop array) {
109101
follow_klass(array->klass());
110102
// Don't push empty arrays to avoid unnecessary work.
@@ -159,16 +151,40 @@ inline void G1FullGCMarker::follow_object(oop obj) {
159151
}
160152
}
161153

162-
void G1FullGCMarker::drain_stack() {
163-
do {
164-
oop obj;
165-
while (pop_object(obj)) {
154+
inline void G1FullGCMarker::drain_oop_stack() {
155+
oop obj;
156+
while (_oop_stack.pop_overflow(obj)) {
157+
if (!_oop_stack.try_push_to_taskqueue(obj)) {
166158
assert(_bitmap->is_marked(obj), "must be marked");
167159
follow_object(obj);
168160
}
169-
// Process ObjArrays one at a time to avoid marking stack bloat.
161+
}
162+
while (_oop_stack.pop_local(obj)) {
163+
assert(_bitmap->is_marked(obj), "must be marked");
164+
follow_object(obj);
165+
}
166+
}
167+
168+
inline bool G1FullGCMarker::transfer_objArray_overflow_stack(ObjArrayTask& task) {
169+
// It is desirable to move as much as possible work from the overflow queue to
170+
// the shared queue as quickly as possible.
171+
while (_objarray_stack.pop_overflow(task)) {
172+
if (!_objarray_stack.try_push_to_taskqueue(task)) {
173+
return true;
174+
}
175+
}
176+
return false;
177+
}
178+
179+
void G1FullGCMarker::drain_stack() {
180+
do {
181+
// First, drain regular oop stack.
182+
drain_oop_stack();
183+
184+
// Then process ObjArrays one at a time to avoid marking stack bloat.
170185
ObjArrayTask task;
171-
if (pop_objarray(task)) {
186+
if (transfer_objArray_overflow_stack(task) ||
187+
_objarray_stack.pop_local(task)) {
172188
follow_array_chunk(objArrayOop(task.obj()), task.index());
173189
}
174190
} while (!is_empty());

0 commit comments

Comments
 (0)