Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modify JIT to support double mapped memory #52600

Merged
merged 6 commits into from
May 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1929,21 +1929,12 @@ bool interceptor_ICJI::runWithErrorTrap(void (*function)(void*), void* param)
}

// get a block of memory for the code, readonly data, and read-write data
void interceptor_ICJI::allocMem(uint32_t hotCodeSize, /* IN */
uint32_t coldCodeSize, /* IN */
uint32_t roDataSize, /* IN */
uint32_t xcptnsCount, /* IN */
CorJitAllocMemFlag flag, /* IN */
void** hotCodeBlock, /* OUT */
void** coldCodeBlock, /* OUT */
void** roDataBlock /* OUT */
)
void interceptor_ICJI::allocMem(AllocMemArgs *pArgs)
{
mc->cr->AddCall("allocMem");
original_ICorJitInfo->allocMem(hotCodeSize, coldCodeSize, roDataSize, xcptnsCount, flag, hotCodeBlock,
coldCodeBlock, roDataBlock);
mc->cr->recAllocMem(hotCodeSize, coldCodeSize, roDataSize, xcptnsCount, flag, hotCodeBlock, coldCodeBlock,
roDataBlock);
original_ICorJitInfo->allocMem(pArgs);
mc->cr->recAllocMem(pArgs->hotCodeSize, pArgs->coldCodeSize, pArgs->roDataSize, pArgs->xcptnsCount, pArgs->flag, &pArgs->hotCodeBlock, &pArgs->coldCodeBlock,
&pArgs->roDataBlock);
}

// Reserve memory for the method/funclet's unwind information.
Expand Down Expand Up @@ -2101,14 +2092,15 @@ void interceptor_ICJI::recordCallSite(uint32_t instrOffset, /* IN *
// A relocation is recorded if we are pre-jitting.
// A jump thunk may be inserted if we are jitting
void interceptor_ICJI::recordRelocation(void* location, /* IN */
void* locationRW, /* IN */
void* target, /* IN */
uint16_t fRelocType, /* IN */
uint16_t slotNum, /* IN */
int32_t addlDelta /* IN */
)
{
mc->cr->AddCall("recordRelocation");
original_ICorJitInfo->recordRelocation(location, target, fRelocType, slotNum, addlDelta);
original_ICorJitInfo->recordRelocation(location, locationRW, target, fRelocType, slotNum, addlDelta);
mc->cr->recRecordRelocation(location, target, fRelocType, slotNum, addlDelta);
}

Expand Down
14 changes: 4 additions & 10 deletions src/coreclr/ToolBox/superpmi/superpmi-shim-counter/icorjitinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1250,17 +1250,10 @@ bool interceptor_ICJI::notifyInstructionSetUsage(
}

void interceptor_ICJI::allocMem(
uint32_t hotCodeSize,
uint32_t coldCodeSize,
uint32_t roDataSize,
uint32_t xcptnsCount,
CorJitAllocMemFlag flag,
void** hotCodeBlock,
void** coldCodeBlock,
void** roDataBlock)
AllocMemArgs* pArgs)
{
mcs->AddCall("allocMem");
original_ICorJitInfo->allocMem(hotCodeSize, coldCodeSize, roDataSize, xcptnsCount, flag, hotCodeBlock, coldCodeBlock, roDataBlock);
original_ICorJitInfo->allocMem(pArgs);
}

void interceptor_ICJI::reserveUnwindInfo(
Expand Down Expand Up @@ -1363,13 +1356,14 @@ void interceptor_ICJI::recordCallSite(

void interceptor_ICJI::recordRelocation(
void* location,
void* locationRW,
void* target,
uint16_t fRelocType,
uint16_t slotNum,
int32_t addlDelta)
{
mcs->AddCall("recordRelocation");
original_ICorJitInfo->recordRelocation(location, target, fRelocType, slotNum, addlDelta);
original_ICorJitInfo->recordRelocation(location, locationRW, target, fRelocType, slotNum, addlDelta);
}

uint16_t interceptor_ICJI::getRelocTypeHint(
Expand Down
14 changes: 4 additions & 10 deletions src/coreclr/ToolBox/superpmi/superpmi-shim-simple/icorjitinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1094,16 +1094,9 @@ bool interceptor_ICJI::notifyInstructionSetUsage(
}

void interceptor_ICJI::allocMem(
uint32_t hotCodeSize,
uint32_t coldCodeSize,
uint32_t roDataSize,
uint32_t xcptnsCount,
CorJitAllocMemFlag flag,
void** hotCodeBlock,
void** coldCodeBlock,
void** roDataBlock)
AllocMemArgs* pArgs)
{
original_ICorJitInfo->allocMem(hotCodeSize, coldCodeSize, roDataSize, xcptnsCount, flag, hotCodeBlock, coldCodeBlock, roDataBlock);
original_ICorJitInfo->allocMem(pArgs);
}

void interceptor_ICJI::reserveUnwindInfo(
Expand Down Expand Up @@ -1195,12 +1188,13 @@ void interceptor_ICJI::recordCallSite(

void interceptor_ICJI::recordRelocation(
void* location,
void* locationRW,
void* target,
uint16_t fRelocType,
uint16_t slotNum,
int32_t addlDelta)
{
original_ICorJitInfo->recordRelocation(location, target, fRelocType, slotNum, addlDelta);
original_ICorJitInfo->recordRelocation(location, locationRW, target, fRelocType, slotNum, addlDelta);
}

uint16_t interceptor_ICJI::getRelocTypeHint(
Expand Down
51 changes: 24 additions & 27 deletions src/coreclr/ToolBox/superpmi/superpmi/icorjitinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1601,54 +1601,46 @@ static void* ALIGN_UP_SPMI(void* val, size_t alignment)
}

// get a block of memory for the code, readonly data, and read-write data
void MyICJI::allocMem(uint32_t hotCodeSize, /* IN */
uint32_t coldCodeSize, /* IN */
uint32_t roDataSize, /* IN */
uint32_t xcptnsCount, /* IN */
CorJitAllocMemFlag flag, /* IN */
void** hotCodeBlock, /* OUT */
void** coldCodeBlock, /* OUT */
void** roDataBlock /* OUT */
)
void MyICJI::allocMem(AllocMemArgs* pArgs)
{
jitInstance->mc->cr->AddCall("allocMem");

// TODO-Cleanup: Could hot block size be ever 0?
size_t codeAlignment = sizeof(void*);
size_t hotCodeAlignedSize = static_cast<size_t>(hotCodeSize);
size_t hotCodeAlignedSize = static_cast<size_t>(pArgs->hotCodeSize);

if ((flag & CORJIT_ALLOCMEM_FLG_32BYTE_ALIGN) != 0)
if ((pArgs->flag & CORJIT_ALLOCMEM_FLG_32BYTE_ALIGN) != 0)
{
codeAlignment = 32;
}
else if ((flag & CORJIT_ALLOCMEM_FLG_16BYTE_ALIGN) != 0)
else if ((pArgs->flag & CORJIT_ALLOCMEM_FLG_16BYTE_ALIGN) != 0)
{
codeAlignment = 16;
}
hotCodeAlignedSize = ALIGN_UP_SPMI(hotCodeAlignedSize, codeAlignment);
hotCodeAlignedSize = hotCodeAlignedSize + (codeAlignment - sizeof(void*));
*hotCodeBlock = jitInstance->mc->cr->allocateMemory(hotCodeAlignedSize);
*hotCodeBlock = ALIGN_UP_SPMI(*hotCodeBlock, codeAlignment);
pArgs->hotCodeBlock = jitInstance->mc->cr->allocateMemory(hotCodeAlignedSize);
pArgs->hotCodeBlock = ALIGN_UP_SPMI(pArgs->hotCodeBlock, codeAlignment);

if (coldCodeSize > 0)
*coldCodeBlock = jitInstance->mc->cr->allocateMemory(coldCodeSize);
if (pArgs->coldCodeSize > 0)
pArgs->coldCodeBlock = jitInstance->mc->cr->allocateMemory(pArgs->coldCodeSize);
else
*coldCodeBlock = nullptr;
pArgs->coldCodeBlock = nullptr;

if (roDataSize > 0)
if (pArgs->roDataSize > 0)
{
size_t roDataAlignment = sizeof(void*);
size_t roDataAlignedSize = static_cast<size_t>(roDataSize);
size_t roDataAlignedSize = static_cast<size_t>(pArgs->roDataSize);

if ((flag & CORJIT_ALLOCMEM_FLG_RODATA_32BYTE_ALIGN) != 0)
if ((pArgs->flag & CORJIT_ALLOCMEM_FLG_RODATA_32BYTE_ALIGN) != 0)
{
roDataAlignment = 32;
}
else if ((flag & CORJIT_ALLOCMEM_FLG_RODATA_16BYTE_ALIGN) != 0)
else if ((pArgs->flag & CORJIT_ALLOCMEM_FLG_RODATA_16BYTE_ALIGN) != 0)
{
roDataAlignment = 16;
}
else if (roDataSize >= 8)
else if (pArgs->roDataSize >= 8)
{
roDataAlignment = 8;
}
Expand All @@ -1660,14 +1652,18 @@ void MyICJI::allocMem(uint32_t hotCodeSize, /* IN */

roDataAlignedSize = ALIGN_UP_SPMI(roDataAlignedSize, roDataAlignment);
roDataAlignedSize = roDataAlignedSize + (roDataAlignment - sizeof(void*));
*roDataBlock = jitInstance->mc->cr->allocateMemory(roDataAlignedSize);
*roDataBlock = ALIGN_UP_SPMI(*roDataBlock, roDataAlignment);
pArgs->roDataBlock = jitInstance->mc->cr->allocateMemory(roDataAlignedSize);
pArgs->roDataBlock = ALIGN_UP_SPMI(pArgs->roDataBlock, roDataAlignment);
}
else
*roDataBlock = nullptr;
pArgs->roDataBlock = nullptr;

jitInstance->mc->cr->recAllocMem(hotCodeSize, coldCodeSize, roDataSize, xcptnsCount, flag, hotCodeBlock,
coldCodeBlock, roDataBlock);
pArgs->hotCodeBlockRW = pArgs->hotCodeBlock;
pArgs->coldCodeBlockRW = pArgs->coldCodeBlock;
pArgs->roDataBlockRW = pArgs->roDataBlock;

jitInstance->mc->cr->recAllocMem(pArgs->hotCodeSize, pArgs->coldCodeSize, pArgs->roDataSize, pArgs->xcptnsCount, pArgs->flag, &pArgs->hotCodeBlock,
&pArgs->coldCodeBlock, &pArgs->roDataBlock);
}

// Reserve memory for the method/funclet's unwind information.
Expand Down Expand Up @@ -1841,6 +1837,7 @@ void MyICJI::recordCallSite(uint32_t instrOffset, /* IN */
// A relocation is recorded if we are pre-jitting.
// A jump thunk may be inserted if we are jitting
void MyICJI::recordRelocation(void* location, /* IN */
void* locationRW, /* IN */
void* target, /* IN */
uint16_t fRelocType, /* IN */
uint16_t slotNum, /* IN */
Expand Down
28 changes: 20 additions & 8 deletions src/coreclr/inc/corjit.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,24 @@ enum CheckedWriteBarrierKinds {
CWBKind_AddrOfLocal, // Store through the address of a local (arguably a bug that this happens at all).
};

struct AllocMemArgs
{
// Input arguments
uint32_t hotCodeSize;
uint32_t coldCodeSize;
uint32_t roDataSize;
uint32_t xcptnsCount;
CorJitAllocMemFlag flag;

// Output arguments
void* hotCodeBlock;
void* hotCodeBlockRW;
void* coldCodeBlock;
void* coldCodeBlockRW;
void* roDataBlock;
void* roDataBlockRW;
};

#include "corjithost.h"

extern "C" void jitStartup(ICorJitHost* host);
Expand Down Expand Up @@ -212,14 +230,7 @@ class ICorJitInfo : public ICorDynamicInfo
public:
// get a block of memory for the code, readonly data, and read-write data
virtual void allocMem (
uint32_t hotCodeSize, /* IN */
uint32_t coldCodeSize, /* IN */
uint32_t roDataSize, /* IN */
uint32_t xcptnsCount, /* IN */
CorJitAllocMemFlag flag, /* IN */
void ** hotCodeBlock, /* OUT */
void ** coldCodeBlock, /* OUT */
void ** roDataBlock /* OUT */
AllocMemArgs *pArgs
) = 0;

// Reserve memory for the method/funclet's unwind information.
Expand Down Expand Up @@ -430,6 +441,7 @@ class ICorJitInfo : public ICorDynamicInfo
// A jump thunk may be inserted if we are jitting
virtual void recordRelocation(
void * location, /* IN */
void * locationRW, /* IN */
void * target, /* IN */
uint16_t fRelocType, /* IN */
uint16_t slotNum = 0, /* IN */
Expand Down
10 changes: 2 additions & 8 deletions src/coreclr/inc/icorjitinfoimpl_generated.h
Original file line number Diff line number Diff line change
Expand Up @@ -635,14 +635,7 @@ bool notifyInstructionSetUsage(
bool supportEnabled) override;

void allocMem(
uint32_t hotCodeSize,
uint32_t coldCodeSize,
uint32_t roDataSize,
uint32_t xcptnsCount,
CorJitAllocMemFlag flag,
void** hotCodeBlock,
void** coldCodeBlock,
void** roDataBlock) override;
AllocMemArgs* pArgs) override;

void reserveUnwindInfo(
bool isFunclet,
Expand Down Expand Up @@ -700,6 +693,7 @@ void recordCallSite(

void recordRelocation(
void* location,
void* locationRW,
void* target,
uint16_t fRelocType,
uint16_t slotNum,
Expand Down
11 changes: 6 additions & 5 deletions src/coreclr/inc/jiteeversionguid.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,14 @@ typedef const GUID *LPCGUID;
#define GUID_DEFINED
#endif // !GUID_DEFINED

constexpr GUID JITEEVersionIdentifier = { /* 12234eca-dfc2-48bc-a320-6155cf25ce17 */
0x12234eca,
0xdfc2,
0x48bc,
{0xa3, 0x20, 0x61, 0x55, 0xcf, 0x25, 0xce, 0x17}
constexpr GUID JITEEVersionIdentifier = { /* 529be99f-ce88-426e-a099-7528a691226c */
0x529be99f,
0xce88,
0x426e,
{ 0xa0, 0x99, 0x75, 0x28, 0xa6, 0x91, 0x22, 0x6c }
};


//////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// END JITEEVersionIdentifier
Expand Down
14 changes: 4 additions & 10 deletions src/coreclr/jit/ICorJitInfo_API_wrapper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1526,17 +1526,10 @@ bool WrapICorJitInfo::notifyInstructionSetUsage(
}

void WrapICorJitInfo::allocMem(
uint32_t hotCodeSize,
uint32_t coldCodeSize,
uint32_t roDataSize,
uint32_t xcptnsCount,
CorJitAllocMemFlag flag,
void** hotCodeBlock,
void** coldCodeBlock,
void** roDataBlock)
AllocMemArgs* pArgs)
{
API_ENTER(allocMem);
wrapHnd->allocMem(hotCodeSize, coldCodeSize, roDataSize, xcptnsCount, flag, hotCodeBlock, coldCodeBlock, roDataBlock);
wrapHnd->allocMem(pArgs);
API_LEAVE(allocMem);
}

Expand Down Expand Up @@ -1656,13 +1649,14 @@ void WrapICorJitInfo::recordCallSite(

void WrapICorJitInfo::recordRelocation(
void* location,
void* locationRW,
void* target,
uint16_t fRelocType,
uint16_t slotNum,
int32_t addlDelta)
{
API_ENTER(recordRelocation);
wrapHnd->recordRelocation(location, target, fRelocType, slotNum, addlDelta);
wrapHnd->recordRelocation(location, locationRW, target, fRelocType, slotNum, addlDelta);
API_LEAVE(recordRelocation);
}

Expand Down
Loading