@@ -224,11 +224,20 @@ void Parse::load_interpreter_state(Node* osr_buf) {
224
224
Node *monitors_addr = basic_plus_adr (osr_buf, osr_buf, (max_locals+mcnt*2 -1 )*wordSize);
225
225
for (index = 0 ; index < mcnt; index ++) {
226
226
// Make a BoxLockNode for the monitor.
227
- Node *box = new BoxLockNode (next_monitor ());
227
+ BoxLockNode* osr_box = new BoxLockNode (next_monitor ());
228
228
// Check for bailout after new BoxLockNode
229
229
if (failing ()) { return ; }
230
- box = _gvn.transform (box);
231
230
231
+ // This OSR locking region is unbalanced because it does not have Lock node:
232
+ // locking was done in Interpreter.
233
+ // This is similar to Coarsened case when Lock node is eliminated
234
+ // and as result the region is marked as Unbalanced.
235
+
236
+ // Emulate Coarsened state transition from Regular to Unbalanced.
237
+ osr_box->set_coarsened ();
238
+ osr_box->set_unbalanced ();
239
+
240
+ Node* box = _gvn.transform (osr_box);
232
241
233
242
// Displaced headers and locked objects are interleaved in the
234
243
// temp OSR buffer. We only copy the locked objects out here.
@@ -1805,11 +1814,24 @@ void Parse::merge_common(Parse::Block* target, int pnum) {
1805
1814
const JVMState* jvms = map ()->jvms ();
1806
1815
if (EliminateNestedLocks &&
1807
1816
jvms->is_mon (j) && jvms->is_monitor_box (j)) {
1808
- // BoxLock nodes are not commoning.
1817
+ // BoxLock nodes are not commoning when EliminateNestedLocks is on .
1809
1818
// Use old BoxLock node as merged box.
1810
1819
assert (newin->jvms ()->is_monitor_box (j), " sanity" );
1811
1820
// This assert also tests that nodes are BoxLock.
1812
1821
assert (BoxLockNode::same_slot (n, m), " sanity" );
1822
+ BoxLockNode* old_box = m->as_BoxLock ();
1823
+ if (n->as_BoxLock ()->is_unbalanced () && !old_box->is_unbalanced ()) {
1824
+ // Preserve Unbalanced status.
1825
+ //
1826
+ // `old_box` can have only Regular or Coarsened status
1827
+ // because this code is executed only during Parse phase and
1828
+ // Incremental Inlining before EA and Macro nodes elimination.
1829
+ //
1830
+ // Incremental Inlining is executed after IGVN optimizations
1831
+ // during which BoxLock can be marked as Coarsened.
1832
+ old_box->set_coarsened (); // Verifies state
1833
+ old_box->set_unbalanced ();
1834
+ }
1813
1835
C->gvn_replace_by (n, m);
1814
1836
} else if (!check_elide_phi || !target->can_elide_SEL_phi (j)) {
1815
1837
phi = ensure_phi (j, nophi);
0 commit comments