Skip to content

Commit 1d2c1e6

Browse files
albertnetymkThomas Schatzl
authored and
Thomas Schatzl
committedMar 3, 2021
8248314: Parallel: Parallelize parallel full gc Adjust Roots phase
Reviewed-by: tschatzl, iwalulya
1 parent 3d3eb5c commit 1d2c1e6

File tree

3 files changed

+80
-38
lines changed

3 files changed

+80
-38
lines changed
 

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

+74-31
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
#include "gc/shared/referenceProcessorPhaseTimes.hpp"
5858
#include "gc/shared/spaceDecorator.inline.hpp"
5959
#include "gc/shared/taskTerminator.hpp"
60-
#include "gc/shared/weakProcessor.hpp"
60+
#include "gc/shared/weakProcessor.inline.hpp"
6161
#include "gc/shared/workerPolicy.hpp"
6262
#include "gc/shared/workgroup.hpp"
6363
#include "logging/log.hpp"
@@ -780,7 +780,7 @@ bool ParallelCompactData::summarize(SplitInfo& split_info,
780780
return true;
781781
}
782782

783-
HeapWord* ParallelCompactData::calc_new_pointer(HeapWord* addr, ParCompactionManager* cm) {
783+
HeapWord* ParallelCompactData::calc_new_pointer(HeapWord* addr, ParCompactionManager* cm) const {
784784
assert(addr != NULL, "Should detect NULL oop earlier");
785785
assert(ParallelScavengeHeap::heap()->is_in(addr), "not in heap");
786786
assert(PSParallelCompact::mark_bitmap()->is_marked(addr), "not marked");
@@ -1788,8 +1788,6 @@ bool PSParallelCompact::invoke_no_policy(bool maximum_heap_compaction) {
17881788
ParCompactionManager::manager_array(ParallelScavengeHeap::heap()->workers().total_workers());
17891789

17901790
{
1791-
ResourceMark rm;
1792-
17931791
const uint active_workers =
17941792
WorkerPolicy::calc_active_workers(ParallelScavengeHeap::heap()->workers().total_workers(),
17951793
ParallelScavengeHeap::heap()->workers().active_workers(),
@@ -1834,7 +1832,7 @@ bool PSParallelCompact::invoke_no_policy(bool maximum_heap_compaction) {
18341832

18351833
// adjust_roots() updates Universe::_intArrayKlassObj which is
18361834
// needed by the compaction for filling holes in the dense prefix.
1837-
adjust_roots(vmthread_cm);
1835+
adjust_roots();
18381836

18391837
compaction_start.update();
18401838
compact();
@@ -2209,35 +2207,81 @@ void PSParallelCompact::marking_phase(ParCompactionManager* cm,
22092207
_gc_tracer.report_object_count_after_gc(is_alive_closure());
22102208
}
22112209

2212-
void PSParallelCompact::adjust_roots(ParCompactionManager* cm) {
2213-
// Adjust the pointers to reflect the new locations
2214-
GCTraceTime(Info, gc, phases) tm("Adjust Roots", &_gc_timer);
2210+
class PSAdjustTask final : public AbstractGangTask {
2211+
SubTasksDone _sub_tasks;
2212+
WeakProcessor::Task _weak_proc_task;
2213+
OopStorageSetStrongParState<false, false> _oop_storage_iter;
2214+
uint _nworkers;
22152215

2216-
// Need new claim bits when tracing through and adjusting pointers.
2217-
ClassLoaderDataGraph::clear_claimed_marks();
2216+
enum PSAdjustSubTask {
2217+
PSAdjustSubTask_code_cache,
2218+
PSAdjustSubTask_aot,
2219+
PSAdjustSubTask_old_ref_process,
2220+
PSAdjustSubTask_young_ref_process,
22182221

2219-
PCAdjustPointerClosure oop_closure(cm);
2222+
PSAdjustSubTask_num_elements
2223+
};
22202224

2221-
// General strong roots.
2222-
Threads::oops_do(&oop_closure, NULL);
2223-
OopStorageSet::strong_oops_do(&oop_closure);
2224-
CLDToOopClosure cld_closure(&oop_closure, ClassLoaderData::_claim_strong);
2225-
ClassLoaderDataGraph::cld_do(&cld_closure);
2225+
public:
2226+
PSAdjustTask(uint nworkers) :
2227+
AbstractGangTask("PSAdjust task"),
2228+
_sub_tasks(PSAdjustSubTask_num_elements),
2229+
_weak_proc_task(nworkers),
2230+
_nworkers(nworkers) {
2231+
// Need new claim bits when tracing through and adjusting pointers.
2232+
ClassLoaderDataGraph::clear_claimed_marks();
2233+
if (nworkers > 1) {
2234+
Threads::change_thread_claim_token();
2235+
}
2236+
}
22262237

2227-
// Now adjust pointers in remaining weak roots. (All of which should
2228-
// have been cleared if they pointed to non-surviving objects.)
2229-
WeakProcessor::oops_do(&oop_closure);
2238+
~PSAdjustTask() {
2239+
Threads::assert_all_threads_claimed();
2240+
}
22302241

2231-
CodeBlobToOopClosure adjust_from_blobs(&oop_closure, CodeBlobToOopClosure::FixRelocations);
2232-
CodeCache::blobs_do(&adjust_from_blobs);
2233-
AOT_ONLY(AOTLoader::oops_do(&oop_closure);)
2242+
void work(uint worker_id) {
2243+
ParCompactionManager* cm = ParCompactionManager::gc_thread_compaction_manager(worker_id);
2244+
PCAdjustPointerClosure adjust(cm);
2245+
{
2246+
ResourceMark rm;
2247+
Threads::possibly_parallel_oops_do(_nworkers > 1, &adjust, nullptr);
2248+
}
2249+
_oop_storage_iter.oops_do(&adjust);
2250+
{
2251+
CLDToOopClosure cld_closure(&adjust, ClassLoaderData::_claim_strong);
2252+
ClassLoaderDataGraph::cld_do(&cld_closure);
2253+
}
2254+
{
2255+
AlwaysTrueClosure always_alive;
2256+
_weak_proc_task.work(worker_id, &always_alive, &adjust);
2257+
}
2258+
if (_sub_tasks.try_claim_task(PSAdjustSubTask_code_cache)) {
2259+
CodeBlobToOopClosure adjust_code(&adjust, CodeBlobToOopClosure::FixRelocations);
2260+
CodeCache::blobs_do(&adjust_code);
2261+
}
2262+
if (_sub_tasks.try_claim_task(PSAdjustSubTask_aot)) {
2263+
AOT_ONLY(AOTLoader::oops_do(&adjust);)
2264+
}
2265+
if (_sub_tasks.try_claim_task(PSAdjustSubTask_old_ref_process)) {
2266+
PSParallelCompact::ref_processor()->weak_oops_do(&adjust);
2267+
}
2268+
if (_sub_tasks.try_claim_task(PSAdjustSubTask_young_ref_process)) {
2269+
// Roots were visited so references into the young gen in roots
2270+
// may have been scanned. Process them also.
2271+
// Should the reference processor have a span that excludes
2272+
// young gen objects?
2273+
PSScavenge::reference_processor()->weak_oops_do(&adjust);
2274+
}
2275+
_sub_tasks.all_tasks_claimed();
2276+
}
2277+
};
22342278

2235-
ref_processor()->weak_oops_do(&oop_closure);
2236-
// Roots were visited so references into the young gen in roots
2237-
// may have been scanned. Process them also.
2238-
// Should the reference processor have a span that excludes
2239-
// young gen objects?
2240-
PSScavenge::reference_processor()->weak_oops_do(&oop_closure);
2279+
void PSParallelCompact::adjust_roots() {
2280+
// Adjust the pointers to reflect the new locations
2281+
GCTraceTime(Info, gc, phases) tm("Adjust Roots", &_gc_timer);
2282+
uint nworkers = ParallelScavengeHeap::heap()->workers().active_workers();
2283+
PSAdjustTask task(nworkers);
2284+
ParallelScavengeHeap::heap()->workers().run_task(&task);
22412285
}
22422286

22432287
// Helper class to print 8 region numbers per line and then print the total at the end.
@@ -2306,7 +2350,7 @@ void PSParallelCompact::prepare_region_draining_tasks(uint parallel_gc_threads)
23062350

23072351
for (size_t cur = end_region - 1; cur + 1 > beg_region; --cur) {
23082352
if (sd.region(cur)->claim_unsafe()) {
2309-
ParCompactionManager* cm = ParCompactionManager::manager_array(worker_id);
2353+
ParCompactionManager* cm = ParCompactionManager::gc_thread_compaction_manager(worker_id);
23102354
bool result = sd.region(cur)->mark_normal();
23112355
assert(result, "Must succeed at this point.");
23122356
cm->region_stack()->push(cur);
@@ -2505,7 +2549,6 @@ static void compaction_with_stealing_work(TaskTerminator* terminator, uint worke
25052549
// Go around again.
25062550
}
25072551
}
2508-
return;
25092552
}
25102553

25112554
class UpdateDensePrefixAndCompactionTask: public AbstractGangTask {
@@ -3133,7 +3176,7 @@ void PSParallelCompact::initialize_shadow_regions(uint parallel_gc_threads)
31333176

31343177
size_t beg_region = sd.addr_to_region_idx(_space_info[old_space_id].dense_prefix());
31353178
for (uint i = 0; i < parallel_gc_threads; i++) {
3136-
ParCompactionManager *cm = ParCompactionManager::manager_array(i);
3179+
ParCompactionManager *cm = ParCompactionManager::gc_thread_compaction_manager(i);
31373180
cm->set_next_shadow_region(beg_region + i);
31383181
}
31393182
}

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -480,9 +480,9 @@ class ParallelCompactData
480480
HeapWord* partial_obj_end(size_t region_idx) const;
481481

482482
// Return the location of the object after compaction.
483-
HeapWord* calc_new_pointer(HeapWord* addr, ParCompactionManager* cm);
483+
HeapWord* calc_new_pointer(HeapWord* addr, ParCompactionManager* cm) const;
484484

485-
HeapWord* calc_new_pointer(oop p, ParCompactionManager* cm) {
485+
HeapWord* calc_new_pointer(oop p, ParCompactionManager* cm) const {
486486
return calc_new_pointer(cast_from_oop<HeapWord*>(p), cm);
487487
}
488488

@@ -1107,7 +1107,7 @@ class PSParallelCompact : AllStatic {
11071107
static void summary_phase(ParCompactionManager* cm, bool maximum_compaction);
11081108

11091109
// Adjust addresses in roots. Does not adjust addresses in heap.
1110-
static void adjust_roots(ParCompactionManager* cm);
1110+
static void adjust_roots();
11111111

11121112
DEBUG_ONLY(static void write_block_fill_histogram();)
11131113

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

+3-4
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,9 @@ inline void PSParallelCompact::adjust_pointer(T* p, ParCompactionManager* cm) {
113113
assert(ParallelScavengeHeap::heap()->is_in(obj), "should be in heap");
114114

115115
oop new_obj = (oop)summary_data().calc_new_pointer(obj, cm);
116-
assert(new_obj != NULL, // is forwarding ptr?
117-
"should be forwarded");
118-
// Just always do the update unconditionally?
119-
if (new_obj != NULL) {
116+
assert(new_obj != NULL, "non-null address for live objects");
117+
// Is it actually relocated at all?
118+
if (new_obj != obj) {
120119
assert(ParallelScavengeHeap::heap()->is_in_reserved(new_obj),
121120
"should be in object space");
122121
RawAccess<IS_NOT_NULL>::oop_store(p, new_obj);

0 commit comments

Comments
 (0)
Please sign in to comment.