@@ -1683,12 +1683,9 @@ void Compiler::fgAddSyncMethodEnterExit()
16831683
16841684 // Create a block for the start of the try region, where the monitor enter call
16851685 // will go.
1686-
1687- assert (fgFirstBB->bbFallsThrough ());
1688-
1689- BasicBlock* tryBegBB = fgNewBBafter (BBJ_NONE, fgFirstBB, false );
1690- BasicBlock* tryNextBB = tryBegBB->bbNext ;
1691- BasicBlock* tryLastBB = fgLastBB;
1686+ BasicBlock* const tryBegBB = fgSplitBlockAtEnd (fgFirstBB);
1687+ BasicBlock* const tryNextBB = tryBegBB->bbNext ;
1688+ BasicBlock* const tryLastBB = fgLastBB;
16921689
16931690 // If we have profile data the new block will inherit the next block's weight
16941691 if (tryNextBB->hasProfileWeight ())
@@ -1799,10 +1796,10 @@ void Compiler::fgAddSyncMethodEnterExit()
17991796
18001797 lvaTable[lvaMonAcquired].lvType = typeMonAcquired;
18011798
1802- { // Scope the variables of the variable initialization
1803-
1804- // Initialize the 'acquired' boolean.
1805-
1799+ // Create IR to initialize the 'acquired' boolean.
1800+ //
1801+ if (!opts. IsOSR ())
1802+ {
18061803 GenTree* zero = gtNewZeroConNode (genActualType (typeMonAcquired));
18071804 GenTree* varNode = gtNewLclvNode (lvaMonAcquired, typeMonAcquired);
18081805 GenTree* initNode = gtNewAssignNode (varNode, zero);
@@ -1825,7 +1822,7 @@ void Compiler::fgAddSyncMethodEnterExit()
18251822 unsigned lvaCopyThis = 0 ;
18261823 if (!info.compIsStatic )
18271824 {
1828- lvaCopyThis = lvaGrabTemp (true DEBUGARG (" Synchronized method monitor acquired boolean " ));
1825+ lvaCopyThis = lvaGrabTemp (true DEBUGARG (" Synchronized method copy of this for handler " ));
18291826 lvaTable[lvaCopyThis].lvType = TYP_REF;
18301827
18311828 GenTree* thisNode = gtNewLclvNode (info.compThisArg , TYP_REF);
@@ -1835,7 +1832,12 @@ void Compiler::fgAddSyncMethodEnterExit()
18351832 fgNewStmtAtEnd (tryBegBB, initNode);
18361833 }
18371834
1838- fgCreateMonitorTree (lvaMonAcquired, info.compThisArg , tryBegBB, true /* enter*/ );
1835+ // For OSR, we do not need the enter tree as the monitor is acquired by the original method.
1836+ //
1837+ if (!opts.IsOSR ())
1838+ {
1839+ fgCreateMonitorTree (lvaMonAcquired, info.compThisArg , tryBegBB, true /* enter*/ );
1840+ }
18391841
18401842 // exceptional case
18411843 fgCreateMonitorTree (lvaMonAcquired, lvaCopyThis, faultBB, false /* exit*/ );
0 commit comments