Skip to content

Commit e1e5efd

Browse files
committed
Separate newobj opcode for string and mdarray
1 parent 0298d2e commit e1e5efd

File tree

3 files changed

+35
-33
lines changed

3 files changed

+35
-33
lines changed

src/coreclr/interpreter/compiler.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3062,7 +3062,7 @@ int InterpCompiler::GenerateCode(CORINFO_METHOD_INFO* methodInfo)
30623062
}
30633063
else
30643064
{
3065-
AddIns(INTOP_NEWOBJ);
3065+
AddIns(isStringOrArray ? INTOP_NEWOBJ_VAROBJSIZE : INTOP_NEWOBJ);
30663066
m_pLastNewIns->data[1] = GetDataItemIndex(ctorClass);
30673067
}
30683068

src/coreclr/interpreter/intops.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,7 @@ OPDEF(INTOP_CALL, "call", 4, 1, 1, InterpOpMethodHandle)
281281
OPDEF(INTOP_CALLVIRT, "callvirt", 4, 1, 1, InterpOpMethodHandle)
282282
OPDEF(INTOP_NEWOBJ, "newobj", 5, 1, 1, InterpOpMethodHandle)
283283
OPDEF(INTOP_NEWOBJ_VT, "newobj.vt", 5, 1, 1, InterpOpMethodHandle)
284+
OPDEF(INTOP_NEWOBJ_VAROBJSIZE, "newobj.varobjsize", 5, 1, 1, InterpOpMethodHandle)
284285

285286
OPDEF(INTOP_CALL_HELPER_PP, "call.helper.pp", 5, 1, 0, InterpOpThreeInts)
286287

src/coreclr/vm/interpexec.cpp

Lines changed: 33 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1187,40 +1187,15 @@ void InterpExecMethod(InterpreterFrame *pInterpreterFrame, InterpMethodContextFr
11871187
methodSlot = ip[3];
11881188

11891189
MethodTable *pClass = (MethodTable*)pMethod->pDataItems[ip[4]];
1190-
// FIXME: Duplicated code from CALL_INTERP_SLOT
1191-
size_t targetMethod = (size_t)pMethod->pDataItems[methodSlot];
1192-
MethodDesc *pMD = nullptr;
1193-
if (targetMethod & INTERP_METHOD_HANDLE_TAG)
1194-
{
1195-
pMD = (MethodDesc*)(targetMethod & ~INTERP_METHOD_HANDLE_TAG);
1196-
}
1190+
OBJECTREF objRef = AllocateObject(pClass);
11971191

1198-
// If we are constructing a type with a component size (i.e. a string) its constructor is a special
1199-
// fcall that is basically a static method that returns the new instance.
1200-
if (pMD && pClass->HasComponentSize())
1201-
{
1202-
// Get the address of the fcall that implements the ctor
1203-
PCODE code = pMD->TryGetMultiCallableAddrOfCode(CORINFO_ACCESS_ANY);
1204-
assert(code);
1205-
1206-
// callArgsOffset points to the ctor arguments, which are what the fcall expects.
1207-
// returnOffset points to where the new instance goes, and the fcall will write it there.
1208-
InvokeCompiledMethod(pMD, stack + callArgsOffset, stack + returnOffset, code);
1209-
ip += 5;
1210-
break;
1211-
}
1212-
else
1213-
{
1214-
OBJECTREF objRef = AllocateObject(pClass);
1215-
1216-
// This is return value
1217-
LOCAL_VAR(returnOffset, OBJECTREF) = objRef;
1218-
// Set `this` arg for ctor call
1219-
LOCAL_VAR(callArgsOffset, OBJECTREF) = objRef;
1220-
ip += 5;
1192+
// This is return value
1193+
LOCAL_VAR(returnOffset, OBJECTREF) = objRef;
1194+
// Set `this` arg for ctor call
1195+
LOCAL_VAR(callArgsOffset, OBJECTREF) = objRef;
1196+
ip += 5;
12211197

1222-
goto CALL_INTERP_SLOT;
1223-
}
1198+
goto CALL_INTERP_SLOT;
12241199
}
12251200
case INTOP_NEWOBJ_VT:
12261201
{
@@ -1239,6 +1214,32 @@ void InterpExecMethod(InterpreterFrame *pInterpreterFrame, InterpMethodContextFr
12391214
ip += 5;
12401215
goto CALL_INTERP_SLOT;
12411216
}
1217+
case INTOP_NEWOBJ_VAROBJSIZE:
1218+
{
1219+
returnOffset = ip[1];
1220+
callArgsOffset = ip[2];
1221+
methodSlot = ip[3];
1222+
1223+
// FIXME: Duplicated code from CALL_INTERP_SLOT
1224+
size_t targetMethod = (size_t)pMethod->pDataItems[methodSlot];
1225+
MethodDesc *pMD = nullptr;
1226+
if (targetMethod & INTERP_METHOD_HANDLE_TAG)
1227+
{
1228+
pMD = (MethodDesc*)(targetMethod & ~INTERP_METHOD_HANDLE_TAG);
1229+
}
1230+
1231+
// If we are constructing a type with a component size (i.e. a string) its constructor is a special
1232+
// fcall that is basically a static method that returns the new instance.
1233+
// Get the address of the fcall that implements the ctor
1234+
PCODE code = pMD->TryGetMultiCallableAddrOfCode(CORINFO_ACCESS_ANY);
1235+
assert(code);
1236+
1237+
// callArgsOffset points to the ctor arguments, which are what the fcall expects.
1238+
// returnOffset points to where the new instance goes, and the fcall will write it there.
1239+
InvokeCompiledMethod(pMD, stack + callArgsOffset, stack + returnOffset, code);
1240+
ip += 5;
1241+
break;
1242+
}
12421243
case INTOP_ZEROBLK_IMM:
12431244
memset(LOCAL_VAR(ip[1], void*), 0, ip[2]);
12441245
ip += 3;

0 commit comments

Comments
 (0)