Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.

Commit

Permalink
Remove dependency on tiered vtable methods for entry point slot backp…
Browse files Browse the repository at this point in the history
…atching infrastructure
  • Loading branch information
kouvel committed Dec 12, 2018
1 parent 62f2893 commit 03d38f9
Show file tree
Hide file tree
Showing 16 changed files with 309 additions and 156 deletions.
8 changes: 7 additions & 1 deletion src/inc/clrconfigvalues.h
Expand Up @@ -646,12 +646,18 @@ RETAIL_CONFIG_DWORD_INFO(EXTERNAL_TieredCompilation, W("TieredCompilation"), 1,
RETAIL_CONFIG_DWORD_INFO(UNSUPPORTED_TieredCompilation_Tier1CallCountThreshold, W("TieredCompilation_Tier1CallCountThreshold"), 30, "Number of times a method must be called after which it is promoted to tier 1.")
RETAIL_CONFIG_DWORD_INFO(UNSUPPORTED_TieredCompilation_Tier1CallCountingDelayMs, W("TieredCompilation_Tier1CallCountingDelayMs"), 100, "A perpetual delay in milliseconds that is applied to tier 1 call counting and jitting, while there is tier 0 activity.")
RETAIL_CONFIG_DWORD_INFO(UNSUPPORTED_TieredCompilation_Tier1DelaySingleProcMultiplier, W("TieredCompilation_Tier1DelaySingleProcMultiplier"), 10, "Multiplier for TieredCompilation_Tier1CallCountingDelayMs that is applied on a single-processor machine or when the process is affinitized to a single processor.")
RETAIL_CONFIG_DWORD_INFO(UNSUPPORTED_TieredCompilation_PatchVtableSlots, W("TieredCompilation_PatchVtableSlots"), 1, "Indicates whether to avoid making virtual calls through a precode and instead to patch virtual slots for a method when its entry point changes.")

RETAIL_CONFIG_DWORD_INFO(UNSUPPORTED_TieredCompilation_Test_CallCounting, W("TieredCompilation_Test_CallCounting"), 1, "Enabled by default (only activates when TieredCompilation is also enabled). If disabled immediately backpatches prestub, and likely prevents any tier1 promotion")
RETAIL_CONFIG_DWORD_INFO(UNSUPPORTED_TieredCompilation_Test_OptimizeTier0, W("TieredCompilation_Test_OptimizeTier0"), 0, "Use optimized codegen (normally used by tier1) in tier0")
#endif

///
/// Entry point slot backpatch
///
#ifndef CROSSGEN_COMPILE
RETAIL_CONFIG_DWORD_INFO(UNSUPPORTED_BackpatchEntryPointSlots, W("BackpatchEntryPointSlots"), 1, "Indicates whether to enable entry point slot backpatching, for instance to avoid making virtual calls through a precode and instead to patch virtual slots for a method when its entry point changes.")
#endif

///
/// TypeLoader
///
Expand Down
6 changes: 4 additions & 2 deletions src/vm/appdomain.cpp
Expand Up @@ -3904,9 +3904,11 @@ void AppDomain::Terminate()
}
#endif // FEATURE_COMINTEROP

#ifdef FEATURE_TIERED_COMPILATION
#ifndef CROSSGEN_COMPILE
// Recorded entry point slots may point into the virtual call stub manager's heaps, so clear it first
GetLoaderAllocator()->GetMethodDescBackpatchInfoTracker()->ClearDependencyMethodDescEntryPointSlotsToBackpatchHash();
GetLoaderAllocator()
->GetMethodDescBackpatchInfoTracker()
->ClearDependencyMethodDescEntryPointSlotsToBackpatchHash(GetLoaderAllocator());
#endif

if (!IsAtProcessExit())
Expand Down
3 changes: 0 additions & 3 deletions src/vm/appdomain.hpp
Expand Up @@ -43,10 +43,7 @@

#include "appxutil.h"

#ifdef FEATURE_TIERED_COMPILATION
#include "tieredcompilation.h"
#include "callcounter.h"
#endif

#include "codeversion.h"

Expand Down
42 changes: 4 additions & 38 deletions src/vm/codeversion.cpp
Expand Up @@ -2246,46 +2246,12 @@ HRESULT CodeVersionManager::PublishNativeCodeVersion(MethodDesc* pMethod, Native
PCODE pCode = nativeCodeVersion.IsNull() ? NULL : nativeCodeVersion.GetNativeCode();
if (pMethod->IsEligibleForTieredCompilation())
{
if (pMethod->IsTieredMethodVersionableWithPrecode())
{
Precode* pPrecode = pMethod->GetOrCreatePrecode();
if (pCode == NULL)
{
EX_TRY
{
pPrecode->Reset();
}
EX_CATCH_HRESULT(hr);
return hr;
}
else
{
EX_TRY
{
pPrecode->SetTargetInterlocked(pCode, FALSE);

// SetTargetInterlocked() would return false if it lost the race with another thread. That is fine, this thread
// can continue assuming it was successful, similarly to it successfully updating the target and another thread
// updating the target again shortly afterwards.
hr = S_OK;
}
EX_CATCH_HRESULT(hr);
return hr;
}
}
else
EX_TRY
{
_ASSERTE(pMethod->IsTieredMethodVersionableWithVtableSlotBackpatch());
if (pCode == NULL)
{
pMethod->BackpatchToResetEntryPointSlots();
}
else
{
pMethod->BackpatchEntryPointSlots(pCode);
}
return S_OK;
pMethod->SetTieredMethodEntryPoint(pCode);
}
EX_CATCH_HRESULT(hr);
return hr;
}
else
{
Expand Down
11 changes: 8 additions & 3 deletions src/vm/eeconfig.cpp
Expand Up @@ -357,9 +357,12 @@ HRESULT EEConfig::Init()
fTieredCompilation_OptimizeTier0 = false;
tieredCompilation_tier1CallCountThreshold = 1;
tieredCompilation_tier1CallCountingDelayMs = 0;
tieredCompilation_patchVtableSlots = false;
#endif


#ifndef CROSSGEN_COMPILE
backpatchEntryPointSlots = false;
#endif

#if defined(FEATURE_GDBJIT) && defined(_DEBUG)
pszGDBJitElfDump = NULL;
#endif // FEATURE_GDBJIT && _DEBUG
Expand Down Expand Up @@ -1232,8 +1235,10 @@ HRESULT EEConfig::sync()
}
}
}
#endif

tieredCompilation_patchVtableSlots = CLRConfig::GetConfigValue(CLRConfig::UNSUPPORTED_TieredCompilation_PatchVtableSlots) != 0;
#ifndef CROSSGEN_COMPILE
backpatchEntryPointSlots = CLRConfig::GetConfigValue(CLRConfig::UNSUPPORTED_BackpatchEntryPointSlots) != 0;
#endif

#if defined(FEATURE_GDBJIT) && defined(_DEBUG)
Expand Down
10 changes: 8 additions & 2 deletions src/vm/eeconfig.h
Expand Up @@ -289,7 +289,10 @@ class EEConfig
bool TieredCompilation_OptimizeTier0() const {LIMITED_METHOD_CONTRACT; return fTieredCompilation_OptimizeTier0; }
DWORD TieredCompilation_Tier1CallCountThreshold() const { LIMITED_METHOD_CONTRACT; return tieredCompilation_tier1CallCountThreshold; }
DWORD TieredCompilation_Tier1CallCountingDelayMs() const { LIMITED_METHOD_CONTRACT; return tieredCompilation_tier1CallCountingDelayMs; }
bool TieredCompilation_PatchVtableSlots() const { LIMITED_METHOD_CONTRACT; return tieredCompilation_patchVtableSlots; }
#endif

#ifndef CROSSGEN_COMPILE
bool BackpatchEntryPointSlots() const { LIMITED_METHOD_CONTRACT; return backpatchEntryPointSlots; }
#endif

#if defined(FEATURE_GDBJIT) && defined(_DEBUG)
Expand Down Expand Up @@ -1023,7 +1026,10 @@ class EEConfig
bool fTieredCompilation_OptimizeTier0;
DWORD tieredCompilation_tier1CallCountThreshold;
DWORD tieredCompilation_tier1CallCountingDelayMs;
bool tieredCompilation_patchVtableSlots;
#endif

#ifndef CROSSGEN_COMPILE
bool backpatchEntryPointSlots;
#endif

#if defined(FEATURE_GDBJIT) && defined(_DEBUG)
Expand Down
2 changes: 1 addition & 1 deletion src/vm/i386/virtualcallstubcpu.hpp
Expand Up @@ -142,7 +142,7 @@ struct DispatchStub
LIMITED_METHOD_CONTRACT;
_ASSERTE(slotTypeRef != nullptr);

*slotTypeRef = EntryPointSlotsToBackpatch::SlotType_IsExecutable_IsRelativeToEndOfSlot;
*slotTypeRef = EntryPointSlotsToBackpatch::SlotType_IsExecutable_IsRel32;
return (TADDR)&_implDispl;
}

Expand Down
4 changes: 1 addition & 3 deletions src/vm/loaderallocator.cpp
Expand Up @@ -596,12 +596,10 @@ void LoaderAllocator::GCLoaderAllocators(LoaderAllocator* pOriginalLoaderAllocat

pDomainLoaderAllocatorDestroyIterator->ReleaseManagedAssemblyLoadContext();

#ifdef FEATURE_TIERED_COMPILATION
// Recorded entry point slots may point into the virtual call stub manager's heaps, so clear it first
pDomainLoaderAllocatorDestroyIterator
->GetMethodDescBackpatchInfoTracker()
->ClearDependencyMethodDescEntryPointSlotsToBackpatchHash();
#endif
->ClearDependencyMethodDescEntryPointSlotsToBackpatchHash(pDomainLoaderAllocatorDestroyIterator);

// The following code was previously happening on delete ~DomainAssembly->Terminate
// We are moving this part here in order to make sure that we can unload a LoaderAllocator
Expand Down
7 changes: 6 additions & 1 deletion src/vm/loaderallocator.hpp
Expand Up @@ -268,6 +268,9 @@ class LoaderAllocator

#ifdef FEATURE_TIERED_COMPILATION
CallCounter m_callCounter;
#endif

#ifndef CROSSGEN_COMPILE
MethodDescBackpatchInfoTracker m_methodDescBackpatchInfoTracker;
#endif

Expand Down Expand Up @@ -583,13 +586,15 @@ class LoaderAllocator
LIMITED_METHOD_CONTRACT;
return &m_callCounter;
}
#endif // FEATURE_TIERED_COMPILATION

#ifndef CROSSGEN_COMPILE
MethodDescBackpatchInfoTracker *GetMethodDescBackpatchInfoTracker()
{
LIMITED_METHOD_CONTRACT;
return &m_methodDescBackpatchInfoTracker;
}
#endif // FEATURE_TIERED_COMPILATION
#endif
}; // class LoaderAllocator

typedef VPTR(LoaderAllocator) PTR_LoaderAllocator;
Expand Down

0 comments on commit 03d38f9

Please sign in to comment.