Skip to content

Commit 4f0f23b

Browse files
committed
Adding support for MMTk (non-moving Immix)
1 parent c1f806d commit 4f0f23b

21 files changed

+1568
-70
lines changed

Make.inc

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

83+
# Use MMTk GC
84+
WITH_MMTK ?= 0
85+
8386
# Enable DTrace support
8487
WITH_DTRACE := 0
8588

@@ -829,6 +832,43 @@ JCXXFLAGS += -DGC_DEBUG_ENV
829832
JCFLAGS += -DGC_DEBUG_ENV
830833
endif
831834

835+
ifeq ($(WITH_MMTK), 1)
836+
ifeq (${MMTK_JULIA_DIR},)
837+
$(error MMTK_JULIA_DIR must be set to use MMTk)
838+
endif
839+
JCXXFLAGS += -DMMTK_GC
840+
JCFLAGS += -DMMTK_GC
841+
ifeq (${MMTK_BUILD},)
842+
ifeq (debug,$(findstring debug,$(MAKECMDGOALS)))
843+
MMTK_BUILD = debug
844+
else
845+
MMTK_BUILD = release
846+
endif
847+
endif
848+
ifeq (${MMTK_PLAN},Immix)
849+
JCXXFLAGS += -DMMTK_PLAN_IMMIX
850+
JCFLAGS += -DMMTK_PLAN_IMMIX
851+
endif
852+
ifeq (${MMTK_PLAN},StickyImmix)
853+
JCXXFLAGS += -DMMTK_PLAN_STICKYIMMIX
854+
JCFLAGS += -DMMTK_PLAN_STICKYIMMIX
855+
endif
856+
MMTK_DIR = ${MMTK_JULIA_DIR}/mmtk
857+
MMTK_API_INC = $(MMTK_DIR)/api
858+
ifeq ($(OS),Linux)
859+
MMTK_LIB_NAME := libmmtk_julia.so
860+
else
861+
$(error "Unsupported OS for MMTk")
862+
endif
863+
MMTK_LIB_SRC := $(MMTK_DIR)/target/$(MMTK_BUILD)/$(MMTK_LIB_NAME)
864+
MMTK_LIB_DST := $(BUILDROOT)/usr/lib/$(MMTK_LIB_NAME)
865+
MMTK_LIB := -lmmtk_julia
866+
LDFLAGS += -Wl,-rpath=$(MMTK_DIR)/target/$(MMTK_BUILD)/
867+
else
868+
MMTK_JULIA_INC :=
869+
MMTK_LIB :=
870+
endif
871+
832872
ifeq ($(WITH_DTRACE), 1)
833873
JCXXFLAGS += -DUSE_DTRACE
834874
JCFLAGS += -DUSE_DTRACE
@@ -1823,6 +1863,9 @@ PRINT_PERL = printf ' %b %b\n' $(PERLCOLOR)PERL$(ENDCOLOR) $(BINCOLOR)$(GOAL)
18231863
PRINT_FLISP = printf ' %b %b\n' $(FLISPCOLOR)FLISP$(ENDCOLOR) $(BINCOLOR)$(GOAL)$(ENDCOLOR); $(1)
18241864
PRINT_JULIA = printf ' %b %b\n' $(JULIACOLOR)JULIA$(ENDCOLOR) $(BINCOLOR)$(GOAL)$(ENDCOLOR); $(1)
18251865
PRINT_DTRACE = printf ' %b %b\n' $(DTRACECOLOR)DTRACE$(ENDCOLOR) $(BINCOLOR)$(GOAL)$(ENDCOLOR); $(1)
1866+
ifeq ($(WITH_MMTK), 1)
1867+
PRINT_MMTK = printf ' %b %b\n' $(LINKCOLOR)MMTK$(ENDCOLOR) $(BINCOLOR)$(GOAL)$(ENDCOLOR); $(1)
1868+
endif
18261869

18271870
else
18281871
QUIET_MAKE =
@@ -1833,6 +1876,9 @@ PRINT_PERL = echo '$(subst ','\'',$(1))'; $(1)
18331876
PRINT_FLISP = echo '$(subst ','\'',$(1))'; $(1)
18341877
PRINT_JULIA = echo '$(subst ','\'',$(1))'; $(1)
18351878
PRINT_DTRACE = echo '$(subst ','\'',$(1))'; $(1)
1879+
ifeq ($(WITH_MMTK), 1)
1880+
PRINT_MMTK = echo '$(subst ','\'',$(1))'; $(1)
1881+
endif
18361882

18371883
endif # VERBOSE
18381884

contrib/refresh_checksums.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ CLANG_TRIPLETS=$(filter %-darwin %-freebsd,$(TRIPLETS))
2424
NON_CLANG_TRIPLETS=$(filter-out %-darwin %-freebsd,$(TRIPLETS))
2525

2626
# These are the projects currently using BinaryBuilder; both GCC-expanded and non-GCC-expanded:
27-
BB_PROJECTS=mbedtls libssh2 nghttp2 mpfr curl libgit2 pcre libuv unwind llvmunwind dsfmt objconv p7zip zlib libsuitesparse openlibm blastrampoline libtracyclient
27+
BB_PROJECTS=mbedtls libssh2 nghttp2 mpfr curl libgit2 pcre libuv unwind llvmunwind dsfmt objconv p7zip zlib libsuitesparse openlibm blastrampoline libtracyclient libmmtk_julia
2828
BB_GCC_EXPANDED_PROJECTS=openblas csl
2929
BB_CXX_EXPANDED_PROJECTS=gmp llvm clang llvm-tools lld
3030
# These are non-BB source-only deps

src/Makefile

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

32+
ifeq ($(WITH_MMTK), 1)
33+
FLAGS += -I$(MMTK_API_INC)
34+
endif
35+
3236
FLAGS += -DJL_BUILD_ARCH='"$(ARCH)"'
3337
ifeq ($(OS),WINNT)
3438
FLAGS += -DJL_BUILD_UNAME='"NT"'
@@ -44,8 +48,8 @@ SRCS := \
4448
jltypes gf typemap smallintset ast builtins module interpreter symbol \
4549
dlload sys init task array genericmemory staticdata toplevel jl_uv datatype \
4650
simplevector runtime_intrinsics precompile jloptions mtarraylist \
47-
threading scheduler stackwalk gc-common gc-stock gc-debug gc-pages gc-stacks gc-alloc-profiler gc-page-profiler method \
48-
jlapi signal-handling safepoint timing subtype rtutils gc-heap-snapshot \
51+
threading scheduler stackwalk gc-common gc-stock gc-mmtk gc-debug gc-pages gc-stacks gc-alloc-profiler gc-page-profiler \
52+
method jlapi signal-handling safepoint timing subtype rtutils gc-heap-snapshot \
4953
crc32c APInt-C processor ircode opaque_closure codegen-stubs coverage runtime_ccall engine
5054

5155
RT_LLVMLINK :=
@@ -103,7 +107,7 @@ ifeq ($(USE_SYSTEM_LIBUV),0)
103107
UV_HEADERS += uv.h
104108
UV_HEADERS += uv/*.h
105109
endif
106-
PUBLIC_HEADERS := $(BUILDDIR)/julia_version.h $(wildcard $(SRCDIR)/support/*.h) $(addprefix $(SRCDIR)/,work-stealing-queue.h gc-interface.h gc-tls.h gc-tls-common.h julia.h julia_assert.h julia_threads.h julia_fasttls.h julia_locks.h julia_atomics.h jloptions.h)
110+
PUBLIC_HEADERS := $(BUILDDIR)/julia_version.h $(wildcard $(SRCDIR)/support/*.h) $(addprefix $(SRCDIR)/,work-stealing-queue.h gc-interface.h gc-tls.h gc-tls-common.h gc-tls-mmtk.h julia.h julia_assert.h julia_threads.h julia_fasttls.h julia_locks.h julia_atomics.h jloptions.h)
107111
ifeq ($(OS),WINNT)
108112
PUBLIC_HEADERS += $(addprefix $(SRCDIR)/,win32_ucontext.h)
109113
endif
@@ -168,8 +172,8 @@ LIBJULIA_PATH_REL := libjulia
168172
endif
169173

170174
COMMON_LIBPATHS := -L$(build_libdir) -L$(build_shlibdir)
171-
RT_LIBS := $(WHOLE_ARCHIVE) $(LIBUV) $(WHOLE_ARCHIVE) $(LIBUTF8PROC) $(NO_WHOLE_ARCHIVE) $(LIBUNWIND) $(RT_LLVMLINK) $(OSLIBS) $(LIBTRACYCLIENT) $(LIBITTAPI)
172-
CG_LIBS := $(LIBUNWIND) $(CG_LLVMLINK) $(OSLIBS) $(LIBTRACYCLIENT) $(LIBITTAPI)
175+
RT_LIBS := $(WHOLE_ARCHIVE) $(LIBUV) $(WHOLE_ARCHIVE) $(LIBUTF8PROC) $(NO_WHOLE_ARCHIVE) $(LIBUNWIND) $(RT_LLVMLINK) $(OSLIBS) $(LIBTRACYCLIENT) $(LIBITTAPI) $(MMTK_LIB)
176+
CG_LIBS := $(LIBUNWIND) $(CG_LLVMLINK) $(OSLIBS) $(LIBTRACYCLIENT) $(LIBITTAPI) $(MMTK_LIB)
173177
RT_DEBUG_LIBS := $(COMMON_LIBPATHS) $(WHOLE_ARCHIVE) $(BUILDDIR)/flisp/libflisp-debug.a $(WHOLE_ARCHIVE) $(BUILDDIR)/support/libsupport-debug.a -ljulia-debug $(RT_LIBS)
174178
CG_DEBUG_LIBS := $(COMMON_LIBPATHS) $(CG_LIBS) -ljulia-debug -ljulia-internal-debug
175179
RT_RELEASE_LIBS := $(COMMON_LIBPATHS) $(WHOLE_ARCHIVE) $(BUILDDIR)/flisp/libflisp.a $(WHOLE_ARCHIVE) $(BUILDDIR)/support/libsupport.a -ljulia $(RT_LIBS)
@@ -226,6 +230,12 @@ $(BUILDDIR)/%.h.gen : $(SRCDIR)/%.d
226230
sed 's/JULIA_/JL_PROBE_/' $@ > $@.tmp
227231
mv $@.tmp $@
228232

233+
# Compile files from the binding side and copy so file into lib folder
234+
ifeq ($(WITH_MMTK), 1)
235+
$(MMTK_LIB_DST): $(MMTK_LIB_SRC)
236+
@$(call PRINT_MMTK, cp $< $@)
237+
endif
238+
229239
$(BUILDDIR)/jl_internal_funcs.inc: $(SRCDIR)/jl_exported_funcs.inc
230240
# Generate `.inc` file that contains a list of `#define` macros to rename functions defined in `libjulia-internal`
231241
# to have a `ijl_` prefix instead of `jl_`, to denote that they are coming from `libjulia-internal`. This avoids
@@ -318,6 +328,7 @@ $(BUILDDIR)/debuginfo.o $(BUILDDIR)/debuginfo.dbg.obj: $(addprefix $(SRCDIR)/,de
318328
$(BUILDDIR)/disasm.o $(BUILDDIR)/disasm.dbg.obj: $(SRCDIR)/debuginfo.h $(SRCDIR)/processor.h
319329
$(BUILDDIR)/gc-debug.o $(BUILDDIR)/gc-debug.dbg.obj: $(SRCDIR)/gc-common.h $(SRCDIR)/gc-stock.h
320330
$(BUILDDIR)/gc-pages.o $(BUILDDIR)/gc-pages.dbg.obj: $(SRCDIR)/gc-common.h $(SRCDIR)/gc-stock.h
331+
$(BUILDDIR)/gc-mmtk.o $(BUILDDIR)/gc-mmtk.dbg.obj: $(SRCDIR)/gc-common.h $(SRCDIR)/gc-heap-snapshot.h $(SRCDIR)/gc-alloc-profiler.h
321332
$(BUILDDIR)/gc-stacks.o $(BUILDDIR)/gc-stacks.dbg.obj: $(SRCDIR)/gc-common.h $(SRCDIR)/gc-stock.h
322333
$(BUILDDIR)/gc-stock.o $(BUILDDIR)/gc.dbg.obj: $(SRCDIR)/gc-common.h $(SRCDIR)/gc-stock.h $(SRCDIR)/gc-heap-snapshot.h $(SRCDIR)/gc-alloc-profiler.h $(SRCDIR)/gc-page-profiler.h
323334
$(BUILDDIR)/gc-heap-snapshot.o $(BUILDDIR)/gc-heap-snapshot.dbg.obj: $(SRCDIR)/gc-heap-snapshot.h
@@ -390,13 +401,13 @@ $(BUILDDIR)/julia.expmap: $(SRCDIR)/julia.expmap.in $(JULIAHOME)/VERSION $(LLVM_
390401
sed <'$<' >'$@' -e "s/@JULIA_SHLIB_SYMBOL_VERSION@/JL_LIBJULIA_$(SOMAJOR)/" \
391402
-e "s/@LLVM_SHLIB_SYMBOL_VERSION@/$(LLVM_SHLIB_SYMBOL_VERSION)/"
392403

393-
$(build_shlibdir)/libjulia-internal.$(JL_MAJOR_MINOR_SHLIB_EXT): $(BUILDDIR)/julia.expmap $(OBJS) $(BUILDDIR)/flisp/libflisp.a $(BUILDDIR)/support/libsupport.a $(LIBUV)
404+
$(build_shlibdir)/libjulia-internal.$(JL_MAJOR_MINOR_SHLIB_EXT): $(BUILDDIR)/julia.expmap $(OBJS) $(MMTK_LIB_DST) $(BUILDDIR)/flisp/libflisp.a $(BUILDDIR)/support/libsupport.a $(LIBUV)
394405
@$(call PRINT_LINK, $(CXXLD) $(call IMPLIB_FLAGS,$@) $(JCXXFLAGS) $(JL_CXXFLAGS) $(CXXLDFLAGS) $(SHIPFLAGS) $(OBJS) $(RPATH_LIB) -o $@ \
395406
$(JLDFLAGS) $(BOLT_LDFLAGS) $(JLIBLDFLAGS) $(RT_RELEASE_LIBS) $(call SONAME_FLAGS,libjulia-internal.$(JL_MAJOR_SHLIB_EXT)))
396407
@$(INSTALL_NAME_CMD)libjulia-internal.$(SHLIB_EXT) $@
397408
$(DSYMUTIL) $@
398409

399-
$(build_shlibdir)/libjulia-internal-debug.$(JL_MAJOR_MINOR_SHLIB_EXT): $(BUILDDIR)/julia.expmap $(DOBJS) $(BUILDDIR)/flisp/libflisp-debug.a $(BUILDDIR)/support/libsupport-debug.a $(LIBUV)
410+
$(build_shlibdir)/libjulia-internal-debug.$(JL_MAJOR_MINOR_SHLIB_EXT): $(BUILDDIR)/julia.expmap $(DOBJS) $(MMTK_LIB_DST) $(BUILDDIR)/flisp/libflisp-debug.a $(BUILDDIR)/support/libsupport-debug.a $(LIBUV)
400411
@$(call PRINT_LINK, $(CXXLD) $(call IMPLIB_FLAGS,$@) $(JCXXFLAGS) $(JL_CXXFLAGS) $(CXXLDFLAGS) $(DEBUGFLAGS) $(DOBJS) $(RPATH_LIB) -o $@ \
401412
$(JLDFLAGS) $(JLIBLDFLAGS) $(RT_DEBUG_LIBS) $(call SONAME_FLAGS,libjulia-internal-debug.$(JL_MAJOR_SHLIB_EXT)))
402413
@$(INSTALL_NAME_CMD)libjulia-internal-debug.$(SHLIB_EXT) $@

src/gc-common.c

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,38 @@ JL_DLLEXPORT jl_value_t *(jl_gc_alloc)(jl_ptls_t ptls, size_t sz, void *ty)
540540
return jl_gc_alloc_(ptls, sz, ty);
541541
}
542542

543+
JL_DLLEXPORT void *jl_malloc(size_t sz)
544+
{
545+
return jl_gc_counted_malloc(sz);
546+
}
547+
548+
//_unchecked_calloc does not check for potential overflow of nm*sz
549+
STATIC_INLINE void *_unchecked_calloc(size_t nm, size_t sz) {
550+
size_t nmsz = nm*sz;
551+
return jl_gc_counted_calloc(nmsz, 1);
552+
}
553+
554+
JL_DLLEXPORT void *jl_calloc(size_t nm, size_t sz)
555+
{
556+
if (nm > SSIZE_MAX/sz)
557+
return NULL;
558+
return _unchecked_calloc(nm, sz);
559+
}
560+
561+
JL_DLLEXPORT void jl_free(void *p)
562+
{
563+
if (p != NULL) {
564+
size_t sz = memory_block_usable_size(p, 0);
565+
return jl_gc_counted_free_with_size(p, sz);
566+
}
567+
}
568+
569+
JL_DLLEXPORT void *jl_realloc(void *p, size_t sz)
570+
{
571+
size_t old = p ? memory_block_usable_size(p, 0) : 0;
572+
return jl_gc_counted_realloc_with_old_size(p, old, sz);
573+
}
574+
543575
// =========================================================================== //
544576
// Generic Memory
545577
// =========================================================================== //

src/gc-common.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,14 @@ extern jl_gc_callback_list_t *gc_cblist_notify_external_alloc;
4343
extern jl_gc_callback_list_t *gc_cblist_notify_external_free;
4444
extern jl_gc_callback_list_t *gc_cblist_notify_gc_pressure;
4545

46+
47+
// FIXME: These are specific to the Stock GC but being declared here
48+
// for now, instead of gc-stock.h. We might want to refactor the
49+
// code in gc-stacks.c that uses these
50+
extern _Atomic(int) gc_ptls_sweep_idx;
51+
extern _Atomic(int) gc_stack_free_idx;
52+
extern _Atomic(int) gc_n_threads_sweeping_stacks;
53+
4654
#define gc_invoke_callbacks(ty, list, args) \
4755
do { \
4856
for (jl_gc_callback_list_t *cb = list; \

src/gc-debug.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// This file is a part of Julia. License is MIT: https://julialang.org/license
22

3+
#ifndef MMTK_GC
34
#include "gc-common.h"
45
#include "gc-stock.h"
56
#include "julia.h"
@@ -1129,3 +1130,5 @@ void _report_gc_finished(uint64_t pause, uint64_t freed, int full, int recollect
11291130
#ifdef __cplusplus
11301131
}
11311132
#endif
1133+
1134+
#endif // !MMTK_GC

src/gc-interface.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,11 @@ JL_DLLEXPORT void *jl_gc_perm_alloc(size_t sz, int zero, unsigned align,
199199
// must be either permanently allocated or have other roots.
200200
struct _jl_value_t *jl_gc_permobj(size_t sz, void *ty) JL_NOTSAFEPOINT;
201201

202+
// This function notifies the GC about memory addresses that are set when loading the boot image.
203+
// The GC may use that information to, for instance, determine that such objects should
204+
// be treated as marked and belonged to the old generation in nursery collections.
205+
void jl_gc_notify_image_load(const char* img_data, size_t len);
206+
202207
// ========================================================================= //
203208
// Runtime Write-Barriers
204209
// ========================================================================= //

0 commit comments

Comments
 (0)