Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
8d9b3ef
NativeAOT: Implement a fake EH filter for generic exceptions
EgorBo Jul 23, 2022
7d4bcbd
Add smoke test
EgorBo Jul 23, 2022
39752c7
Update GenericExceptions.cs
EgorBo Jul 23, 2022
3a045da
CI test
EgorBo Jul 23, 2022
fd57c28
Merge branch 'nativeaot-eh-generic-exception' of github.com:EgorBo/ru…
EgorBo Jul 23, 2022
f24208a
Address feedback & fix AVE
EgorBo Jul 23, 2022
f7c55a7
Clean up
EgorBo Jul 23, 2022
861c6c3
Fix runtime lookup for NativeAOT & Crossgen
EgorBo Jul 23, 2022
8a72927
Another attempt to fix runtime lookup (now should be working)
EgorBo Jul 23, 2022
58d3b77
Remove tests from issues.targets
EgorBo Jul 24, 2022
54763a7
Move fgCreateFiltersForGenericExceptions to fgAddInternal
EgorBo Jul 24, 2022
a32b92a
simplify runtime lookup
EgorBo Jul 24, 2022
3668e25
Address feedback
EgorBo Jul 24, 2022
49635eb
Implement HELPER_SimpleIsInstanceOf
EgorBo Jul 25, 2022
f8a50a5
Merge branch 'main' of github.com:dotnet/runtime into nativeaot-eh-ge…
EgorBo Jul 25, 2022
2a47ff9
Clean up
EgorBo Jul 25, 2022
bee1fb3
Add Jan's IL test
EgorBo Jul 25, 2022
10ca969
Address feedback (NativeAOT's part is not finished yet)
EgorBo Jul 25, 2022
79e87b8
remove dead code
EgorBo Jul 25, 2022
5420035
Update src/tests/JIT/Generics/Exceptions/GenericCatchInterfaceProgram.cs
EgorBo Jul 25, 2022
9cf10d2
Fix test
EgorBo Jul 25, 2022
fd3130e
NativeAOT fix
EgorBo Jul 25, 2022
22f2520
remove "variance" block
EgorBo Jul 25, 2022
9110e5f
Address feedback
EgorBo Jul 25, 2022
d3c01cb
Remove IsPolyType
EgorBo Jul 25, 2022
aaa075e
rename csproj to ilproj
EgorBo Jul 25, 2022
98ce006
Update src/coreclr/tools/aot/ILCompiler.Compiler/IL/ILImporter.Scanne…
EgorBo Jul 26, 2022
5c7c157
Disable test on mono
EgorBo Jul 26, 2022
40ca568
Merge branch 'main' of github.com:dotnet/runtime into nativeaot-eh-ge…
EgorBo Jul 26, 2022
d13147d
Update src/coreclr/jit/jiteh.cpp
EgorBo Jul 28, 2022
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
Prev Previous commit
Next Next commit
Address feedback & fix AVE
  • Loading branch information
EgorBo committed Jul 23, 2022
commit f24208a47ab86d87d5cac9e4854432cfd3395c42
3 changes: 2 additions & 1 deletion src/coreclr/jit/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -2217,7 +2217,8 @@ class Compiler
bool fgNormalizeEHCase1();
bool fgNormalizeEHCase2();
bool fgNormalizeEHCase3();
bool fgNormalizeEHCase_NativeAot();

bool fgCreateFiltersForGenericExceptions();

void fgCheckForLoopsInHandlers();

Expand Down
23 changes: 10 additions & 13 deletions src/coreclr/jit/jiteh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2127,8 +2127,7 @@ void Compiler::fgNormalizeEH()

#endif // 0

// For NativeAOT we need to create a fake exception filter for generic handlers
if (/*IsTargetAbi(CORINFO_NATIVEAOT_ABI) &&*/ fgNormalizeEHCase_NativeAot())
if (fgCreateFiltersForGenericExceptions())
{
modified = true;
}
Expand Down Expand Up @@ -2513,7 +2512,7 @@ bool Compiler::fgNormalizeEHCase2()
}

//------------------------------------------------------------------------
// fgNormalizeEHCase_NativeAot:
// fgCreateFiltersForGenericExceptions:
// For Exception types which require runtime lookup it creates a "fake" single-block
// EH filter that performs "catchArg isinst T!!" and in case of success forwards to the
// original EH handler.
Expand All @@ -2522,11 +2521,8 @@ bool Compiler::fgNormalizeEHCase2()
// true if basic block layout was changed
//

bool Compiler::fgNormalizeEHCase_NativeAot()
bool Compiler::fgCreateFiltersForGenericExceptions()
{
// CI test, let's run the logic for JIT
//assert(IsTargetAbi(CORINFO_NATIVEAOT_ABI));

bool modified = false;
for (unsigned XTnum = 0; XTnum < compHndBBtabCount; XTnum++)
{
Expand All @@ -2540,9 +2536,9 @@ bool Compiler::fgNormalizeEHCase_NativeAot()
resolvedToken.tokenType = CORINFO_TOKENKIND_Casting;
info.compCompHnd->resolveToken(&resolvedToken);

bool runtimeLookupNeeded = false;
GenTree* runtimeLookup = impTokenToHandle(&resolvedToken, &runtimeLookupNeeded, false);
if (!runtimeLookupNeeded)
CORINFO_GENERICHANDLE_RESULT embedInfo;
info.compCompHnd->embedGenericHandle(&resolvedToken, true, &embedInfo);
if (!embedInfo.lookup.lookupKind.needsRuntimeLookup)
{
// Exception type does not need runtime lookup
continue;
Expand Down Expand Up @@ -2570,9 +2566,10 @@ bool Compiler::fgNormalizeEHCase_NativeAot()
fgInsertStmtAtBeg(filterBb, gtNewStmt(argAsg));

// Create "catchArg is TException" tree
GenTree* isInstOfT = gtNewHelperCallNode(CORINFO_HELP_ISINSTANCEOFANY, TYP_REF, runtimeLookup, arg);
GenTree* cmp = gtNewOperNode(GT_NE, TYP_INT, isInstOfT, gtNewNull());
GenTree* retFilt = gtNewOperNode(GT_RETFILT, TYP_INT, cmp);
GenTree* runtimeLookup = getTokenHandleTree(&resolvedToken, true);
GenTree* isInstOfT = gtNewHelperCallNode(CORINFO_HELP_ISINSTANCEOFANY, TYP_REF, runtimeLookup, arg);
GenTree* cmp = gtNewOperNode(GT_NE, TYP_INT, isInstOfT, gtNewNull());
GenTree* retFilt = gtNewOperNode(GT_RETFILT, TYP_INT, cmp);

// Insert it right before the handler (and make it a pred of the handler)
fgInsertBBbefore(handlerBb, filterBb);
Expand Down
18 changes: 0 additions & 18 deletions src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -737,24 +737,6 @@ private bool Get_CORINFO_METHOD_INFO(MethodDesc method, MethodIL methodIL, CORIN
Get_CORINFO_SIG_INFO(method, sig: &methodInfo->args, methodIL);
Get_CORINFO_SIG_INFO(methodIL.GetLocals(), &methodInfo->locals);

#if READYTORUN
if ((methodInfo->options & CorInfoOptions.CORINFO_GENERICS_CTXT_MASK) != 0)
{
foreach (var region in exceptionRegions)
{
if (region.Kind == ILExceptionRegionKind.Catch)
{
TypeDesc catchType = (TypeDesc)methodIL.GetObject(region.ClassToken);
if (catchType.IsCanonicalSubtype(CanonicalFormKind.Any))
{
methodInfo->options |= CorInfoOptions.CORINFO_GENERICS_CTXT_KEEP_ALIVE;
break;
}
}
}
}
#endif

return true;
}

Expand Down
61 changes: 0 additions & 61 deletions src/coreclr/vm/codeman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3476,36 +3476,6 @@ TypeHandle EEJitManager::ResolveEHClause(EE_ILEXCEPTION_CLAUSE* pEHClause,
PREFIX_ASSUME(pModule != NULL);

SigTypeContext typeContext(pMD);
VarKind k = hasNoVars;

// In the vast majority of cases the code under the "if" below
// will not be executed.
//
// First grab the representative instantiations. For code
// shared by multiple generic instantiations these are the
// canonical (representative) instantiation.
if (TypeFromToken(typeTok) == mdtTypeSpec)
{
PCCOR_SIGNATURE pSig;
ULONG cSig;
IfFailThrow(pModule->GetMDImport()->GetTypeSpecFromToken(typeTok, &pSig, &cSig));

SigPointer psig(pSig, cSig);
k = psig.IsPolyType(&typeContext);

// Grab the active class and method instantiation. This exact instantiation is only
// needed in the corner case of "generic" exception catching in shared
// generic code. We don't need the exact instantiation if the token
// doesn't contain E_T_VAR or E_T_MVAR.
if ((k & hasSharableVarsMask) != 0)
{
Instantiation classInst;
Instantiation methodInst;
pCf->GetExactGenericInstantiations(&classInst, &methodInst);
SigTypeContext::InitTypeContext(pMD,classInst, methodInst,&typeContext);
}
}

return ClassLoader::LoadTypeDefOrRefOrSpecThrowing(pModule, typeTok, &typeContext,
ClassLoader::ReturnNullIfNotFound);
}
Expand Down Expand Up @@ -6001,38 +5971,7 @@ TypeHandle ReadyToRunJitManager::ResolveEHClause(EE_ILEXCEPTION_CLAUSE* pEHClaus
PREFIX_ASSUME(pModule != NULL);

SigTypeContext typeContext(pMD);
VarKind k = hasNoVars;

mdToken typeTok = pEHClause->ClassToken;

// In the vast majority of cases the code un der the "if" below
// will not be executed.
//
// First grab the representative instantiations. For code
// shared by multiple generic instantiations these are the
// canonical (representative) instantiation.
if (TypeFromToken(typeTok) == mdtTypeSpec)
{
PCCOR_SIGNATURE pSig;
ULONG cSig;
IfFailThrow(pModule->GetMDImport()->GetTypeSpecFromToken(typeTok, &pSig, &cSig));

SigPointer psig(pSig, cSig);
k = psig.IsPolyType(&typeContext);

// Grab the active class and method instantiation. This exact instantiation is only
// needed in the corner case of "generic" exception catching in shared
// generic code. We don't need the exact instantiation if the token
// doesn't contain E_T_VAR or E_T_MVAR.
if ((k & hasSharableVarsMask) != 0)
{
Instantiation classInst;
Instantiation methodInst;
pCf->GetExactGenericInstantiations(&classInst,&methodInst);
SigTypeContext::InitTypeContext(pMD,classInst, methodInst,&typeContext);
}
}

return ClassLoader::LoadTypeDefOrRefOrSpecThrowing(pModule, typeTok, &typeContext,
ClassLoader::ReturnNullIfNotFound);
}
Expand Down
42 changes: 0 additions & 42 deletions src/coreclr/vm/jitinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7514,49 +7514,7 @@ getMethodInfoHelper(
{
methInfo->options = CorInfoOptions(methInfo->options|CORINFO_GENERICS_CTXT_KEEP_ALIVE);
}
else
#endif // defined(PROFILING_SUPPORTED)
{
// Check all the exception clauses

if (ftn->IsDynamicMethod())
{
// @TODO: how do we detect the need to mark this flag?
}
else
{
COR_ILMETHOD_SECT_EH_CLAUSE_FAT ehClause;

for (unsigned i = 0; i < methInfo->EHcount; i++)
{
const COR_ILMETHOD_SECT_EH_CLAUSE_FAT* ehInfo =
(COR_ILMETHOD_SECT_EH_CLAUSE_FAT*)header->EH->EHClause(i, &ehClause);

// Is it a typed catch clause?
if (ehInfo->GetFlags() != COR_ILEXCEPTION_CLAUSE_NONE)
continue;

// Check if we catch "C<T>" ?

DWORD catchTypeToken = ehInfo->GetClassToken();
if (TypeFromToken(catchTypeToken) != mdtTypeSpec)
continue;

PCCOR_SIGNATURE pSig;
ULONG cSig;
IfFailThrow(ftn->GetMDImport()->GetTypeSpecFromToken(catchTypeToken, &pSig, &cSig));

SigPointer psig(pSig, cSig);

SigTypeContext sigTypeContext(ftn);
if (psig.IsPolyType(&sigTypeContext) & hasSharableVarsMask)
{
methInfo->options = CorInfoOptions(methInfo->options|CORINFO_GENERICS_CTXT_KEEP_ALIVE);
break;
}
}
}
}
}

PCCOR_SIGNATURE pSig = NULL;
Expand Down