Skip to content

Commit 468c24a

Browse files
committed
Add a temporary intrinsic for Environment.FailFast
Because we currently don't have support for interoping between interpreter and jit, in order to signal test failure in interpreter test we will just crash instead.
1 parent 71997ec commit 468c24a

File tree

5 files changed

+55
-0
lines changed

5 files changed

+55
-0
lines changed

src/coreclr/interpreter/compiler.cpp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1352,6 +1352,31 @@ int32_t InterpCompiler::GetMethodDataItemIndex(CORINFO_METHOD_HANDLE mHandle)
13521352
return GetDataItemIndex((void*)data);
13531353
}
13541354

1355+
bool InterpCompiler::EmitCallIntrinsics(CORINFO_METHOD_HANDLE method, CORINFO_SIG_INFO sig)
1356+
{
1357+
const char *className = NULL;
1358+
const char *namespaceName = NULL;
1359+
const char *methodName = m_compHnd->getMethodNameFromMetadata(method, &className, &namespaceName, NULL, 0);
1360+
int32_t opcode = -1;
1361+
1362+
if (namespaceName && !strcmp(namespaceName, "System"))
1363+
{
1364+
if (className && !strcmp(className, "Environment"))
1365+
{
1366+
if (methodName && !strcmp(methodName, "FailFast"))
1367+
opcode = INTOP_FAILFAST; // to be removed, not really an intrisic
1368+
}
1369+
}
1370+
1371+
if (opcode != -1)
1372+
{
1373+
AddIns(opcode);
1374+
return true;
1375+
}
1376+
1377+
return false;
1378+
}
1379+
13551380
void InterpCompiler::EmitCall(CORINFO_CLASS_HANDLE constrainedClass, bool readonly, bool tailcall)
13561381
{
13571382
uint32_t token = getU4LittleEndian(m_ip + 1);
@@ -1368,6 +1393,12 @@ void InterpCompiler::EmitCall(CORINFO_CLASS_HANDLE constrainedClass, bool readon
13681393
CORINFO_SIG_INFO targetSignature;
13691394
m_compHnd->getMethodSig(targetMethod, &targetSignature);
13701395

1396+
if (EmitCallIntrinsics(targetMethod, targetSignature))
1397+
{
1398+
m_ip += 5;
1399+
return;
1400+
}
1401+
13711402
// Process sVars
13721403
int numArgs = targetSignature.numArgs + targetSignature.hasThis();
13731404
m_pStackPointer -= numArgs;
@@ -1598,6 +1629,12 @@ int InterpCompiler::GenerateCode(CORINFO_METHOD_INFO* methodInfo)
15981629
m_pLastIns->SetDVar(m_pStackPointer[-1].var);
15991630
m_ip += 2;
16001631
break;
1632+
case CEE_LDNULL:
1633+
AddIns(INTOP_LDNULL);
1634+
PushStackType(StackTypeO, NULL);
1635+
m_pLastIns->SetDVar(m_pStackPointer[-1].var);
1636+
m_ip++;
1637+
break;
16011638

16021639
case CEE_LDARG_S:
16031640
EmitLoadVar(m_ip[1]);

src/coreclr/interpreter/compiler.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,7 @@ class InterpCompiler
308308
void EmitShiftOp(int32_t opBase);
309309
void EmitCompareOp(int32_t opBase);
310310
void EmitCall(CORINFO_CLASS_HANDLE constrainedClass, bool readonly, bool tailcall);
311+
bool EmitCallIntrinsics(CORINFO_METHOD_HANDLE method, CORINFO_SIG_INFO sig);
311312

312313
// Var Offset allocator
313314
TArray<InterpInst*> *m_pActiveCalls;

src/coreclr/interpreter/intops.def

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ OPDEF(INTOP_RET, "ret", 2, 0, 1, InterpOpNoArgs)
1111
OPDEF(INTOP_RET_VOID, "ret.void", 1, 0, 0, InterpOpNoArgs)
1212

1313
OPDEF(INTOP_LDC_I4, "ldc.i4", 3, 1, 0, InterpOpInt)
14+
OPDEF(INTOP_LDC_I4_0, "ldc.i4.0", 2, 1, 0, InterpOpNoArgs)
15+
OPDEF(INTOP_LDC_I8_0, "ldc.i8.0", 2, 1, 0, InterpOpNoArgs)
1416

1517
OPDEF(INTOP_MOV_I4_I1, "mov.i4.i1", 3, 1, 1, InterpOpNoArgs)
1618
OPDEF(INTOP_MOV_I4_U1, "mov.i4.u1", 3, 1, 1, InterpOpNoArgs)
@@ -190,3 +192,5 @@ OPDEF(INTOP_CLT_UN_R8, "clt.un.r8", 4, 1, 2, InterpOpNoArgs)
190192

191193
// Calls
192194
OPDEF(INTOP_CALL, "call", 4, 1, 1, InterpOpMethodToken)
195+
196+
OPDEF(INTOP_FAILFAST, "failfast", 1, 0, 0, InterpOpNoArgs)

src/coreclr/interpreter/intops.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,10 @@ int CEEOpcodeSize(const uint8_t *ip, const uint8_t *codeEnd);
3838

3939
#ifdef TARGET_64BIT
4040
#define INTOP_MOV_P INTOP_MOV_8
41+
#define INTOP_LDNULL INTOP_LDC_I8_0
4142
#else
4243
#define INTOP_MOV_P INTOP_MOV_4
44+
#define INTOP_LDNULL INTOP_LDC_I4_0
4345
#endif
4446

4547
static inline bool InterpOpIsUncondBranch(int32_t opcode)

src/coreclr/vm/interpexec.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,14 @@ void InterpExecMethod(InterpMethodContextFrame *pFrame, InterpThreadContext *pTh
5252
LOCAL_VAR(ip[1], int32_t) = ip[2];
5353
ip += 3;
5454
break;
55+
case INTOP_LDC_I4_0:
56+
LOCAL_VAR(ip[1], int32_t) = 0;
57+
ip += 2;
58+
break;
59+
case INTOP_LDC_I8_0:
60+
LOCAL_VAR(ip[1], int64_t) = 0;
61+
ip += 2;
62+
break;
5563
case INTOP_RET:
5664
// Return stack slot sized value
5765
*(int64_t*)pFrame->pRetVal = LOCAL_VAR(ip[1], int64_t);
@@ -726,6 +734,9 @@ void InterpExecMethod(InterpMethodContextFrame *pFrame, InterpThreadContext *pTh
726734
pThreadContext->pStackPointer = stack + pMethod->allocaSize;
727735
break;
728736
}
737+
case INTOP_FAILFAST:
738+
assert(0);
739+
break;
729740
default:
730741
assert(0);
731742
break;

0 commit comments

Comments
 (0)