summaryrefslogtreecommitdiff
path: root/src/gc
diff options
context:
space:
mode:
authorSean Gillespie <segilles@microsoft.com>2017-05-17 15:07:34 -0700
committerSean Gillespie <segilles@microsoft.com>2017-06-01 10:19:59 -0700
commit1a183684b1ecf63ece8a2fd80173f083c0deea52 (patch)
tree907b31b417732768b28e80adfb4d920497f0d3f0 /src/gc
parentdde63bc1aa39aabae77fb89aad583483965c523e (diff)
downloadcoreclr-1a183684b1ecf63ece8a2fd80173f083c0deea52.tar.gz
coreclr-1a183684b1ecf63ece8a2fd80173f083c0deea52.tar.bz2
coreclr-1a183684b1ecf63ece8a2fd80173f083c0deea52.zip
[Local GC] Scaffolding for loading a standalone GC (#11242)
* Configure the build system to build a CoreCLR capable of loading a standalone GC * Proto-implementation of dynamic GC loading * Build the GC with the VM's CMakeLists when doing a non-standalone build of the GC * [Local GC] Introduce a new feature define, FEATURE_STANDALONE_GC_ONLY, to be used by the CI to explicitly test local GC dynamic loading code paths * Fix the FEATURE_STANDALONE_GC_ONLY build for unix linkers * Rebase against master * Code review feedback: use the existing Unix exports file
Diffstat (limited to 'src/gc')
-rw-r--r--src/gc/CMakeLists.txt42
-rw-r--r--src/gc/dac/CMakeLists.txt2
-rw-r--r--src/gc/gc.h7
-rw-r--r--src/gc/gccommon.cpp31
-rw-r--r--src/gc/gcenv.ee.standalone.inl9
-rw-r--r--src/gc/gcinterface.ee.h4
-rw-r--r--src/gc/gcinterface.h19
-rw-r--r--src/gc/sample/GCSample.cpp2
-rw-r--r--src/gc/sample/gcenv.h6
-rw-r--r--src/gc/unix/gcenv.unix.cpp6
-rw-r--r--src/gc/wks/CMakeLists.txt1
11 files changed, 75 insertions, 54 deletions
diff --git a/src/gc/CMakeLists.txt b/src/gc/CMakeLists.txt
index 59c18ffd87..f55c1a9a6f 100644
--- a/src/gc/CMakeLists.txt
+++ b/src/gc/CMakeLists.txt
@@ -1,24 +1,16 @@
set(CMAKE_INCLUDE_CURRENT_DIR ON)
-include_directories(BEFORE ${CMAKE_CURRENT_SOURCE_DIR})
+include_directories(BEFORE ${CMAKE_CURRENT_SOURCE_DIR})
include_directories(BEFORE ${CLR_DIR}/src/vm)
include_directories(BEFORE ${CLR_DIR}/src/vm/${ARCH_SOURCES_DIR})
+add_definitions(-DBUILD_AS_STANDALONE)
+
if(CLR_CMAKE_PLATFORM_UNIX)
add_compile_options(-fPIC)
endif(CLR_CMAKE_PLATFORM_UNIX)
-if(CMAKE_CONFIGURATION_TYPES)
- foreach (Config DEBUG CHECKED)
- set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS $<$<CONFIG:${Config}>:WRITE_BARRIER_CHECK=1>)
- endforeach (Config)
-else()
- if(UPPERCASE_CMAKE_BUILD_TYPE STREQUAL DEBUG OR UPPERCASE_CMAKE_BUILD_TYPE STREQUAL CHECKED)
- add_definitions(-DWRITE_BARRIER_CHECK=1)
- endif(UPPERCASE_CMAKE_BUILD_TYPE STREQUAL DEBUG OR UPPERCASE_CMAKE_BUILD_TYPE STREQUAL CHECKED)
-endif(CMAKE_CONFIGURATION_TYPES)
-
-set( GC_SOURCES_DAC_AND_WKS_COMMON
+set( GC_SOURCES
gccommon.cpp
gcscan.cpp
gcsvr.cpp
@@ -27,28 +19,18 @@ set( GC_SOURCES_DAC_AND_WKS_COMMON
handletablecore.cpp
handletablescan.cpp
objecthandle.cpp
- softwarewritewatch.cpp)
-
-set( GC_SOURCES_WKS
- ${GC_SOURCES_DAC_AND_WKS_COMMON}
+ softwarewritewatch.cpp
gchandletable.cpp
gceesvr.cpp
gceewks.cpp
handletablecache.cpp)
-set( GC_SOURCES_DAC
- ${GC_SOURCES_DAC_AND_WKS_COMMON})
-
-if(FEATURE_STANDALONE_GC)
- if(NOT CLR_CMAKE_PLATFORM_UNIX)
- set ( GC_SOURCES_WKS
- ${GC_SOURCES_WKS}
- windows/gcenv.windows.cpp)
- endif(NOT CLR_CMAKE_PLATFORM_UNIX)
-endif(FEATURE_STANDALONE_GC)
+if(NOT CLR_CMAKE_PLATFORM_UNIX)
+set ( GC_SOURCES
+ ${GC_SOURCES}
+ windows/gcenv.windows.cpp)
+endif(NOT CLR_CMAKE_PLATFORM_UNIX)
-convert_to_absolute_path(GC_SOURCES_WKS ${GC_SOURCES_WKS})
-convert_to_absolute_path(GC_SOURCES_DAC ${GC_SOURCES_DAC})
+convert_to_absolute_path(GC_SOURCES ${GC_SOURCES})
-add_subdirectory(wks)
-add_subdirectory(dac)
+add_library_clr(gc_standalone STATIC ${GC_SOURCES})
diff --git a/src/gc/dac/CMakeLists.txt b/src/gc/dac/CMakeLists.txt
deleted file mode 100644
index 1f1c9ebe5c..0000000000
--- a/src/gc/dac/CMakeLists.txt
+++ /dev/null
@@ -1,2 +0,0 @@
-include(${CLR_DIR}/dac.cmake)
-add_library_clr(gc_dac STATIC ${GC_SOURCES_DAC})
diff --git a/src/gc/gc.h b/src/gc/gc.h
index 07ae6c916c..2da0cb3966 100644
--- a/src/gc/gc.h
+++ b/src/gc/gc.h
@@ -27,16 +27,17 @@ Module Name:
#include "gcinterface.h"
#include "env/gcenv.os.h"
-#include "env/gcenv.ee.h"
-#ifdef FEATURE_STANDALONE_GC
+#ifdef BUILD_AS_STANDALONE
#include "gcenv.ee.standalone.inl"
// GCStress does not currently work with Standalone GC
#ifdef STRESS_HEAP
#undef STRESS_HEAP
#endif // STRESS_HEAP
-#endif // FEATURE_STANDALONE_GC
+#else
+#include "env/gcenv.ee.h"
+#endif // BUILD_AS_STANDALONE
/*
* Promotion Function Prototypes
diff --git a/src/gc/gccommon.cpp b/src/gc/gccommon.cpp
index 4950809cda..d7c572260a 100644
--- a/src/gc/gccommon.cpp
+++ b/src/gc/gccommon.cpp
@@ -17,9 +17,9 @@
IGCHeapInternal* g_theGCHeap;
IGCHandleManager* g_theGCHandleManager;
-#ifdef FEATURE_STANDALONE_GC
+#ifdef BUILD_AS_STANDALONE
IGCToCLR* g_theGCToCLR;
-#endif // FEATURE_STANDALONE_GC
+#endif // BUILD_AS_STANDALONE
#ifdef GC_CONFIG_DRIVEN
size_t gc_global_mechanisms[MAX_GLOBAL_GC_MECHANISMS_COUNT];
@@ -143,7 +143,30 @@ namespace SVR
extern void PopulateDacVars(GcDacVars* dacVars);
}
-bool InitializeGarbageCollector(IGCToCLR* clrToGC, IGCHeap** gcHeap, IGCHandleManager** gcHandleManager, GcDacVars* gcDacVars)
+//------------------------------------------------------------------
+// Externally-facing GC symbols, used to initialize the GC
+// -----------------------------------------------------------------
+
+#ifdef _MSC_VER
+#define DLLEXPORT __declspec(dllexport)
+#else
+#define DLLEXPORT __attribute__ ((visibility ("default")))
+#endif // _MSC_VER
+
+#ifdef BUILD_AS_STANDALONE
+#define GC_API extern "C" DLLEXPORT
+#else
+#define GC_API extern "C"
+#endif // BUILD_AS_STANDALONE
+
+GC_API
+bool
+InitializeGarbageCollector(
+ /* In */ IGCToCLR* clrToGC,
+ /* Out */ IGCHeap** gcHeap,
+ /* Out */ IGCHandleManager** gcHandleManager,
+ /* Out */ GcDacVars* gcDacVars
+ )
{
LIMITED_METHOD_CONTRACT;
@@ -184,7 +207,7 @@ bool InitializeGarbageCollector(IGCToCLR* clrToGC, IGCHeap** gcHeap, IGCHandleMa
g_theGCHeap = heap;
-#ifdef FEATURE_STANDALONE_GC
+#ifdef BUILD_AS_STANDALONE
assert(clrToGC != nullptr);
g_theGCToCLR = clrToGC;
#else
diff --git a/src/gc/gcenv.ee.standalone.inl b/src/gc/gcenv.ee.standalone.inl
index f6954fc476..31c3455d7b 100644
--- a/src/gc/gcenv.ee.standalone.inl
+++ b/src/gc/gcenv.ee.standalone.inl
@@ -5,12 +5,17 @@
#ifndef __GCTOENV_EE_STANDALONE_INL__
#define __GCTOENV_EE_STANDALONE_INL__
-#include "env/gcenv.ee.h"
+#include "gcinterface.h"
// The singular interface instance. All calls in GCToEEInterface
// will be fowarded to this interface instance.
extern IGCToCLR* g_theGCToCLR;
+namespace
+{
+
+#include "env/gcenv.ee.h"
+
// A note about this:
// In general, we don't want to pretend to be smarter than the compiler
// and force it to inline things. However, inlining is here is required
@@ -238,4 +243,6 @@ ALWAYS_INLINE MethodTable* GCToEEInterface::GetFreeObjectMethodTable()
}
#undef ALWAYS_INLINE
+} // anonymous namespace
+
#endif // __GCTOENV_EE_STANDALONE_INL__
diff --git a/src/gc/gcinterface.ee.h b/src/gc/gcinterface.ee.h
index 7b868e780e..8290572cd4 100644
--- a/src/gc/gcinterface.ee.h
+++ b/src/gc/gcinterface.ee.h
@@ -9,9 +9,9 @@
// of the execution engine. Everything that the GC does that requires the EE
// to be informed or that requires EE action must go through this interface.
//
-// When FEATURE_STANDALONE_GC is defined, this class is named IGCToCLR and is
+// When BUILD_AS_STANDALONE is defined, this class is named IGCToCLR and is
// an abstract class. The EE will provide a class that fulfills this interface,
-// and the GC will dispatch virtually on it to call into the EE. When FEATURE_STANDALONE_GC
+// and the GC will dispatch virtually on it to call into the EE. When BUILD_AS_STANDALONE
// is not defined, this class is named GCToEEInterface and the GC will dispatch statically on it.
class IGCToCLR {
public:
diff --git a/src/gc/gcinterface.h b/src/gc/gcinterface.h
index 552a8caec8..425745b0cb 100644
--- a/src/gc/gcinterface.h
+++ b/src/gc/gcinterface.h
@@ -171,15 +171,24 @@ class Object;
class IGCHeap;
class IGCHandleManager;
-// Initializes the garbage collector. Should only be called
-// once, during EE startup. Returns true if the initialization
-// was successful, false otherwise.
-bool InitializeGarbageCollector(IGCToCLR* clrToGC, IGCHeap** gcHeap, IGCHandleManager** gcHandleTable, GcDacVars* gcDacVars);
+// The function that initialzes the garbage collector.
+// Should only be called once: here, during EE startup.
+// Returns true if the initialization was successful, false otherwise.
+typedef bool (*InitializeGarbageCollectorFunction)(
+ /* In */ IGCToCLR*,
+ /* Out */ IGCHeap**,
+ /* Out */ IGCHandleManager**,
+ /* Out */ GcDacVars*
+);
+
+// The name of the function that initializes the garbage collector,
+// to be used as an argument to GetProcAddress.
+#define INITIALIZE_GC_FUNCTION_NAME "InitializeGarbageCollector"
// The runtime needs to know whether we're using workstation or server GC
// long before the GCHeap is created. This function sets the type of
// heap that will be created, before InitializeGarbageCollector is called
-// and the heap is actually recated.
+// and the heap is actually created.
void InitializeHeapType(bool bServerHeap);
#ifdef WRITE_BARRIER_CHECK
diff --git a/src/gc/sample/GCSample.cpp b/src/gc/sample/GCSample.cpp
index 0a771b7e91..43cb23878e 100644
--- a/src/gc/sample/GCSample.cpp
+++ b/src/gc/sample/GCSample.cpp
@@ -107,6 +107,8 @@ void WriteBarrier(Object ** dst, Object * ref)
ErectWriteBarrier(dst, ref);
}
+extern "C" bool InitializeGarbageCollector(IGCToCLR* clrToGC, IGCHeap** gcHeap, IGCHandleManager** gcHandleManager, GcDacVars* gcDacVars);
+
int __cdecl main(int argc, char* argv[])
{
//
diff --git a/src/gc/sample/gcenv.h b/src/gc/sample/gcenv.h
index 4505f1af30..14f60d8c6e 100644
--- a/src/gc/sample/gcenv.h
+++ b/src/gc/sample/gcenv.h
@@ -4,9 +4,9 @@
// The sample is to be kept simple, so building the sample
// in tandem with a standalone GC is currently not supported.
-#ifdef FEATURE_STANDALONE_GC
-#undef FEATURE_STANDALONE_GC
-#endif // FEATURE_STANDALONE_GC
+#ifdef BUILD_AS_STANDALONE
+#undef BUILD_AS_STANDALONE
+#endif // BUILD_AS_STANDALONE
#if defined(_DEBUG)
#ifndef _DEBUG_IMPL
diff --git a/src/gc/unix/gcenv.unix.cpp b/src/gc/unix/gcenv.unix.cpp
index bca0dfedf2..cebc515345 100644
--- a/src/gc/unix/gcenv.unix.cpp
+++ b/src/gc/unix/gcenv.unix.cpp
@@ -32,9 +32,9 @@ static_assert(sizeof(uint64_t) == 8, "unsigned long isn't 8 bytes");
#include "gcenv.base.h"
#include "gcenv.os.h"
-#ifndef FEATURE_STANDALONE_GC
- #error "A GC-private implementation of GCToOSInterface should only be used with FEATURE_STANDALONE_GC"
-#endif // FEATURE_STANDALONE_GC
+#ifndef BUILD_AS_STANDALONE
+ #error "A GC-private implementation of GCToOSInterface should only be used with BUILD_AS_STANDALONE"
+#endif // BUILD_AS_STANDALONE
#if HAVE_SYS_TIME_H
#include <sys/time.h>
diff --git a/src/gc/wks/CMakeLists.txt b/src/gc/wks/CMakeLists.txt
deleted file mode 100644
index fcb95a385e..0000000000
--- a/src/gc/wks/CMakeLists.txt
+++ /dev/null
@@ -1 +0,0 @@
-add_library_clr(gc_wks STATIC ${GC_SOURCES_WKS})