Skip to content

Commit 239ac2a

Browse files
committedJun 1, 2022
8286829: Shenandoah: fix Shenandoah Loom support
Reviewed-by: shade
1 parent 67ecd30 commit 239ac2a

15 files changed

+105
-35
lines changed
 

‎src/hotspot/share/gc/shenandoah/shenandoahBarrierSetNMethod.cpp

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2019, 2021, Red Hat, Inc. All rights reserved.
2+
* Copyright (c) 2019, 2022, 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
@@ -60,8 +60,13 @@ bool ShenandoahBarrierSetNMethod::nmethod_entry_barrier(nmethod* nm) {
6060
return false;
6161
}
6262

63-
// Heal oops and disarm
63+
// Heal oops
6464
ShenandoahNMethod::heal_nmethod(nm);
65+
66+
// CodeCache sweeper support
67+
nm->mark_as_maybe_on_continuation();
68+
69+
// Disarm
6570
ShenandoahNMethod::disarm_nmethod(nm);
6671
return true;
6772
}

‎src/hotspot/share/gc/shenandoah/shenandoahClosures.hpp

+10-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2019, 2020, Red Hat, Inc. All rights reserved.
2+
* Copyright (c) 2019, 2022, 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
@@ -24,6 +24,7 @@
2424
#ifndef SHARE_GC_SHENANDOAH_SHENANDOAHCLOSURES_HPP
2525
#define SHARE_GC_SHENANDOAH_SHENANDOAHCLOSURES_HPP
2626

27+
#include "code/nmethod.hpp"
2728
#include "memory/iterator.hpp"
2829
#include "oops/accessDecorators.hpp"
2930
#include "runtime/handshake.hpp"
@@ -71,7 +72,12 @@ class ShenandoahKeepAliveClosure : public OopClosure {
7172
void do_oop_work(T* p);
7273
};
7374

74-
class ShenandoahUpdateRefsClosure: public OopClosure {
75+
class ShenandoahOopClosureBase : public MetadataVisitingOopIterateClosure {
76+
public:
77+
inline void do_nmethod(nmethod* nm);
78+
};
79+
80+
class ShenandoahUpdateRefsClosure: public ShenandoahOopClosureBase {
7581
private:
7682
ShenandoahHeap* _heap;
7783
public:
@@ -84,7 +90,7 @@ class ShenandoahUpdateRefsClosure: public OopClosure {
8490
};
8591

8692
template <DecoratorSet MO = MO_UNORDERED>
87-
class ShenandoahEvacuateUpdateMetadataClosure: public BasicOopIterateClosure {
93+
class ShenandoahEvacuateUpdateMetadataClosure: public ShenandoahOopClosureBase {
8894
private:
8995
ShenandoahHeap* const _heap;
9096
Thread* const _thread;
@@ -99,7 +105,7 @@ class ShenandoahEvacuateUpdateMetadataClosure: public BasicOopIterateClosure {
99105
};
100106

101107
// Context free version, cannot cache calling thread
102-
class ShenandoahEvacuateUpdateRootsClosure : public BasicOopIterateClosure {
108+
class ShenandoahEvacuateUpdateRootsClosure : public ShenandoahOopClosureBase {
103109
private:
104110
ShenandoahHeap* const _heap;
105111
public:

‎src/hotspot/share/gc/shenandoah/shenandoahClosures.inline.hpp

+6-1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include "gc/shenandoah/shenandoahAsserts.hpp"
3131
#include "gc/shenandoah/shenandoahBarrierSet.hpp"
3232
#include "gc/shenandoah/shenandoahEvacOOMHandler.inline.hpp"
33+
#include "gc/shenandoah/shenandoahMarkingContext.inline.hpp"
3334
#include "gc/shenandoah/shenandoahHeap.inline.hpp"
3435
#include "gc/shenandoah/shenandoahNMethod.inline.hpp"
3536
#include "oops/compressedOops.inline.hpp"
@@ -67,8 +68,12 @@ BoolObjectClosure* ShenandoahIsAliveSelector::is_alive_closure() {
6768
reinterpret_cast<BoolObjectClosure*>(&_alive_cl);
6869
}
6970

71+
void ShenandoahOopClosureBase::do_nmethod(nmethod* nm) {
72+
nm->run_nmethod_entry_barrier();
73+
}
74+
7075
ShenandoahKeepAliveClosure::ShenandoahKeepAliveClosure() :
71-
_bs(static_cast<ShenandoahBarrierSet*>(BarrierSet::barrier_set())) {
76+
_bs(ShenandoahBarrierSet::barrier_set()) {
7277
}
7378

7479
void ShenandoahKeepAliveClosure::do_oop(oop* p) {

‎src/hotspot/share/gc/shenandoah/shenandoahCodeRoots.cpp

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, 2021, Red Hat, Inc. All rights reserved.
2+
* Copyright (c) 2017, 2022, 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
@@ -244,7 +244,13 @@ class ShenandoahNMethodUnlinkClosure : public NMethodClosure {
244244
if (_bs->is_armed(nm)) {
245245
ShenandoahEvacOOMScope oom_evac_scope;
246246
ShenandoahNMethod::heal_nmethod_metadata(nm_data);
247-
_bs->disarm(nm);
247+
if (Continuations::enabled()) {
248+
// Loom needs to know about visited nmethods. Arm the nmethods to get
249+
// mark_as_maybe_on_continuation() callbacks when they are used again.
250+
_bs->arm(nm, 0);
251+
} else {
252+
_bs->disarm(nm);
253+
}
248254
}
249255

250256
// Clear compiled ICs and exception caches

‎src/hotspot/share/gc/shenandoah/shenandoahConcurrentGC.cpp

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2021, Red Hat, Inc. All rights reserved.
2+
* Copyright (c) 2021, 2022, 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
@@ -26,6 +26,7 @@
2626

2727
#include "gc/shared/barrierSetNMethod.hpp"
2828
#include "gc/shared/collectorCounters.hpp"
29+
#include "gc/shared/continuationGCSupport.inline.hpp"
2930
#include "gc/shenandoah/shenandoahBreakpoint.hpp"
3031
#include "gc/shenandoah/shenandoahCollectorPolicy.hpp"
3132
#include "gc/shenandoah/shenandoahConcurrentGC.hpp"
@@ -506,6 +507,10 @@ class ShenandoahInitMarkUpdateRegionStateClosure : public ShenandoahHeapRegionCl
506507
bool is_thread_safe() { return true; }
507508
};
508509

510+
void ShenandoahConcurrentGC::start_mark() {
511+
_mark.start_mark();
512+
}
513+
509514
void ShenandoahConcurrentGC::op_init_mark() {
510515
ShenandoahHeap* const heap = ShenandoahHeap::heap();
511516
assert(ShenandoahSafepoint::is_at_shenandoah_safepoint(), "Should be at safepoint");
@@ -525,6 +530,8 @@ void ShenandoahConcurrentGC::op_init_mark() {
525530

526531
heap->set_concurrent_mark_in_progress(true);
527532

533+
start_mark();
534+
528535
{
529536
ShenandoahGCPhase phase(ShenandoahPhaseTimings::init_update_region_states);
530537
ShenandoahInitMarkUpdateRegionStateClosure cl;

‎src/hotspot/share/gc/shenandoah/shenandoahConcurrentGC.hpp

+2
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ class ShenandoahConcurrentGC : public ShenandoahGC {
106106
void op_final_roots();
107107
void op_cleanup_complete();
108108

109+
void start_mark();
110+
109111
// Messages for GC trace events, they have to be immortal for
110112
// passing around the logging/tracing systems
111113
const char* init_mark_event_message() const;

‎src/hotspot/share/gc/shenandoah/shenandoahConcurrentMark.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
#include "gc/shenandoah/shenandoahUtils.hpp"
4242
#include "memory/iterator.inline.hpp"
4343
#include "memory/resourceArea.hpp"
44+
#include "runtime/continuation.hpp"
4445

4546
class ShenandoahConcurrentMarkingTask : public WorkerTask {
4647
private:
@@ -238,6 +239,8 @@ void ShenandoahConcurrentMark::finish_mark() {
238239
ShenandoahHeap* const heap = ShenandoahHeap::heap();
239240
heap->set_concurrent_mark_in_progress(false);
240241
heap->mark_complete_marking_context();
242+
243+
end_mark();
241244
}
242245

243246
void ShenandoahConcurrentMark::finish_mark_work() {

‎src/hotspot/share/gc/shenandoah/shenandoahHeap.cpp

+8-9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2013, 2021, Red Hat, Inc. All rights reserved.
2+
* Copyright (c) 2013, 2022, 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
@@ -2312,16 +2312,15 @@ bool ShenandoahHeap::requires_barriers(stackChunkOop obj) const {
23122312

23132313
// Objects allocated after marking start are implicitly alive, don't need any barriers during
23142314
// marking phase.
2315-
if (is_concurrent_mark_in_progress() && marking_context()->allocated_after_mark_start(obj)) {
2316-
return false;
2315+
if (is_concurrent_mark_in_progress() &&
2316+
!marking_context()->allocated_after_mark_start(obj)) {
2317+
return true;
23172318
}
23182319

2319-
// Objects allocated after evacuation start are guaranteed in to-space, don't need any barriers
2320-
// during evacuation/update references phases.
2321-
if (has_forwarded_objects() &&
2322-
cast_from_oop<HeapWord*>(obj) >= heap_region_containing(obj)->get_update_watermark()) {
2323-
return false;
2320+
// Can not guarantee obj is deeply good.
2321+
if (has_forwarded_objects()) {
2322+
return true;
23242323
}
23252324

2326-
return true;
2325+
return false;
23272326
}

‎src/hotspot/share/gc/shenandoah/shenandoahMark.cpp

+16-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2021, Red Hat, Inc. All rights reserved.
2+
* Copyright (c) 2021, 2022, 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
@@ -33,6 +33,7 @@
3333
#include "gc/shenandoah/shenandoahTaskqueue.inline.hpp"
3434
#include "gc/shenandoah/shenandoahUtils.hpp"
3535
#include "gc/shenandoah/shenandoahVerifier.hpp"
36+
#include "runtime/continuation.hpp"
3637

3738
ShenandoahMarkRefsSuperClosure::ShenandoahMarkRefsSuperClosure(ShenandoahObjToScanQueue* q, ShenandoahReferenceProcessor* rp) :
3839
MetadataVisitingOopIterateClosure(rp),
@@ -45,6 +46,20 @@ ShenandoahMark::ShenandoahMark() :
4546
_task_queues(ShenandoahHeap::heap()->marking_context()->task_queues()) {
4647
}
4748

49+
void ShenandoahMark::start_mark() {
50+
// Tell the sweeper that we start a marking cycle.
51+
if (!Continuations::is_gc_marking_cycle_active()) {
52+
Continuations::on_gc_marking_cycle_start();
53+
}
54+
}
55+
56+
void ShenandoahMark::end_mark() {
57+
// Tell the sweeper that we finished a marking cycle.
58+
// Unlike other GCs, we do not arm the nmethods
59+
// when marking terminates.
60+
Continuations::on_gc_marking_cycle_finish();
61+
}
62+
4863
void ShenandoahMark::clear() {
4964
// Clean up marking stacks.
5065
ShenandoahObjToScanQueueSet* queues = ShenandoahHeap::heap()->marking_context()->task_queues();

‎src/hotspot/share/gc/shenandoah/shenandoahMark.hpp

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2021, Red Hat, Inc. All rights reserved.
2+
* Copyright (c) 2021, 2022, 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
@@ -50,6 +50,10 @@ class ShenandoahMark: public StackObj {
5050

5151
static void clear();
5252

53+
// Loom support
54+
void start_mark();
55+
void end_mark();
56+
5357
// Helpers
5458
inline ShenandoahObjToScanQueueSet* task_queues() const;
5559
inline ShenandoahObjToScanQueue* get_queue(uint index) const;

‎src/hotspot/share/gc/shenandoah/shenandoahMark.inline.hpp

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2015, 2021, Red Hat, Inc. All rights reserved.
2+
* Copyright (c) 2015, 2022, 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
@@ -27,6 +27,7 @@
2727

2828
#include "gc/shenandoah/shenandoahMark.hpp"
2929

30+
#include "gc/shared/continuationGCSupport.inline.hpp"
3031
#include "gc/shenandoah/shenandoahAsserts.hpp"
3132
#include "gc/shenandoah/shenandoahBarrierSet.inline.hpp"
3233
#include "gc/shenandoah/shenandoahHeap.inline.hpp"
@@ -69,6 +70,12 @@ void ShenandoahMark::do_task(ShenandoahObjToScanQueue* q, T* cl, ShenandoahLiveD
6970
if (task->is_not_chunked()) {
7071
if (obj->is_instance()) {
7172
// Case 1: Normal oop, process as usual.
73+
if (ContinuationGCSupport::relativize_stack_chunk(obj)) {
74+
// Loom doesn't support mixing of weak marking and strong marking of
75+
// stack chunks.
76+
cl->set_weak(false);
77+
}
78+
7279
obj->oop_iterate(cl);
7380
dedup_string<STRING_DEDUP>(obj, req);
7481
} else if (obj->is_objArray()) {

‎src/hotspot/share/gc/shenandoah/shenandoahNMethod.cpp

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2019, 2021, Red Hat, Inc. All rights reserved.
2+
* Copyright (c) 2019, 2022, 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
@@ -27,7 +27,9 @@
2727
#include "gc/shenandoah/shenandoahClosures.inline.hpp"
2828
#include "gc/shenandoah/shenandoahHeap.inline.hpp"
2929
#include "gc/shenandoah/shenandoahNMethod.inline.hpp"
30+
#include "gc/shenandoah/shenandoahOopClosures.inline.hpp"
3031
#include "memory/resourceArea.hpp"
32+
#include "runtime/continuation.hpp"
3133

3234
ShenandoahNMethod::ShenandoahNMethod(nmethod* nm, GrowableArray<oop*>& oops, bool non_immediate_oops) :
3335
_nm(nm), _oops(NULL), _oops_count(0), _unregistered(false) {
@@ -159,14 +161,14 @@ void ShenandoahNMethod::heal_nmethod(nmethod* nm) {
159161
ShenandoahKeepAliveClosure cl;
160162
data->oops_do(&cl);
161163
} else if (heap->is_concurrent_weak_root_in_progress() ||
162-
heap->is_concurrent_strong_root_in_progress()) {
164+
heap->is_concurrent_strong_root_in_progress() ) {
163165
ShenandoahEvacOOMScope evac_scope;
164166
heal_nmethod_metadata(data);
165167
} else {
166168
// There is possibility that GC is cancelled when it arrives final mark.
167169
// In this case, concurrent root phase is skipped and degenerated GC should be
168170
// followed, where nmethods are disarmed.
169-
assert(heap->cancelled_gc(), "What else?");
171+
assert(heap->cancelled_gc() || Continuations::enabled(), "What else?");
170172
}
171173
}
172174

‎src/hotspot/share/gc/shenandoah/shenandoahOopClosures.hpp

+8-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2015, 2021, Red Hat, Inc. All rights reserved.
2+
* Copyright (c) 2015, 2022, 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
@@ -26,6 +26,7 @@
2626
#define SHARE_GC_SHENANDOAH_SHENANDOAHOOPCLOSURES_HPP
2727

2828
#include "gc/shared/stringdedup/stringDedup.hpp"
29+
#include "gc/shenandoah/shenandoahClosures.inline.hpp"
2930
#include "gc/shenandoah/shenandoahHeap.inline.hpp"
3031
#include "gc/shenandoah/shenandoahTaskqueue.hpp"
3132
#include "gc/shenandoah/shenandoahUtils.hpp"
@@ -58,6 +59,11 @@ class ShenandoahMarkRefsSuperClosure : public MetadataVisitingOopIterateClosure
5859
void set_weak(bool weak) {
5960
_weak = weak;
6061
}
62+
63+
virtual void do_nmethod(nmethod* nm) {
64+
assert(!is_weak(), "Can't handle weak marking of nmethods");
65+
nm->run_nmethod_entry_barrier();
66+
}
6167
};
6268

6369
class ShenandoahMarkUpdateRefsSuperClosure : public ShenandoahMarkRefsSuperClosure {
@@ -86,7 +92,6 @@ class ShenandoahMarkUpdateRefsClosure : public ShenandoahMarkUpdateRefsSuperClos
8692

8793
virtual void do_oop(narrowOop* p) { do_oop_work(p); }
8894
virtual void do_oop(oop* p) { do_oop_work(p); }
89-
virtual bool do_metadata() { return false; }
9095
};
9196

9297
class ShenandoahMarkUpdateRefsMetadataClosure : public ShenandoahMarkUpdateRefsSuperClosure {
@@ -100,7 +105,6 @@ class ShenandoahMarkUpdateRefsMetadataClosure : public ShenandoahMarkUpdateRefsS
100105

101106
virtual void do_oop(narrowOop* p) { do_oop_work(p); }
102107
virtual void do_oop(oop* p) { do_oop_work(p); }
103-
virtual bool do_metadata() { return true; }
104108
};
105109

106110

@@ -115,7 +119,6 @@ class ShenandoahMarkRefsClosure : public ShenandoahMarkRefsSuperClosure {
115119

116120
virtual void do_oop(narrowOop* p) { do_oop_work(p); }
117121
virtual void do_oop(oop* p) { do_oop_work(p); }
118-
virtual bool do_metadata() { return false; }
119122
};
120123

121124

@@ -130,10 +133,9 @@ class ShenandoahMarkRefsMetadataClosure : public ShenandoahMarkRefsSuperClosure
130133

131134
virtual void do_oop(narrowOop* p) { do_oop_work(p); }
132135
virtual void do_oop(oop* p) { do_oop_work(p); }
133-
virtual bool do_metadata() { return true; }
134136
};
135137

136-
class ShenandoahUpdateRefsSuperClosure : public BasicOopIterateClosure {
138+
class ShenandoahUpdateRefsSuperClosure : public ShenandoahOopClosureBase {
137139
protected:
138140
ShenandoahHeap* _heap;
139141

‎src/hotspot/share/gc/shenandoah/shenandoahSTWMark.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2021, Red Hat, Inc. All rights reserved.
2+
* Copyright (c) 2021, 2022, 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
@@ -101,6 +101,8 @@ void ShenandoahSTWMark::mark() {
101101
heap->verifier()->verify_roots_no_forwarded();
102102
}
103103

104+
start_mark();
105+
104106
uint nworkers = heap->workers()->active_workers();
105107
task_queues()->reserve(nworkers);
106108

@@ -116,6 +118,7 @@ void ShenandoahSTWMark::mark() {
116118
}
117119

118120
heap->mark_complete_marking_context();
121+
end_mark();
119122

120123
assert(task_queues()->is_empty(), "Should be empty");
121124
TASKQUEUE_STATS_ONLY(task_queues()->print_taskqueue_stats());

‎src/hotspot/share/runtime/continuationFreezeThaw.cpp

+7-3
Original file line numberDiff line numberDiff line change
@@ -1199,7 +1199,6 @@ NOINLINE void FreezeBase::finish_freeze(const frame& f, const frame& top) {
11991199
// old chunks are all in GC mode.
12001200
assert(!UseG1GC, "G1 can not deal with allocating outside of eden");
12011201
assert(!UseZGC, "ZGC can not deal with allocating chunks visible to marking");
1202-
assert(!UseShenandoahGC, "Shenandoah can not deal with allocating chunks visible to marking");
12031202
ContinuationGCSupport::transform_stack_chunk(_cont.tail());
12041203
// For objects in the old generation we must maintain the remembered set
12051204
_cont.tail()->do_barriers<stackChunkOopDesc::BarrierType::Store>();
@@ -1282,11 +1281,16 @@ stackChunkOop Freeze<ConfigT>::allocate_chunk(size_t stack_size) {
12821281

12831282
assert(chunk->parent() == nullptr || chunk->parent()->is_stackChunk(), "");
12841283

1284+
// Shenandoah: even continuation is good, it does not mean it is deeply good.
1285+
if (UseShenandoahGC && chunk->requires_barriers()) {
1286+
fast_oop = nullptr;
1287+
}
1288+
12851289
if (fast_oop != nullptr) {
12861290
assert(!chunk->requires_barriers(), "Unfamiliar GC requires barriers on TLAB allocation");
12871291
} else {
1288-
assert(!UseZGC || !UseShenandoahGC || !chunk->requires_barriers(), "Allocated ZGC/ShenandoahGC object requires barriers");
1289-
_barriers = !UseZGC && !UseShenandoahGC && chunk->requires_barriers();
1292+
assert(!UseZGC || !chunk->requires_barriers(), "Allocated ZGC object requires barriers");
1293+
_barriers = !UseZGC && chunk->requires_barriers();
12901294

12911295
if (_barriers) {
12921296
log_develop_trace(continuations)("allocation requires barriers");

0 commit comments

Comments
 (0)
Please sign in to comment.