Skip to content

Commit

Permalink
Reflect PR feedback and few fixes
Browse files Browse the repository at this point in the history
* Change the CallCountingStub to not to use return address of an
unbalanced call as a stub identifying token. The counter address is used
instead on all targets.
* Fix some tabs instead of spaces
* Fix getTargetMethodDesc - in some cases, we get address of the start
of the FixupPrecode too.
* Remove a leftover comment
  • Loading branch information
janvorli committed Feb 25, 2022
1 parent 5e0d202 commit ad97eed
Show file tree
Hide file tree
Showing 18 changed files with 114 additions and 146 deletions.
110 changes: 55 additions & 55 deletions src/coreclr/utilcode/executableallocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -426,43 +426,43 @@ void ExecutableAllocator::Release(void* pRX)

if (IsDoubleMappingEnabled())
{
CRITSEC_Holder csh(m_CriticalSection);

// Locate the RX block corresponding to the pRX and remove it from the linked list
BlockRX* pBlock;
BlockRX* pPrevBlock = NULL;

for (pBlock = m_pFirstBlockRX; pBlock != NULL; pBlock = pBlock->next)
{
if (pRX == pBlock->baseRX)
{
if (pPrevBlock == NULL)
{
m_pFirstBlockRX = pBlock->next;
}
else
{
pPrevBlock->next = pBlock->next;
}

break;
}
pPrevBlock = pBlock;
}

if (pBlock != NULL)
{
CRITSEC_Holder csh(m_CriticalSection);

// Locate the RX block corresponding to the pRX and remove it from the linked list
BlockRX* pBlock;
BlockRX* pPrevBlock = NULL;

for (pBlock = m_pFirstBlockRX; pBlock != NULL; pBlock = pBlock->next)
{
if (pRX == pBlock->baseRX)
{
if (pPrevBlock == NULL)
{
m_pFirstBlockRX = pBlock->next;
}
else
{
pPrevBlock->next = pBlock->next;
}

break;
}
pPrevBlock = pBlock;
}

if (pBlock != NULL)
{
VMToOSInterface::ReleaseDoubleMappedMemory(m_doubleMemoryMapperHandle, pRX, pBlock->offset, pBlock->size);
// Put the released block into the free block list
pBlock->baseRX = NULL;
pBlock->next = m_pFirstFreeBlockRX;
m_pFirstFreeBlockRX = pBlock;
}
else
{
// The block was not found, which should never happen.
g_fatalErrorHandler(COR_E_EXECUTIONENGINE, W("The RX block to release was not found"));
}
pBlock->baseRX = NULL;
pBlock->next = m_pFirstFreeBlockRX;
m_pFirstFreeBlockRX = pBlock;
}
else
{
// The block was not found, which should never happen.
g_fatalErrorHandler(COR_E_EXECUTIONENGINE, W("The RX block to release was not found"));
}
}
else
{
Expand Down Expand Up @@ -573,9 +573,9 @@ void* ExecutableAllocator::ReserveWithinRange(size_t size, const void* loAddress
bool isFreeBlock;
BlockRX* block = AllocateBlock(size, &isFreeBlock);
if (block == NULL)
{
return NULL;
}
{
return NULL;
}

void *result = VMToOSInterface::ReserveDoubleMappedMemory(m_doubleMemoryMapperHandle, block->offset, size, loAddress, hiAddress);

Expand Down Expand Up @@ -660,14 +660,14 @@ void* ExecutableAllocator::Reserve(size_t size)
{
if (IsDoubleMappingEnabled())
{
CRITSEC_Holder csh(m_CriticalSection);
CRITSEC_Holder csh(m_CriticalSection);

bool isFreeBlock;
bool isFreeBlock;
BlockRX* block = AllocateBlock(size, &isFreeBlock);
if (block == NULL)
{
return NULL;
}
if (block == NULL)
{
return NULL;
}

result = (BYTE*)VMToOSInterface::ReserveDoubleMappedMemory(m_doubleMemoryMapperHandle, block->offset, size, 0, 0);

Expand Down Expand Up @@ -753,7 +753,7 @@ void* ExecutableAllocator::MapRW(void* pRX, size_t size)
}

#ifdef LOG_EXECUTABLE_ALLOCATOR_STATISTICS
StopWatch swAll(&g_mapTimeWithLockSum);
StopWatch swAll(&g_mapTimeWithLockSum);
#endif

CRITSEC_Holder csh(m_CriticalSection);
Expand All @@ -762,13 +762,13 @@ void* ExecutableAllocator::MapRW(void* pRX, size_t size)
StopWatch sw(&g_mapTimeSum);
#endif

void* result = FindRWBlock(pRX, size);
if (result != NULL)
{
return result;
}
void* result = FindRWBlock(pRX, size);
if (result != NULL)
{
return result;
}
#ifdef LOG_EXECUTABLE_ALLOCATOR_STATISTICS
StopWatch sw2(&g_mapFindRXTimeSum);
StopWatch sw2(&g_mapFindRXTimeSum);
#endif

for (BlockRX* pBlock = m_pFirstBlockRX; pBlock != NULL; pBlock = pBlock->next)
Expand Down Expand Up @@ -836,10 +836,10 @@ void ExecutableAllocator::UnmapRW(void* pRW)
void* unmapAddress = NULL;
size_t unmapSize;

if (!RemoveRWBlock(pRW, &unmapAddress, &unmapSize))
{
g_fatalErrorHandler(COR_E_EXECUTIONENGINE, W("The RW block to unmap was not found"));
}
if (!RemoveRWBlock(pRW, &unmapAddress, &unmapSize))
{
g_fatalErrorHandler(COR_E_EXECUTIONENGINE, W("The RW block to unmap was not found"));
}

if (unmapAddress && !VMToOSInterface::ReleaseRWMapping(unmapAddress, unmapSize))
{
Expand Down
10 changes: 2 additions & 8 deletions src/coreclr/vm/amd64/AsmHelpers.asm
Original file line number Diff line number Diff line change
Expand Up @@ -697,13 +697,7 @@ ifdef FEATURE_TIERED_COMPILATION

extern OnCallCountThresholdReached:proc

LEAF_ENTRY OnCallCountThresholdReachedStub, _TEXT
; Pop the return address (the stub-identifying token) into a non-argument volatile register that can be trashed
pop rax
jmp OnCallCountThresholdReachedStub2
LEAF_END OnCallCountThresholdReachedStub, _TEXT

NESTED_ENTRY OnCallCountThresholdReachedStub2, _TEXT
NESTED_ENTRY OnCallCountThresholdReachedStub, _TEXT
PROLOG_WITH_TRANSITION_BLOCK

lea rcx, [rsp + __PWTB_TransitionBlock] ; TransitionBlock *
Expand All @@ -712,7 +706,7 @@ NESTED_ENTRY OnCallCountThresholdReachedStub2, _TEXT

EPILOG_WITH_TRANSITION_BLOCK_TAILCALL
TAILJMP_RAX
NESTED_END OnCallCountThresholdReachedStub2, _TEXT
NESTED_END OnCallCountThresholdReachedStub, _TEXT

endif ; FEATURE_TIERED_COMPILATION

Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/vm/amd64/thunktemplates.S
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ LEAF_ENTRY CallCountingStubCode, _TEXT
je LOCAL_LABEL(CountReachedZero)
jmp QWORD PTR [rip + DATA_SLOT(CallCountingStub, TargetForMethod)]
LOCAL_LABEL(CountReachedZero):
call QWORD PTR [rip + DATA_SLOT(CallCountingStub, TargetForThresholdReached)]
jmp QWORD PTR [rip + DATA_SLOT(CallCountingStub, TargetForThresholdReached)]
LEAF_END_MARKED CallCountingStubCode, _TEXT

LEAF_ENTRY LookupStubCode, _TEXT
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/vm/amd64/thunktemplates.asm
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ LEAF_ENTRY CallCountingStubCode, _TEXT
je CountReachedZero
jmp QWORD PTR [DATA_SLOT(CallCountingStub, TargetForMethod)]
CountReachedZero:
call QWORD PTR [DATA_SLOT(CallCountingStub, TargetForThresholdReached)]
jmp QWORD PTR [DATA_SLOT(CallCountingStub, TargetForThresholdReached)]
LEAF_END_MARKED CallCountingStubCode, _TEXT

LEAF_ENTRY LookupStubCode, _TEXT
Expand Down
10 changes: 2 additions & 8 deletions src/coreclr/vm/amd64/unixasmhelpers.S
Original file line number Diff line number Diff line change
Expand Up @@ -207,13 +207,7 @@ LEAF_END SinglecastDelegateInvokeStub, _TEXT

#ifdef FEATURE_TIERED_COMPILATION

LEAF_ENTRY OnCallCountThresholdReachedStub, _TEXT
// Pop the return address (the stub-identifying token) into a non-argument volatile register that can be trashed
pop rax
jmp C_FUNC(OnCallCountThresholdReachedStub2)
LEAF_END OnCallCountThresholdReachedStub, _TEXT

NESTED_ENTRY OnCallCountThresholdReachedStub2, _TEXT, NoHandler
NESTED_ENTRY OnCallCountThresholdReachedStub, _TEXT, NoHandler
PROLOG_WITH_TRANSITION_BLOCK

lea rdi, [rsp + __PWTB_TransitionBlock] // TransitionBlock *
Expand All @@ -222,6 +216,6 @@ NESTED_ENTRY OnCallCountThresholdReachedStub2, _TEXT, NoHandler

EPILOG_WITH_TRANSITION_BLOCK_TAILCALL
TAILJMP_RAX
NESTED_END OnCallCountThresholdReachedStub2, _TEXT
NESTED_END OnCallCountThresholdReachedStub, _TEXT

#endif // FEATURE_TIERED_COMPILATION
1 change: 0 additions & 1 deletion src/coreclr/vm/arm/thunktemplates.S
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ PAGE_SIZE = 4096
beq LOCAL_LABEL(CountReachedZero)
ldr pc, DATA_SLOT(CallCountingStub, TargetForMethod)
LOCAL_LABEL(CountReachedZero):
adr r12, CallCountingStubCode
ldr pc, DATA_SLOT(CallCountingStub, TargetForThresholdReached)
LEAF_END_MARKED CallCountingStubCode

Expand Down
1 change: 0 additions & 1 deletion src/coreclr/vm/arm/thunktemplates.asm
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
beq CountReachedZero
ldr pc, DATA_SLOT(CallCountingStub, TargetForMethod)
CountReachedZero
adr r12, CallCountingStubCode
ldr pc, DATA_SLOT(CallCountingStub, TargetForThresholdReached)
LEAF_END_MARKED CallCountingStubCode

Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/vm/arm64/asmhelpers.S
Original file line number Diff line number Diff line change
Expand Up @@ -957,7 +957,7 @@ NESTED_ENTRY OnCallCountThresholdReachedStub, _TEXT, NoHandler
PROLOG_WITH_TRANSITION_BLOCK

add x0, sp, #__PWTB_TransitionBlock // TransitionBlock *
mov x1, x10 // stub-identifying token
mov x1, x9 // stub-identifying token
bl C_FUNC(OnCallCountThresholdReached)
mov x9, x0

Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/vm/arm64/asmhelpers.asm
Original file line number Diff line number Diff line change
Expand Up @@ -1370,7 +1370,7 @@ __HelperNakedFuncName SETS "$helper":CC:"Naked"
PROLOG_WITH_TRANSITION_BLOCK

add x0, sp, #__PWTB_TransitionBlock ; TransitionBlock *
mov x1, x10 ; stub-identifying token
mov x1, x9 ; stub-identifying token
bl OnCallCountThresholdReached
mov x9, x0

Expand Down
5 changes: 2 additions & 3 deletions src/coreclr/vm/arm64/thunktemplates.S
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,8 @@ LOCAL_LABEL(StubStart\PAGE_SIZE):
ldr x9, DATA_SLOT(CallCountingStub, TargetForMethod)
br x9
LOCAL_LABEL(CountReachedZero\PAGE_SIZE):
adr x10, LOCAL_LABEL(StubStart\PAGE_SIZE)
ldr x9, DATA_SLOT(CallCountingStub, TargetForThresholdReached)
br x9
ldr x10, DATA_SLOT(CallCountingStub, TargetForThresholdReached)
br x10
LEAF_END_MARKED CallCountingStubCode\PAGE_SIZE


Expand Down
5 changes: 2 additions & 3 deletions src/coreclr/vm/arm64/thunktemplates.asm
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,8 @@
ldr x9, DATA_SLOT(CallCountingStub, TargetForMethod)
br x9
CountReachedZero
adr x10, CallCountingStubCode
ldr x9, DATA_SLOT(CallCountingStub, TargetForThresholdReached)
br x9
ldr x10, DATA_SLOT(CallCountingStub, TargetForThresholdReached)
br x10
LEAF_END_MARKED CallCountingStubCode


Expand Down
65 changes: 33 additions & 32 deletions src/coreclr/vm/callcounting.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,16 +91,12 @@ class CallCountingStub
public:
#if defined(TARGET_AMD64)
static const int CodeSize = 24;
static const int StubIdentifyingTokenOffset = 24;
#elif defined(TARGET_X86)
static const int CodeSize = 24;
static const int StubIdentifyingTokenOffset = 22;
#elif defined(TARGET_ARM64)
static const int CodeSize = 40;
static const int StubIdentifyingTokenOffset = 0;
#elif defined(TARGET_ARM)
static const int CodeSize = 32;
static const int StubIdentifyingTokenOffset = 0;
#endif

private:
Expand Down Expand Up @@ -158,34 +154,6 @@ class CallCountingStub
DISABLE_COPY(CallCountingStub);
};

////////////////////////////////////////////////////////////////
// CallCountingStub definitions

#ifndef DACCESS_COMPILE
inline const CallCountingStub *CallCountingStub::From(TADDR stubIdentifyingToken)
{
WRAPPER_NO_CONTRACT;
_ASSERTE(stubIdentifyingToken != NULL);

const CallCountingStub *stub = (const CallCountingStub *)(stubIdentifyingToken - StubIdentifyingTokenOffset);

_ASSERTE(IS_ALIGNED(stub, Alignment));
return stub;
}
#endif

inline PTR_CallCount CallCountingStub::GetRemainingCallCountCell() const
{
WRAPPER_NO_CONTRACT;
return GetData()->RemainingCallCountCell;
}

inline PCODE CallCountingStub::GetTargetForMethod() const
{
WRAPPER_NO_CONTRACT;
return GetData()->TargetForMethod;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// CallCountingManager

Expand Down Expand Up @@ -398,6 +366,10 @@ class CallCountingManager

public:
static void StopAndDeleteAllCallCountingStubs();
static const CallCountingStub* GetCallCountingStub(CallCount *pCallCount)
{
return CallCountingInfo::From(pCallCount)->GetCallCountingStub();
}
private:
static void StopAllCallCounting(TieredCompilationManager *tieredCompilationManager);
static void DeleteAllCallCountingStubs();
Expand All @@ -414,6 +386,35 @@ class CallCountingManager
DISABLE_COPY(CallCountingManager);
};

////////////////////////////////////////////////////////////////
// CallCountingStub definitions

#ifndef DACCESS_COMPILE
inline const CallCountingStub *CallCountingStub::From(TADDR stubIdentifyingToken)
{
WRAPPER_NO_CONTRACT;
_ASSERTE(stubIdentifyingToken != NULL);

// The stubIdentifyingToken is the pointer to the CallCount
const CallCountingStub *stub = CallCountingManager::GetCallCountingStub((CallCount*)stubIdentifyingToken);

_ASSERTE(IS_ALIGNED(stub, Alignment));
return stub;
}
#endif

inline PTR_CallCount CallCountingStub::GetRemainingCallCountCell() const
{
WRAPPER_NO_CONTRACT;
return GetData()->RemainingCallCountCell;
}

inline PCODE CallCountingStub::GetTargetForMethod() const
{
WRAPPER_NO_CONTRACT;
return GetData()->TargetForMethod;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// CallCountingManager::CallCountingStubManager

Expand Down
Loading

0 comments on commit ad97eed

Please sign in to comment.