Skip to content

Commit f09c355

Browse files
committed
8305896: Alternative full GC forwarding
1 parent 5726d31 commit f09c355

20 files changed

+527
-28
lines changed

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

Lines changed: 3 additions & 0 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"
@@ -1675,6 +1676,8 @@ jint G1CollectedHeap::initialize() {
16751676

16761677
G1InitLogger::print();
16771678

1679+
GCForwarding::initialize(heap_rs.region(), HeapRegion::LogOfHRGrainBytes - LogHeapWordSize);
1680+
16781681
return JNI_OK;
16791682
}
16801683

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
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"
@@ -207,6 +208,8 @@ void G1FullCollector::collect() {
207208
// Don't add any more derived pointers during later phases
208209
deactivate_derived_pointers();
209210

211+
GCForwarding::begin();
212+
210213
phase2_prepare_compaction();
211214

212215
if (has_compaction_targets()) {
@@ -219,6 +222,8 @@ void G1FullCollector::collect() {
219222
log_info(gc, phases) ("No Regions selected for compaction. Skipping Phase 3: Adjust pointers and Phase 4: Compact heap");
220223
}
221224

225+
GCForwarding::end();
226+
222227
phase5_reset_metadata();
223228

224229
G1CollectedHeap::finish_codecache_marking_cycle();
@@ -341,7 +346,7 @@ void G1FullCollector::phase2_prepare_compaction() {
341346
// Try to avoid OOM immediately after Full GC in case there are no free regions
342347
// left after determining the result locations (i.e. this phase). Prepare to
343348
// maximally compact the tail regions of the compaction queues serially.
344-
if (scope()->do_maximal_compaction() || !has_free_compaction_targets) {
349+
if (!UseAltGCForwarding && (scope()->do_maximal_compaction() || !has_free_compaction_targets)) {
345350
phase2c_prepare_serial_compaction();
346351
}
347352
}

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
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"
3334
#include "logging/log.hpp"
3435
#include "oops/oop.inline.hpp"
@@ -41,8 +42,8 @@ void G1FullGCCompactTask::G1CompactRegionClosure::clear_in_bitmap(oop obj) {
4142

4243
size_t G1FullGCCompactTask::G1CompactRegionClosure::apply(oop obj) {
4344
size_t size = obj->size();
44-
if (obj->is_forwarded()) {
45-
HeapWord* destination = cast_from_oop<HeapWord*>(obj->forwardee());
45+
if (GCForwarding::is_forwarded(obj)) {
46+
HeapWord* destination = cast_from_oop<HeapWord*>(GCForwarding::forwardee(obj));
4647

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

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +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/gcForwarding.inline.hpp"
2930
#include "oops/oop.inline.hpp"
3031
#include "utilities/debug.hpp"
3132

@@ -101,10 +102,10 @@ void G1FullGCCompactionPoint::forward(oop object, size_t size) {
101102

102103
// Store a forwarding pointer if the object should be moved.
103104
if (cast_from_oop<HeapWord*>(object) != _compaction_top) {
104-
object->forward_to(cast_to_oop(_compaction_top));
105-
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");
106107
} else {
107-
assert(!object->is_forwarded(), "must not be forwarded");
108+
assert(GCForwarding::is_not_forwarded(object), "must not be forwarded");
108109
}
109110

110111
// Update compaction values.

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +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/gcForwarding.inline.hpp"
3536
#include "memory/iterator.inline.hpp"
3637
#include "memory/universe.hpp"
3738
#include "oops/access.inline.hpp"
@@ -65,8 +66,8 @@ template <class T> inline void G1AdjustClosure::adjust_pointer(T* p) {
6566
return;
6667
}
6768

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

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include "gc/g1/g1FullGCCompactionPoint.hpp"
3333
#include "gc/g1/g1FullGCScope.hpp"
3434
#include "gc/g1/heapRegion.inline.hpp"
35+
#include "gc/shared/gcForwarding.hpp"
3536

3637
template<bool is_humongous>
3738
void G1DetermineCompactionQueueClosure::free_pinned_region(HeapRegion* hr) {
@@ -112,10 +113,10 @@ inline bool G1DetermineCompactionQueueClosure::do_heap_region(HeapRegion* hr) {
112113
}
113114

114115
inline size_t G1SerialRePrepareClosure::apply(oop obj) {
115-
if (obj->is_forwarded()) {
116+
if (GCForwarding::is_forwarded(obj)) {
116117
// We skip objects compiled into the first region or
117118
// into regions not part of the serial compaction point.
118-
if (cast_from_oop<HeapWord*>(obj->forwardee()) < _dense_prefix_top) {
119+
if (cast_from_oop<HeapWord*>(GCForwarding::forwardee(obj)) < _dense_prefix_top) {
119120
return obj->size();
120121
}
121122
}

src/hotspot/share/gc/serial/genMarkSweep.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include "gc/serial/genMarkSweep.hpp"
3737
#include "gc/serial/serialGcRefProcProxyTask.hpp"
3838
#include "gc/shared/collectedHeap.inline.hpp"
39+
#include "gc/shared/gcForwarding.hpp"
3940
#include "gc/shared/gcHeapSummary.hpp"
4041
#include "gc/shared/gcTimer.hpp"
4142
#include "gc/shared/gcTrace.hpp"
@@ -87,6 +88,8 @@ void GenMarkSweep::invoke_at_safepoint(bool clear_all_softrefs) {
8788

8889
mark_sweep_phase1(clear_all_softrefs);
8990

91+
GCForwarding::begin();
92+
9093
mark_sweep_phase2();
9194

9295
// Don't add any more derived pointers during phase3
@@ -105,6 +108,8 @@ void GenMarkSweep::invoke_at_safepoint(bool clear_all_softrefs) {
105108
// (Should this be in general part?)
106109
gch->save_marks();
107110

111+
GCForwarding::end();
112+
108113
deallocate_stacks();
109114

110115
MarkSweep::_string_dedup_requests->flush();

src/hotspot/share/gc/serial/markSweep.inline.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include "classfile/classLoaderData.inline.hpp"
3131
#include "classfile/javaClasses.inline.hpp"
3232
#include "gc/shared/continuationGCSupport.inline.hpp"
33+
#include "gc/shared/gcForwarding.inline.hpp"
3334
#include "gc/serial/serialStringDedup.hpp"
3435
#include "memory/universe.hpp"
3536
#include "oops/markWord.hpp"
@@ -45,8 +46,8 @@ template <class T> inline void MarkSweep::adjust_pointer(T* p) {
4546
oop obj = CompressedOops::decode_not_null(heap_oop);
4647
assert(Universe::heap()->is_in(obj), "should be in heap");
4748

48-
if (obj->is_forwarded()) {
49-
oop new_obj = obj->forwardee();
49+
if (GCForwarding::is_forwarded(obj)) {
50+
oop new_obj = GCForwarding::forwardee(obj);
5051
assert(is_object_aligned(new_obj), "oop must be aligned");
5152
RawAccess<IS_NOT_NULL>::oop_store(p, new_obj);
5253
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
* Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* version 2 for more details (a copy is included in the LICENSE file that
13+
* accompanied this code).
14+
*
15+
* You should have received a copy of the GNU General Public License version
16+
* 2 along with this work; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*
19+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20+
* or visit www.oracle.com if you need additional information or have any
21+
* questions.
22+
*
23+
*/
24+
25+
#include "precompiled.hpp"
26+
#include "gc/shared/gcForwarding.hpp"
27+
#include "gc/shared/gc_globals.hpp"
28+
#include "gc/shared/slidingForwarding.hpp"
29+
30+
SlidingForwarding* GCForwarding::_sliding_forwarding = nullptr;
31+
32+
void GCForwarding::initialize(MemRegion heap) {
33+
if (UseAltGCForwarding) {
34+
assert(_sliding_forwarding == nullptr, "only call this once");
35+
_sliding_forwarding = new SlidingForwarding(heap);
36+
}
37+
}
38+
39+
void GCForwarding::initialize(MemRegion heap, size_t region_size_words_shift) {
40+
if (UseAltGCForwarding) {
41+
assert(_sliding_forwarding == nullptr, "only call this once");
42+
_sliding_forwarding = new SlidingForwarding(heap, region_size_words_shift);
43+
}
44+
}
45+
46+
void GCForwarding::begin() {
47+
if (UseAltGCForwarding) {
48+
assert(_sliding_forwarding != nullptr, "expect sliding forwarding initialized");
49+
_sliding_forwarding->clear();
50+
}
51+
}
52+
53+
void GCForwarding::end() {
54+
if (UseAltGCForwarding) {
55+
assert(_sliding_forwarding != nullptr, "expect sliding forwarding initialized");
56+
}
57+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* version 2 for more details (a copy is included in the LICENSE file that
13+
* accompanied this code).
14+
*
15+
* You should have received a copy of the GNU General Public License version
16+
* 2 along with this work; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*
19+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20+
* or visit www.oracle.com if you need additional information or have any
21+
* questions.
22+
*
23+
*/
24+
25+
#ifndef SHARE_GC_SHARED_GCFORWARDING_HPP
26+
#define SHARE_GC_SHARED_GCFORWARDING_HPP
27+
28+
#include "memory/allStatic.hpp"
29+
#include "memory/memRegion.hpp"
30+
#include "oops/oopsHierarchy.hpp"
31+
32+
class SlidingForwarding;
33+
34+
class GCForwarding : public AllStatic {
35+
private:
36+
static SlidingForwarding* _sliding_forwarding;
37+
38+
public:
39+
static void initialize(MemRegion heap);
40+
static void initialize(MemRegion heap, size_t region_size_words_shift);
41+
static void begin();
42+
static void end();
43+
44+
static inline bool is_forwarded(oop obj);
45+
static inline bool is_not_forwarded(oop obj);
46+
static inline oop forwardee(oop obj);
47+
static inline void forward_to(oop obj, oop fwd);
48+
};
49+
50+
#endif // SHARE_GC_SHARED_GCFORWARDING_HPP

0 commit comments

Comments
 (0)