Skip to content

Commit

Permalink
Changes after first review
Browse files Browse the repository at this point in the history
  • Loading branch information
lkorinth committed Mar 5, 2021
1 parent 2e7aa79 commit 8a928e4
Show file tree
Hide file tree
Showing 13 changed files with 196 additions and 156 deletions.
63 changes: 34 additions & 29 deletions src/hotspot/share/gc/g1/g1CollectedHeap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3312,26 +3312,25 @@ class G1STWDrainQueueClosure: public VoidClosure {
}
};

class G1STWRefProcClosureContext : public AbstractClosureContext {
uint _max_workers;
uint _queues;
G1CollectedHeap& _g1h;
G1ParScanThreadStateSet& _pss;
G1ScannerTasksQueueSet& _task_queues;
TaskTerminator _terminator;
G1STWIsAliveClosure _is_alive;
G1CopyingKeepAliveClosure* _keep_alive;
class G1STWRefProcClosureContext : public AbstractRefProcClosureContext {
uint _max_workers;
uint _queues;
G1CollectedHeap& _g1h;
G1ParScanThreadStateSet& _pss;
G1ScannerTasksQueueSet& _task_queues;
TaskTerminator _terminator;
G1STWIsAliveClosure _is_alive;
G1CopyingKeepAliveClosure* _keep_alive;
G1ParEvacuateFollowersClosure* _parallel_complete_gc;
G1CopyingKeepAliveClosure _serial_keep_alive;
G1STWDrainQueueClosure _serial_complete_gc;
ThreadModel _tm;
G1CopyingKeepAliveClosure _serial_keep_alive;
G1STWDrainQueueClosure _serial_complete_gc;
RefProcThreadModel _tm;

public:
G1STWRefProcClosureContext(
uint max_workers,
G1CollectedHeap& g1h,
G1ParScanThreadStateSet& pss,
G1ScannerTasksQueueSet& task_queues)
G1STWRefProcClosureContext(uint max_workers,
G1CollectedHeap& g1h,
G1ParScanThreadStateSet& pss,
G1ScannerTasksQueueSet& task_queues)
: _max_workers(max_workers),
_queues(0),
_g1h(g1h),
Expand All @@ -3343,37 +3342,43 @@ class G1STWRefProcClosureContext : public AbstractClosureContext {
_parallel_complete_gc(NEW_C_HEAP_ARRAY(G1ParEvacuateFollowersClosure, _max_workers, mtGC)),
_serial_keep_alive(&g1h, _pss.state_for_worker(0)),
_serial_complete_gc(&g1h, _pss.state_for_worker(0)),
_tm(ThreadModel::Single) {}
_tm(RefProcThreadModel::Single) {}

~G1STWRefProcClosureContext() {
FREE_C_HEAP_ARRAY(G1CopyingKeepAliveClosure, _keep_alive);
FREE_C_HEAP_ARRAY(G1ParEvacuateFollowersClosure, _parallel_complete_gc);
}

BoolObjectClosure* is_alive(uint worker_id) { return &_is_alive; }
BoolObjectClosure* is_alive(uint worker_id) {
return &_is_alive;
}

OopClosure* keep_alive(uint worker_id) {
assert(worker_id < _queues || _tm == ThreadModel::Single, "sanity");
if (_tm == ThreadModel::Single) {
return ::new (&_serial_keep_alive) G1CopyingKeepAliveClosure(&_g1h, _pss.state_for_worker(0));
assert(worker_id < _queues || _tm == RefProcThreadModel::Single, "sanity");
if (_tm == RefProcThreadModel::Single) {
return &_serial_keep_alive;
} else {
return ::new (&_keep_alive[worker_id]) G1CopyingKeepAliveClosure(&_g1h, _pss.state_for_worker(worker_id));
}
return ::new (&_keep_alive[worker_id]) G1CopyingKeepAliveClosure(&_g1h, _pss.state_for_worker(worker_id));
}

VoidClosure* complete_gc(uint worker_id) {
assert(worker_id < _queues || _tm == ThreadModel::Single, "sanity");
if (_tm == ThreadModel::Single) {
return ::new (&_serial_complete_gc) G1STWDrainQueueClosure(&_g1h, _pss.state_for_worker(0));
assert(worker_id < _queues || _tm == RefProcThreadModel::Single, "sanity");
if (_tm == RefProcThreadModel::Single) {
return &_serial_complete_gc;
} else {
return ::new (&_parallel_complete_gc[worker_id]) G1ParEvacuateFollowersClosure(&_g1h, _pss.state_for_worker(worker_id), &_task_queues, &_terminator, G1GCPhaseTimes::ObjCopy);
}
return ::new (&_parallel_complete_gc[worker_id]) G1ParEvacuateFollowersClosure(&_g1h, _pss.state_for_worker(worker_id), &_task_queues, &_terminator, G1GCPhaseTimes::ObjCopy);
}

void prepare_run_task(uint queue_count, ThreadModel tm, bool marks_oops_alive) {
void prepare_run_task(uint queue_count, RefProcThreadModel tm, bool marks_oops_alive) {
log_debug(gc, ref)("G1STWRefProcClosureContext: prepare_run_task");
assert(queue_count <= _max_workers, "sanity");
_queues = queue_count;
_tm = tm;

for (uint qid = 0; qid < index(queue_count, tm); ++qid ) {
_pss.state_for_worker(qid)->set_ref_discoverer(nullptr); // move?, maybe not...
_pss.state_for_worker(qid)->set_ref_discoverer(nullptr);
}
_terminator.reset_for_reuse(queue_count);
};
Expand Down
38 changes: 20 additions & 18 deletions src/hotspot/share/gc/g1/g1ConcurrentMark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1461,41 +1461,45 @@ class G1CMDrainMarkingStackClosure : public VoidClosure {
}
};

class G1CMRefProcClosureContext : public AbstractClosureContext {
uint _max_workers;
G1ConcurrentMark& _cm;
G1CMIsAliveClosure _is_alive;
class G1CMRefProcClosureContext : public AbstractRefProcClosureContext {
uint _max_workers;
G1ConcurrentMark& _cm;
G1CMIsAliveClosure _is_alive;
G1CMKeepAliveAndDrainClosure* _keep_alive;
G1CMDrainMarkingStackClosure* _complete_gc;
ThreadModel _tm;
RefProcThreadModel _tm;

public:
G1CMRefProcClosureContext(
uint max_workers,
G1CollectedHeap& g1h,
G1ConcurrentMark& cm)
G1CMRefProcClosureContext(uint max_workers,
G1CollectedHeap& g1h,
G1ConcurrentMark& cm)
: _max_workers(max_workers),
_cm(cm),
_is_alive(&g1h),
_keep_alive(NEW_C_HEAP_ARRAY(G1CMKeepAliveAndDrainClosure, _max_workers, mtGC)),
_complete_gc(NEW_C_HEAP_ARRAY(G1CMDrainMarkingStackClosure, _max_workers, mtGC)),
_tm(ThreadModel::Single) {}
_tm(RefProcThreadModel::Single) {}

~G1CMRefProcClosureContext() {
FREE_C_HEAP_ARRAY(G1CMKeepAliveAndDrainClosure, _keep_alive);
FREE_C_HEAP_ARRAY(G1CMDrainMarkingStackClosure, _complete_gc);
}

BoolObjectClosure* is_alive(uint worker_id) { return &_is_alive; }
OopClosure* keep_alive(uint worker_id) {
BoolObjectClosure* is_alive(uint worker_id) {
return &_is_alive;
}

OopClosure* keep_alive(uint worker_id) {
assert(worker_id < _max_workers, "sanity");
return ::new (&_keep_alive[index(worker_id, _tm)]) G1CMKeepAliveAndDrainClosure(&_cm, _cm.task(index(worker_id, _tm)), _tm == ThreadModel::Single );
return ::new (&_keep_alive[index(worker_id, _tm)]) G1CMKeepAliveAndDrainClosure(&_cm, _cm.task(index(worker_id, _tm)), _tm == RefProcThreadModel::Single );
}
VoidClosure* complete_gc(uint worker_id) {

VoidClosure* complete_gc(uint worker_id) {
assert(worker_id < _max_workers, "sanity");
return ::new (&_complete_gc[index(worker_id, _tm)]) G1CMDrainMarkingStackClosure(&_cm, _cm.task(index(worker_id, _tm)), _tm == ThreadModel::Single);
return ::new (&_complete_gc[index(worker_id, _tm)]) G1CMDrainMarkingStackClosure(&_cm, _cm.task(index(worker_id, _tm)), _tm == RefProcThreadModel::Single);
}
void prepare_run_task(uint queue_count, ThreadModel tm, bool marks_oops_alive) {

void prepare_run_task(uint queue_count, RefProcThreadModel tm, bool marks_oops_alive) {
log_debug(gc, ref)("G1CMRefProcClosureContext: prepare_run_task");
assert(queue_count <= _max_workers, "sanity");
_tm = tm;
Expand Down Expand Up @@ -1530,8 +1534,6 @@ void G1ConcurrentMark::weak_refs_work(bool clear_all_soft_refs) {
bool processing_is_mt = rp->processing_is_mt();
uint active_workers = (processing_is_mt ? _g1h->workers()->active_workers() : 1U);
active_workers = clamp(active_workers, 1u, _max_num_tasks);

// reference processing context.
G1CMRefProcClosureContext context(rp->max_num_queues(), *_g1h, *this);

// Set the concurrency level. The phase was already set prior to
Expand Down
8 changes: 4 additions & 4 deletions src/hotspot/share/gc/g1/g1ConcurrentMark.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -278,14 +278,14 @@ class G1CMRootMemRegions {
// This class manages data structures and methods for doing liveness analysis in
// G1's concurrent cycle.
class G1ConcurrentMark : public CHeapObj<mtGC> {
friend class G1ConcurrentMarkThread;
friend class G1CMRefProcClosureContext;
friend class G1CMKeepAliveAndDrainClosure;
friend class G1CMDrainMarkingStackClosure;
friend class G1CMBitMapClosure;
friend class G1CMConcurrentMarkingTask;
friend class G1CMDrainMarkingStackClosure;
friend class G1CMKeepAliveAndDrainClosure;
friend class G1CMRefProcClosureContext;
friend class G1CMRemarkTask;
friend class G1CMTask;
friend class G1ConcurrentMarkThread;

G1ConcurrentMarkThread* _cm_thread; // The thread doing the work
G1CollectedHeap* _g1h; // The heap
Expand Down
32 changes: 20 additions & 12 deletions src/hotspot/share/gc/g1/g1FullCollector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,34 +229,42 @@ void G1FullCollector::update_attribute_table(HeapRegion* hr) {
}
}

class G1FullRefProcClosureContext : public AbstractClosureContext {
uint _max_workers;
G1FullCollector& _collector;
G1IsAliveClosure _is_alive;
class G1FullGCRefProcClosureContext : public AbstractRefProcClosureContext {
uint _max_workers;
G1FullCollector& _collector;
G1IsAliveClosure _is_alive;
G1FullKeepAliveClosure* _keep_alive;
ThreadModel _tm;
RefProcThreadModel _tm;

public:
G1FullRefProcClosureContext(G1FullCollector& collector, uint max_workers)
: _max_workers(max_workers), _collector(collector), _is_alive(&collector), _keep_alive(NEW_C_HEAP_ARRAY(G1FullKeepAliveClosure, max_workers, mtGC)), _tm(ThreadModel::Single) {}

~G1FullRefProcClosureContext() {
G1FullGCRefProcClosureContext(G1FullCollector& collector, uint max_workers)
: _max_workers(max_workers),
_collector(collector),
_is_alive(&collector),
_keep_alive(NEW_C_HEAP_ARRAY(G1FullKeepAliveClosure, max_workers, mtGC)),
_tm(RefProcThreadModel::Single) {}

~G1FullGCRefProcClosureContext() {
FREE_C_HEAP_ARRAY(G1FullKeepAliveClosure, _keep_alive);
}

BoolObjectClosure* is_alive(uint worker_id) {
assert(worker_id < _max_workers, "sanity");
return &_is_alive;
}

OopClosure* keep_alive(uint worker_id) {
assert(worker_id < _max_workers, "sanity");
return ::new (&_keep_alive[index(worker_id, _tm)]) G1FullKeepAliveClosure(_collector.marker(index(worker_id, _tm)));
};

VoidClosure* complete_gc(uint worker_id) {
assert(worker_id < _max_workers, "sanity");
return _collector.marker(index(worker_id, _tm))->stack_closure();
}
void prepare_run_task(uint queue_count, ThreadModel tm, bool marks_oops_alive) {
log_debug(gc, ref)("G1FullRefProcClosureContext: prepare_run_task");

void prepare_run_task(uint queue_count, RefProcThreadModel tm, bool marks_oops_alive) {
log_debug(gc, ref)("G1FullGCRefProcClosureContext: prepare_run_task");
assert(queue_count <= _max_workers, "sanity");
_tm = tm;
};
Expand All @@ -278,7 +286,7 @@ void G1FullCollector::phase1_mark_live_objects() {
GCTraceTime(Debug, gc, phases) debug("Phase 1: Reference Processing", scope()->timer());
// Process reference objects found during marking.
ReferenceProcessorPhaseTimes pt(scope()->timer(), reference_processor()->max_num_queues());
G1FullRefProcClosureContext context(*this, reference_processor()->max_num_queues());
G1FullGCRefProcClosureContext context(*this, reference_processor()->max_num_queues());
const ReferenceProcessorStats& stats = reference_processor()->process_discovered_references(context, pt);
scope()->tracer()->report_gc_reference_stats(stats);
pt.print_all_references();
Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/share/gc/parallel/psCompactionManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class ParCompactionManager : public CHeapObj<mtGC> {
friend class CompactionWithStealingTask;
friend class MarkFromRootsTask;
friend class ParMarkBitMap;
friend class PCRefProcClosureContext;
friend class ParallelCompactRefProcClosureContext;
friend class PSParallelCompact;
friend class RefProcClosureContext;
friend class UpdateAndFillClosure;
Expand Down
27 changes: 15 additions & 12 deletions src/hotspot/share/gc/parallel/psParallelCompact.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2095,39 +2095,42 @@ class MarkFromRootsTask : public AbstractGangTask {
}
};

class PCRefProcClosureContext : public AbstractClosureContext {
uint _max_workers;
TaskTerminator _terminator;
PCMarkAndPushClosure* _keep_alive;
class ParallelCompactRefProcClosureContext : public AbstractRefProcClosureContext {
uint _max_workers;
TaskTerminator _terminator;
PCMarkAndPushClosure* _keep_alive;
ParCompactionManager::FollowStackClosure* _complete_gc;
ThreadModel _tm;
RefProcThreadModel _tm;

public:
PCRefProcClosureContext(uint max_workers)
ParallelCompactRefProcClosureContext(uint max_workers)
: _max_workers(max_workers),
_terminator(_max_workers, ParCompactionManager::oop_task_queues()),
_keep_alive(NEW_C_HEAP_ARRAY(PCMarkAndPushClosure, _max_workers, mtGC)),
_complete_gc(NEW_C_HEAP_ARRAY(ParCompactionManager::FollowStackClosure, _max_workers, mtGC)),
_tm(ThreadModel::Single) {}
_tm(RefProcThreadModel::Single) {}

~PCRefProcClosureContext() {
~ParallelCompactRefProcClosureContext() {
FREE_C_HEAP_ARRAY(PCMarkAndPushClosure, _keep_alive);
FREE_C_HEAP_ARRAY(ParCompactionManager::FollowStackClosure, _complete_gc);
}

BoolObjectClosure* is_alive(uint worker_id) {
return PSParallelCompact::is_alive_closure();
}

OopClosure* keep_alive(uint worker_id) {
ParCompactionManager* cm = ParCompactionManager::gc_thread_compaction_manager(worker_id);
return ::new (&_keep_alive[worker_id]) PCMarkAndPushClosure(cm);
}

VoidClosure* complete_gc(uint worker_id) {
ParCompactionManager* cm = ParCompactionManager::gc_thread_compaction_manager(worker_id);
return ::new (&_complete_gc[worker_id]) ParCompactionManager::FollowStackClosure(cm, (_tm == ThreadModel::Single)?nullptr:&_terminator, worker_id);
return ::new (&_complete_gc[worker_id]) ParCompactionManager::FollowStackClosure(cm, (_tm == RefProcThreadModel::Single) ? nullptr : &_terminator, worker_id);
}
void prepare_run_task(uint queue_count, ThreadModel tm, bool marks_oops_alive) {
log_debug(gc, ref)("PCRefProcClosureContext: prepare_run_task");

void prepare_run_task(uint queue_count, RefProcThreadModel tm, bool marks_oops_alive) {
log_debug(gc, ref)("ParallelCompactRefProcClosureContext: prepare_run_task");
assert(queue_count <= _max_workers, "sanity");
_tm = tm;
_terminator.reset_for_reuse(queue_count);
Expand Down Expand Up @@ -2160,7 +2163,7 @@ void PSParallelCompact::marking_phase(ParCompactionManager* cm,
ReferenceProcessorPhaseTimes pt(&_gc_timer, ref_processor()->max_num_queues());

ref_processor()->set_active_mt_degree(active_gc_threads);
PCRefProcClosureContext context(ref_processor()->max_num_queues());
ParallelCompactRefProcClosureContext context(ref_processor()->max_num_queues());
stats = ref_processor()->process_discovered_references(context, pt);

gc_tracer->report_gc_reference_stats(stats);
Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/share/gc/parallel/psPromotionManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class PSOldGen;
class ParCompactionManager;

class PSPromotionManager {
friend class PSRefProcClosureContext;
friend class ParallelScavengeRefProcClosureContext;
friend class PSScavenge;
friend class ScavengeRootsTask;

Expand Down
Loading

0 comments on commit 8a928e4

Please sign in to comment.