Skip to content

Commit

Permalink
Merge pull request dotnet#1547 from jkotas/standalone-gc
Browse files Browse the repository at this point in the history
Initial port of GC sample to Linux
  • Loading branch information
jkotas committed Sep 14, 2015
2 parents 8b45ec0 + eeb7076 commit 98c63c1
Show file tree
Hide file tree
Showing 9 changed files with 767 additions and 19 deletions.
49 changes: 49 additions & 0 deletions src/gc/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
project(clrgc)

set(CMAKE_INCLUDE_CURRENT_DIR ON)

include_directories(env)

set(SOURCES
gccommon.cpp
gceewks.cpp
gcscan.cpp
gcwks.cpp
handletable.cpp
handletablecache.cpp
handletablecore.cpp
handletablescan.cpp
objecthandle.cpp
)

if(WIN32)
list(APPEND SOURCES
env/gcenv.windows.cpp)
else()
list(APPEND SOURCES
env/gcenv.unix.cpp)
endif()

if(CLR_CMAKE_PLATFORM_ARCH_AMD64)
add_definitions(-D_TARGET_AMD64_=1)
add_definitions(-D_WIN64=1)
elseif(CLR_CMAKE_PLATFORM_ARCH_I386)
add_definitions(-D_TARGET_X86_=1)
add_definitions(-D_WIN32=1)
elseif(CLR_CMAKE_PLATFORM_ARCH_ARM)
add_definitions(-D_TARGET_ARM_=1)
add_definitions(-D_WIN32=1)
elseif(CLR_CMAKE_PLATFORM_ARCH_ARM64)
add_definitions(-D_TARGET_ARM64_=1)
add_definitions(-D_WIN64=1)
else()
clr_unknown_arch()
endif()

add_compile_options(-Wno-format)
add_compile_options(-Wno-unused-variable)
add_compile_options(-Wno-unused-private-field)
add_compile_options(-Wno-tautological-undefined-compare)

add_library(clrgc STATIC ${SOURCES})

8 changes: 7 additions & 1 deletion src/gc/env/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,17 @@
#define _CRT_SECURE_NO_WARNINGS

#include <stdint.h>
#include <stddef.h>
#include <stdio.h>
#include <tchar.h>
#include <wchar.h>
#include <assert.h>
#include <stdarg.h>
#include <memory.h>

#include <new>

#ifndef WIN32
#include <pthread.h>
#endif

using namespace std;
58 changes: 51 additions & 7 deletions src/gc/env/gcenv.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@
#define FEATURE_REDHAWK 1
#define FEATURE_CONSERVATIVE_GC 1

#ifndef _MSC_VER
#define __stdcall
#define __forceinline inline
#endif

#ifndef _INC_WINDOWS

// -----------------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -99,7 +104,7 @@ inline HRESULT HRESULT_FROM_WIN32(unsigned long x)
#define E_INVALIDARG 0x80070057

#define NOERROR 0x0
#define ERROR_TIMEOUT 1460
#define ERROR_TIMEOUT 1460

#define TRUE true
#define FALSE false
Expand Down Expand Up @@ -129,6 +134,13 @@ inline HRESULT HRESULT_FROM_WIN32(unsigned long x)

#define INVALID_HANDLE_VALUE ((HANDLE)-1)

#ifndef WIN32
#define _vsnprintf vsnprintf
#define sprintf_s snprintf
#endif

#ifdef WIN32

#pragma pack(push, 8)

typedef struct _RTL_CRITICAL_SECTION {
Expand All @@ -148,6 +160,14 @@ typedef struct _RTL_CRITICAL_SECTION {

#pragma pack(pop)

#else

typedef struct _RTL_CRITICAL_SECTION {
pthread_mutex_t mutex;
} CRITICAL_SECTION, RTL_CRITICAL_SECTION, *PRTL_CRITICAL_SECTION;

#endif

typedef struct _MEMORYSTATUSEX {
DWORD dwLength;
DWORD dwMemoryLoad;
Expand All @@ -160,11 +180,11 @@ typedef struct _MEMORYSTATUSEX {
DWORDLONG ullAvailExtendedVirtual;
} MEMORYSTATUSEX, *LPMEMORYSTATUSEX;

typedef DWORD (__stdcall *PTHREAD_START_ROUTINE)(void* lpThreadParameter);

#define WINBASEAPI extern "C"
#define WINAPI __stdcall

typedef DWORD (WINAPI *PTHREAD_START_ROUTINE)(PVOID lpThreadParameter);

WINBASEAPI
void
WINAPI
Expand Down Expand Up @@ -271,14 +291,37 @@ WINAPI
FlushFileBuffers(
HANDLE hFile);

#ifdef _MSC_VER

extern "C" VOID
_mm_pause (
VOID
);

extern "C" VOID
_mm_mfence (
VOID
);

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

#define YieldProcessor _mm_pause
#define MemoryBarrier _mm_mfence

#else // _MSC_VER

WINBASEAPI
VOID
WINAPI
YieldProcessor();

WINBASEAPI
VOID
WINAPI
MemoryBarrier();

#endif // _MSC_VER

#endif // _INC_WINDOWS

Expand Down Expand Up @@ -1003,7 +1046,7 @@ class EEConfig
GCSTRESS_UNIQUE = 16, // GC only on a unique stack trace
};

int GetHeapVerifyLevel();
int GetHeapVerifyLevel() { return 0; }
bool IsHeapVerifyEnabled() { return GetHeapVerifyLevel() != 0; }

GCStressFlags GetGCStressLevel() const { return GCSTRESS_NONE; }
Expand Down Expand Up @@ -1066,7 +1109,9 @@ class CLRConfig

case Config_COUNT:
default:
#ifdef _MSC_VER
#pragma warning(suppress:4127) // Constant conditional expression in ASSERT below
#endif
ASSERT(!"Unknown config value type");
return 0;
}
Expand Down Expand Up @@ -1169,7 +1214,6 @@ class CLREventStatic
bool Set();
bool Reset();
uint32_t Wait(uint32_t dwMilliseconds, bool bAlertable);
HANDLE GetOSEvent();

private:
HANDLE m_hEvent;
Expand Down Expand Up @@ -1270,9 +1314,9 @@ class NewHolder
}
};

inline bool FitsInU1(unsigned __int64 val)
inline bool FitsInU1(uint64_t val)
{
return val == (unsigned __int64)(unsigned __int8)val;
return val == (uint64_t)(uint8_t)val;
}

// -----------------------------------------------------------------------------------------------------------
Expand Down
Loading

0 comments on commit 98c63c1

Please sign in to comment.