Skip to content

Commit 9730266

Browse files
committed
8262973: Verify ParCompactionManager instance in PCAdjustPointerClosure
Reviewed-by: kbarrett, tschatzl
1 parent d91550e commit 9730266

File tree

5 files changed

+47
-29
lines changed

5 files changed

+47
-29
lines changed

src/hotspot/share/gc/parallel/psCompactionManager.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,3 +179,19 @@ void ParCompactionManager::push_shadow_region(size_t shadow_region) {
179179
void ParCompactionManager::remove_all_shadow_regions() {
180180
_shadow_region_array->clear();
181181
}
182+
183+
#ifdef ASSERT
184+
void ParCompactionManager::verify_all_marking_stack_empty() {
185+
uint parallel_gc_threads = ParallelGCThreads;
186+
for (uint i = 0; i <= parallel_gc_threads; i++) {
187+
assert(_manager_array[i]->marking_stacks_empty(), "Marking stack should be empty");
188+
}
189+
}
190+
191+
void ParCompactionManager::verify_all_region_stack_empty() {
192+
uint parallel_gc_threads = ParallelGCThreads;
193+
for (uint i = 0; i <= parallel_gc_threads; i++) {
194+
assert(_manager_array[i]->region_stack()->is_empty(), "Region stack should be empty");
195+
}
196+
}
197+
#endif

src/hotspot/share/gc/parallel/psCompactionManager.hpp

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,6 @@ class ParCompactionManager : public CHeapObj<mtGC> {
4646
friend class PCRefProcTask;
4747
friend class MarkFromRootsTask;
4848
friend class UpdateDensePrefixAndCompactionTask;
49-
50-
public:
51-
52-
5349
private:
5450
typedef GenericTaskQueue<oop, mtGC> OopTaskQueue;
5551
typedef GenericTaskQueueSet<OopTaskQueue, mtGC> OopTaskQueueSet;
@@ -69,7 +65,6 @@ class ParCompactionManager : public CHeapObj<mtGC> {
6965
static RegionTaskQueueSet* _region_task_queues;
7066
static PSOldGen* _old_gen;
7167

72-
private:
7368
OverflowTaskQueue<oop, mtGC> _marking_stack;
7469
ObjArrayTaskQueue _objarray_stack;
7570
size_t _next_shadow_region;
@@ -143,7 +138,7 @@ class ParCompactionManager : public CHeapObj<mtGC> {
143138

144139
RegionTaskQueue* region_stack() { return &_region_stack; }
145140

146-
inline static ParCompactionManager* manager_array(uint index);
141+
static ParCompactionManager* get_vmthread_cm() { return _manager_array[ParallelGCThreads]; }
147142

148143
ParCompactionManager();
149144

@@ -196,13 +191,13 @@ class ParCompactionManager : public CHeapObj<mtGC> {
196191
FollowStackClosure(ParCompactionManager* cm) : _compaction_manager(cm) { }
197192
virtual void do_void();
198193
};
199-
};
200194

201-
inline ParCompactionManager* ParCompactionManager::manager_array(uint index) {
202-
assert(_manager_array != NULL, "access of NULL manager_array");
203-
assert(index <= ParallelGCThreads, "out of range manager_array access");
204-
return _manager_array[index];
205-
}
195+
// Called after marking.
196+
static void verify_all_marking_stack_empty() NOT_DEBUG_RETURN;
197+
198+
// Region staks hold regions in from-space; called after compaction.
199+
static void verify_all_region_stack_empty() NOT_DEBUG_RETURN;
200+
};
206201

207202
bool ParCompactionManager::marking_stacks_empty() const {
208203
return _marking_stack.is_empty() && _objarray_stack.is_empty();

src/hotspot/share/gc/parallel/psParallelCompact.cpp

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1784,8 +1784,7 @@ bool PSParallelCompact::invoke_no_policy(bool maximum_heap_compaction) {
17841784
const PreGenGCValues pre_gc_values = heap->get_pre_gc_values();
17851785

17861786
// Get the compaction manager reserved for the VM thread.
1787-
ParCompactionManager* const vmthread_cm =
1788-
ParCompactionManager::manager_array(ParallelScavengeHeap::heap()->workers().total_workers());
1787+
ParCompactionManager* const vmthread_cm = ParCompactionManager::get_vmthread_cm();
17891788

17901789
{
17911790
const uint active_workers =
@@ -1837,6 +1836,8 @@ bool PSParallelCompact::invoke_no_policy(bool maximum_heap_compaction) {
18371836
compaction_start.update();
18381837
compact();
18391838

1839+
ParCompactionManager::verify_all_region_stack_empty();
1840+
18401841
// Reset the mark bitmap, summary data, and do other bookkeeping. Must be
18411842
// done before resizing.
18421843
post_compact();
@@ -1933,15 +1934,6 @@ bool PSParallelCompact::invoke_no_policy(bool maximum_heap_compaction) {
19331934
heap->post_full_gc_dump(&_gc_timer);
19341935
}
19351936

1936-
#ifdef ASSERT
1937-
for (size_t i = 0; i < ParallelGCThreads + 1; ++i) {
1938-
ParCompactionManager* const cm =
1939-
ParCompactionManager::manager_array(int(i));
1940-
assert(cm->marking_stack()->is_empty(), "should be empty");
1941-
assert(cm->region_stack()->is_empty(), "Region stack " SIZE_FORMAT " is not empty", i);
1942-
}
1943-
#endif // ASSERT
1944-
19451937
if (VerifyAfterGC && heap->total_collections() >= VerifyGCStartAt) {
19461938
Universe::verify("After GC");
19471939
}
@@ -2181,7 +2173,7 @@ void PSParallelCompact::marking_phase(ParCompactionManager* cm,
21812173
}
21822174

21832175
// This is the point where the entire marking should have completed.
2184-
assert(cm->marking_stacks_empty(), "Marking should have completed");
2176+
ParCompactionManager::verify_all_marking_stack_empty();
21852177

21862178
{
21872179
GCTraceTime(Debug, gc, phases) tm("Weak Processing", &_gc_timer);
@@ -2207,6 +2199,19 @@ void PSParallelCompact::marking_phase(ParCompactionManager* cm,
22072199
_gc_tracer.report_object_count_after_gc(is_alive_closure());
22082200
}
22092201

2202+
#ifdef ASSERT
2203+
void PCAdjustPointerClosure::verify_cm(ParCompactionManager* cm) {
2204+
assert(cm != NULL, "associate ParCompactionManage should not be NULL");
2205+
auto vmthread_cm = ParCompactionManager::get_vmthread_cm();
2206+
if (Thread::current()->is_VM_thread()) {
2207+
assert(cm == vmthread_cm, "VM threads should use ParCompactionManager from get_vmthread_cm()");
2208+
} else {
2209+
assert(Thread::current()->is_GC_task_thread(), "Must be a GC thread");
2210+
assert(cm != vmthread_cm, "GC threads should use ParCompactionManager from gc_thread_compaction_manager()");
2211+
}
2212+
}
2213+
#endif
2214+
22102215
class PSAdjustTask final : public AbstractGangTask {
22112216
SubTasksDone _sub_tasks;
22122217
WeakProcessor::Task _weak_proc_task;
@@ -2614,9 +2619,11 @@ void PSParallelCompact::compact() {
26142619
}
26152620

26162621
{
2617-
// Update the deferred objects, if any. Any compaction manager can be used.
26182622
GCTraceTime(Trace, gc, phases) tm("Deferred Updates", &_gc_timer);
2619-
ParCompactionManager* cm = ParCompactionManager::manager_array(0);
2623+
// Update the deferred objects, if any. In principle, any compaction
2624+
// manager can be used. However, since the current thread is VM thread, we
2625+
// use the rightful one to keep the verification logic happy.
2626+
ParCompactionManager* cm = ParCompactionManager::get_vmthread_cm();
26202627
for (unsigned int id = old_space_id; id < last_space_id; ++id) {
26212628
update_deferred_objects(cm, SpaceId(id));
26222629
}

src/hotspot/share/gc/parallel/psParallelCompact.inline.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ inline void PSParallelCompact::adjust_pointer(T* p, ParCompactionManager* cm) {
126126
class PCAdjustPointerClosure: public BasicOopIterateClosure {
127127
public:
128128
PCAdjustPointerClosure(ParCompactionManager* cm) {
129-
assert(cm != NULL, "associate ParCompactionManage should not be NULL");
129+
verify_cm(cm);
130130
_cm = cm;
131131
}
132132
template <typename T> void do_oop_nv(T* p) { PSParallelCompact::adjust_pointer(p, _cm); }
@@ -136,6 +136,8 @@ class PCAdjustPointerClosure: public BasicOopIterateClosure {
136136
virtual ReferenceIterationMode reference_iteration_mode() { return DO_FIELDS; }
137137
private:
138138
ParCompactionManager* _cm;
139+
140+
static void verify_cm(ParCompactionManager* cm) NOT_DEBUG_RETURN;
139141
};
140142

141143
#endif // SHARE_GC_PARALLEL_PSPARALLELCOMPACT_INLINE_HPP

test/hotspot/gtest/gc/parallel/test_psParallelCompact.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,6 @@ TEST_VM(PSParallelCompact, print_generic_summary_data) {
4949
// end region. The end region should not be printed because it
5050
// corresponds to the space after the end of the heap.
5151
ParallelScavengeHeap* heap = ParallelScavengeHeap::heap();
52-
ParCompactionManager* const vmthread_cm =
53-
ParCompactionManager::manager_array(ParallelGCThreads);
5452
HeapWord* begin_heap =
5553
(HeapWord*) heap->old_gen()->virtual_space()->low_boundary();
5654
HeapWord* end_heap =

0 commit comments

Comments
 (0)