Skip to content

Commit 9aac610

Browse files
committed
Decoupling MMTk from the code and adding it as a third-party heap option
1 parent c117f9b commit 9aac610

File tree

7 files changed

+59
-33
lines changed

7 files changed

+59
-33
lines changed

Make.inc

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,6 @@ HAVE_SSP := 0
8080
WITH_GC_VERIFY := 0
8181
WITH_GC_DEBUG_ENV := 0
8282

83-
# Use stock if MMTK_PLAN hasn't been defined
84-
MMTK_PLAN ?= None
85-
8683
# Enable DTrace support
8784
WITH_DTRACE := 0
8885

@@ -836,34 +833,42 @@ JCXXFLAGS += -DGC_DEBUG_ENV
836833
JCFLAGS += -DGC_DEBUG_ENV
837834
endif
838835

839-
ifneq (${MMTK_PLAN},None)
840-
JCXXFLAGS += -DMMTK_GC
841-
JCFLAGS += -DMMTK_GC
842-
# Do a release build on the binding by default
843-
MMTK_BUILD ?= release
836+
# By default we use the stock GC
837+
WITH_THIRD_PARTY_GC ?= 0
838+
839+
# Convert to lowercase
840+
USE_THIRD_PARTY_GC := $(shell echo $(WITH_THIRD_PARTY_GC) | tr A-Z a-z)
841+
842+
# NB: When adding a new GC, make sure to add -DWITH_THIRD_PARTY_HEAP=<#NEW_GC>
843+
# to the variables JCFLAGS and JCXXFLAGS according to the mapping (MMTK=1, #NEW_GC=2)
844+
845+
ifeq (${USE_THIRD_PARTY_GC},mmtk)
846+
JCXXFLAGS += -DWITH_THIRD_PARTY_HEAP=1
847+
JCFLAGS += -DWITH_THIRD_PARTY_HEAP=1
848+
849+
# Must specify a supported MMTk Plan: Immix or StickyImmix
844850
ifeq (${MMTK_PLAN},Immix)
845851
JCXXFLAGS += -DMMTK_PLAN_IMMIX
846852
JCFLAGS += -DMMTK_PLAN_IMMIX
847853
else ifeq (${MMTK_PLAN},StickyImmix)
848854
JCXXFLAGS += -DMMTK_PLAN_STICKYIMMIX
849855
JCFLAGS += -DMMTK_PLAN_STICKYIMMIX
850856
else
851-
$(error "Unsupported MMTk plan: $(MMTK_PLAN)")
857+
$(error "Unsupported MMTk plan: $(MMTK_PLAN). Supported plans: Immix or StickyImmix.")
852858
endif
853859

860+
# Do a release build on the binding by default
861+
MMTK_BUILD ?= release
862+
854863
# Location of mmtk-julia binding
855864
# (needed for api/*.h and .so file)
856865
MMTK_JULIA_DIR ?= $(BUILDROOT)/usr/lib/mmtk_julia
857-
858866
MMTK_DIR = ${MMTK_JULIA_DIR}/mmtk
859867
MMTK_API_INC = ${MMTK_DIR}/api
860-
861868
MMTK_LIB := -lmmtk_julia
862-
else
863-
MMTK_JULIA_INC :=
864-
MMTK_LIB :=
865869
endif
866870

871+
867872
ifeq ($(WITH_DTRACE), 1)
868873
JCXXFLAGS += -DUSE_DTRACE
869874
JCFLAGS += -DUSE_DTRACE
@@ -964,19 +969,17 @@ ARCH := $(BUILD_OS)
964969
endif
965970
endif
966971

967-
# MMTk is only available on x86_64 Linux for now
968-
ifneq (${MMTK_PLAN},None)
969972

973+
ifeq (${USE_THIRD_PARTY_GC},mmtk)
974+
# MMTk is only available on x86_64 Linux for now
970975
ifeq ($(OS),Linux)
971976
MMTK_LIB_NAME := libmmtk_julia.so
972977
else
973978
$(error "Unsupported OS for MMTk")
974979
endif
975-
976980
ifneq ($(ARCH),x86_64)
977981
$(error "Unsupported build architecture for MMTk")
978982
endif
979-
980983
endif
981984

982985
# Detect common pre-SSE2 JULIA_CPU_TARGET values known not to work (#7185)
@@ -1405,7 +1408,12 @@ CSL_NEXT_GLIBCXX_VERSION=GLIBCXX_3\.4\.34|GLIBCXX_3\.5\.|GLIBCXX_4\.
14051408
# Note: we explicitly _do not_ define `CSL` here, since it requires some more
14061409
# advanced techniques to decide whether it should be installed from a BB source
14071410
# or not. See `deps/csl.mk` for more detail.
1408-
BB_PROJECTS := BLASTRAMPOLINE OPENBLAS LLVM LIBSUITESPARSE OPENLIBM GMP OPENSSL LIBSSH2 NGHTTP2 MPFR CURL LIBGIT2 PCRE LIBUV LIBUNWIND DSFMT OBJCONV ZLIB P7ZIP LLD LIBTRACYCLIENT BOLT MMTK_JULIA
1411+
BB_PROJECTS := BLASTRAMPOLINE OPENBLAS LLVM LIBSUITESPARSE OPENLIBM GMP OPENSSL LIBSSH2 NGHTTP2 MPFR CURL LIBGIT2 PCRE LIBUV LIBUNWIND DSFMT OBJCONV ZLIB P7ZIP LLD LIBTRACYCLIENT BOLT
1412+
1413+
ifeq (${USE_THIRD_PARTY_GC},mmtk)
1414+
BB_PROJECTS += MMTK_JULIA
1415+
endif
1416+
14091417
define SET_BB_DEFAULT
14101418
# First, check to see if BB is disabled on a global setting
14111419
ifeq ($$(USE_BINARYBUILDER),0)

Makefile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ endif
281281
endif
282282
endif
283283

284-
ifneq (${MMTK_PLAN},None)
284+
ifeq (${USE_THIRD_PARTY_GC},mmtk)
285285
# Make sure we use the right version of $MMTK_PLAN, $MMTK_MOVING and $MMTK_BUILD
286286
# if we use the BinaryBuilder version of mmtk-julia
287287
ifeq ($(USE_BINARYBUILDER_MMTK_JULIA),1)
@@ -291,10 +291,10 @@ else ifeq (${MMTK_PLAN},StickyImmix)
291291
LIB_PATH_PLAN = sticky
292292
endif
293293

294-
ifeq ($(MMTK_MOVING), 0)
295-
LIB_PATH_MOVING := non_moving
296-
else
294+
ifeq ($(MMTK_MOVING), 1)
297295
LIB_PATH_MOVING := moving
296+
else
297+
LIB_PATH_MOVING := non_moving
298298
endif
299299

300300
JL_PRIVATE_LIBS-0 += $(LIB_PATH_PLAN)/$(LIB_PATH_MOVING)/$(MMTK_BUILD)/libmmtk_julia

deps/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ DEP_LIBS += libwhich
195195
endif
196196
endif
197197

198-
ifneq (${MMTK_PLAN},None)
198+
ifeq (${USE_THIRD_PARTY_GC},mmtk)
199199
DEP_LIBS += mmtk_julia
200200
endif
201201

doc/src/devdocs/gc-mmtk.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ There has been quite a lot of effort to refactor the GC code inside Julia to sup
77
88
## Building Julia with MMTk
99

10-
There are 3 different ways of building Julia with MMTk: building from source using a fixed release of the binding, checking out a custom version in the mmtk-julia [repository](https://github.com/mmtk/mmtk-julia) or using a precompiled binary from Julia's BinaryBuilder. The easiest way is to use the BinaryBuilder binary. Simply set the variable `MMTK_PLAN` to one of the supported plans below and build Julia as usual.
10+
There are 3 different ways of building Julia with MMTk: building from source using a fixed release of the binding, checking out a custom version in the mmtk-julia [repository](https://github.com/mmtk/mmtk-julia) or using a precompiled binary from Julia's BinaryBuilder. The easiest way is to use the BinaryBuilder binary. First, to enable MMTk as a third-party GC, set the variable `WITH_THIRD_PARTY_GC` to `mmtk`. Then, simply set the variable `MMTK_PLAN` to one of the supported plans below and build Julia as usual.
1111

1212
There are different configurations supported by the following variables, which can be set in a `Make.user` file or as an environment variable.
1313

src/Makefile

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ ifeq ($(USECLANG),1)
2929
FLAGS += -Wno-return-type-c-linkage -Wno-atomic-alignment
3030
endif
3131

32-
ifneq (${MMTK_PLAN},None)
32+
ifeq (${USE_THIRD_PARTY_GC},mmtk)
3333
FLAGS += -I$(MMTK_API_INC)
3434
endif
3535

@@ -46,7 +46,7 @@ endif
4646

4747
# GC source code. It depends on which GC implementation to use.
4848
GC_SRCS := gc-common gc-stacks gc-alloc-profiler gc-heap-snapshot
49-
ifneq (${MMTK_PLAN},None)
49+
ifeq (${USE_THIRD_PARTY_GC},mmtk)
5050
GC_SRCS += gc-mmtk
5151
else
5252
GC_SRCS += gc-stock gc-debug gc-pages gc-page-profiler
@@ -67,7 +67,7 @@ CG_LLVMLINK :=
6767
ifeq ($(JULIACODEGEN),LLVM)
6868
# Currently these files are used by both GCs. But we should make the list specific to stock, and MMTk should have its own implementation.
6969
GC_CODEGEN_SRCS := llvm-final-gc-lowering llvm-late-gc-lowering llvm-gc-invariant-verifier
70-
ifneq (${MMTK_PLAN},None)
70+
ifeq (${USE_THIRD_PARTY_GC},mmtk)
7171
FLAGS += -I$(MMTK_API_INC)
7272
GC_CODEGEN_SRCS += llvm-late-gc-lowering-mmtk
7373
else
@@ -122,7 +122,7 @@ UV_HEADERS += uv.h
122122
UV_HEADERS += uv/*.h
123123
endif
124124
PUBLIC_HEADERS := $(BUILDDIR)/julia_version.h $(wildcard $(SRCDIR)/support/*.h) $(addprefix $(SRCDIR)/,work-stealing-queue.h gc-interface.h gc-tls-common.h julia.h julia_assert.h julia_threads.h julia_fasttls.h julia_locks.h julia_atomics.h jloptions.h)
125-
ifneq (${MMTK_PLAN},None)
125+
ifeq (${USE_THIRD_PARTY_GC},mmtk)
126126
PUBLIC_HEADERS += $(addprefix $(SRCDIR)/,gc-tls-mmtk.h)
127127
else
128128
PUBLIC_HEADERS += $(addprefix $(SRCDIR)/,gc-tls-stock.h)
@@ -191,8 +191,14 @@ LIBJULIA_PATH_REL := libjulia
191191
endif
192192

193193
COMMON_LIBPATHS := -L$(build_libdir) -L$(build_shlibdir)
194-
RT_LIBS := $(WHOLE_ARCHIVE) $(LIBUV) $(WHOLE_ARCHIVE) $(LIBUTF8PROC) $(NO_WHOLE_ARCHIVE) $(LIBUNWIND) $(RT_LLVMLINK) $(OSLIBS) $(LIBTRACYCLIENT) $(LIBITTAPI) $(MMTK_LIB)
195-
CG_LIBS := $(LIBUNWIND) $(CG_LLVMLINK) $(OSLIBS) $(LIBTRACYCLIENT) $(LIBITTAPI) $(MMTK_LIB)
194+
RT_LIBS := $(WHOLE_ARCHIVE) $(LIBUV) $(WHOLE_ARCHIVE) $(LIBUTF8PROC) $(NO_WHOLE_ARCHIVE) $(LIBUNWIND) $(RT_LLVMLINK) $(OSLIBS) $(LIBTRACYCLIENT) $(LIBITTAPI)
195+
CG_LIBS := $(LIBUNWIND) $(CG_LLVMLINK) $(OSLIBS) $(LIBTRACYCLIENT) $(LIBITTAPI)
196+
197+
ifeq (${USE_THIRD_PARTY_GC},mmtk)
198+
RT_LIBS += $(MMTK_LIB)
199+
CG_LIBS += $(MMTK_LIB)
200+
endif
201+
196202
RT_DEBUG_LIBS := $(COMMON_LIBPATHS) $(WHOLE_ARCHIVE) $(BUILDDIR)/flisp/libflisp-debug.a $(WHOLE_ARCHIVE) $(BUILDDIR)/support/libsupport-debug.a -ljulia-debug $(RT_LIBS)
197203
CG_DEBUG_LIBS := $(COMMON_LIBPATHS) $(CG_LIBS) -ljulia-debug -ljulia-internal-debug
198204
RT_RELEASE_LIBS := $(COMMON_LIBPATHS) $(WHOLE_ARCHIVE) $(BUILDDIR)/flisp/libflisp.a $(WHOLE_ARCHIVE) $(BUILDDIR)/support/libsupport.a -ljulia $(RT_LIBS)

src/gc-tls-third-party.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// This file is a part of Julia. License is MIT: https://julialang.org/license
2+
3+
// Pick the appropriate third-party implementation
4+
#ifdef WITH_THIRD_PARTY_HEAP
5+
#if WITH_THIRD_PARTY_HEAP == 1
6+
#include "gc-tls-mmtk.h"
7+
#endif
8+
// To be extended by other GC implementations
9+
// #if WITH_THIRD_PARTY_HEAP == X
10+
// #include gc-tls-XXXX.h
11+
// #endif
12+
#endif

src/julia_threads.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
#ifndef JL_THREADS_H
55
#define JL_THREADS_H
66

7-
#ifndef MMTK_GC
7+
#ifndef WITH_THIRD_PARTY_HEAP
88
#include "gc-tls-stock.h"
99
#else
10-
#include "gc-tls-mmtk.h"
10+
#include "gc-tls-third-party.h"
1111
#endif
1212
#include "gc-tls-common.h"
1313
#include "julia_atomics.h"

0 commit comments

Comments
 (0)