Skip to content

Commit 085dbe3

Browse files
Bin LiaoRealCLanger
Bin Liao
authored andcommitted
8215624: Add parallel heap iteration for jmap –histo
8253763: ParallelObjectIterator should have virtual destructor Chunk and parallelize the heap scan Reviewed-by: clanger Backport-of: 3498a10
1 parent 2de01c1 commit 085dbe3

18 files changed

+292
-45
lines changed

src/hotspot/share/gc/cms/cmsHeap.hpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2017, 2021, 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
@@ -67,6 +67,9 @@ class CMSHeap : public GenCollectedHeap {
6767

6868
virtual void print_gc_threads_on(outputStream* st) const;
6969
virtual void gc_threads_do(ThreadClosure* tc) const;
70+
// Runs the given AbstractGangTask with the current active workers.
71+
// No workGang for CmsHeap, work serially with thread 0
72+
virtual void run_task(AbstractGangTask* task) { task->work(0); }
7073
virtual void print_on_error(outputStream* st) const;
7174

7275
// Perform a full collection of the heap; intended for use in implementing

src/hotspot/share/gc/epsilon/epsilonHeap.hpp

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, 2018, Red Hat, Inc. All rights reserved.
2+
* Copyright (c) 2017, 2021, Red Hat, Inc. 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
@@ -136,6 +136,10 @@ class EpsilonHeap : public CollectedHeap {
136136
virtual void print_gc_threads_on(outputStream* st) const {}
137137
virtual void gc_threads_do(ThreadClosure* tc) const {}
138138

139+
// Runs the given AbstractGangTask with the current active workers
140+
// No workGang for EpsilonHeap, work serially with thread 0
141+
virtual void run_task(AbstractGangTask* task) { task->work(0); }
142+
139143
// No heap verification
140144
virtual void prepare_for_verify() {}
141145
virtual void verify(VerifyOption option) {}

src/hotspot/share/gc/g1/g1CollectedHeap.cpp

+29-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2001, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2001, 2021, 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
@@ -78,6 +78,7 @@
7878
#include "logging/log.hpp"
7979
#include "memory/allocation.hpp"
8080
#include "memory/iterator.hpp"
81+
#include "memory/heapInspection.hpp"
8182
#include "memory/metaspaceShared.hpp"
8283
#include "memory/resourceArea.hpp"
8384
#include "oops/access.inline.hpp"
@@ -152,6 +153,9 @@ void G1RegionMappingChangedListener::on_commit(uint start_idx, size_t num_region
152153
reset_from_card_cache(start_idx, num_regions);
153154
}
154155

156+
void G1CollectedHeap::run_task(AbstractGangTask* task) {
157+
workers()->run_task(task, workers()->active_workers());
158+
}
155159

156160
HeapRegion* G1CollectedHeap::new_heap_region(uint hrs_index,
157161
MemRegion mr) {
@@ -2120,6 +2124,30 @@ void G1CollectedHeap::object_iterate(ObjectClosure* cl) {
21202124
heap_region_iterate(&blk);
21212125
}
21222126

2127+
class G1ParallelObjectIterator : public ParallelObjectIterator {
2128+
private:
2129+
G1CollectedHeap* _heap;
2130+
HeapRegionClaimer _claimer;
2131+
2132+
public:
2133+
G1ParallelObjectIterator(uint thread_num) :
2134+
_heap(G1CollectedHeap::heap()),
2135+
_claimer(thread_num == 0 ? G1CollectedHeap::heap()->workers()->active_workers() : thread_num) {}
2136+
2137+
virtual void object_iterate(ObjectClosure* cl, uint worker_id) {
2138+
_heap->object_iterate_parallel(cl, worker_id, &_claimer);
2139+
}
2140+
};
2141+
2142+
ParallelObjectIterator* G1CollectedHeap::parallel_object_iterator(uint thread_num) {
2143+
return new G1ParallelObjectIterator(thread_num);
2144+
}
2145+
2146+
void G1CollectedHeap::object_iterate_parallel(ObjectClosure* cl, uint worker_id, HeapRegionClaimer* claimer) {
2147+
IterateObjectClosureRegionClosure blk(cl);
2148+
heap_region_par_iterate_from_worker_offset(&blk, claimer, worker_id);
2149+
}
2150+
21232151
void G1CollectedHeap::keep_alive(oop obj) {
21242152
G1BarrierSet::enqueue(obj);
21252153
}

src/hotspot/share/gc/g1/g1CollectedHeap.hpp

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2001, 2018, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2001, 2021, 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
@@ -528,6 +528,9 @@ class G1CollectedHeap : public CollectedHeap {
528528

529529
WorkGang* workers() const { return _workers; }
530530

531+
// Runs the given AbstractGangTask with the current active workers.
532+
virtual void run_task(AbstractGangTask* task);
533+
531534
G1Allocator* allocator() {
532535
return _allocator;
533536
}
@@ -1116,13 +1119,17 @@ class G1CollectedHeap : public CollectedHeap {
11161119

11171120
// Iteration functions.
11181121

1122+
void object_iterate_parallel(ObjectClosure* cl, uint worker_id, HeapRegionClaimer* claimer);
1123+
11191124
// Iterate over all objects, calling "cl.do_object" on each.
11201125
virtual void object_iterate(ObjectClosure* cl);
11211126

11221127
virtual void safe_object_iterate(ObjectClosure* cl) {
11231128
object_iterate(cl);
11241129
}
11251130

1131+
virtual ParallelObjectIterator* parallel_object_iterator(uint thread_num);
1132+
11261133
// Keep alive an object that was loaded with AS_NO_KEEPALIVE.
11271134
virtual void keep_alive(oop obj);
11281135

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

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2001, 2018, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2001, 2021, 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
@@ -604,6 +604,12 @@ void ParallelScavengeHeap::print_gc_threads_on(outputStream* st) const {
604604
PSScavenge::gc_task_manager()->print_threads_on(st);
605605
}
606606

607+
void ParallelScavengeHeap::run_task(AbstractGangTask* task) {
608+
WorkGang workers("GC Threads", ParallelGCThreads, true, false);
609+
workers.initialize_workers();
610+
workers.run_task(task);
611+
}
612+
607613
void ParallelScavengeHeap::print_tracing_info() const {
608614
AdaptiveSizePolicyOutput::print();
609615
log_debug(gc, heap, exit)("Accumulated young generation GC time %3.7f secs", PSScavenge::accumulated_time()->seconds());

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

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2001, 2018, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2001, 2021, 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
@@ -49,6 +49,7 @@ class MemoryPool;
4949
class PSAdaptiveSizePolicy;
5050
class PSCardTable;
5151
class PSHeapSummary;
52+
class WorkGang;
5253

5354
class ParallelScavengeHeap : public CollectedHeap {
5455
friend class VMStructs;
@@ -230,6 +231,8 @@ class ParallelScavengeHeap : public CollectedHeap {
230231
virtual void print_on_error(outputStream* st) const;
231232
virtual void print_gc_threads_on(outputStream* st) const;
232233
virtual void gc_threads_do(ThreadClosure* tc) const;
234+
// Runs the given AbstractGangTask with the current active workers.
235+
virtual void run_task(AbstractGangTask* task);
233236
virtual void print_tracing_info() const;
234237

235238
void verify(VerifyOption option /* ignored */);

src/hotspot/share/gc/serial/serialHeap.hpp

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2017, 2021, 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
@@ -81,6 +81,10 @@ class SerialHeap : public GenCollectedHeap {
8181
template <typename OopClosureType1, typename OopClosureType2>
8282
void oop_since_save_marks_iterate(OopClosureType1* cur,
8383
OopClosureType2* older);
84+
85+
// Runs the given AbstractGangTask with the current active workers.
86+
// No workGang for SerialHeap, work serially with thread 0.
87+
virtual void run_task(AbstractGangTask* task) { task->work(0); }
8488
};
8589

8690
#endif // SHARE_VM_GC_CMS_CMSHEAP_HPP

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

+16-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2001, 2018, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2001, 2021, 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
@@ -28,6 +28,7 @@
2828
#include "gc/shared/gcCause.hpp"
2929
#include "gc/shared/gcWhen.hpp"
3030
#include "memory/allocation.hpp"
31+
#include "memory/heapInspection.hpp"
3132
#include "runtime/handles.hpp"
3233
#include "runtime/perfData.hpp"
3334
#include "runtime/safepoint.hpp"
@@ -42,6 +43,7 @@
4243
// class defines the functions that a heap must implement, and contains
4344
// infrastructure common to all heaps.
4445

46+
class AbstractGangTask;
4547
class AdaptiveSizePolicy;
4648
class BarrierSet;
4749
class CollectorPolicy;
@@ -83,6 +85,12 @@ class GCHeapLog : public EventLogBase<GCMessage> {
8385
}
8486
};
8587

88+
class ParallelObjectIterator : public CHeapObj<mtGC> {
89+
public:
90+
virtual void object_iterate(ObjectClosure* cl, uint worker_id) = 0;
91+
virtual ~ParallelObjectIterator() {}
92+
};
93+
8694
//
8795
// CollectedHeap
8896
// GenCollectedHeap
@@ -465,6 +473,10 @@ class CollectedHeap : public CHeapObj<mtInternal> {
465473
// the block is an object.
466474
virtual bool block_is_obj(const HeapWord* addr) const = 0;
467475

476+
virtual ParallelObjectIterator* parallel_object_iterator(uint thread_num) {
477+
return NULL;
478+
}
479+
468480
// Keep alive an object that was loaded with AS_NO_KEEPALIVE.
469481
virtual void keep_alive(oop obj) {}
470482

@@ -516,6 +528,9 @@ class CollectedHeap : public CHeapObj<mtInternal> {
516528
// Iterator for all GC threads (other than VM thread)
517529
virtual void gc_threads_do(ThreadClosure* tc) const = 0;
518530

531+
// Run given task. Possibly in parallel if the GC supports it.
532+
virtual void run_task(AbstractGangTask* task) = 0;
533+
519534
// Print any relevant tracing info that flags imply.
520535
// Default implementation does nothing.
521536
virtual void print_tracing_info() const = 0;

src/hotspot/share/gc/shared/vmGCOperations.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2005, 2017, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2005, 2021, 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
@@ -154,7 +154,7 @@ void VM_GC_HeapInspection::doit() {
154154
}
155155
HeapInspection inspect(_csv_format, _print_help, _print_class_stats,
156156
_columns);
157-
inspect.heap_inspection(_out);
157+
inspect.heap_inspection(_out, _parallel_thread_num);
158158
}
159159

160160

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

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2005, 2018, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2005, 2021, 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
@@ -125,18 +125,21 @@ class VM_GC_HeapInspection: public VM_GC_Operation {
125125
private:
126126
outputStream* _out;
127127
bool _full_gc;
128+
uint _parallel_thread_num;
128129
bool _csv_format; // "comma separated values" format for spreadsheet.
129130
bool _print_help;
130131
bool _print_class_stats;
131132
const char* _columns;
132133
public:
133-
VM_GC_HeapInspection(outputStream* out, bool request_full_gc) :
134+
VM_GC_HeapInspection(outputStream* out, bool request_full_gc,
135+
uint parallel_thread_num = 1) :
134136
VM_GC_Operation(0 /* total collections, dummy, ignored */,
135137
GCCause::_heap_inspection /* GC Cause */,
136138
0 /* total full collections, dummy, ignored */,
137139
request_full_gc) {
138140
_out = out;
139141
_full_gc = request_full_gc;
142+
_parallel_thread_num = parallel_thread_num;
140143
_csv_format = false;
141144
_print_help = false;
142145
_print_class_stats = false;

src/hotspot/share/gc/shenandoah/shenandoahHeap.hpp

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2013, 2020, Red Hat, Inc. All rights reserved.
2+
* Copyright (c) 2013, 2021, Red Hat, Inc. All rights reserved.
33
*
44
* This code is free software; you can redistribute it and/or modify it
55
* under the terms of the GNU General Public License version 2 only, as
@@ -206,6 +206,10 @@ class ShenandoahHeap : public CollectedHeap {
206206

207207
void gc_threads_do(ThreadClosure* tcl) const;
208208

209+
// Runs the given AbstractGangTask with the current active workers
210+
// No workGang for shenandoahHeap, work serially with thread 0
211+
virtual void run_task(AbstractGangTask* task) { task->work(0); }
212+
209213
// ---------- Heap regions handling machinery
210214
//
211215
private:

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

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2015, 2021, 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
@@ -103,6 +103,10 @@ class ZCollectedHeap : public CollectedHeap {
103103
virtual void object_iterate(ObjectClosure* cl);
104104
virtual void safe_object_iterate(ObjectClosure* cl);
105105

106+
// Runs the given AbstractGangTask with the current active workers.
107+
// No workGang for zHeap, work serially with thread 0
108+
virtual void run_task(AbstractGangTask* task) { task->work(0); }
109+
106110
virtual HeapWord* block_start(const void* addr) const;
107111
virtual size_t block_size(const HeapWord* addr) const;
108112
virtual bool block_is_obj(const HeapWord* addr) const;

0 commit comments

Comments
 (0)