Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JIT: Keep delegate object alive during invoke #105099

Closed
wants to merge 21 commits into from
Closed
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
4 changes: 4 additions & 0 deletions src/coreclr/jit/codegenarmarch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,10 @@ void CodeGen::genCodeForTreeNode(GenTree* treeNode)
GetEmitter()->emitDisableGC();
break;

case GT_STOP_NONGC:
GetEmitter()->emitEnableGC();
break;

case GT_START_PREEMPTGC:
// Kill callee saves GC registers, and create a label
// so that information gets propagated to the emitter.
Expand Down
4 changes: 4 additions & 0 deletions src/coreclr/jit/codegenloongarch64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4206,6 +4206,10 @@ void CodeGen::genCodeForTreeNode(GenTree* treeNode)
GetEmitter()->emitDisableGC();
break;

case GT_STOP_NONGC:
GetEmitter()->emitEnableGC();
break;

case GT_START_PREEMPTGC:
// Kill callee saves GC registers, and create a label
// so that information gets propagated to the emitter.
Expand Down
4 changes: 4 additions & 0 deletions src/coreclr/jit/codegenriscv64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4285,6 +4285,10 @@ void CodeGen::genCodeForTreeNode(GenTree* treeNode)
GetEmitter()->emitDisableGC();
break;

case GT_STOP_NONGC:
GetEmitter()->emitEnableGC();
break;

case GT_START_PREEMPTGC:
// Kill callee saves GC registers, and create a label
// so that information gets propagated to the emitter.
Expand Down
4 changes: 4 additions & 0 deletions src/coreclr/jit/codegenxarch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1873,6 +1873,10 @@ void CodeGen::genCodeForTreeNode(GenTree* treeNode)
case GT_START_NONGC:
GetEmitter()->emitDisableGC();
break;

case GT_STOP_NONGC:
GetEmitter()->emitEnableGC();
break;
#endif // !defined(JIT32_GCENCODER)

case GT_START_PREEMPTGC:
Expand Down
1 change: 1 addition & 0 deletions src/coreclr/jit/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -11732,6 +11732,7 @@ class GenTreeVisitor
case GT_SETCC:
case GT_NO_OP:
case GT_START_NONGC:
case GT_STOP_NONGC:
case GT_START_PREEMPTGC:
case GT_PROF_HOOK:
#if defined(FEATURE_EH_WINDOWS_X86)
Expand Down
1 change: 1 addition & 0 deletions src/coreclr/jit/compiler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4365,6 +4365,7 @@ void GenTree::VisitOperands(TVisitor visitor)
case GT_SETCC:
case GT_NO_OP:
case GT_START_NONGC:
case GT_STOP_NONGC:
case GT_START_PREEMPTGC:
case GT_PROF_HOOK:
#if defined(FEATURE_EH_WINDOWS_X86)
Expand Down
5 changes: 3 additions & 2 deletions src/coreclr/jit/error.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -268,9 +268,10 @@ extern "C" void __cdecl assertAbort(const char* why, const char* file, unsigned
{
phaseName = PhaseNames[env->compiler->mostRecentlyActivePhase];
_snprintf_s(buff, BUFF_SIZE, _TRUNCATE,
"Assertion failed '%s' in '%s' during '%s' (IL size %d; hash 0x%08x; %s)\n", why,
"Assertion failed '%s' in '%s' during '%s' (IL size %d; BBs: %d; hash 0x%08x; %s)\n", why,
env->compiler->info.compFullName, phaseName, env->compiler->info.compILCodeSize,
env->compiler->info.compMethodHash(), env->compiler->compGetTieringName(/* short name */ true));
env->compiler->fgBBcount, env->compiler->info.compMethodHash(),
env->compiler->compGetTieringName(/* short name */ true));
msg = buff;
}
printf(""); // null string means flush
Expand Down
3 changes: 3 additions & 0 deletions src/coreclr/jit/gentree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6651,6 +6651,7 @@ bool GenTree::TryGetUse(GenTree* operand, GenTree*** pUse)
case GT_SETCC:
case GT_NO_OP:
case GT_START_NONGC:
case GT_STOP_NONGC:
case GT_START_PREEMPTGC:
case GT_PROF_HOOK:
#if defined(FEATURE_EH_WINDOWS_X86)
Expand Down Expand Up @@ -10202,6 +10203,7 @@ GenTreeUseEdgeIterator::GenTreeUseEdgeIterator(GenTree* node)
case GT_SETCC:
case GT_NO_OP:
case GT_START_NONGC:
case GT_STOP_NONGC:
case GT_START_PREEMPTGC:
case GT_PROF_HOOK:
#if defined(FEATURE_EH_WINDOWS_X86)
Expand Down Expand Up @@ -12357,6 +12359,7 @@ void Compiler::gtDispLeaf(GenTree* tree, IndentStack* indentStack)
case GT_NOP:
case GT_NO_OP:
case GT_START_NONGC:
case GT_STOP_NONGC:
case GT_START_PREEMPTGC:
case GT_PROF_HOOK:
case GT_CATCH_ARG:
Expand Down
1 change: 1 addition & 0 deletions src/coreclr/jit/gtlist.h
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ GTNODE(SWITCH , GenTreeOp ,0,1,GTK_UNOP|GTK_NOVALUE)
GTNODE(NO_OP , GenTree ,0,0,GTK_LEAF|GTK_NOVALUE) // A NOP that cannot be deleted.

GTNODE(START_NONGC , GenTree ,0,0,GTK_LEAF|GTK_NOVALUE|DBK_NOTHIR) // Starts a new instruction group that will be non-gc interruptible.
GTNODE(STOP_NONGC , GenTree ,0,0,GTK_LEAF|GTK_NOVALUE|DBK_NOTHIR) // Tries to end the non-gc interruptible instruction group
GTNODE(START_PREEMPTGC , GenTree ,0,0,GTK_LEAF|GTK_NOVALUE|DBK_NOTHIR) // Starts a new instruction group where preemptive GC is enabled.
GTNODE(PROF_HOOK , GenTree ,0,0,GTK_LEAF|GTK_NOVALUE|DBK_NOTHIR) // Profiler Enter/Leave/TailCall hook.

Expand Down
1 change: 1 addition & 0 deletions src/coreclr/jit/liveness.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1438,6 +1438,7 @@ void Compiler::fgComputeLifeLIR(VARSET_TP& life, BasicBlock* block, VARSET_VALAR
case GT_SWITCH:
case GT_RETFILT:
case GT_START_NONGC:
case GT_STOP_NONGC:
case GT_START_PREEMPTGC:
case GT_PROF_HOOK:
#if defined(FEATURE_EH_WINDOWS_X86)
Expand Down
19 changes: 18 additions & 1 deletion src/coreclr/jit/lower.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -743,7 +743,6 @@ GenTree* Lowering::LowerArrLength(GenTreeArrCommon* node)
// Create the expression `*(array_addr + lenOffset)`

GenTree* addr;
noway_assert(arr->gtNext == node);

if ((arr->gtOper == GT_CNS_INT) && (arr->AsIntCon()->gtIconVal == 0))
{
Expand Down Expand Up @@ -5556,6 +5555,24 @@ GenTree* Lowering::LowerDelegateInvoke(GenTreeCall* call)
BlockRange().Remove(thisArgNode);
BlockRange().InsertBefore(call, newThisAddr, newThis, thisArgNode);

#if !defined(TARGET_XARCH)
if (comp->GetInterruptible())
{
// If the target's backend doesn't support indirect calls with immediate operands (contained)
// and the method is marked as interruptible, we need to insert a GT_START_NONGC before the call.
// to keep the delegate object alive while we're obtaining the function pointer.
GenTree* startNonGCNode = new (comp, GT_START_NONGC) GenTree(GT_START_NONGC, TYP_VOID);
GenTree* stopNonGCNode = new (comp, GT_STOP_NONGC) GenTree(GT_STOP_NONGC, TYP_VOID);
BlockRange().InsertAfter(base, startNonGCNode);
/*if (!call->IsTailCall())
{
// We don't have to insert the STOP_NONGC node for tail calls, as the call itself is
// a safe point and effectively the last node.
BlockRange().InsertAfter(call, stopNonGCNode);
}*/
}
#endif

ContainCheckIndir(newThis->AsIndir());

// the control target is
Expand Down
1 change: 1 addition & 0 deletions src/coreclr/jit/lsraarm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,7 @@ int LinearScan::BuildNode(GenTree* tree)

case GT_NO_OP:
case GT_START_NONGC:
case GT_STOP_NONGC:
case GT_PROF_HOOK:
srcCount = 0;
assert(dstCount == 0);
Expand Down
1 change: 1 addition & 0 deletions src/coreclr/jit/lsraarm64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,7 @@ int LinearScan::BuildNode(GenTree* tree)

case GT_NO_OP:
case GT_START_NONGC:
case GT_STOP_NONGC:
srcCount = 0;
assert(dstCount == 0);
break;
Expand Down
1 change: 1 addition & 0 deletions src/coreclr/jit/lsraloongarch64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ int LinearScan::BuildNode(GenTree* tree)

case GT_NO_OP:
case GT_START_NONGC:
case GT_STOP_NONGC:
srcCount = 0;
assert(dstCount == 0);
break;
Expand Down
1 change: 1 addition & 0 deletions src/coreclr/jit/lsrariscv64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ int LinearScan::BuildNode(GenTree* tree)

case GT_NO_OP:
case GT_START_NONGC:
case GT_STOP_NONGC:
srcCount = 0;
assert(dstCount == 0);
break;
Expand Down
1 change: 1 addition & 0 deletions src/coreclr/jit/lsraxarch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ int LinearScan::BuildNode(GenTree* tree)

case GT_NO_OP:
case GT_START_NONGC:
case GT_STOP_NONGC:
srcCount = 0;
assert(dstCount == 0);
break;
Expand Down
Loading