diff options
author | David Wrighton <davidwr@microsoft.com> | 2019-06-11 13:13:09 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-06-11 13:13:09 -0700 |
commit | 93675fbf467f54ab0f1f5d183c70750c9822c9ca (patch) | |
tree | 9fc2f0d0e6507da062ce55f371c46402da2a2f8f /src/vm/prestub.cpp | |
parent | 118711549ecdc024719d5023a004a2250705cdf9 (diff) | |
download | coreclr-93675fbf467f54ab0f1f5d183c70750c9822c9ca.tar.gz coreclr-93675fbf467f54ab0f1f5d183c70750c9822c9ca.tar.bz2 coreclr-93675fbf467f54ab0f1f5d183c70750c9822c9ca.zip |
R2R ilstubs (#24823)
* Basic support for precompiled pinvoke stubs
* Generate R2R file with multiple references to same IL stub (one per method which the IL stub is associated with)
* Not all il stubs are p/invokes. Don't fail when they aren't.
* Consistently use IsDynamicScope and GetModule to avoid unsafe memory access in IL stub compilation paths
* Enable full p/invoke il stubs when compiling System.Private.Corelib
* Disable IL Stub generation in crossgen for ARM32.
- The cross bitness logic is not correct for IL Stub generation
Diffstat (limited to 'src/vm/prestub.cpp')
-rw-r--r-- | src/vm/prestub.cpp | 52 |
1 files changed, 49 insertions, 3 deletions
diff --git a/src/vm/prestub.cpp b/src/vm/prestub.cpp index d83c419e22..45ee0f02df 100644 --- a/src/vm/prestub.cpp +++ b/src/vm/prestub.cpp @@ -358,6 +358,20 @@ PCODE MethodDesc::PrepareCode(PrepareCodeConfig* pConfig) return PrepareILBasedCode(pConfig); } +bool MayUsePrecompiledILStub() +{ + if (g_pConfig->InteropValidatePinnedObjects()) + return false; + + if (CORProfilerTrackTransitions()) + return false; + + if (g_pConfig->InteropLogArguments()) + return false; + + return true; +} + PCODE MethodDesc::PrepareILBasedCode(PrepareCodeConfig* pConfig) { STANDARD_VM_CONTRACT; @@ -365,7 +379,39 @@ PCODE MethodDesc::PrepareILBasedCode(PrepareCodeConfig* pConfig) if (pConfig->MayUsePrecompiledCode()) { - pCode = GetPrecompiledCode(pConfig); +#ifdef FEATURE_READYTORUN + if (this->IsDynamicMethod() && GetLoaderModule()->IsSystem() && MayUsePrecompiledILStub()) + { + DynamicMethodDesc *stubMethodDesc = this->AsDynamicMethodDesc(); + if (stubMethodDesc->IsILStub() && stubMethodDesc->IsPInvokeStub()) + { + ILStubResolver *pStubResolver = stubMethodDesc->GetILStubResolver(); + if (pStubResolver->IsCLRToNativeInteropStub()) + { + MethodDesc *pTargetMD = stubMethodDesc->GetILStubResolver()->GetStubTargetMethodDesc(); + if (pTargetMD != NULL) + { + pCode = pTargetMD->GetPrecompiledR2RCode(pConfig); + if (pCode != NULL) + { + LOG((LF_ZAP, LL_INFO10000, + "ZAP: Using R2R precompiled code" FMT_ADDR " for %s.%s sig=\"%s\" (token %x).\n", + DBG_ADDR(pCode), + m_pszDebugClassName, + m_pszDebugMethodName, + m_pszDebugMethodSignature, + GetMemberDef())); + + pConfig->SetNativeCode(pCode, &pCode); + } + } + } + } + } +#endif // FEATURE_READYTORUN + + if (pCode == NULL) + pCode = GetPrecompiledCode(pConfig); } if (pCode == NULL) @@ -412,7 +458,7 @@ PCODE MethodDesc::GetPrecompiledCode(PrepareCodeConfig* pConfig) if (pCode != NULL) { LOG((LF_ZAP, LL_INFO10000, - "ZAP: Using R2R precompiled code" FMT_ADDR "for %s.%s sig=\"%s\" (token %x).\n", + "ZAP: Using R2R precompiled code" FMT_ADDR " for %s.%s sig=\"%s\" (token %x).\n", DBG_ADDR(pCode), m_pszDebugClassName, m_pszDebugMethodName, @@ -471,7 +517,7 @@ PCODE MethodDesc::GetPrecompiledNgenCode(PrepareCodeConfig* pConfig) if (pCode != NULL) { LOG((LF_ZAP, LL_INFO10000, - "ZAP: Using NGEN precompiled code" FMT_ADDR "for %s.%s sig=\"%s\" (token %x).\n", + "ZAP: Using NGEN precompiled code " FMT_ADDR " for %s.%s sig=\"%s\" (token %x).\n", DBG_ADDR(pCode), m_pszDebugClassName, m_pszDebugMethodName, |