Skip to content

Commit dbd7587

Browse files
committed
More cleanup
1 parent a5c9613 commit dbd7587

File tree

6 files changed

+42
-77
lines changed

6 files changed

+42
-77
lines changed

src/coreclr/vm/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,6 @@ set(VM_SOURCES_WKS
307307
cachelinealloc.cpp
308308
callconvbuilder.cpp
309309
callhelpers.cpp
310-
callsiteinspect.cpp
311310
callstubgenerator.cpp
312311
clrconfignative.cpp
313312
clrex.cpp
@@ -589,6 +588,7 @@ if(CLR_CMAKE_TARGET_WIN32)
589588

590589
# COM interop scenarios
591590
list(APPEND VM_SOURCES_WKS
591+
callsiteinspect.cpp
592592
classcompat.cpp
593593
comcache.cpp
594594
comcallablewrapper.cpp

src/coreclr/vm/callsiteinspect.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -194,11 +194,9 @@ namespace
194194

195195
_ASSERTE((*src) != NULL || Nullable::IsNullableType(ty));
196196
#ifdef TARGET_UNIX
197-
// Unboxing on non-Windows ABIs must be special cased
198-
COMPlusThrowHR(COR_E_NOTSUPPORTED);
199-
#else
200-
ty.GetMethodTable()->UnBoxIntoUnchecked(pvDest, (*src));
197+
#error Non-Windows ABIs must be special cased
201198
#endif
199+
ty.GetMethodTable()->UnBoxIntoUnchecked(pvDest, (*src));
202200

203201
// return the object so it can be stored in the frame and
204202
// propagated to the root set

src/coreclr/vm/frames.cpp

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1724,22 +1724,32 @@ void CLRToCOMMethodFrame::GcScanRoots_Impl(promote_func* fn, ScanContext* sc)
17241724
FramedMethodFrame::GcScanRoots_Impl(fn, sc);
17251725
PromoteCallerStack(fn, sc);
17261726

1727-
1727+
//
17281728
// Promote the returned object
1729-
MethodDesc* methodDesc = GetFunction();
1730-
ReturnKind returnKind = methodDesc->GetReturnKind();
1731-
if (returnKind == RT_Object)
1729+
//
1730+
1731+
MetaSig sig(GetFunction());
1732+
1733+
TypeHandle thValueType;
1734+
CorElementType et = sig.GetReturnTypeNormalized(&thValueType);
1735+
if (CorTypeInfo::IsObjRef(et))
17321736
{
17331737
(*fn)(GetReturnObjectPtr(), sc, CHECK_APP_DOMAIN);
17341738
}
1735-
else if (returnKind == RT_ByRef)
1739+
else if (CorTypeInfo::IsByRef(et))
17361740
{
17371741
PromoteCarefully(fn, GetReturnObjectPtr(), sc, GC_CALL_INTERIOR | CHECK_APP_DOMAIN);
17381742
}
1739-
else
1743+
else if (et == ELEMENT_TYPE_VALUETYPE)
17401744
{
1741-
_ASSERTE_MSG(!IsStructReturnKind(returnKind), "NYI: We can't promote multiregs struct returns");
1742-
_ASSERTE_MSG(IsScalarReturnKind(returnKind), "Non-scalar types must be promoted.");
1745+
ArgIterator argit(&sig);
1746+
if (!argit.HasRetBuffArg())
1747+
{
1748+
#ifdef TARGET_UNIX
1749+
#error Non-Windows ABIs must be special cased
1750+
#endif
1751+
ReportPointersFromValueType(fn, sc, thValueType.AsMethodTable(), GetReturnObjectPtr());
1752+
}
17431753
}
17441754
}
17451755
#endif // FEATURE_COMINTEROP

src/coreclr/vm/gccover.cpp

Lines changed: 3 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -438,44 +438,16 @@ static MethodDesc* getTargetMethodDesc(PCODE target)
438438

439439
void ReplaceInstrAfterCall(PBYTE instrToReplace, MethodDesc* callMD)
440440
{
441-
ReturnKind returnKind = callMD->GetReturnKind(true);
441+
ReturnKind returnKind = callMD->GetReturnKind();
442442
if (!IsValidReturnKind(returnKind))
443443
{
444444
// SKip GC coverage after the call.
445445
return;
446446
}
447-
_ASSERTE(IsValidReturnKind(returnKind));
448447

449-
bool ispointerKind = IsPointerReturnKind(returnKind);
450-
if (ispointerKind)
448+
if (IsPointerReturnKind(returnKind))
451449
{
452-
bool protectRegister[2] = { false, false };
453-
454-
bool moreRegisters = false;
455-
456-
ReturnKind fieldKind1 = ExtractRegReturnKind(returnKind, 0, moreRegisters);
457-
if (IsPointerFieldReturnKind(fieldKind1))
458-
{
459-
protectRegister[0] = true;
460-
}
461-
if (moreRegisters)
462-
{
463-
ReturnKind fieldKind2 = ExtractRegReturnKind(returnKind, 1, moreRegisters);
464-
if (IsPointerFieldReturnKind(fieldKind2))
465-
{
466-
protectRegister[1] = true;
467-
}
468-
}
469-
_ASSERTE(!moreRegisters);
470-
471-
if (protectRegister[0] && !protectRegister[1])
472-
{
473-
*instrToReplace = INTERRUPT_INSTR_PROTECT_FIRST_RET;
474-
}
475-
else
476-
{
477-
_ASSERTE(!"Not expected multi reg return with pointers.");
478-
}
450+
*instrToReplace = INTERRUPT_INSTR_PROTECT_FIRST_RET;
479451
}
480452
else
481453
{

src/coreclr/vm/method.cpp

Lines changed: 12 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1234,9 +1234,9 @@ COR_ILMETHOD* MethodDesc::GetILHeader()
12341234
#endif // !DACCESS_COMPILE
12351235
}
12361236

1237-
#if defined(TARGET_X86) || defined(FEATURE_COMINTEROP)
1237+
#if defined(TARGET_X86) && defined(HAVE_GCCOVER)
12381238
//*******************************************************************************
1239-
ReturnKind MethodDesc::GetReturnKind(INDEBUG(bool supportStringConstructors))
1239+
ReturnKind MethodDesc::GetReturnKind()
12401240
{
12411241
CONTRACTL
12421242
{
@@ -1263,15 +1263,13 @@ ReturnKind MethodDesc::GetReturnKind(INDEBUG(bool supportStringConstructors))
12631263

12641264
switch (et)
12651265
{
1266-
#ifdef TARGET_X86
12671266
case ELEMENT_TYPE_R4:
12681267
case ELEMENT_TYPE_R8:
12691268
// Figuring out whether the function returns FP or not is hard to do
12701269
// on-the-fly, so we use a different callback helper on x86 where this
12711270
// piece of information is needed in order to perform the right save &
12721271
// restore of the return value around the call to OnHijackScalarWorker.
12731272
return RT_Float;
1274-
#endif
12751273

12761274
case ELEMENT_TYPE_STRING:
12771275
case ELEMENT_TYPE_CLASS:
@@ -1281,7 +1279,6 @@ ReturnKind MethodDesc::GetReturnKind(INDEBUG(bool supportStringConstructors))
12811279
case ELEMENT_TYPE_VAR:
12821280
return RT_Object;
12831281

1284-
#ifdef ENREGISTERED_RETURNTYPE_INTEGER_MAXSIZE
12851282
case ELEMENT_TYPE_VALUETYPE:
12861283
// We return value types in registers if they fit in ENREGISTERED_RETURNTYPE_MAXSIZE
12871284
// These valuetypes could contain gc refs.
@@ -1294,40 +1291,29 @@ ReturnKind MethodDesc::GetReturnKind(INDEBUG(bool supportStringConstructors))
12941291
if (!thValueType.IsTypeDesc())
12951292
{
12961293
MethodTable * pReturnTypeMT = thValueType.AsMethodTable();
1294+
if (pReturnTypeMT->ContainsGCPointers())
1295+
{
1296+
_ASSERTE(pReturnTypeMT->GetNumInstanceFieldBytes() == sizeof(void*));
1297+
return RT_Object;
1298+
}
12971299

1298-
if (pReturnTypeMT->ContainsGCPointers() || pReturnTypeMT->IsByRefLike())
1300+
if (pReturnTypeMT->IsByRefLike())
12991301
{
1300-
if (pReturnTypeMT->GetNumInstanceFields() == 1)
1301-
{
1302-
_ASSERTE(pReturnTypeMT->GetNumInstanceFieldBytes() == sizeof(void*));
1303-
// Note: we can't distinguish RT_Object from RT_ByRef, the caller has to tolerate that.
1304-
return RT_Object;
1305-
}
1306-
else
1307-
{
1308-
// Multi reg return case with pointers, can't restore the actual kind.
1309-
return RT_Illegal;
1310-
}
1302+
// This would require going through all fields
1303+
return RT_Illegal;
13111304
}
13121305
}
13131306
}
13141307
}
13151308
break;
1316-
#endif // ENREGISTERED_RETURNTYPE_INTEGER_MAXSIZE
13171309

1318-
#ifdef _DEBUG
13191310
case ELEMENT_TYPE_VOID:
1320-
// String constructors return objects. We should not have any ecall string
1321-
// constructors, except when called from gc coverage codes (which is only
1322-
// done under debug). We will therefore optimize the retail version of this
1323-
// method to not support string constructors.
1311+
// String constructors return objects..
13241312
if (IsCtor() && GetMethodTable()->HasComponentSize())
13251313
{
1326-
_ASSERTE(supportStringConstructors);
13271314
return RT_Object;
13281315
}
13291316
break;
1330-
#endif // _DEBUG
13311317

13321318
case ELEMENT_TYPE_BYREF:
13331319
return RT_ByRef;
@@ -1338,7 +1324,7 @@ ReturnKind MethodDesc::GetReturnKind(INDEBUG(bool supportStringConstructors))
13381324

13391325
return RT_Scalar;
13401326
}
1341-
#endif // TARGET_X86 || FEATURE_COMINTEROP
1327+
#endif // TARGET_X86 && HAVE_GCCOVER
13421328

13431329
#ifdef FEATURE_COMINTEROP
13441330

src/coreclr/vm/method.hpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1688,14 +1688,13 @@ class MethodDesc
16881688
// corresponding instantiation of the target of a call.
16891689
MethodDesc *ResolveGenericVirtualMethod(OBJECTREF *orThis);
16901690

1691-
#if defined(TARGET_X86) || defined(FEATURE_COMINTEROP)
1691+
#if defined(TARGET_X86) && defined(HAVE_GCCOVER)
16921692
public:
1693-
// This method is used to restore ReturnKind using the class handle.
1694-
// It does not support multi-reg return case with pointers. Use this method only when you can't hit
1695-
// this case (like CLRToCOMMethodFrame::GcScanRoots) or when you can tolerate RT_Illegal return.
1696-
// Also, for a single field struct return case the function can't distinguish RT_Object and RT_ByRef.
1697-
ReturnKind GetReturnKind(INDEBUG(bool supportStringConstructors = false));
1698-
#endif // TARGET_X86 || FEATURE_COMINTEROP
1693+
// This method is used to restore ReturnKind using the class handle. It will return
1694+
// RT_Illegal for rare cases like byref-like types. Use this method only when you can tolerate
1695+
// RT_Illegal return.
1696+
ReturnKind GetReturnKind();
1697+
#endif // TARGET_X86 && HAVE_GCCOVER
16991698

17001699
public:
17011700
// In general you don't want to call GetCallTarget - you want to

0 commit comments

Comments
 (0)