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

Commit

Permalink
Update GC from CoreRT
Browse files Browse the repository at this point in the history
  • Loading branch information
jkotas committed Jan 26, 2016
1 parent 82e5fba commit 0462be1
Show file tree
Hide file tree
Showing 17 changed files with 68 additions and 102 deletions.
1 change: 1 addition & 0 deletions src/gc/env/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <stdint.h>
#include <stddef.h>
#include <stdio.h>
#include <string.h>
#include <wchar.h>
#include <assert.h>
#include <stdarg.h>
Expand Down
59 changes: 24 additions & 35 deletions src/gc/env/gcenv.base.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,6 @@
typedef uint32_t BOOL;
typedef uint32_t DWORD;
typedef void* LPVOID;
typedef uint32_t UINT;
typedef int32_t LONG;
typedef uintptr_t ULONG_PTR;
typedef void VOID;
typedef void* PVOID;
typedef void * LPSECURITY_ATTRIBUTES;
typedef void const * LPCVOID;
typedef wchar_t * PWSTR, *LPWSTR;
typedef const wchar_t *LPCWSTR, *PCWSTR;
typedef size_t SIZE_T;

typedef void * HANDLE;

// -----------------------------------------------------------------------------------------------------------
// HRESULT subset.
Expand Down Expand Up @@ -105,14 +93,24 @@ inline HRESULT HRESULT_FROM_WIN32(unsigned long x)

#define UNREFERENCED_PARAMETER(P) (void)(P)

#define INVALID_HANDLE_VALUE ((HANDLE)-1)

#ifdef PLATFORM_UNIX
#define _vsnprintf vsnprintf
#define sprintf_s snprintf
#define swprintf_s swprintf
#endif

#ifdef UNICODE
#define _tcslen wcslen
#define _tcscpy wcscpy
#define _stprintf_s swprintf_s
#define _tfopen _wfopen
#else
#define _tcslen strlen
#define _tcscpy strcpy
#define _stprintf_s sprintf_s
#define _tfopen fopen
#endif

#define WINAPI __stdcall

typedef DWORD (WINAPI *PTHREAD_START_ROUTINE)(void* lpThreadParameter);
Expand All @@ -123,12 +121,12 @@ typedef DWORD (WINAPI *PTHREAD_START_ROUTINE)(void* lpThreadParameter);

#if defined(_MSC_VER)
#if defined(_ARM_)

__forceinline void YieldProcessor() { }
extern "C" void __emit(const unsigned __int32 opcode);
#pragma intrinsic(__emit)
#define MemoryBarrier() { __emit(0xF3BF); __emit(0x8F5F); }

#elif defined(_ARM64_)

extern "C" void __yield(void);
Expand All @@ -141,34 +139,34 @@ typedef DWORD (WINAPI *PTHREAD_START_ROUTINE)(void* lpThreadParameter);

#elif defined(_AMD64_)

extern "C" VOID
extern "C" void
_mm_pause (
VOID
void
);

extern "C" VOID
extern "C" void
_mm_mfence (
VOID
void
);

#pragma intrinsic(_mm_pause)
#pragma intrinsic(_mm_mfence)

#define YieldProcessor _mm_pause
#define MemoryBarrier _mm_mfence

#elif defined(_X86_)

#define YieldProcessor() __asm { rep nop }

__forceinline void MemoryBarrier()
{
int32_t Barrier;
__asm {
xchg Barrier, eax
}
}

#else // !_ARM_ && !_AMD64_ && !_X86_
#error Unsupported architecture
#endif
Expand Down Expand Up @@ -465,15 +463,6 @@ class FinalizerThread
#ifdef FEATURE_REDHAWK
typedef uint32_t (__stdcall *BackgroundCallback)(void* pCallbackContext);
REDHAWK_PALIMPORT bool REDHAWK_PALAPI PalStartBackgroundGCThread(BackgroundCallback callback, void* pCallbackContext);

enum PalCapability
{
WriteWatchCapability = 0x00000001, // GetWriteWatch() and friends
LowMemoryNotificationCapability = 0x00000002, // CreateMemoryResourceNotification() and friends
GetCurrentProcessorNumberCapability = 0x00000004, // GetCurrentProcessorNumber()
};

REDHAWK_PALIMPORT bool REDHAWK_PALAPI PalHasCapability(PalCapability capability);
#endif // FEATURE_REDHAWK

void DestroyThread(Thread * pThread);
Expand Down Expand Up @@ -530,7 +519,7 @@ namespace ETW

#define LOG(x)

VOID LogSpewAlways(const char *fmt, ...);
void LogSpewAlways(const char *fmt, ...);

#define LL_INFO10 4

Expand Down Expand Up @@ -581,7 +570,7 @@ class CLRConfig
typedef CLRConfigTypes ConfigStringInfo;

static uint32_t GetConfigValue(ConfigDWORDInfo eType);
static HRESULT GetConfigValue(ConfigStringInfo /*eType*/, wchar_t * * outVal);
static HRESULT GetConfigValue(ConfigStringInfo /*eType*/, TCHAR * * outVal);
};

inline bool FitsInU1(uint64_t val)
Expand Down
4 changes: 2 additions & 2 deletions src/gc/env/gcenv.interlocked.inl
Original file line number Diff line number Diff line change
Expand Up @@ -188,12 +188,12 @@ __forceinline T Interlocked::CompareExchangePointer(T volatile *destination, T e
{
#ifdef _MSC_VER
#ifdef BIT64
return (T)(TADDR)_InterlockedCompareExchangePointer((void* volatile *)destination, exchange, comparand);
return (T)(TADDR)_InterlockedCompareExchangePointer((void* volatile *)destination, (void*)exchange, (void*)comparand);
#else
return (T)(TADDR)_InterlockedCompareExchange((long volatile *)(void* volatile *)destination, (long)(void*)exchange, (long)(void*)comparand);
#endif
#else
return (T)(TADDR)__sync_val_compare_and_swap((void* volatile *)destination, comparand, exchange);
return (T)(TADDR)__sync_val_compare_and_swap((void* volatile *)destination, (void*)comparand, (void*)exchange);
#endif
}

Expand Down
12 changes: 0 additions & 12 deletions src/gc/env/gcenv.os.h
Original file line number Diff line number Diff line change
Expand Up @@ -257,18 +257,6 @@ class GCToOSInterface
// Return:
// Time stamp in milliseconds
static uint32_t GetLowPrecisionTimeStamp();

//
// File
//

// Open a file
// Parameters:
// filename - name of the file to open
// mode - mode to open the file in (like in the CRT fopen)
// Return:
// FILE* of the opened file
static FILE* OpenFile(const WCHAR* filename, const WCHAR* mode);
};

#endif // __GCENV_OS_H__
16 changes: 15 additions & 1 deletion src/gc/env/gcenv.structs.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,20 @@ typedef void * HANDLE;

#ifdef PLATFORM_UNIX

typedef char TCHAR;
#define _T(s) s

#else

#ifndef _INC_WINDOWS
typedef wchar_t TCHAR;
#define _T(s) L##s
#endif

#endif

#ifdef PLATFORM_UNIX

class EEThreadId
{
pthread_t m_id;
Expand Down Expand Up @@ -76,7 +90,7 @@ class EEThreadId

void SetToCurrentThread()
{
m_uiId = ::GetCurrentThreadId();
m_uiId = ::GetCurrentThreadId();
}

void Clear()
Expand Down
22 changes: 11 additions & 11 deletions src/gc/gc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ size_t GetHighPrecisionTimeStamp()
GCStatistics g_GCStatistics;
GCStatistics g_LastGCStatistics;

WCHAR* GCStatistics::logFileName = NULL;
TCHAR* GCStatistics::logFileName = NULL;
FILE* GCStatistics::logFile = NULL;

void GCStatistics::AddGCStats(const gc_mechanisms& settings, size_t timeInMSec)
Expand Down Expand Up @@ -9507,21 +9507,22 @@ void gc_heap::adjust_ephemeral_limits ()
FILE* CreateLogFile(const CLRConfig::ConfigStringInfo & info, BOOL is_config)
{
FILE* logFile;
LPWSTR temp_logfile_name = NULL;
TCHAR * temp_logfile_name = NULL;
CLRConfig::GetConfigValue(info, &temp_logfile_name);

WCHAR logfile_name[MAX_LONGPATH+1];
TCHAR logfile_name[MAX_LONGPATH+1];
if (temp_logfile_name != 0)
{
wcscpy(logfile_name, temp_logfile_name);
_tcscpy(logfile_name, temp_logfile_name);
}

size_t logfile_name_len = wcslen(logfile_name);
WCHAR* szPid = logfile_name + logfile_name_len;
size_t logfile_name_len = _tcslen(logfile_name);
TCHAR* szPid = logfile_name + logfile_name_len;
size_t remaining_space = MAX_LONGPATH + 1 - logfile_name_len;
swprintf_s(szPid, remaining_space, W(".%d%s"), GCToOSInterface::GetCurrentProcessId(), (is_config ? W(".config.log") : W(".log")));

logFile = GCToOSInterface::OpenFile(logfile_name, W("wb"));
_stprintf_s(szPid, remaining_space, _T(".%d%s"), GCToOSInterface::GetCurrentProcessId(), (is_config ? _T(".config.log") : _T(".log")));

logFile = _tfopen(logfile_name, _T("wb"));

delete temp_logfile_name;

Expand Down Expand Up @@ -9614,9 +9615,8 @@ HRESULT gc_heap::initialize_gc (size_t segment_size,
GCStatistics::logFileName = CLRConfig::GetConfigValue(CLRConfig::UNSUPPORTED_GCMixLog);
if (GCStatistics::logFileName != NULL)
{
GCStatistics::logFile = GCToOSInterface::OpenFile((LPCWSTR)GCStatistics::logFileName, W("a"));
GCStatistics::logFile = _tfopen(GCStatistics::logFileName, _T("a"));
}

#endif // GC_STATS

HRESULT hres = S_OK;
Expand Down Expand Up @@ -14567,7 +14567,7 @@ int gc_heap::generation_to_condemn (int n_initial,
// Need to get it early enough for all heaps to use.
available_physical_mem = ms.ullAvailPhys;
local_settings->entry_memory_load = ms.dwMemoryLoad;

// @TODO: Force compaction more often under GCSTRESS
if (ms.dwMemoryLoad >= high_memory_load_th || low_memory_detected)
{
Expand Down
2 changes: 1 addition & 1 deletion src/gc/gcee.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ BOOL ProfilerShouldTrackConditionalWeakTableElements() {
#if defined(GC_PROFILING)
return CORProfilerTrackConditionalWeakTableElements();
#else
return FALSE;
return FALSE;
#endif // defined (GC_PROFILING)
}

Expand Down
2 changes: 1 addition & 1 deletion src/gc/gcpriv.h
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,7 @@ struct GCStatistics
: public StatisticsBase
{
// initialized to the contents of COMPLUS_GcMixLog, or NULL, if not present
static WCHAR* logFileName;
static TCHAR* logFileName;
static FILE* logFile;

// number of times we executed a background GC, a foreground GC, or a
Expand Down
2 changes: 1 addition & 1 deletion src/gc/handletable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ void ValidateFetchObjrefForHandle(OBJECTREF objref, ADIndex appDomainIndex)
_ASSERTE(!pDomain->NoAccessToHandleTable());

#if CHECK_APP_DOMAIN_LEAKS
if (g_pConfig->AppDomainLeaks() && objref != NULL)
if (g_pConfig->AppDomainLeaks() && objref != NULL)
{
if (appDomainIndex.m_dwIndex)
objref->TryAssignAppDomain(pDomain);
Expand Down
1 change: 1 addition & 0 deletions src/gc/sample/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ set(SOURCES
if(WIN32)
list(APPEND SOURCES
gcenv.windows.cpp)
add_definitions(-DUNICODE=1)
else()
list(APPEND SOURCES
gcenv.unix.cpp)
Expand Down
4 changes: 2 additions & 2 deletions src/gc/sample/gcenv.ee.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ void StompWriteBarrierResize(bool /*bReqUpperBoundsCheck*/)
{
}

VOID LogSpewAlways(const char * /*fmt*/, ...)
void LogSpewAlways(const char * /*fmt*/, ...)
{
}

Expand Down Expand Up @@ -282,7 +282,7 @@ uint32_t CLRConfig::GetConfigValue(ConfigDWORDInfo eType)
}
}

HRESULT CLRConfig::GetConfigValue(ConfigStringInfo /*eType*/, wchar_t * * outVal)
HRESULT CLRConfig::GetConfigValue(ConfigStringInfo /*eType*/, TCHAR * * outVal)
{
*outVal = NULL;
return 0;
Expand Down
3 changes: 0 additions & 3 deletions src/gc/sample/gcenv.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@
#define _ASSERTE(_expr) ASSERT(_expr)
#endif

typedef wchar_t WCHAR;
#define W(s) L##s

#include "gcenv.structs.h"
#include "gcenv.base.h"
#include "gcenv.ee.h"
Expand Down
6 changes: 0 additions & 6 deletions src/gc/sample/gcenv.unix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -307,12 +307,6 @@ bool IsGCSpecialThread()

#endif // 0

bool PalHasCapability(PalCapability capability)
{
// TODO: Implement for background GC
return false;
}

WINBASEAPI
UINT
WINAPI
Expand Down
15 changes: 2 additions & 13 deletions src/gc/sample/gcenv.windows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ bool GCToOSInterface::SetCurrentThreadIdealAffinity(GCThreadAffinity* affinity)
proc.Group = (WORD)affinity->Group;
proc.Number = (BYTE)affinity->Processor;
proc.Reserved = 0;

success = !!SetThreadIdealProcessorEx(GetCurrentThread(), &proc, NULL);
}
else
Expand All @@ -94,7 +94,7 @@ bool GCToOSInterface::SetCurrentThreadIdealAffinity(GCThreadAffinity* affinity)
{
proc.Number = affinity->Processor;
success = !!SetThreadIdealProcessorEx(GetCurrentThread(), &proc, NULL);
}
}
}
#endif

Expand Down Expand Up @@ -414,17 +414,6 @@ bool GCToOSInterface::CreateThread(GCThreadFunction function, void* param, GCThr
return true;
}

// Open a file
// Parameters:
// filename - name of the file to open
// mode - mode to open the file in (like in the CRT fopen)
// Return:
// FILE* of the opened file
FILE* GCToOSInterface::OpenFile(const WCHAR* filename, const WCHAR* mode)
{
return _wfopen(filename, mode);
}

// Initialize the critical section
void CLRCriticalSection::Initialize()
{
Expand Down
2 changes: 1 addition & 1 deletion src/inc/winwrap.h
Original file line number Diff line number Diff line change
Expand Up @@ -721,7 +721,7 @@
#endif // FEATURE_CORESYSTEM

#ifndef _T
#define _T(str) L ## str
#define _T(str) W(str)
#endif


Expand Down
Loading

0 comments on commit 0462be1

Please sign in to comment.