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 if (ShenandoahGCStateCheckHotpatch) {
59 char gc_state = ShenandoahHeap::heap()->gc_state();
60 log_info(gc)("Arming nmethods with GC state: %d [%s%s%s%s%s%s%s]",
61 gc_state,
62 ((gc_state & ShenandoahHeap::HAS_FORWARDED) > 0) ? "HAS_FORWARDED " : "",
63 ((gc_state & ShenandoahHeap::MARKING) > 0) ? "MARKING " : "",
64 ((gc_state & ShenandoahHeap::EVACUATION) > 0) ? "EVACUATION " : "",
65 ((gc_state & ShenandoahHeap::UPDATE_REFS) > 0) ? "UPDATE_REFS " : "",
66 ((gc_state & ShenandoahHeap::WEAK_ROOTS) > 0) ? "WEAK_ROOTS " : "",
67 ((gc_state & ShenandoahHeap::YOUNG_MARKING) > 0) ? "YOUNG_MARKING " : "",
68 ((gc_state & ShenandoahHeap::OLD_MARKING) > 0) ? "OLD_MARKING " : ""
69 );
70 }
71 BarrierSet::barrier_set()->barrier_set_nmethod()->arm_all_nmethods();
72 }
73
74 class ShenandoahDisarmNMethodClosure : public NMethodClosure {
75 public:
76 virtual void do_nmethod(nmethod* nm) {
77 ShenandoahNMethod::disarm_nmethod(nm);
78 }
79 };
80
81 class ShenandoahDisarmNMethodsTask : public WorkerTask {
82 private:
83 ShenandoahDisarmNMethodClosure _cl;
84 ShenandoahConcurrentNMethodIterator _iterator;
85
86 public:
87 ShenandoahDisarmNMethodsTask() :
88 WorkerTask("Shenandoah Disarm NMethods"),
89 _iterator(ShenandoahCodeRoots::table()) {}
90
91 virtual void work(uint worker_id) {
92 ShenandoahParallelWorkerSession worker_session(worker_id);
93 _iterator.nmethods_do(&_cl);
94 }
95 };
96
97 void ShenandoahCodeRoots::disarm_nmethods() {
98 ShenandoahDisarmNMethodsTask task;
99 ShenandoahHeap::heap()->workers()->run_task(&task);
100 }
101
102 class ShenandoahNMethodUnlinkClosure : public NMethodClosure {
103 private:
104 bool _unloading_occurred;
105 ShenandoahHeap* const _heap;
106 BarrierSetNMethod* const _bs;
107
108 public:
109 ShenandoahNMethodUnlinkClosure(bool unloading_occurred) :
110 _unloading_occurred(unloading_occurred),
111 _heap(ShenandoahHeap::heap()),
112 _bs(ShenandoahBarrierSet::barrier_set()->barrier_set_nmethod()) {}
113
114 virtual void do_nmethod(nmethod* nm) {
115 assert(_heap->is_concurrent_weak_root_in_progress(), "Only this phase");
116
117 ShenandoahNMethod* nm_data = ShenandoahNMethod::gc_data(nm);
118 assert(!nm_data->is_unregistered(), "Should not see unregistered entry");
119
|