diff --git a/Make.inc b/Make.inc index 2cd5797e88a41..fe7236a328d12 100644 --- a/Make.inc +++ b/Make.inc @@ -80,9 +80,6 @@ HAVE_SSP := 0 WITH_GC_VERIFY := 0 WITH_GC_DEBUG_ENV := 0 -# Use stock if MMTK_PLAN hasn't been defined -MMTK_PLAN ?= None - # Enable DTrace support WITH_DTRACE := 0 @@ -836,11 +833,20 @@ JCXXFLAGS += -DGC_DEBUG_ENV JCFLAGS += -DGC_DEBUG_ENV endif -ifneq (${MMTK_PLAN},None) -JCXXFLAGS += -DMMTK_GC -JCFLAGS += -DMMTK_GC -# Do a release build on the binding by default -MMTK_BUILD ?= release +# By default we use the stock GC +WITH_THIRD_PARTY_GC ?= 0 + +# Convert to lowercase +USE_THIRD_PARTY_GC := $(shell echo $(WITH_THIRD_PARTY_GC) | tr A-Z a-z) + +# NB: When adding a new GC, make sure to add -DWITH_THIRD_PARTY_HEAP=<#NEW_GC> +# to the variables JCFLAGS and JCXXFLAGS according to the mapping (MMTK=1, #NEW_GC=2) + +ifeq (${USE_THIRD_PARTY_GC},mmtk) +JCXXFLAGS += -DWITH_THIRD_PARTY_HEAP=1 +JCFLAGS += -DWITH_THIRD_PARTY_HEAP=1 + +# Must specify a supported MMTk Plan: Immix or StickyImmix ifeq (${MMTK_PLAN},Immix) JCXXFLAGS += -DMMTK_PLAN_IMMIX JCFLAGS += -DMMTK_PLAN_IMMIX @@ -848,22 +854,21 @@ else ifeq (${MMTK_PLAN},StickyImmix) JCXXFLAGS += -DMMTK_PLAN_STICKYIMMIX JCFLAGS += -DMMTK_PLAN_STICKYIMMIX else -$(error "Unsupported MMTk plan: $(MMTK_PLAN)") +$(error "Unsupported MMTk plan: $(MMTK_PLAN). Supported plans: Immix or StickyImmix.") endif +# Do a release build on the binding by default +MMTK_BUILD ?= release + # Location of mmtk-julia binding # (needed for api/*.h and .so file) MMTK_JULIA_DIR ?= $(BUILDROOT)/usr/lib/mmtk_julia - MMTK_DIR = ${MMTK_JULIA_DIR}/mmtk MMTK_API_INC = ${MMTK_DIR}/api - MMTK_LIB := -lmmtk_julia -else -MMTK_JULIA_INC := -MMTK_LIB := endif + ifeq ($(WITH_DTRACE), 1) JCXXFLAGS += -DUSE_DTRACE JCFLAGS += -DUSE_DTRACE @@ -964,19 +969,17 @@ ARCH := $(BUILD_OS) endif endif -# MMTk is only available on x86_64 Linux for now -ifneq (${MMTK_PLAN},None) +ifeq (${USE_THIRD_PARTY_GC},mmtk) +# MMTk is only available on x86_64 Linux for now ifeq ($(OS),Linux) MMTK_LIB_NAME := libmmtk_julia.so else $(error "Unsupported OS for MMTk") endif - ifneq ($(ARCH),x86_64) $(error "Unsupported build architecture for MMTk") endif - endif # 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\. # Note: we explicitly _do not_ define `CSL` here, since it requires some more # advanced techniques to decide whether it should be installed from a BB source # or not. See `deps/csl.mk` for more detail. -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 +BB_PROJECTS := BLASTRAMPOLINE OPENBLAS LLVM LIBSUITESPARSE OPENLIBM GMP OPENSSL LIBSSH2 NGHTTP2 MPFR CURL LIBGIT2 PCRE LIBUV LIBUNWIND DSFMT OBJCONV ZLIB P7ZIP LLD LIBTRACYCLIENT BOLT + +ifeq (${USE_THIRD_PARTY_GC},mmtk) +BB_PROJECTS += MMTK_JULIA +endif + define SET_BB_DEFAULT # First, check to see if BB is disabled on a global setting ifeq ($$(USE_BINARYBUILDER),0) diff --git a/Makefile b/Makefile index 0f1e8c45edf40..a9f23592ec631 100644 --- a/Makefile +++ b/Makefile @@ -281,7 +281,7 @@ endif endif endif -ifneq (${MMTK_PLAN},None) +ifeq (${USE_THIRD_PARTY_GC},mmtk) # Make sure we use the right version of $MMTK_PLAN, $MMTK_MOVING and $MMTK_BUILD # if we use the BinaryBuilder version of mmtk-julia ifeq ($(USE_BINARYBUILDER_MMTK_JULIA),1) @@ -291,10 +291,10 @@ else ifeq (${MMTK_PLAN},StickyImmix) LIB_PATH_PLAN = sticky endif -ifeq ($(MMTK_MOVING), 0) -LIB_PATH_MOVING := non_moving -else +ifeq ($(MMTK_MOVING), 1) LIB_PATH_MOVING := moving +else +LIB_PATH_MOVING := non_moving endif JL_PRIVATE_LIBS-0 += $(LIB_PATH_PLAN)/$(LIB_PATH_MOVING)/$(MMTK_BUILD)/libmmtk_julia diff --git a/deps/Makefile b/deps/Makefile index 396b1021c2ddd..4ad4df9ec4ba4 100644 --- a/deps/Makefile +++ b/deps/Makefile @@ -195,7 +195,7 @@ DEP_LIBS += libwhich endif endif -ifneq (${MMTK_PLAN},None) +ifeq (${USE_THIRD_PARTY_GC},mmtk) DEP_LIBS += mmtk_julia endif diff --git a/doc/src/devdocs/gc-mmtk.md b/doc/src/devdocs/gc-mmtk.md index 323e7901b6d2f..cd877e074ec34 100644 --- a/doc/src/devdocs/gc-mmtk.md +++ b/doc/src/devdocs/gc-mmtk.md @@ -7,7 +7,7 @@ There has been quite a lot of effort to refactor the GC code inside Julia to sup ## Building Julia with MMTk -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. +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. There are different configurations supported by the following variables, which can be set in a `Make.user` file or as an environment variable. diff --git a/src/Makefile b/src/Makefile index 130c35960f2d0..a4a6d6f54d7fb 100644 --- a/src/Makefile +++ b/src/Makefile @@ -29,7 +29,7 @@ ifeq ($(USECLANG),1) FLAGS += -Wno-return-type-c-linkage -Wno-atomic-alignment endif -ifneq (${MMTK_PLAN},None) +ifeq (${USE_THIRD_PARTY_GC},mmtk) FLAGS += -I$(MMTK_API_INC) endif @@ -46,7 +46,7 @@ endif # GC source code. It depends on which GC implementation to use. GC_SRCS := gc-common gc-stacks gc-alloc-profiler gc-heap-snapshot -ifneq (${MMTK_PLAN},None) +ifeq (${USE_THIRD_PARTY_GC},mmtk) GC_SRCS += gc-mmtk else GC_SRCS += gc-stock gc-debug gc-pages gc-page-profiler @@ -67,7 +67,7 @@ CG_LLVMLINK := ifeq ($(JULIACODEGEN),LLVM) # Currently these files are used by both GCs. But we should make the list specific to stock, and MMTk should have its own implementation. GC_CODEGEN_SRCS := llvm-final-gc-lowering llvm-late-gc-lowering llvm-gc-invariant-verifier -ifneq (${MMTK_PLAN},None) +ifeq (${USE_THIRD_PARTY_GC},mmtk) FLAGS += -I$(MMTK_API_INC) GC_CODEGEN_SRCS += llvm-late-gc-lowering-mmtk else @@ -122,7 +122,7 @@ UV_HEADERS += uv.h UV_HEADERS += uv/*.h endif 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) -ifneq (${MMTK_PLAN},None) +ifeq (${USE_THIRD_PARTY_GC},mmtk) PUBLIC_HEADERS += $(addprefix $(SRCDIR)/,gc-tls-mmtk.h) else PUBLIC_HEADERS += $(addprefix $(SRCDIR)/,gc-tls-stock.h) @@ -191,8 +191,14 @@ LIBJULIA_PATH_REL := libjulia endif COMMON_LIBPATHS := -L$(build_libdir) -L$(build_shlibdir) -RT_LIBS := $(WHOLE_ARCHIVE) $(LIBUV) $(WHOLE_ARCHIVE) $(LIBUTF8PROC) $(NO_WHOLE_ARCHIVE) $(LIBUNWIND) $(RT_LLVMLINK) $(OSLIBS) $(LIBTRACYCLIENT) $(LIBITTAPI) $(MMTK_LIB) -CG_LIBS := $(LIBUNWIND) $(CG_LLVMLINK) $(OSLIBS) $(LIBTRACYCLIENT) $(LIBITTAPI) $(MMTK_LIB) +RT_LIBS := $(WHOLE_ARCHIVE) $(LIBUV) $(WHOLE_ARCHIVE) $(LIBUTF8PROC) $(NO_WHOLE_ARCHIVE) $(LIBUNWIND) $(RT_LLVMLINK) $(OSLIBS) $(LIBTRACYCLIENT) $(LIBITTAPI) +CG_LIBS := $(LIBUNWIND) $(CG_LLVMLINK) $(OSLIBS) $(LIBTRACYCLIENT) $(LIBITTAPI) + +ifeq (${USE_THIRD_PARTY_GC},mmtk) +RT_LIBS += $(MMTK_LIB) +CG_LIBS += $(MMTK_LIB) +endif + RT_DEBUG_LIBS := $(COMMON_LIBPATHS) $(WHOLE_ARCHIVE) $(BUILDDIR)/flisp/libflisp-debug.a $(WHOLE_ARCHIVE) $(BUILDDIR)/support/libsupport-debug.a -ljulia-debug $(RT_LIBS) CG_DEBUG_LIBS := $(COMMON_LIBPATHS) $(CG_LIBS) -ljulia-debug -ljulia-internal-debug RT_RELEASE_LIBS := $(COMMON_LIBPATHS) $(WHOLE_ARCHIVE) $(BUILDDIR)/flisp/libflisp.a $(WHOLE_ARCHIVE) $(BUILDDIR)/support/libsupport.a -ljulia $(RT_LIBS) diff --git a/src/gc-tls-third-party.h b/src/gc-tls-third-party.h new file mode 100644 index 0000000000000..bd7a2a76b011c --- /dev/null +++ b/src/gc-tls-third-party.h @@ -0,0 +1,12 @@ +// This file is a part of Julia. License is MIT: https://julialang.org/license + +// Pick the appropriate third-party implementation +#ifdef WITH_THIRD_PARTY_HEAP +#if WITH_THIRD_PARTY_HEAP == 1 +#include "gc-tls-mmtk.h" +#endif +// To be extended by other GC implementations +// #if WITH_THIRD_PARTY_HEAP == X +// #include gc-tls-XXXX.h +// #endif +#endif \ No newline at end of file diff --git a/src/julia_threads.h b/src/julia_threads.h index 061eb9266e7a7..b422942d52c8d 100644 --- a/src/julia_threads.h +++ b/src/julia_threads.h @@ -4,10 +4,10 @@ #ifndef JL_THREADS_H #define JL_THREADS_H -#ifndef MMTK_GC +#ifndef WITH_THIRD_PARTY_HEAP #include "gc-tls-stock.h" #else -#include "gc-tls-mmtk.h" +#include "gc-tls-third-party.h" #endif #include "gc-tls-common.h" #include "julia_atomics.h"