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

Commit 603cce1

Browse files
committed
Hello World now works
1 parent 86b01c7 commit 603cce1

File tree

5 files changed

+18
-46
lines changed

5 files changed

+18
-46
lines changed

src/gc/env/gcenv.os.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -204,13 +204,12 @@ class GCToOSInterface
204204
// true if it has succeeded, false if it has failed
205205
static bool VirtualCommit(void *address, size_t size, uint32_t node = NUMA_NODE_UNDEFINED);
206206

207-
// Commit virtual memory range. It must be part of a range reserved using VirtualReserve.
207+
// Reserve and Commit virtual memory range for Large Pages
208208
// Parameters:
209-
// address - starting virtual address
210209
// size - size of the virtual memory range
211210
// Return:
212-
// true if it has succeeded, false if it has failed
213-
static void* VirtualReserveAndCommitLargePages(size_t size, uint32_t node = NUMA_NODE_UNDEFINED);
211+
// Address of the allocated memory
212+
static void* VirtualReserveAndCommitLargePages(size_t size);
214213

215214
// Decomit virtual memory range.
216215
// Parameters:

src/gc/gc.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4504,7 +4504,7 @@ void* virtual_alloc (size_t size, bool use_large_pages_p)
45044504
}
45054505
#endif // !FEATURE_USE_SOFTWARE_WRITE_WATCH_FOR_GC_HEAP
45064506

4507-
void* prgmem = use_large_pages_p ? GCToOSInterface::VirtualReserveAndCommitLargePages(requested_size, card_size * card_word_width) : GCToOSInterface::VirtualReserve(requested_size, card_size * card_word_width, flags);
4507+
void* prgmem = use_large_pages_p ? GCToOSInterface::VirtualReserveAndCommitLargePages(requested_size) : GCToOSInterface::VirtualReserve(requested_size, card_size * card_word_width, flags);
45084508
void *aligned_mem = prgmem;
45094509

45104510
// We don't want (prgmem + size) to be right at the end of the address space
@@ -5562,10 +5562,8 @@ bool gc_heap::virtual_commit (void* address, size_t size, int h_number, bool* ha
55625562
}
55635563
}
55645564

5565-
// If it's a valid heap number it means it's commiting for memory on the GC heap.
5566-
bool commit_succeeded_p = ((h_number >= 0) ?
5567-
virtual_alloc_commit_for_heap (address, size, h_number) :
5568-
GCToOSInterface::VirtualCommit(address, size));
5565+
// If it's a valid heap number it means it's commiting for memory on the GC heap. In addition if large pages is enabled, we set commit_succeeded_p to true because memory is already committed.
5566+
bool commit_succeeded_p = ((h_number >= 0) ? (use_large_pages_p ? true : virtual_alloc_commit_for_heap (address, size, h_number)) : GCToOSInterface::VirtualCommit(address, size));
55695567

55705568
if (!commit_succeeded_p && heap_hard_limit)
55715569
{

src/gc/unix/gcenv.unix.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ void GCToOSInterface::YieldThread(uint32_t switchCount)
271271
// flags - flags to control special settings like write watching
272272
// Return:
273273
// Starting virtual address of the reserved range
274-
static VirtualReserveInner(size_t size, size_t alignment, uint32_t flags, uint32_t hugePagesFlag = 0)
274+
static void* VirtualReserveInner(size_t size, size_t alignment, uint32_t flags, uint32_t hugePagesFlag = 0)
275275
{
276276
assert(!(flags & VirtualReserveFlags::WriteWatch) && "WriteWatch not supported on Unix");
277277
if (alignment == 0)
@@ -333,15 +333,12 @@ bool GCToOSInterface::VirtualRelease(void* address, size_t size)
333333
// Commit virtual memory range.
334334
// Parameters:
335335
// size - size of the virtual memory range
336-
// alignment - requested memory alignment, 0 means no specific alignment requested
337-
// flags - flags to control special settings like write watching
338-
// node - NUMA node
339336
// Return:
340337
// Starting virtual address of the committed range
341-
void* GCToOSInterface::VirtualReserveAndCommitLargePages(size_t size, uint32_t node)
338+
void* GCToOSInterface::VirtualReserveAndCommitLargePages(size_t size)
342339
{
343-
void* pRetVal = VirtualReserveInner(size, alignment, 0, MAP_HUGETLB);
344-
if (VirtualCommit(pRetVal, size, node))
340+
void* pRetVal = VirtualReserveInner(size, OS_PAGE_SIZE, 0, MAP_HUGETLB);
341+
if (VirtualCommit(pRetVal, size, NUMA_NODE_UNDEFINED))
345342
{
346343
return pRetVal;
347344
}

src/gc/windows/gcenv.windows.cpp

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -111,14 +111,15 @@ bool InitLargePagesPrivilege()
111111
}
112112

113113
auto retVal = AdjustTokenPrivileges(token, FALSE, &tp, 0, nullptr, 0);
114+
auto gls = GetLastError();
114115
CloseHandle(token);
115116

116117
if (!retVal)
117118
{
118119
return false;
119120
}
120121

121-
if (GetLastError() != 0)
122+
if (gls != 0)
122123
{
123124
return false;
124125
}
@@ -639,12 +640,9 @@ bool GCToOSInterface::VirtualRelease(void* address, size_t size)
639640
// Commit virtual memory range.
640641
// Parameters:
641642
// size - size of the virtual memory range
642-
// alignment - requested memory alignment, 0 means no specific alignment requested
643-
// flags - flags to control special settings like write watching
644-
// node - NUMA node
645643
// Return:
646644
// Starting virtual address of the committed range
647-
void* GCToOSInterface::VirtualReserveAndCommitLargePages(size_t size, uint32_t node)
645+
void* GCToOSInterface::VirtualReserveAndCommitLargePages(size_t size)
648646
{
649647
void* pRetVal = nullptr;
650648

@@ -661,17 +659,7 @@ void* GCToOSInterface::VirtualReserveAndCommitLargePages(size_t size, uint32_t n
661659
auto largePageMinimum = GetLargePageMinimum();
662660
size = (size + (largePageMinimum - 1)) & ~(largePageMinimum - 1);
663661

664-
if (node == NUMA_NODE_UNDEFINED)
665-
{
666-
pRetVal = ::VirtualAlloc(nullptr, size, MEM_RESERVE | MEM_COMMIT | MEM_LARGE_PAGES, PAGE_READWRITE);
667-
}
668-
else
669-
{
670-
assert(g_fEnableGCNumaAware);
671-
pRetVal = ::VirtualAllocExNuma(::GetCurrentProcess(), nullptr, size, MEM_RESERVE | MEM_COMMIT | MEM_LARGE_PAGES, PAGE_READWRITE, node);
672-
}
673-
674-
return pRetVal;
662+
return ::VirtualAlloc(nullptr, size, MEM_RESERVE | MEM_COMMIT | MEM_LARGE_PAGES, PAGE_READWRITE);
675663
}
676664

677665
// Commit virtual memory range. It must be part of a range reserved using VirtualReserve.

src/vm/gcenv.os.cpp

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,15 @@ bool InitLargePagesPrivilege()
5454
}
5555

5656
auto retVal = AdjustTokenPrivileges(token, FALSE, &tp, 0, nullptr, 0);
57+
auto gls = GetLastError();
5758
CloseHandle(token);
5859

5960
if (!retVal)
6061
{
6162
return false;
6263
}
6364

64-
if (GetLastError() != 0)
65+
if (gls != 0)
6566
{
6667
return false;
6768
}
@@ -248,10 +249,9 @@ bool GCToOSInterface::VirtualRelease(void* address, size_t size)
248249
// Commit virtual memory range.
249250
// Parameters:
250251
// size - size of the virtual memory range
251-
// node - NUMA node
252252
// Return:
253253
// Starting virtual address of the committed range
254-
void* GCToOSInterface::VirtualReserveAndCommitLargePages(size_t size, uint32_t node)
254+
void* GCToOSInterface::VirtualReserveAndCommitLargePages(size_t size)
255255
{
256256
LIMITED_METHOD_CONTRACT;
257257

@@ -270,17 +270,7 @@ void* GCToOSInterface::VirtualReserveAndCommitLargePages(size_t size, uint32_t n
270270
size = (size + (largePageMinimum - 1)) & ~(largePageMinimum - 1);
271271
#endif
272272

273-
void* pRetVal = nullptr;
274-
if (node == NUMA_NODE_UNDEFINED)
275-
{
276-
pRetVal = ::ClrVirtualAlloc(nullptr, size, MEM_RESERVE | MEM_COMMIT | MEM_LARGE_PAGES, PAGE_READWRITE);
277-
}
278-
else
279-
{
280-
pRetVal = NumaNodeInfo::VirtualAllocExNuma(::GetCurrentProcess(), nullptr, size, MEM_RESERVE | MEM_COMMIT | MEM_LARGE_PAGES, PAGE_READWRITE, node);
281-
}
282-
283-
return pRetVal;
273+
return ::ClrVirtualAlloc(nullptr, size, MEM_RESERVE | MEM_COMMIT | MEM_LARGE_PAGES, PAGE_READWRITE);
284274
}
285275

286276
// Commit virtual memory range. It must be part of a range reserved using VirtualReserve.

0 commit comments

Comments
 (0)