mirror of
https://github.com/VSadov/Satori.git
synced 2025-06-08 03:27:04 +09:00
Fix after rebase
This commit is contained in:
parent
9991147ab5
commit
960a20e046
1 changed files with 56 additions and 8 deletions
|
@ -28,14 +28,33 @@ Object* FrozenObjectHeapManager::TryAllocateObject(PTR_MethodTable type, size_t
|
|||
THROWS;
|
||||
MODE_COOPERATIVE;
|
||||
}
|
||||
CONTRACTL_END
|
||||
CONTRACTL_END
|
||||
|
||||
#ifndef FEATURE_BASICFREEZE
|
||||
// GC is required to support frozen segments
|
||||
return nullptr;
|
||||
// GC is required to support frozen segments
|
||||
return nullptr;
|
||||
#else // FEATURE_BASICFREEZE
|
||||
|
||||
Object* obj = nullptr;
|
||||
|
||||
#if FEATURE_SATORI_GC
|
||||
if (objectSize > FOH_COMMIT_SIZE)
|
||||
{
|
||||
// The current design doesn't allow objects larger than FOH_COMMIT_SIZE and
|
||||
// since FrozenObjectHeap is just an optimization, let's not fill it with huge objects.
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
obj = AllocateImmortalObject(type, objectSize);
|
||||
if (initFunc != nullptr)
|
||||
{
|
||||
initFunc(obj, pParam);
|
||||
}
|
||||
|
||||
return obj;
|
||||
#endif
|
||||
|
||||
|
||||
FrozenObjectSegment* curSeg = nullptr;
|
||||
uint8_t* curSegmentCurrent = nullptr;
|
||||
size_t curSegSizeCommitted = 0;
|
||||
|
@ -119,6 +138,35 @@ Object* FrozenObjectHeapManager::TryAllocateObject(PTR_MethodTable type, size_t
|
|||
#endif // !FEATURE_BASICFREEZE
|
||||
}
|
||||
|
||||
static void* ReserveMemory(size_t size)
|
||||
{
|
||||
#if defined(TARGET_X86) || defined(TARGET_AMD64)
|
||||
// We have plenty of space in-range on X86/AMD64 so we can afford keeping
|
||||
// FOH segments there so e.g. JIT can use relocs for frozen objects.
|
||||
return ExecutableAllocator::Instance()->Reserve(size);
|
||||
#else
|
||||
return ClrVirtualAlloc(nullptr, size, MEM_RESERVE, PAGE_READWRITE);
|
||||
#endif
|
||||
}
|
||||
|
||||
static void* CommitMemory(void* ptr, size_t size)
|
||||
{
|
||||
#if defined(TARGET_X86) || defined(TARGET_AMD64)
|
||||
return ExecutableAllocator::Instance()->Commit(ptr, size, /*isExecutable*/ false);
|
||||
#else
|
||||
return ClrVirtualAlloc(ptr, size, MEM_COMMIT, PAGE_READWRITE);
|
||||
#endif
|
||||
}
|
||||
|
||||
static void ReleaseMemory(void* ptr)
|
||||
{
|
||||
#if defined(TARGET_X86) || defined(TARGET_AMD64)
|
||||
ExecutableAllocator::Instance()->Release(ptr);
|
||||
#else
|
||||
ClrVirtualFree(ptr, 0, MEM_RELEASE);
|
||||
#endif
|
||||
}
|
||||
|
||||
// Reserve sizeHint bytes of memory for the given frozen segment.
|
||||
// The requested size can be be ignored in case of memory pressure and FOH_SEGMENT_DEFAULT_SIZE is used instead.
|
||||
FrozenObjectSegment::FrozenObjectSegment(size_t sizeHint) :
|
||||
|
@ -132,7 +180,7 @@ FrozenObjectSegment::FrozenObjectSegment(size_t sizeHint) :
|
|||
_ASSERT(m_Size > FOH_COMMIT_SIZE);
|
||||
_ASSERT(m_Size % FOH_COMMIT_SIZE == 0);
|
||||
|
||||
void* alloc = ClrVirtualAlloc(nullptr, m_Size, MEM_RESERVE, PAGE_READWRITE);
|
||||
void* alloc = ReserveMemory(m_Size);
|
||||
if (alloc == nullptr)
|
||||
{
|
||||
// Try again with the default FOH size
|
||||
|
@ -141,7 +189,7 @@ FrozenObjectSegment::FrozenObjectSegment(size_t sizeHint) :
|
|||
m_Size = FOH_SEGMENT_DEFAULT_SIZE;
|
||||
_ASSERT(m_Size > FOH_COMMIT_SIZE);
|
||||
_ASSERT(m_Size % FOH_COMMIT_SIZE == 0);
|
||||
alloc = ClrVirtualAlloc(nullptr, m_Size, MEM_RESERVE, PAGE_READWRITE);
|
||||
alloc = ReserveMemory(m_Size);
|
||||
}
|
||||
|
||||
if (alloc == nullptr)
|
||||
|
@ -151,10 +199,10 @@ FrozenObjectSegment::FrozenObjectSegment(size_t sizeHint) :
|
|||
}
|
||||
|
||||
// Commit a chunk in advance
|
||||
void* committedAlloc = ClrVirtualAlloc(alloc, FOH_COMMIT_SIZE, MEM_COMMIT, PAGE_READWRITE);
|
||||
void* committedAlloc = CommitMemory(alloc, FOH_COMMIT_SIZE);
|
||||
if (committedAlloc == nullptr)
|
||||
{
|
||||
ClrVirtualFree(alloc, 0, MEM_RELEASE);
|
||||
ReleaseMemory(alloc);
|
||||
ThrowOutOfMemory();
|
||||
}
|
||||
|
||||
|
@ -236,7 +284,7 @@ Object* FrozenObjectSegment::TryAllocateObject(PTR_MethodTable type, size_t obje
|
|||
// Make sure we don't go out of bounds during this commit
|
||||
_ASSERT(m_SizeCommitted + FOH_COMMIT_SIZE <= m_Size);
|
||||
|
||||
if (ClrVirtualAlloc(m_pStart + m_SizeCommitted, FOH_COMMIT_SIZE, MEM_COMMIT, PAGE_READWRITE) == nullptr)
|
||||
if (CommitMemory(m_pStart + m_SizeCommitted, FOH_COMMIT_SIZE) == nullptr)
|
||||
{
|
||||
ThrowOutOfMemory();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue