23 *
24 */
25
26 #include "code/codeCache.hpp"
27 #include "code/nmethod.hpp"
28 #include "gc/shared/classUnloadingContext.hpp"
29 #include "gc/shenandoah/shenandoahClosures.inline.hpp"
30 #include "gc/shenandoah/shenandoahEvacOOMHandler.inline.hpp"
31 #include "gc/shenandoah/shenandoahHeap.inline.hpp"
32 #include "gc/shenandoah/shenandoahNMethod.inline.hpp"
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;
99
100 public:
101 ShenandoahDisarmNMethodsTask() :
102 WorkerTask("Shenandoah Disarm NMethods"),
103 _iterator(ShenandoahCodeRoots::table()) {
104 assert(SafepointSynchronize::is_at_safepoint(), "Only at a safepoint");
105 }
106
107 virtual void work(uint worker_id) {
108 ShenandoahParallelWorkerSession worker_session(worker_id);
109 _iterator.nmethods_do(&_cl);
110 }
111 };
112
113 void ShenandoahCodeRoots::disarm_nmethods() {
114 if (use_nmethod_barriers_for_mark()) {
115 ShenandoahDisarmNMethodsTask task;
116 ShenandoahHeap::heap()->workers()->run_task(&task);
117 }
118 }
119
120 class ShenandoahNMethodUnlinkClosure : public NMethodClosure {
121 private:
122 bool _unloading_occurred;
123 ShenandoahHeap* const _heap;
124 BarrierSetNMethod* const _bs;
125
126 public:
127 ShenandoahNMethodUnlinkClosure(bool unloading_occurred) :
128 _unloading_occurred(unloading_occurred),
129 _heap(ShenandoahHeap::heap()),
130 _bs(ShenandoahBarrierSet::barrier_set()->barrier_set_nmethod()) {}
131
132 virtual void do_nmethod(nmethod* nm) {
133 assert(_heap->is_concurrent_weak_root_in_progress(), "Only this phase");
134
135 ShenandoahNMethod* nm_data = ShenandoahNMethod::gc_data(nm);
136 assert(!nm_data->is_unregistered(), "Should not see unregistered entry");
137
|
23 *
24 */
25
26 #include "code/codeCache.hpp"
27 #include "code/nmethod.hpp"
28 #include "gc/shared/classUnloadingContext.hpp"
29 #include "gc/shenandoah/shenandoahClosures.inline.hpp"
30 #include "gc/shenandoah/shenandoahEvacOOMHandler.inline.hpp"
31 #include "gc/shenandoah/shenandoahHeap.inline.hpp"
32 #include "gc/shenandoah/shenandoahNMethod.inline.hpp"
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 void ShenandoahCodeRoots::initialize() {
44 _nmethod_table = new ShenandoahNMethodTable();
45 }
46
47 void ShenandoahCodeRoots::register_nmethod(nmethod* nm) {
48 assert(CodeCache_lock->owned_by_self(), "Must have CodeCache_lock held");
49 _nmethod_table->register_nmethod(nm);
50 }
51
52 void ShenandoahCodeRoots::unregister_nmethod(nmethod* nm) {
53 assert_locked_or_safepoint(CodeCache_lock);
54 _nmethod_table->unregister_nmethod(nm);
55 }
56
57 void ShenandoahCodeRoots::arm_nmethods() {
58 char gc_state = ShenandoahHeap::heap()->gc_state();
59 log_info(gc)("Arming nmethods with GC state: %d [%s%s%s%s%s%s%s]",
60 gc_state,
61 ((gc_state & ShenandoahHeap::HAS_FORWARDED) > 0) ? "HAS_FORWARDED " : "",
62 ((gc_state & ShenandoahHeap::MARKING) > 0) ? "MARKING " : "",
63 ((gc_state & ShenandoahHeap::EVACUATION) > 0) ? "EVACUATION " : "",
64 ((gc_state & ShenandoahHeap::UPDATE_REFS) > 0) ? "UPDATE_REFS " : "",
65 ((gc_state & ShenandoahHeap::WEAK_ROOTS) > 0) ? "WEAK_ROOTS " : "",
66 ((gc_state & ShenandoahHeap::YOUNG_MARKING) > 0) ? "YOUNG_MARKING " : "",
67 ((gc_state & ShenandoahHeap::OLD_MARKING) > 0) ? "OLD_MARKING " : ""
68 );
69 BarrierSet::barrier_set()->barrier_set_nmethod()->arm_all_nmethods();
70 }
71
72 class ShenandoahDisarmNMethodClosure : public NMethodClosure {
73 public:
74 virtual void do_nmethod(nmethod* nm) {
75 ShenandoahNMethod::disarm_nmethod(nm);
76 }
77 };
78
79 class ShenandoahDisarmNMethodsTask : public WorkerTask {
80 private:
81 ShenandoahDisarmNMethodClosure _cl;
82 ShenandoahConcurrentNMethodIterator _iterator;
83
84 public:
85 ShenandoahDisarmNMethodsTask() :
86 WorkerTask("Shenandoah Disarm NMethods"),
87 _iterator(ShenandoahCodeRoots::table()) {}
88
89 virtual void work(uint worker_id) {
90 ShenandoahParallelWorkerSession worker_session(worker_id);
91 _iterator.nmethods_do(&_cl);
92 }
93 };
94
95 void ShenandoahCodeRoots::disarm_nmethods() {
96 ShenandoahDisarmNMethodsTask task;
97 ShenandoahHeap::heap()->workers()->run_task(&task);
98 }
99
100 class ShenandoahNMethodUnlinkClosure : public NMethodClosure {
101 private:
102 bool _unloading_occurred;
103 ShenandoahHeap* const _heap;
104 BarrierSetNMethod* const _bs;
105
106 public:
107 ShenandoahNMethodUnlinkClosure(bool unloading_occurred) :
108 _unloading_occurred(unloading_occurred),
109 _heap(ShenandoahHeap::heap()),
110 _bs(ShenandoahBarrierSet::barrier_set()->barrier_set_nmethod()) {}
111
112 virtual void do_nmethod(nmethod* nm) {
113 assert(_heap->is_concurrent_weak_root_in_progress(), "Only this phase");
114
115 ShenandoahNMethod* nm_data = ShenandoahNMethod::gc_data(nm);
116 assert(!nm_data->is_unregistered(), "Should not see unregistered entry");
117
|