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

Commit

Permalink
Refactor some things
Browse files Browse the repository at this point in the history
  • Loading branch information
kouvel committed Sep 19, 2018
1 parent d26503c commit bdbf2bc
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 66 deletions.
2 changes: 1 addition & 1 deletion src/vm/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ set(VM_SOURCES_DAC_AND_WKS_COMMON
threadpoolrequest.cpp
threads.cpp
threadstatics.cpp
tieredcompilation.cpp
typectxt.cpp
typedesc.cpp
typehandle.cpp
Expand Down Expand Up @@ -253,7 +254,6 @@ set(VM_SOURCES_WKS
synch.cpp
synchronizationcontextnative.cpp
testhookmgr.cpp
tieredcompilation.cpp
threaddebugblockinginfo.cpp
threadsuspend.cpp
typeparse.cpp
Expand Down
33 changes: 3 additions & 30 deletions src/vm/codeversion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,15 +150,8 @@ void NativeCodeVersionNode::SetActiveChildFlag(BOOL isActive)
NativeCodeVersion::OptimizationTier NativeCodeVersionNode::GetOptimizationTier() const
{
LIMITED_METHOD_DAC_CONTRACT;
return m_optTier.Load();
return m_optTier;
}
#ifndef DACCESS_COMPILE
void NativeCodeVersionNode::SetOptimizationTier(NativeCodeVersion::OptimizationTier tier)
{
LIMITED_METHOD_DAC_CONTRACT;
m_optTier.Store(tier);
}
#endif
#endif // FEATURE_TIERED_COMPILATION

NativeCodeVersion::NativeCodeVersion() :
Expand Down Expand Up @@ -343,27 +336,9 @@ NativeCodeVersion::OptimizationTier NativeCodeVersion::GetOptimizationTier() con
}
else
{
return
GetMethodDesc()->RequestedAggressiveOptimization()
? NativeCodeVersion::OptimizationTier1
: NativeCodeVersion::OptimizationTier0;
return TieredCompilationManager::GetInitialOptimizationTier(GetMethodDesc());
}
}

#ifndef DACCESS_COMPILE
void NativeCodeVersion::SetOptimizationTier(NativeCodeVersion::OptimizationTier tier)
{
LIMITED_METHOD_CONTRACT;
if (m_storageKind == StorageKind::Explicit)
{
AsNode()->SetOptimizationTier(tier);
}
else
{
_ASSERTE(!"Do not call SetOptimizationTier on default code versions - these versions are immutable");
}
}
#endif
#endif

PTR_NativeCodeVersionNode NativeCodeVersion::AsNode() const
Expand Down Expand Up @@ -915,9 +890,7 @@ HRESULT ILCodeVersion::GetOrCreateActiveNativeCodeVersion(MethodDesc* pClosedMet
if (activeNativeChild.IsNull())
{
NativeCodeVersion::OptimizationTier optimizationTier =
pClosedMethodDesc->RequestedAggressiveOptimization()
? NativeCodeVersion::OptimizationTier1
: NativeCodeVersion::OptimizationTier0;
TieredCompilationManager::GetInitialOptimizationTier(pClosedMethodDesc);
if (FAILED(hr = AddNativeCodeVersion(pClosedMethodDesc, optimizationTier, &activeNativeChild)))
{
_ASSERTE(hr == E_OUTOFMEMORY);
Expand Down
8 changes: 1 addition & 7 deletions src/vm/codeversion.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,6 @@ class NativeCodeVersion
};
#ifdef FEATURE_TIERED_COMPILATION
OptimizationTier GetOptimizationTier() const;
#ifndef DACCESS_COMPILE
void SetOptimizationTier(OptimizationTier tier);
#endif
#endif // FEATURE_TIERED_COMPILATION
bool operator==(const NativeCodeVersion & rhs) const;
bool operator!=(const NativeCodeVersion & rhs) const;
Expand Down Expand Up @@ -240,9 +237,6 @@ class NativeCodeVersionNode
#endif
#ifdef FEATURE_TIERED_COMPILATION
NativeCodeVersion::OptimizationTier GetOptimizationTier() const;
#ifndef DACCESS_COMPILE
void SetOptimizationTier(NativeCodeVersion::OptimizationTier tier);
#endif
#endif

private:
Expand All @@ -256,7 +250,7 @@ class NativeCodeVersionNode
PTR_NativeCodeVersionNode m_pNextMethodDescSibling;
NativeCodeVersionId m_id;
#ifdef FEATURE_TIERED_COMPILATION
Volatile<NativeCodeVersion::OptimizationTier> m_optTier;
NativeCodeVersion::OptimizationTier m_optTier;
#endif

enum NativeCodeVersionNodeFlags
Expand Down
27 changes: 10 additions & 17 deletions src/vm/prestub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1745,25 +1745,16 @@ PCODE MethodDesc::DoPrestub(MethodTable *pDispatchingMT)
// When the TieredCompilationManager has received enough call notifications
// for this method only then do we back-patch it.
BOOL fCanBackpatchPrestub = TRUE;
BOOL fEligibleForCallCounting = FALSE;
#ifdef FEATURE_TIERED_COMPILATION
BOOL fNeedsCallCounting = FALSE;
TieredCompilationManager* pTieredCompilationManager = nullptr;
BOOL fEligibleForTieredCompilation = IsEligibleForTieredCompilation();
BOOL fWasPromotedToTier1 = FALSE;
if (fEligibleForTieredCompilation)
if (IsEligibleForTieredCompilation() && TieredCompilationManager::RequiresCallCounting(this))
{
if (RequestedAggressiveOptimization())
{
fWasPromotedToTier1 = TRUE;
}
else if (g_pConfig->TieredCompilation_CallCounting())
{
fEligibleForCallCounting = TRUE;

pTieredCompilationManager = GetAppDomain()->GetTieredCompilationManager();
CallCounter * pCallCounter = GetCallCounter();
pCallCounter->OnMethodCalled(this, pTieredCompilationManager, &fCanBackpatchPrestub, &fWasPromotedToTier1);
}
pTieredCompilationManager = GetAppDomain()->GetTieredCompilationManager();
CallCounter * pCallCounter = GetCallCounter();
BOOL fWasPromotedToTier1 = FALSE;
pCallCounter->OnMethodCalled(this, pTieredCompilationManager, &fCanBackpatchPrestub, &fWasPromotedToTier1);
fNeedsCallCounting = !fWasPromotedToTier1;
}
#endif

Expand All @@ -1776,10 +1767,12 @@ PCODE MethodDesc::DoPrestub(MethodTable *pDispatchingMT)
{
pCode = GetCodeVersionManager()->PublishVersionableCodeIfNecessary(this, fCanBackpatchPrestub);

if (pTieredCompilationManager != nullptr && fEligibleForCallCounting && fCanBackpatchPrestub && pCode != NULL && !fWasPromotedToTier1)
#ifdef FEATURE_TIERED_COMPILATION
if (pTieredCompilationManager != nullptr && fNeedsCallCounting && fCanBackpatchPrestub && pCode != NULL)
{
pTieredCompilationManager->OnMethodCallCountingStoppedWithoutTier1Promotion(this);
}
#endif

fIsPointingToPrestub = IsPointingToPrestub();
}
Expand Down
36 changes: 34 additions & 2 deletions src/vm/tieredcompilation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
// errors are limited to OS resource exhaustion or poorly behaved managed code
// (for example within an AssemblyResolve event or static constructor triggered by the JIT).

#ifdef FEATURE_TIERED_COMPILATION
#if defined(FEATURE_TIERED_COMPILATION) && !defined(DACCESS_COMPILE)

// Called at AppDomain construction
TieredCompilationManager::TieredCompilationManager() :
Expand Down Expand Up @@ -91,6 +91,38 @@ void TieredCompilationManager::Init(ADID appDomainId)
m_callCountOptimizationThreshhold = g_pConfig->TieredCompilation_Tier1CallCountThreshold();
}

#endif // FEATURE_TIERED_COMPILATION && !DACCESS_COMPILE

NativeCodeVersion::OptimizationTier TieredCompilationManager::GetInitialOptimizationTier(PTR_MethodDesc pMethodDesc)
{
WRAPPER_NO_CONTRACT;
_ASSERTE(pMethodDesc != NULL);

#ifdef FEATURE_TIERED_COMPILATION
if (pMethodDesc->RequestedAggressiveOptimization())
{
// Methods flagged with MethodImplOptions.AggressiveOptimization begin at tier 1, as a workaround to cold methods with
// hot loops performing poorly (https://github.com/dotnet/coreclr/issues/19751)
return NativeCodeVersion::OptimizationTier1;
}
#endif // FEATURE_TIERED_COMPILATION

return NativeCodeVersion::OptimizationTier0;
}

#if defined(FEATURE_TIERED_COMPILATION) && !defined(DACCESS_COMPILE)

bool TieredCompilationManager::RequiresCallCounting(MethodDesc* pMethodDesc)
{
WRAPPER_NO_CONTRACT;
_ASSERTE(pMethodDesc != NULL);
_ASSERTE(pMethodDesc->IsEligibleForTieredCompilation());

return
g_pConfig->TieredCompilation_CallCounting() &&
GetInitialOptimizationTier(pMethodDesc) == NativeCodeVersion::OptimizationTier0;
}

// Called each time code in this AppDomain has been run. This is our sole entrypoint to begin
// tiered compilation for now. Returns TRUE if no more notifications are necessary, but
// more notifications may come anyways.
Expand Down Expand Up @@ -790,4 +822,4 @@ CORJIT_FLAGS TieredCompilationManager::GetJitFlags(NativeCodeVersion nativeCodeV
return flags;
}

#endif // FEATURE_TIERED_COMPILATION
#endif // FEATURE_TIERED_COMPILATION && !DACCESS_COMPILE
14 changes: 11 additions & 3 deletions src/vm/tieredcompilation.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
#ifndef TIERED_COMPILATION_H
#define TIERED_COMPILATION_H

#ifdef FEATURE_TIERED_COMPILATION

// TieredCompilationManager determines which methods should be recompiled and
// how they should be recompiled to best optimize the running code. It then
// handles logistics of getting new code created and installed.
class TieredCompilationManager
{
#ifdef FEATURE_TIERED_COMPILATION

public:
#if defined(DACCESS_COMPILE) || defined(CROSSGEN_COMPILE)
TieredCompilationManager() {}
Expand All @@ -26,7 +26,15 @@ class TieredCompilationManager

void Init(ADID appDomainId);

#endif // FEATURE_TIERED_COMPILATION

public:
static NativeCodeVersion::OptimizationTier GetInitialOptimizationTier(PTR_MethodDesc pMethodDesc);

#ifdef FEATURE_TIERED_COMPILATION

public:
static bool RequiresCallCounting(MethodDesc* pMethodDesc);
void OnMethodCalled(MethodDesc* pMethodDesc, DWORD currentCallCount, BOOL* shouldStopCountingCallsRef, BOOL* wasPromotedToTier1Ref);
void OnMethodCallCountingStoppedWithoutTier1Promotion(MethodDesc* pMethodDesc);
void AsyncPromoteMethodToTier1(MethodDesc* pMethodDesc);
Expand Down Expand Up @@ -68,8 +76,8 @@ class TieredCompilationManager
bool m_tier1CallCountingCandidateMethodRecentlyRecorded;

CLREvent m_asyncWorkDoneEvent;
};

#endif // FEATURE_TIERED_COMPILATION
};

#endif // TIERED_COMPILATION_H
14 changes: 8 additions & 6 deletions src/zap/zapinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -437,15 +437,17 @@ void ZapInfo::CompileMethod()

m_jitFlags = ComputeJitFlags(m_currentMethodHandle);

if (m_jitFlags.IsSet(CORJIT_FLAGS::CORJIT_FLAG_AGGRESSIVE_OPT))
{
// Skip methods marked with MethodImplOptions.AggressiveOptimization, they will be jitted instead. In the future,
// consider letting the JIT determine whether aggressively optimized code can/should be pregenerated for the method
// instead of this check.
return;
}

#ifdef FEATURE_READYTORUN_COMPILER
if (IsReadyToRunCompilation())
{
if (m_jitFlags.IsSet(CORJIT_FLAGS::CORJIT_FLAG_AGGRESSIVE_OPT))
{
// Skip methods marked with MethodImplOptions.AggressiveOptimization, they will be jitted instead
return;
}

// READYTORUN: FUTURE: Producedure spliting
m_jitFlags.Clear(CORJIT_FLAGS::CORJIT_FLAG_PROCSPLIT);

Expand Down

0 comments on commit bdbf2bc

Please sign in to comment.