From e92fb114f4abe0a187732eff5083c521f5e7447e Mon Sep 17 00:00:00 2001 From: John Chen Date: Wed, 1 Jun 2016 18:36:23 -0700 Subject: [PATCH] Add limit to number of generics methods to compile by CrossGen (dotnet/coreclr#5383) Recursive generic definitions can easily make CrossGen take very long time to complete. This is the cause of a failure in issue dotnet/coreclr#5366. This is fixed by limiting the number of methods to compile by CrossGen. Commit migrated from https://github.com/dotnet/coreclr/commit/4b7c2f4e64380e8286b9edc85ff477417bd62c54 --- src/coreclr/src/vm/compile.cpp | 6 ++++-- src/coreclr/src/vm/compile.h | 11 +++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/coreclr/src/vm/compile.cpp b/src/coreclr/src/vm/compile.cpp index e3bdf34..90607f7 100644 --- a/src/coreclr/src/vm/compile.cpp +++ b/src/coreclr/src/vm/compile.cpp @@ -4939,6 +4939,8 @@ CEEPreloader::CEEPreloader(Module *pModule, GetAppDomain()->ToCompilationDomain()->SetTargetImage(m_image, this); + m_methodCompileLimit = pModule->GetMDImport()->GetCountWithTokenKind(mdtMethodDef) * 10; + #ifdef FEATURE_FULL_NGEN m_fSpeculativeTriage = FALSE; m_fDictionariesPopulated = FALSE; @@ -5148,7 +5150,7 @@ void CEEPreloader::MethodReferencedByCompiledCode(CORINFO_METHOD_HANDLE handle) if (pEntry->fScheduled) return; - m_uncompiledMethods.Append(pMD); + AppendUncompiledMethod(pMD); } else { @@ -5358,7 +5360,7 @@ void CEEPreloader::AddToUncompiledMethods(MethodDesc *pMD, BOOL fForStubs) } // Add it to the set of uncompiled methods - m_uncompiledMethods.Append(pMD); + AppendUncompiledMethod(pMD); } // diff --git a/src/coreclr/src/vm/compile.h b/src/coreclr/src/vm/compile.h index 9a9cc14..97c6cc1 100644 --- a/src/coreclr/src/vm/compile.h +++ b/src/coreclr/src/vm/compile.h @@ -527,6 +527,17 @@ class CEEPreloader : public ICorCompilePreloader // Array of methods that we need to compile. SArray m_uncompiledMethods; + int m_methodCompileLimit; + + void AppendUncompiledMethod(MethodDesc *pMD) + { + if (m_methodCompileLimit > 0) + { + m_uncompiledMethods.Append(pMD); + m_methodCompileLimit--; + } + } + struct DuplicateMethodEntry { MethodDesc * pMD; -- 2.7.4