Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/coreclr/interpreter/compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1418,6 +1418,10 @@ void InterpCompiler::EmitBranch(InterpOpcode opcode, int32_t ilOffset)
if (target < 0 || target >= m_ILCodeSize)
assert(0);

// Backwards branch, emit safepoint
if (ilOffset < 0)
AddIns(INTOP_SAFEPOINT);

InterpBasicBlock *pTargetBB = m_ppOffsetToBB[target];
assert(pTargetBB != NULL);

Expand Down Expand Up @@ -2113,6 +2117,10 @@ int InterpCompiler::GenerateCode(CORINFO_METHOD_INFO* methodInfo)

codeEnd = m_ip + m_ILCodeSize;

// Safepoint at each method entry. This could be done as part of a call, rather than
// adding an opcode.
AddIns(INTOP_SAFEPOINT);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any reason to not to do it as part of the call that made you add the instruction instead?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a very serious reason. Felt cleaner to have a separate instruction for now, given calls in general are an area that will keep suffering modifications in the future.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regular CoreCLR JIT expects the safe point to be at the callsite, not in the method entry.

This mismatch between the regular CoreCLR JIT suspension model and interpreter suspension model can lead to GC starvation (GC suspension taking a long time in corner cases). It may be better to inserts the safe point after the call to avoid these subtle issues.


linkBBlocks = true;
needsRetryEmit = false;
retry_emit:
Expand Down
1 change: 1 addition & 0 deletions src/coreclr/interpreter/intops.def
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ OPDEF(INTOP_LDLOCA, "ldloca", 3, 1, 0, InterpOpInt)

OPDEF(INTOP_SWITCH, "switch", 0, 0, 1, InterpOpSwitch)

OPDEF(INTOP_SAFEPOINT, "safepoint", 1, 0, 0, InterpOpNoArgs)
OPDEF(INTOP_BR, "br", 2, 0, 0, InterpOpBranch)

OPDEF(INTOP_BRFALSE_I4, "brfalse.i4", 3, 0, 1, InterpOpBranch)
Expand Down
13 changes: 13 additions & 0 deletions src/coreclr/vm/interpexec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ static void InterpBreakpoint()

void InterpExecMethod(InterpreterFrame *pInterpreterFrame, InterpMethodContextFrame *pFrame, InterpThreadContext *pThreadContext)
{
CONTRACTL
{
GC_TRIGGERS;
MODE_COOPERATIVE;
}
CONTRACTL_END;

#if defined(HOST_AMD64) && defined(HOST_WINDOWS)
pInterpreterFrame->SetInterpExecMethodSSP((TADDR)_rdsspq());
#endif // HOST_AMD64 && HOST_WINDOWS
Expand Down Expand Up @@ -292,6 +299,12 @@ void InterpExecMethod(InterpreterFrame *pInterpreterFrame, InterpMethodContextFr
break;
}

case INTOP_SAFEPOINT:
if (g_TrapReturningThreads)
JIT_PollGC();
ip++;
break;

case INTOP_BR:
ip += ip[1];
break;
Expand Down