16 * You should have received a copy of the GNU General Public License version
17 * 2 along with this work; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19 *
20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21 * or visit www.oracle.com if you need additional information or have any
22 * questions.
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/shenandoahHeap.inline.hpp"
31 #include "gc/shenandoah/shenandoahNMethod.inline.hpp"
32 #include "gc/shenandoah/shenandoahUtils.hpp"
33 #include "memory/resourceArea.hpp"
34 #include "memory/universe.hpp"
35 #include "runtime/atomicAccess.hpp"
36 #include "utilities/powerOfTwo.hpp"
37
38
39 ShenandoahNMethodTable* ShenandoahCodeRoots::_nmethod_table;
40 int ShenandoahCodeRoots::_disarmed_value = 1;
41
42 void ShenandoahCodeRoots::initialize() {
43 _nmethod_table = new ShenandoahNMethodTable();
44 }
45
46 void ShenandoahCodeRoots::register_nmethod(nmethod* nm) {
47 assert(CodeCache_lock->owned_by_self(), "Must have CodeCache_lock held");
48 _nmethod_table->register_nmethod(nm);
49 }
50
51 void ShenandoahCodeRoots::unregister_nmethod(nmethod* nm) {
52 assert_locked_or_safepoint(CodeCache_lock);
53 _nmethod_table->unregister_nmethod(nm);
54 }
55
56 void ShenandoahCodeRoots::arm_nmethods() {
57 BarrierSet::barrier_set()->barrier_set_nmethod()->arm_all_nmethods();
58 }
59
60 class ShenandoahDisarmNMethodClosure : public NMethodClosure {
61 public:
62 virtual void do_nmethod(nmethod* nm) {
63 ShenandoahNMethod::disarm_nmethod(nm);
64 }
65 };
66
67 class ShenandoahDisarmNMethodsTask : public WorkerTask {
68 private:
69 ShenandoahDisarmNMethodClosure _cl;
70 ShenandoahConcurrentNMethodIterator _iterator;
71
72 public:
73 ShenandoahDisarmNMethodsTask() :
74 WorkerTask("Shenandoah Disarm NMethods"),
75 _iterator(ShenandoahCodeRoots::table()) {
76 assert(SafepointSynchronize::is_at_safepoint(), "Only at a safepoint");
77 }
78
79 virtual void work(uint worker_id) {
80 ShenandoahParallelWorkerSession worker_session(worker_id);
81 _iterator.nmethods_do(&_cl);
82 }
83 };
84
85 void ShenandoahCodeRoots::disarm_nmethods() {
86 ShenandoahDisarmNMethodsTask task;
87 ShenandoahHeap::heap()->workers()->run_task(&task);
88 }
89
90 class ShenandoahNMethodUnlinkClosure : public NMethodClosure {
91 private:
92 bool _unloading_occurred;
93 ShenandoahHeap* const _heap;
94 BarrierSetNMethod* const _bs;
95
96 public:
97 ShenandoahNMethodUnlinkClosure(bool unloading_occurred) :
98 _unloading_occurred(unloading_occurred),
99 _heap(ShenandoahHeap::heap()),
100 _bs(ShenandoahBarrierSet::barrier_set()->barrier_set_nmethod()) {}
101
102 virtual void do_nmethod(nmethod* nm) {
103 assert(_heap->is_concurrent_weak_root_in_progress(), "Only this phase");
104
105 ShenandoahNMethod* nm_data = ShenandoahNMethod::gc_data(nm);
106 assert(!nm_data->is_unregistered(), "Should not see unregistered entry");
107
108 if (nm->is_unloading()) {
109 ShenandoahNMethodLocker locker(nm_data->lock());
110 nm->unlink();
111 return;
112 }
113
114 {
115 ShenandoahNMethodLocker locker(nm_data->lock());
116
117 // Heal oops
118 if (_bs->is_armed(nm)) {
119 ShenandoahNMethod::heal_nmethod_metadata(nm_data);
120 // Must remain armed to complete remaining work in nmethod entry barrier
121 assert(_bs->is_armed(nm), "Should remain armed");
122 }
123 }
124
125 // Clear compiled ICs and exception caches
126 ShenandoahNMethodLocker locker(nm_data->ic_lock());
127 nm->unload_nmethod_caches(_unloading_occurred);
128 }
129 };
130
131 class ShenandoahUnlinkTask : public WorkerTask {
132 private:
133 ShenandoahNMethodUnlinkClosure _cl;
134 ShenandoahConcurrentNMethodIterator _iterator;
|
16 * You should have received a copy of the GNU General Public License version
17 * 2 along with this work; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19 *
20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21 * or visit www.oracle.com if you need additional information or have any
22 * questions.
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/shenandoahHeap.inline.hpp"
31 #include "gc/shenandoah/shenandoahNMethod.inline.hpp"
32 #include "gc/shenandoah/shenandoahUtils.hpp"
33 #include "memory/resourceArea.hpp"
34 #include "memory/universe.hpp"
35 #include "runtime/atomicAccess.hpp"
36 #include "utilities/events.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 Events::log(Thread::current(), "Arming nmethods, 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 log_info(gc)("Arming nmethods with GC state: %d [%s%s%s%s%s%s%s]",
70 gc_state,
71 ((gc_state & ShenandoahHeap::HAS_FORWARDED) > 0) ? "HAS_FORWARDED " : "",
72 ((gc_state & ShenandoahHeap::MARKING) > 0) ? "MARKING " : "",
73 ((gc_state & ShenandoahHeap::EVACUATION) > 0) ? "EVACUATION " : "",
74 ((gc_state & ShenandoahHeap::UPDATE_REFS) > 0) ? "UPDATE_REFS " : "",
75 ((gc_state & ShenandoahHeap::WEAK_ROOTS) > 0) ? "WEAK_ROOTS " : "",
76 ((gc_state & ShenandoahHeap::YOUNG_MARKING) > 0) ? "YOUNG_MARKING " : "",
77 ((gc_state & ShenandoahHeap::OLD_MARKING) > 0) ? "OLD_MARKING " : ""
78 );
79 BarrierSet::barrier_set()->barrier_set_nmethod()->arm_all_nmethods();
80 }
81
82 class ShenandoahDisarmNMethodClosure : public NMethodClosure {
83 public:
84 virtual void do_nmethod(nmethod* nm) {
85 ShenandoahNMethod::complete_and_disarm_nmethod(nm);
86 }
87 };
88
89 class ShenandoahDisarmNMethodsTask : public WorkerTask {
90 private:
91 ShenandoahDisarmNMethodClosure _cl;
92 ShenandoahConcurrentNMethodIterator _iterator;
93
94 public:
95 ShenandoahDisarmNMethodsTask() :
96 WorkerTask("Shenandoah Disarm NMethods"),
97 _iterator(ShenandoahCodeRoots::table()) {}
98
99 virtual void work(uint worker_id) {
100 ShenandoahParallelWorkerSession worker_session(worker_id);
101 _iterator.nmethods_do(&_cl);
102 }
103 };
104
105 void ShenandoahCodeRoots::disarm_nmethods() {
106 Events::log(Thread::current(), "Disarming nmethod barriers");
107 log_info(gc)("Disarming nmethod barriers");
108
109 ShenandoahDisarmNMethodsTask task;
110 ShenandoahHeap::heap()->workers()->run_task(&task);
111
112 Events::log(Thread::current(), "Disarming nmethod barriers complete");
113 log_info(gc)("Disarming nmethod barriers complete");
114 }
115
116 #ifdef ASSERT
117 class ShenandoahCheckNMethodClosure : public NMethodClosure {
118 bool const _armed;
119 public:
120 ShenandoahCheckNMethodClosure(int armed) : _armed(armed) {}
121 virtual void do_nmethod(nmethod* nm) {
122 ShenandoahNMethod::assert_barriers(nm, _armed);
123 }
124 };
125
126 class ShenandoahCheckNMethodsTask : public WorkerTask {
127 private:
128 ShenandoahCheckNMethodClosure _cl;
129 ShenandoahConcurrentNMethodIterator _iterator;
130
131 public:
132 ShenandoahCheckNMethodsTask() :
133 WorkerTask("Shenandoah Check NMethods"),
134 _cl(!ShenandoahHeap::heap()->is_idle()),
135 _iterator(ShenandoahCodeRoots::table()) {}
136
137 virtual void work(uint worker_id) {
138 _iterator.nmethods_do(&_cl);
139 }
140 };
141
142 void ShenandoahCodeRoots::check_barriers() {
143 ShenandoahCheckNMethodsTask task;
144 ShenandoahHeap::heap()->workers()->run_task(&task);
145 }
146 #endif
147
148 class ShenandoahNMethodUnlinkClosure : public NMethodClosure {
149 private:
150 bool _unloading_occurred;
151 ShenandoahHeap* const _heap;
152 BarrierSetNMethod* const _bs;
153
154 public:
155 ShenandoahNMethodUnlinkClosure(bool unloading_occurred) :
156 _unloading_occurred(unloading_occurred),
157 _heap(ShenandoahHeap::heap()),
158 _bs(ShenandoahBarrierSet::barrier_set()->barrier_set_nmethod()) {}
159
160 virtual void do_nmethod(nmethod* nm) {
161 assert(_heap->is_concurrent_weak_root_in_progress(), "Only this phase");
162
163 ShenandoahNMethod* nm_data = ShenandoahNMethod::gc_data(nm);
164 assert(!nm_data->is_unregistered(), "Should not see unregistered entry");
165
166 if (nm->is_unloading()) {
167 ShenandoahNMethodLocker locker(nm_data->lock());
168 nm->unlink();
169 return;
170 }
171
172 if (_heap->is_evacuation_in_progress()) {
173 ShenandoahNMethodLocker locker(nm_data->lock());
174
175 // Heal oops
176 if (_bs->is_armed(nm)) {
177 ShenandoahNMethod::heal_nmethod_metadata(nm_data);
178 // Must remain armed to complete remaining work in nmethod entry barrier
179 assert(_bs->is_armed(nm), "Should remain armed");
180 }
181 }
182
183 // Clear compiled ICs and exception caches
184 ShenandoahNMethodLocker locker(nm_data->ic_lock());
185 nm->unload_nmethod_caches(_unloading_occurred);
186 }
187 };
188
189 class ShenandoahUnlinkTask : public WorkerTask {
190 private:
191 ShenandoahNMethodUnlinkClosure _cl;
192 ShenandoahConcurrentNMethodIterator _iterator;
|