33 #include "gc/shenandoah/shenandoahUtils.hpp"
34 #include "memory/resourceArea.hpp"
35 #include "memory/universe.hpp"
36 #include "runtime/atomicAccess.hpp"
37 #include "utilities/powerOfTwo.hpp"
38
39
40 ShenandoahNMethodTable* ShenandoahCodeRoots::_nmethod_table;
41 int ShenandoahCodeRoots::_disarmed_value = 1;
42
43 bool ShenandoahCodeRoots::use_nmethod_barriers_for_mark() {
44 // Continuations need nmethod barriers for scanning stack chunk nmethods.
45 if (Continuations::enabled()) return true;
46
47 // Concurrent class unloading needs nmethod barriers.
48 // When a nmethod is about to be executed, we need to make sure that all its
49 // metadata are marked. The alternative is to remark thread roots at final mark
50 // pause, which would cause latency issues.
51 if (ShenandoahHeap::heap()->unload_classes()) return true;
52
53 // Otherwise, we can go without nmethod barriers.
54 return false;
55 }
56
57 void ShenandoahCodeRoots::initialize() {
58 _nmethod_table = new ShenandoahNMethodTable();
59 }
60
61 void ShenandoahCodeRoots::register_nmethod(nmethod* nm) {
62 assert(CodeCache_lock->owned_by_self(), "Must have CodeCache_lock held");
63 _nmethod_table->register_nmethod(nm);
64 }
65
66 void ShenandoahCodeRoots::unregister_nmethod(nmethod* nm) {
67 assert_locked_or_safepoint(CodeCache_lock);
68 _nmethod_table->unregister_nmethod(nm);
69 }
70
71 void ShenandoahCodeRoots::arm_nmethods_for_mark() {
72 if (use_nmethod_barriers_for_mark()) {
73 BarrierSet::barrier_set()->barrier_set_nmethod()->arm_all_nmethods();
74 }
75 }
76
77 void ShenandoahCodeRoots::arm_nmethods_for_evac() {
78 BarrierSet::barrier_set()->barrier_set_nmethod()->arm_all_nmethods();
79 }
80
81 class ShenandoahDisarmNMethodClosure : public NMethodClosure {
82 private:
83 BarrierSetNMethod* const _bs;
84
85 public:
86 ShenandoahDisarmNMethodClosure() :
87 _bs(BarrierSet::barrier_set()->barrier_set_nmethod()) {
88 }
89
90 virtual void do_nmethod(nmethod* nm) {
91 _bs->disarm(nm);
92 }
93 };
94
95 class ShenandoahDisarmNMethodsTask : public WorkerTask {
96 private:
97 ShenandoahDisarmNMethodClosure _cl;
98 ShenandoahConcurrentNMethodIterator _iterator;
|
33 #include "gc/shenandoah/shenandoahUtils.hpp"
34 #include "memory/resourceArea.hpp"
35 #include "memory/universe.hpp"
36 #include "runtime/atomicAccess.hpp"
37 #include "utilities/powerOfTwo.hpp"
38
39
40 ShenandoahNMethodTable* ShenandoahCodeRoots::_nmethod_table;
41 int ShenandoahCodeRoots::_disarmed_value = 1;
42
43 bool ShenandoahCodeRoots::use_nmethod_barriers_for_mark() {
44 // Continuations need nmethod barriers for scanning stack chunk nmethods.
45 if (Continuations::enabled()) return true;
46
47 // Concurrent class unloading needs nmethod barriers.
48 // When a nmethod is about to be executed, we need to make sure that all its
49 // metadata are marked. The alternative is to remark thread roots at final mark
50 // pause, which would cause latency issues.
51 if (ShenandoahHeap::heap()->unload_classes()) return true;
52
53 // First pause: need to enable GC barriers for GC cycle.
54 if (ShenandoahGCStateCheckHotpatch) return true;
55
56 // Otherwise, we can go without nmethod barriers.
57 return false;
58 }
59
60 void ShenandoahCodeRoots::initialize() {
61 _nmethod_table = new ShenandoahNMethodTable();
62 }
63
64 void ShenandoahCodeRoots::register_nmethod(nmethod* nm) {
65 assert(CodeCache_lock->owned_by_self(), "Must have CodeCache_lock held");
66 _nmethod_table->register_nmethod(nm);
67 }
68
69 void ShenandoahCodeRoots::unregister_nmethod(nmethod* nm) {
70 assert_locked_or_safepoint(CodeCache_lock);
71 _nmethod_table->unregister_nmethod(nm);
72 }
73
74 void ShenandoahCodeRoots::arm_nmethods() {
75 if (ShenandoahGCStateCheckHotpatch) {
76 char gc_state = ShenandoahHeap::heap()->gc_state();
77 log_info(gc)("Arming nmethods with GC state: %d [%s%s%s%s%s%s%s]",
78 gc_state,
79 ((gc_state & ShenandoahHeap::HAS_FORWARDED) > 0) ? "HAS_FORWARDED " : "",
80 ((gc_state & ShenandoahHeap::MARKING) > 0) ? "MARKING " : "",
81 ((gc_state & ShenandoahHeap::EVACUATION) > 0) ? "EVACUATION " : "",
82 ((gc_state & ShenandoahHeap::UPDATE_REFS) > 0) ? "UPDATE_REFS " : "",
83 ((gc_state & ShenandoahHeap::WEAK_ROOTS) > 0) ? "WEAK_ROOTS " : "",
84 ((gc_state & ShenandoahHeap::YOUNG_MARKING) > 0) ? "YOUNG_MARKING " : "",
85 ((gc_state & ShenandoahHeap::OLD_MARKING) > 0) ? "OLD_MARKING " : ""
86 );
87 }
88 BarrierSet::barrier_set()->barrier_set_nmethod()->arm_all_nmethods();
89 }
90
91 void ShenandoahCodeRoots::arm_nmethods_for_mark() {
92 if (use_nmethod_barriers_for_mark()) {
93 arm_nmethods();
94 }
95 }
96
97 void ShenandoahCodeRoots::arm_nmethods_for_evac() {
98 arm_nmethods();
99 }
100
101 class ShenandoahDisarmNMethodClosure : public NMethodClosure {
102 private:
103 BarrierSetNMethod* const _bs;
104
105 public:
106 ShenandoahDisarmNMethodClosure() :
107 _bs(BarrierSet::barrier_set()->barrier_set_nmethod()) {
108 }
109
110 virtual void do_nmethod(nmethod* nm) {
111 _bs->disarm(nm);
112 }
113 };
114
115 class ShenandoahDisarmNMethodsTask : public WorkerTask {
116 private:
117 ShenandoahDisarmNMethodClosure _cl;
118 ShenandoahConcurrentNMethodIterator _iterator;
|