Skip to content

Commit 239ac2a

Browse files
committed
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

Lines changed: 7 additions & 2 deletions
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

Lines changed: 10 additions & 4 deletions
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

Lines changed: 6 additions & 1 deletion
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

Lines changed: 8 additions & 2 deletions
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

Lines changed: 8 additions & 1 deletion
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

Lines changed: 2 additions & 0 deletions
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

Lines changed: 3 additions & 0 deletions
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

Lines changed: 8 additions & 9 deletions
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

Lines changed: 16 additions & 1 deletion
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

Lines changed: 5 additions & 1 deletion
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;

0 commit comments

Comments
 (0)