From 1e528c865ab4f2288afefde1dd4f5876d6be74fa Mon Sep 17 00:00:00 2001 From: Jan Vorlicek Date: Tue, 12 Jan 2016 18:59:14 +0100 Subject: [PATCH] Fix few details in the GC - For Unix, the definition of __forceinline was missing the inline - Allocation of GCThreadStubParams was missing a check for failure - Removed few unnecessary #ifdefs for FEATURE_PAL from the GC sample - Removed several obsolete functions from the GC sample --- src/gc/env/gcenv.base.h | 2 +- src/gc/sample/gcenv.unix.cpp | 150 -------------------------------- src/gc/sample/gcenv.windows.cpp | 9 +- src/vm/gcenv.os.cpp | 9 +- 4 files changed, 15 insertions(+), 155 deletions(-) diff --git a/src/gc/env/gcenv.base.h b/src/gc/env/gcenv.base.h index 791648fe8ad5..fdfa0fc5ebdc 100644 --- a/src/gc/env/gcenv.base.h +++ b/src/gc/env/gcenv.base.h @@ -19,7 +19,7 @@ #ifndef _MSC_VER #define __stdcall #ifdef __clang__ -#define __forceinline __attribute__((always_inline)) +#define __forceinline __attribute__((always_inline)) inline #else // __clang__ #define __forceinline inline #endif // __clang__ diff --git a/src/gc/sample/gcenv.unix.cpp b/src/gc/sample/gcenv.unix.cpp index 33d9bd649c55..f3c502c78c58 100644 --- a/src/gc/sample/gcenv.unix.cpp +++ b/src/gc/sample/gcenv.unix.cpp @@ -81,40 +81,6 @@ void UnsafeDeleteCriticalSection(CRITICAL_SECTION *lpCriticalSection) pthread_mutex_destroy(&lpCriticalSection->mutex); } - -void GetProcessMemoryLoad(GCMemoryStatus* pGCMemStatus) -{ - CONTRACTL - { - NOTHROW; - GC_NOTRIGGER; - } - CONTRACTL_END; - - pGCMemStatus->dwMemoryLoad = 0; - pGCMemStatus->ullTotalPageFile = 0; - pGCMemStatus->ullAvailPageFile = 0; - - // There is no API to get the total virtual address space size on - // Unix, so we use a constant value representing 128TB, which is - // the approximate size of total user virtual address space on - // the currently supported Unix systems. - static const uint64_t _128TB = (1ull << 47); - pGCMemStatus->ullTotalVirtual = _128TB; - pGCMemStatus->ullAvailVirtual = _128TB; - - // TODO: Implement - pGCMemStatus->ullTotalPhys = _128TB; - pGCMemStatus->ullAvailPhys = _128TB; - - // If the machine has more RAM than virtual address limit, let us cap it. - // Our GC can never use more than virtual address limit. - if (pGCMemStatus->ullAvailPhys > pGCMemStatus->ullTotalVirtual) - { - pGCMemStatus->ullAvailPhys = pGCMemStatus->ullAvailVirtual; - } -} - #if 0 void CLREventStatic::CreateManualEvent(bool bInitialState) { @@ -209,15 +175,6 @@ bool __SwitchToThread(uint32_t dwSleepMSec, uint32_t dwSwitchCount) return sched_yield() == 0; } -void * ClrVirtualAlloc( - void * lpAddress, - size_t dwSize, - uint32_t flAllocationType, - uint32_t flProtect) -{ - return ClrVirtualAllocAligned(lpAddress, dwSize, flAllocationType, flProtect, OS_PAGE_SIZE); -} - static int W32toUnixAccessControl(uint32_t flProtect) { int prot = 0; @@ -237,87 +194,6 @@ static int W32toUnixAccessControl(uint32_t flProtect) return prot; } -void * ClrVirtualAllocAligned( - void * lpAddress, - size_t dwSize, - uint32_t flAllocationType, - uint32_t flProtect, - size_t dwAlignment) -{ - if ((flAllocationType & ~(MEM_RESERVE | MEM_COMMIT)) != 0) - { - // TODO: Implement - return NULL; - } - - _ASSERTE(((size_t)lpAddress & (OS_PAGE_SIZE - 1)) == 0); - - // Align size to whole pages - dwSize = (dwSize + (OS_PAGE_SIZE - 1)) & ~(OS_PAGE_SIZE - 1); - - if (flAllocationType & MEM_RESERVE) - { - size_t alignedSize = dwSize; - - if (dwAlignment > OS_PAGE_SIZE) - alignedSize += (dwAlignment - OS_PAGE_SIZE); - - void * pRetVal = mmap(lpAddress, alignedSize, W32toUnixAccessControl(flProtect), - MAP_ANON | MAP_PRIVATE, -1, 0); - - if (dwAlignment > OS_PAGE_SIZE && pRetVal != NULL) - { - void * pAlignedRetVal = (void *)(((size_t)pRetVal + (dwAlignment - 1)) & ~(dwAlignment - 1)); - - size_t startPadding = (size_t)pAlignedRetVal - (size_t)pRetVal; - if (startPadding != 0) - { - int ret = munmap(pRetVal, startPadding); - _ASSERTE(ret == 0); - } - - size_t endPadding = alignedSize - (startPadding + dwSize); - if (endPadding != 0) - { - int ret = munmap((void *)((size_t)pAlignedRetVal + dwSize), endPadding); - _ASSERTE(ret == 0); - } - - pRetVal = pAlignedRetVal; - } - - return pRetVal; - } - - if (flAllocationType & MEM_COMMIT) - { - int ret = mprotect(lpAddress, dwSize, W32toUnixAccessControl(flProtect)); - return (ret == 0) ? lpAddress : NULL; - } - - return NULL; -} - -bool ClrVirtualFree( - void * lpAddress, - size_t dwSize, - uint32_t dwFreeType) -{ - // TODO: Implement - return false; -} - -bool -ClrVirtualProtect( - void * lpAddress, - size_t dwSize, - uint32_t flNewProtect, - uint32_t * lpflOldProtect) -{ - // TODO: Implement, not currently used - return false; -} - MethodTable * g_pFreeObjectMethodTable; GCSystemInfo g_SystemInfo; @@ -469,19 +345,6 @@ ResetWriteWatch( return 1; } -WINBASEAPI -BOOL -WINAPI -VirtualUnlock( - LPVOID lpAddress, - SIZE_T dwSize - ) -{ - // TODO: Implement - return false; -} - - const int tccSecondsToMillieSeconds = 1000; const int tccSecondsToMicroSeconds = 1000000; const int tccMillieSecondsToMicroSeconds = 1000; // 10^3 @@ -563,19 +426,6 @@ MemoryBarrier() // File I/O - Used for tracking only -WINBASEAPI -DWORD -WINAPI -SetFilePointer( - HANDLE hFile, - int32_t lDistanceToMove, - int32_t * lpDistanceToMoveHigh, - DWORD dwMoveMethod) -{ - // TODO: Reimplement callers using CRT - return 0; -} - WINBASEAPI BOOL WINAPI diff --git a/src/gc/sample/gcenv.windows.cpp b/src/gc/sample/gcenv.windows.cpp index 6fbc21ab14b0..bce8496fdaf3 100644 --- a/src/gc/sample/gcenv.windows.cpp +++ b/src/gc/sample/gcenv.windows.cpp @@ -77,7 +77,7 @@ bool GCToOSInterface::SetCurrentThreadIdealAffinity(GCThreadAffinity* affinity) #if !defined(FEATURE_CORESYSTEM) SetThreadIdealProcessor(GetCurrentThread(), (DWORD)affinity->Processor); -#elif !defined(FEATURE_PAL) +#else PROCESSOR_NUMBER proc; if (affinity->Group != -1) @@ -207,13 +207,11 @@ bool GCToOSInterface::VirtualDecommit(void* address, size_t size) bool GCToOSInterface::VirtualReset(void * address, size_t size, bool unlock) { bool success = ::VirtualAlloc(address, size, MEM_RESET, PAGE_READWRITE) != NULL; -#ifndef FEATURE_PAL if (success && unlock) { // Remove the page range from the working set ::VirtualUnlock(address, size); } -#endif // FEATURE_PAL return success; } @@ -391,6 +389,11 @@ bool GCToOSInterface::CreateThread(GCThreadFunction function, void* param, GCThr DWORD thread_id; GCThreadStubParam* stubParam = new (nothrow) GCThreadStubParam(); + if (stubParam == NULL) + { + return false; + } + stubParam->GCThreadFunction = function; stubParam->GCThreadParam = param; diff --git a/src/vm/gcenv.os.cpp b/src/vm/gcenv.os.cpp index 6d72cee3bd53..20fb179fe8b5 100644 --- a/src/vm/gcenv.os.cpp +++ b/src/vm/gcenv.os.cpp @@ -439,7 +439,12 @@ bool GCToOSInterface::CreateThread(GCThreadFunction function, void* param, GCThr uint32_t thread_id; - GCThreadStubParam* stubParam = new (nothrow) GCThreadStubParam(); + NewHolder stubParam = new (nothrow) GCThreadStubParam(); + if (stubParam == NULL) + { + return false; + } + stubParam->GCThreadFunction = function; stubParam->GCThreadParam = param; @@ -450,6 +455,8 @@ bool GCToOSInterface::CreateThread(GCThreadFunction function, void* param, GCThr return false; } + stubParam.SuppressRelease(); + SetThreadPriority(gc_thread, /* THREAD_PRIORITY_ABOVE_NORMAL );*/ THREAD_PRIORITY_HIGHEST ); #ifndef FEATURE_CORECLR