170 OptoRuntime::new_named_counter(state, NamedCounter::RTMLockingCounter);
171 _stack_rtm_counters = rlnc->counters();
172 }
173 }
174 #endif
175 }
176
177 //=============================================================================
178 //------------------------------do_monitor_enter-------------------------------
179 void Parse::do_monitor_enter() {
180 kill_dead_locals();
181
182 // Null check; get casted pointer.
183 Node* obj = null_check(peek());
184 // Check for locking null object
185 if (stopped()) return;
186
187 // the monitor object is not part of debug info expression stack
188 pop();
189
190 // Insert a FastLockNode which takes as arguments the current thread pointer,
191 // the obj pointer & the address of the stack slot pair used for the lock.
192 shared_lock(obj);
193 }
194
195 //------------------------------do_monitor_exit--------------------------------
196 void Parse::do_monitor_exit() {
197 kill_dead_locals();
198
199 pop(); // Pop oop to unlock
200 // Because monitors are guaranteed paired (else we bail out), we know
201 // the matching Lock for this Unlock. Hence we know there is no need
202 // for a null check on Unlock.
203 shared_unlock(map()->peek_monitor_box(), map()->peek_monitor_obj());
204 }
|
170 OptoRuntime::new_named_counter(state, NamedCounter::RTMLockingCounter);
171 _stack_rtm_counters = rlnc->counters();
172 }
173 }
174 #endif
175 }
176
177 //=============================================================================
178 //------------------------------do_monitor_enter-------------------------------
179 void Parse::do_monitor_enter() {
180 kill_dead_locals();
181
182 // Null check; get casted pointer.
183 Node* obj = null_check(peek());
184 // Check for locking null object
185 if (stopped()) return;
186
187 // the monitor object is not part of debug info expression stack
188 pop();
189
190 if (DoPartialEscapeAnalysis) {
191 PEAState& state = jvms()->alloc_state();
192 VirtualState* vs = state.as_virtual(PEA(), obj);
193
194 if (vs != nullptr) {
195 vs->lock_inc();
196 }
197 }
198
199 // Insert a FastLockNode which takes as arguments the current thread pointer,
200 // the obj pointer & the address of the stack slot pair used for the lock.
201 shared_lock(obj);
202 }
203
204 //------------------------------do_monitor_exit--------------------------------
205 void Parse::do_monitor_exit() {
206 kill_dead_locals();
207
208 // need to set it for monitor exit as well.
209 // OSR compiled methods can start with lock taken
210 C->set_has_monitors(true);
211 Node* obj = map()->peek_monitor_obj();
212
213 if (DoPartialEscapeAnalysis) {
214 PEAState& state = jvms()->alloc_state();
215 ObjID id = PEA()->is_alias(obj); //
216 if (id != nullptr && state.contains(id)) {
217 ObjectState* os = state.get_object_state(id);
218 if (os->is_virtual()) {
219 static_cast<VirtualState*>(os)->lock_dec();
220 } else {
221 auto materialized = state.get_materialized_value(id);
222 if (materialized != nullptr) {
223 obj = materialized;
224
225 if (obj->is_Phi()) {
226 pop();
227
228 // We need to split Phi + Unlock like this:
229 // +------+ +-----+ +------+
230 // |Region| | obj | | obj' | (PEA materialized object)
231 // +------+ +-----+ +------+
232 // \ | /
233 // +------------+
234 // |phi| |
235 // +------------+
236 // |P0
237 // +--------------+
238 // | UnlockNode |
239 // +--------------+
240 //
241 // split this phi because it helps EA and ME eliminate Unlock nodes.
242 // bytecode monitor_exit post-dominates the object, so PhiNode has been finalized.
243 // for GraphKit::shared_unlock(), the only side-effect is ctrl + abio + memory.
244 //
245 //
246 // +------+ +-----+ +------+
247 // |Region| | obj | | obj' |
248 // +------+ +-----+ +------+
249 // | /
250 // |P0 |P0
251 // +--------------+ +--------------+
252 // | UnlockNode | | UnlockNode |
253 // +--------------+ +--------------+
254 // | |abio |memory | |abio |memory
255 // | /-----/
256 // | ctrl / ctrl
257 // +--------------------+
258 // | new_rgn | ( new_rgn merges abio and memory as well)
259 // +--------------------+
260 // |ctrl |abio |memory
261 // +--------------------+
262 // | sfpt (map) |
263 // +--------------------+
264 //
265 RegionNode* region = obj->in(0)->as_Region();
266 BoxLockNode* box = map()->peek_monitor_box()->as_BoxLock();
267
268 Node* new_rgn = new RegionNode(region->req());
269 gvn().set_type(new_rgn, Type::CONTROL);
270
271 bool merged = false;
272 GraphKit saved_ctx = {clone_map()->jvms()};
273
274 // reverse i to simulate merging normal paths.
275 // merge_memory_edges() will do GVN when i == 1
276 for (uint i = region->req()-1; i > 0; --i) {
277 Node* ctrl = region->in(i);
278 Node* abio = nullptr;
279 MergeMemNode* mem = nullptr;
280
281 if (ctrl != nullptr && ctrl != C->top()) {
282 SafePointNode* curr = saved_ctx.clone_map();
283 GraphKit kit = { curr->jvms() };
284
285 kit.set_control(ctrl);
286 // We need to resume SafePointNode to the state as if it was the predecessor controlled by region->in(i).
287 for (uint j = 1; j < curr->req(); ++j) {
288 Node* m = curr->in(j);
289
290 if (j == TypeFunc::Memory) {
291 if (m->is_Phi() && m->in(0) == region) {
292 m = m->in(i);
293 } else if (m->is_MergeMem()) {
294 // a blank memory
295 MergeMemNode* new_all_mem = MergeMemNode::make(MergeMemNode::make_empty_memory());
296 new_all_mem->grow_to_match(m->as_MergeMem());
297 for (MergeMemStream mms(m->as_MergeMem()); mms.next_non_empty(); ) {
298 Node* p = mms.memory();
299 if (p->is_Phi() && p->in(0) == region) {
300 new_all_mem->set_req(mms.alias_idx(), p->in(i));
301 } else {
302 new_all_mem->set_req(mms.alias_idx(), p);
303 }
304 }
305 m = new_all_mem;
306 }
307 curr->set_memory(m);
308 } else if (m != nullptr && m->is_Phi() && m->in(0) == region) {
309 curr->set_req(j, m->in(i));
310 }
311 }
312
313 kit.shared_unlock(box, obj->in(i), true);
314
315 ctrl = kit.control();
316 mem = kit.merged_memory();
317 abio = kit.i_o();
318 } else {
319 assert(false, "impossible! monitorExit must post-dominate the PhiNode.");
320 }
321
322 new_rgn->init_req(i, ctrl);
323
324 if (!merged) {
325 merged = true;
326 set_control(new_rgn); // merge_memory_edges() requires that ctrl() is a RegionNode.
327 set_all_memory(mem);
328 set_i_o(abio);
329 } else {
330 merge_memory_edges(mem, i, false);
331 Node* phi = i_o();
332 if (!(phi->is_Phi() && phi->in(0) != new_rgn)) {
333 phi = PhiNode::make(new_rgn, phi);
334 gvn().set_type(phi, Type::ABIO);
335 record_for_igvn(phi);
336 }
337 phi->set_req(i, abio);
338 set_i_o(phi);
339 }
340 }
341
342 new_rgn = _gvn.transform(new_rgn);
343 set_control(new_rgn);
344 record_for_igvn(new_rgn);
345
346 map()->pop_monitor();
347 return ;
348 }
349 }
350 }
351 }
352 }
353
354 pop(); // Pop oop to unlock
355 // Because monitors are guaranteed paired (else we bail out), we know
356 // the matching Lock for this Unlock. Hence we know there is no need
357 // for a null check on Unlock.
358 shared_unlock(map()->peek_monitor_box(), obj);
359 }
|