Skip to content

Commit e12ed8a

Browse files
committed
8306122: [Lilliput] Refactor full GC forwarding
Reviewed-by: shade
1 parent 40a549b commit e12ed8a

38 files changed

+406
-241
lines changed

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
#include "gc/g1/heapRegionSet.inline.hpp"
7777
#include "gc/shared/concurrentGCBreakpoints.hpp"
7878
#include "gc/shared/gcBehaviours.hpp"
79+
#include "gc/shared/gcForwarding.hpp"
7980
#include "gc/shared/gcHeapSummary.hpp"
8081
#include "gc/shared/gcId.hpp"
8182
#include "gc/shared/gcLocker.inline.hpp"
@@ -86,8 +87,6 @@
8687
#include "gc/shared/locationPrinter.inline.hpp"
8788
#include "gc/shared/oopStorageParState.hpp"
8889
#include "gc/shared/preservedMarks.inline.hpp"
89-
#include "gc/shared/slidingForwarding.inline.hpp"
90-
#include "gc/shared/suspendibleThreadSet.hpp"
9190
#include "gc/shared/referenceProcessor.inline.hpp"
9291
#include "gc/shared/suspendibleThreadSet.hpp"
9392
#include "gc/shared/taskqueue.inline.hpp"
@@ -1522,8 +1521,6 @@ jint G1CollectedHeap::initialize() {
15221521

15231522
initialize_reserved_region(heap_rs);
15241523

1525-
_forwarding = new SlidingForwarding(heap_rs.region(), HeapRegion::LogOfHRGrainBytes - LogHeapWordSize);
1526-
15271524
// Create the barrier set for the entire reserved region.
15281525
G1CardTable* ct = new G1CardTable(heap_rs.region());
15291526
ct->initialize();
@@ -1673,6 +1670,8 @@ jint G1CollectedHeap::initialize() {
16731670

16741671
G1InitLogger::print();
16751672

1673+
GCForwarding::initialize(heap_rs.region(), HeapRegion::LogOfHRGrainBytes - LogHeapWordSize);
1674+
16761675
return JNI_OK;
16771676
}
16781677

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

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ class MemoryPool;
8585
class nmethod;
8686
class ReferenceProcessor;
8787
class STWGCTimer;
88-
class SlidingForwarding;
8988
class WorkerThreads;
9089

9190
typedef OverflowTaskQueue<ScannerTask, mtGC> G1ScannerTasksQueue;
@@ -253,8 +252,6 @@ class G1CollectedHeap : public CollectedHeap {
253252
// Helper for monitoring and management support.
254253
G1MonitoringSupport* _monitoring_support;
255254

256-
SlidingForwarding* _forwarding;
257-
258255
uint _num_humongous_objects; // Current amount of (all) humongous objects found in the heap.
259256
uint _num_humongous_reclaim_candidates; // Number of humongous object eager reclaim candidates.
260257
public:
@@ -268,10 +265,6 @@ class G1CollectedHeap : public CollectedHeap {
268265
void set_collection_set_candidates_stats(G1MonotonicArenaMemoryStats& stats);
269266
void set_young_gen_card_set_stats(const G1MonotonicArenaMemoryStats& stats);
270267

271-
SlidingForwarding* forwarding() const {
272-
return _forwarding;
273-
}
274-
275268
private:
276269

277270
G1HRPrinter _hr_printer;

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

Lines changed: 62 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@
3939
#include "gc/g1/g1OopClosures.hpp"
4040
#include "gc/g1/g1Policy.hpp"
4141
#include "gc/g1/g1RegionMarkStatsCache.inline.hpp"
42+
#include "gc/shared/gcForwarding.hpp"
4243
#include "gc/shared/gcTraceTime.inline.hpp"
4344
#include "gc/shared/preservedMarks.hpp"
4445
#include "gc/shared/referenceProcessor.hpp"
45-
#include "gc/shared/slidingForwarding.hpp"
4646
#include "gc/shared/verifyOption.hpp"
4747
#include "gc/shared/weakProcessor.inline.hpp"
4848
#include "gc/shared/workerPolicy.hpp"
@@ -208,6 +208,7 @@ void G1FullCollector::collect() {
208208
// Don't add any more derived pointers during later phases
209209
deactivate_derived_pointers();
210210

211+
GCForwarding::begin();
211212
phase2_prepare_compaction();
212213

213214
if (has_compaction_targets()) {
@@ -220,6 +221,8 @@ void G1FullCollector::collect() {
220221
log_info(gc, phases) ("No Regions selected for compaction. Skipping Phase 3: Adjust pointers and Phase 4: Compact heap");
221222
}
222223

224+
GCForwarding::end();
225+
223226
phase5_reset_metadata();
224227

225228
G1CollectedHeap::finish_codecache_marking_cycle();
@@ -331,8 +334,6 @@ void G1FullCollector::phase1_mark_live_objects() {
331334
void G1FullCollector::phase2_prepare_compaction() {
332335
GCTraceTime(Info, gc, phases) info("Phase 2: Prepare compaction", scope()->timer());
333336

334-
_heap->forwarding()->clear();
335-
336337
phase2a_determine_worklists();
337338

338339
if (!has_compaction_targets()) {
@@ -344,10 +345,9 @@ void G1FullCollector::phase2_prepare_compaction() {
344345
// Try to avoid OOM immediately after Full GC in case there are no free regions
345346
// left after determining the result locations (i.e. this phase). Prepare to
346347
// maximally compact the tail regions of the compaction queues serially.
347-
// TODO: Disabled for now because it violates sliding-forwarding assumption.
348-
// if (scope()->do_maximal_compaction() || !has_free_compaction_targets) {
349-
// phase2c_prepare_serial_compaction();
350-
// }
348+
if (!UseCompactObjectHeaders && (scope()->do_maximal_compaction() || !has_free_compaction_targets)) {
349+
phase2c_prepare_serial_compaction();
350+
}
351351
}
352352

353353
void G1FullCollector::phase2a_determine_worklists() {
@@ -366,61 +366,61 @@ bool G1FullCollector::phase2b_forward_oops() {
366366
return task.has_free_compaction_targets();
367367
}
368368

369-
//uint G1FullCollector::truncate_parallel_cps() {
370-
// uint lowest_current = (uint)-1;
371-
// for (uint i = 0; i < workers(); i++) {
372-
// G1FullGCCompactionPoint* cp = compaction_point(i);
373-
// if (cp->has_regions()) {
374-
// lowest_current = MIN2(lowest_current, cp->current_region()->hrm_index());
375-
// }
376-
// }
377-
378-
// for (uint i = 0; i < workers(); i++) {
379-
// G1FullGCCompactionPoint* cp = compaction_point(i);
380-
// if (cp->has_regions()) {
381-
// cp->remove_at_or_above(lowest_current);
382-
// }
383-
// }
384-
// return lowest_current;
385-
//}
386-
387-
//void G1FullCollector::phase2c_prepare_serial_compaction() {
388-
// GCTraceTime(Debug, gc, phases) debug("Phase 2: Prepare serial compaction", scope()->timer());
389-
// // At this point, we know that after parallel compaction there will be regions that
390-
// // are partially compacted into. Thus, the last compaction region of all
391-
// // compaction queues still have space in them. We try to re-compact these regions
392-
// // in serial to avoid a premature OOM when the mutator wants to allocate the first
393-
// // eden region after gc.
394-
//
395-
// // For maximum compaction, we need to re-prepare all objects above the lowest
396-
// // region among the current regions for all thread compaction points. It may
397-
// // happen that due to the uneven distribution of objects to parallel threads, holes
398-
// // have been created as threads compact to different target regions between the
399-
// // lowest and the highest region in the tails of the compaction points.
400-
//
401-
// uint start_serial = truncate_parallel_cps();
402-
// assert(start_serial < _heap->max_reserved_regions(), "Called on empty parallel compaction queues");
403-
//
404-
// G1FullGCCompactionPoint* serial_cp = serial_compaction_point();
405-
// assert(!serial_cp->is_initialized(), "sanity!");
406-
//
407-
// HeapRegion* start_hr = _heap->region_at(start_serial);
408-
// serial_cp->add(start_hr);
409-
// serial_cp->initialize(start_hr);
410-
//
411-
// HeapWord* dense_prefix_top = compaction_top(start_hr);
412-
// G1SerialRePrepareClosure re_prepare(serial_cp, dense_prefix_top);
413-
//
414-
// for (uint i = start_serial + 1; i < _heap->max_reserved_regions(); i++) {
415-
// if (is_compaction_target(i)) {
416-
// HeapRegion* current = _heap->region_at(i);
417-
// set_compaction_top(current, current->bottom());
418-
// serial_cp->add(current);
419-
// current->apply_to_marked_objects(mark_bitmap(), &re_prepare);
420-
// }
421-
// }
422-
// serial_cp->update();
423-
//}
369+
uint G1FullCollector::truncate_parallel_cps() {
370+
uint lowest_current = (uint)-1;
371+
for (uint i = 0; i < workers(); i++) {
372+
G1FullGCCompactionPoint* cp = compaction_point(i);
373+
if (cp->has_regions()) {
374+
lowest_current = MIN2(lowest_current, cp->current_region()->hrm_index());
375+
}
376+
}
377+
378+
for (uint i = 0; i < workers(); i++) {
379+
G1FullGCCompactionPoint* cp = compaction_point(i);
380+
if (cp->has_regions()) {
381+
cp->remove_at_or_above(lowest_current);
382+
}
383+
}
384+
return lowest_current;
385+
}
386+
387+
void G1FullCollector::phase2c_prepare_serial_compaction() {
388+
GCTraceTime(Debug, gc, phases) debug("Phase 2: Prepare serial compaction", scope()->timer());
389+
// At this point, we know that after parallel compaction there will be regions that
390+
// are partially compacted into. Thus, the last compaction region of all
391+
// compaction queues still have space in them. We try to re-compact these regions
392+
// in serial to avoid a premature OOM when the mutator wants to allocate the first
393+
// eden region after gc.
394+
395+
// For maximum compaction, we need to re-prepare all objects above the lowest
396+
// region among the current regions for all thread compaction points. It may
397+
// happen that due to the uneven distribution of objects to parallel threads, holes
398+
// have been created as threads compact to different target regions between the
399+
// lowest and the highest region in the tails of the compaction points.
400+
401+
uint start_serial = truncate_parallel_cps();
402+
assert(start_serial < _heap->max_reserved_regions(), "Called on empty parallel compaction queues");
403+
404+
G1FullGCCompactionPoint* serial_cp = serial_compaction_point();
405+
assert(!serial_cp->is_initialized(), "sanity!");
406+
407+
HeapRegion* start_hr = _heap->region_at(start_serial);
408+
serial_cp->add(start_hr);
409+
serial_cp->initialize(start_hr);
410+
411+
HeapWord* dense_prefix_top = compaction_top(start_hr);
412+
G1SerialRePrepareClosure re_prepare(serial_cp, dense_prefix_top);
413+
414+
for (uint i = start_serial + 1; i < _heap->max_reserved_regions(); i++) {
415+
if (is_compaction_target(i)) {
416+
HeapRegion* current = _heap->region_at(i);
417+
set_compaction_top(current, current->bottom());
418+
serial_cp->add(current);
419+
current->apply_to_marked_objects(mark_bitmap(), &re_prepare);
420+
}
421+
}
422+
serial_cp->update();
423+
}
424424

425425
void G1FullCollector::phase3_adjust_pointers() {
426426
// Adjust the pointers to reflect the new locations

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,7 @@ void G1FullGCAdjustTask::work(uint worker_id) {
9494

9595
// Adjust preserved marks first since they are not balanced.
9696
G1FullGCMarker* marker = collector()->marker(worker_id);
97-
const SlidingForwarding* const forwarding = G1CollectedHeap::heap()->forwarding();
98-
marker->preserved_stack()->adjust_during_full_gc(forwarding);
97+
marker->preserved_stack()->adjust_during_full_gc();
9998

10099
{
101100
// Adjust the weak roots.

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@
2929
#include "gc/g1/g1FullGCCompactionPoint.hpp"
3030
#include "gc/g1/g1FullGCCompactTask.hpp"
3131
#include "gc/g1/heapRegion.inline.hpp"
32+
#include "gc/shared/gcForwarding.inline.hpp"
3233
#include "gc/shared/gcTraceTime.inline.hpp"
33-
#include "gc/shared/slidingForwarding.inline.hpp"
3434
#include "logging/log.hpp"
3535
#include "oops/oop.inline.hpp"
3636
#include "utilities/ticks.hpp"
@@ -42,8 +42,8 @@ void G1FullGCCompactTask::G1CompactRegionClosure::clear_in_bitmap(oop obj) {
4242

4343
size_t G1FullGCCompactTask::G1CompactRegionClosure::apply(oop obj) {
4444
size_t size = obj->size();
45-
if (obj->is_forwarded()) {
46-
HeapWord* destination = cast_from_oop<HeapWord*>(_forwarding->forwardee(obj));
45+
if (GCForwarding::is_forwarded(obj)) {
46+
HeapWord* destination = cast_from_oop<HeapWord*>(GCForwarding::forwardee(obj));
4747

4848
// copy object and reinit its mark
4949
HeapWord* obj_addr = cast_from_oop<HeapWord*>(obj);

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333

3434
class G1CollectedHeap;
3535
class G1CMBitMap;
36-
class SlidingForwarding;
3736
class G1FullCollector;
3837

3938
class G1FullGCCompactTask : public G1FullGCTask {
@@ -52,12 +51,9 @@ class G1FullGCCompactTask : public G1FullGCTask {
5251

5352
class G1CompactRegionClosure : public StackObj {
5453
G1CMBitMap* _bitmap;
55-
const SlidingForwarding* const _forwarding;
5654
void clear_in_bitmap(oop object);
5755
public:
58-
G1CompactRegionClosure(G1CMBitMap* bitmap) :
59-
_bitmap(bitmap),
60-
_forwarding(G1CollectedHeap::heap()->forwarding()) { }
56+
G1CompactRegionClosure(G1CMBitMap* bitmap) : _bitmap(bitmap) { }
6157
size_t apply(oop object);
6258
};
6359
};

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
#include "gc/g1/g1FullCollector.inline.hpp"
2727
#include "gc/g1/g1FullGCCompactionPoint.hpp"
2828
#include "gc/g1/heapRegion.hpp"
29-
#include "gc/shared/slidingForwarding.inline.hpp"
29+
#include "gc/shared/gcForwarding.inline.hpp"
3030
#include "oops/oop.inline.hpp"
3131
#include "utilities/debug.hpp"
3232

@@ -92,7 +92,7 @@ void G1FullGCCompactionPoint::switch_region() {
9292
initialize_values();
9393
}
9494

95-
void G1FullGCCompactionPoint::forward(SlidingForwarding* const forwarding, oop object, size_t size) {
95+
void G1FullGCCompactionPoint::forward(oop object, size_t size) {
9696
assert(_current_region != NULL, "Must have been initialized");
9797

9898
// Ensure the object fit in the current region.
@@ -102,10 +102,10 @@ void G1FullGCCompactionPoint::forward(SlidingForwarding* const forwarding, oop o
102102

103103
// Store a forwarding pointer if the object should be moved.
104104
if (cast_from_oop<HeapWord*>(object) != _compaction_top) {
105-
forwarding->forward_to(object, cast_to_oop(_compaction_top));
106-
assert(object->is_forwarded(), "must be forwarded");
105+
GCForwarding::forward_to(object, cast_to_oop(_compaction_top));
106+
assert(GCForwarding::is_forwarded(object), "must be forwarded");
107107
} else {
108-
assert(!object->is_forwarded(), "must not be forwarded");
108+
assert(GCForwarding::is_not_forwarded(object), "must not be forwarded");
109109
}
110110

111111
// Update compaction values.

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131

3232
class G1FullCollector;
3333
class HeapRegion;
34-
class SlidingForwarding;
3534

3635
class G1FullGCCompactionPoint : public CHeapObj<mtGC> {
3736
G1FullCollector* _collector;
@@ -53,7 +52,7 @@ class G1FullGCCompactionPoint : public CHeapObj<mtGC> {
5352
bool is_initialized();
5453
void initialize(HeapRegion* hr);
5554
void update();
56-
void forward(SlidingForwarding* const forwarding, oop object, size_t size);
55+
void forward(oop object, size_t size);
5756
void add(HeapRegion* hr);
5857

5958
void remove_at_or_above(uint bottom);

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

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,13 @@
2525
#ifndef SHARE_GC_G1_G1FULLGCOOPCLOSURES_HPP
2626
#define SHARE_GC_G1_G1FULLGCOOPCLOSURES_HPP
2727

28-
#include "gc/g1/g1CollectedHeap.hpp"
2928
#include "gc/shared/verifyOption.hpp"
3029
#include "memory/iterator.hpp"
3130

3231
class G1CollectedHeap;
3332
class G1FullCollector;
3433
class G1CMBitMap;
3534
class G1FullGCMarker;
36-
class SlidingForwarding;
3735

3836
// Below are closures used by the G1 Full GC.
3937
class G1IsAliveClosure : public BoolObjectClosure {
@@ -77,13 +75,10 @@ class G1MarkAndPushClosure : public ClaimMetadataVisitingOopIterateClosure {
7775

7876
class G1AdjustClosure : public BasicOopIterateClosure {
7977
G1FullCollector* _collector;
80-
const SlidingForwarding* const _forwarding;
8178

8279
template <class T> inline void adjust_pointer(T* p);
8380
public:
84-
G1AdjustClosure(G1FullCollector* collector) :
85-
_collector(collector),
86-
_forwarding(G1CollectedHeap::heap()->forwarding()) { }
81+
G1AdjustClosure(G1FullCollector* collector) : _collector(collector) { }
8782
template <class T> void do_oop_work(T* p) { adjust_pointer(p); }
8883
virtual void do_oop(oop* p);
8984
virtual void do_oop(narrowOop* p);

src/hotspot/share/gc/g1/g1FullGCOopClosures.inline.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
#include "gc/g1/g1ConcurrentMarkBitMap.inline.hpp"
3333
#include "gc/g1/g1FullGCMarker.inline.hpp"
3434
#include "gc/g1/heapRegionRemSet.inline.hpp"
35-
#include "gc/shared/slidingForwarding.inline.hpp"
35+
#include "gc/shared/gcForwarding.inline.hpp"
3636
#include "memory/iterator.inline.hpp"
3737
#include "memory/universe.hpp"
3838
#include "oops/access.inline.hpp"
@@ -66,8 +66,8 @@ template <class T> inline void G1AdjustClosure::adjust_pointer(T* p) {
6666
return;
6767
}
6868

69-
if (obj->is_forwarded()) {
70-
oop forwardee = _forwarding->forwardee(obj);
69+
if (GCForwarding::is_forwarded(obj)) {
70+
oop forwardee = GCForwarding::forwardee(obj);
7171
// Forwarded, just update.
7272
assert(G1CollectedHeap::heap()->is_in_reserved(forwardee), "should be in object space");
7373
RawAccess<IS_NOT_NULL>::oop_store(p, forwardee);

0 commit comments

Comments
 (0)