Skip to content

Commit fc608a5

Browse files
committed
Add makefile support (#82)
* Adding makefile support for building with mmtk
1 parent ef05833 commit fc608a5

File tree

8 files changed

+120
-43
lines changed

8 files changed

+120
-43
lines changed

Make.inc

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -833,35 +833,25 @@ JCFLAGS += -DGC_DEBUG_ENV
833833
endif
834834

835835
ifneq (${MMTK_PLAN},None)
836-
ifeq (${MMTK_JULIA_DIR},)
837-
$(error MMTK_JULIA_DIR must be set to use MMTk)
838-
endif
839836
JCXXFLAGS += -DMMTK_GC
840837
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
838+
# Do a release build on the binding by default
839+
MMTK_BUILD ?= release
848840
ifeq (${MMTK_PLAN},Immix)
849841
JCXXFLAGS += -DMMTK_PLAN_IMMIX
850842
JCFLAGS += -DMMTK_PLAN_IMMIX
851843
else
852844
$(error "Unsupported MMTk plan: $(MMTK_PLAN)")
853845
endif
846+
847+
# Location of mmtk-julia binding
848+
# (needed for api/*.h and .so file)
849+
MMTK_JULIA_DIR ?= $(BUILDROOT)/usr/lib/mmtk_julia
850+
854851
MMTK_DIR = ${MMTK_JULIA_DIR}/mmtk
855-
MMTK_API_INC = $(MMTK_DIR)/api
856-
ifeq ($(OS),Linux)
857-
MMTK_LIB_NAME := libmmtk_julia.so
858-
else
859-
$(error "Unsupported OS for MMTk")
860-
endif
861-
MMTK_LIB_SRC := $(MMTK_DIR)/target/$(MMTK_BUILD)/$(MMTK_LIB_NAME)
862-
MMTK_LIB_DST := $(BUILDROOT)/usr/lib/$(MMTK_LIB_NAME)
852+
MMTK_API_INC = ${MMTK_DIR}/api
853+
863854
MMTK_LIB := -lmmtk_julia
864-
LDFLAGS += -Wl,-rpath=$(MMTK_DIR)/target/$(MMTK_BUILD)/
865855
else
866856
MMTK_JULIA_INC :=
867857
MMTK_LIB :=
@@ -967,6 +957,21 @@ ARCH := $(BUILD_OS)
967957
endif
968958
endif
969959

960+
# MMTk is only available on x86_64 Linux for now
961+
ifneq (${MMTK_PLAN},None)
962+
963+
ifeq ($(OS),Linux)
964+
MMTK_LIB_NAME := libmmtk_julia.so
965+
else
966+
$(error "Unsupported OS for MMTk")
967+
endif
968+
969+
ifneq ($(ARCH),x86_64)
970+
$(error "Unsupported build architecture for MMTk")
971+
endif
972+
973+
endif
974+
970975
# Detect common pre-SSE2 JULIA_CPU_TARGET values known not to work (#7185)
971976
ifeq ($(MARCH),)
972977
ifneq ($(findstring $(ARCH),i386 i486 i586 i686),)
@@ -1861,9 +1866,6 @@ PRINT_PERL = printf ' %b %b\n' $(PERLCOLOR)PERL$(ENDCOLOR) $(BINCOLOR)$(GOAL)
18611866
PRINT_FLISP = printf ' %b %b\n' $(FLISPCOLOR)FLISP$(ENDCOLOR) $(BINCOLOR)$(GOAL)$(ENDCOLOR); $(1)
18621867
PRINT_JULIA = printf ' %b %b\n' $(JULIACOLOR)JULIA$(ENDCOLOR) $(BINCOLOR)$(GOAL)$(ENDCOLOR); $(1)
18631868
PRINT_DTRACE = printf ' %b %b\n' $(DTRACECOLOR)DTRACE$(ENDCOLOR) $(BINCOLOR)$(GOAL)$(ENDCOLOR); $(1)
1864-
ifneq (${MMTK_PLAN},None)
1865-
PRINT_MMTK = printf ' %b %b\n' $(LINKCOLOR)MMTK$(ENDCOLOR) $(BINCOLOR)$(GOAL)$(ENDCOLOR); $(1)
1866-
endif
18671869

18681870
else
18691871
QUIET_MAKE =
@@ -1874,9 +1876,6 @@ PRINT_PERL = echo '$(subst ','\'',$(1))'; $(1)
18741876
PRINT_FLISP = echo '$(subst ','\'',$(1))'; $(1)
18751877
PRINT_JULIA = echo '$(subst ','\'',$(1))'; $(1)
18761878
PRINT_DTRACE = echo '$(subst ','\'',$(1))'; $(1)
1877-
ifneq (${MMTK_PLAN},None)
1878-
PRINT_MMTK = echo '$(subst ','\'',$(1))'; $(1)
1879-
endif
18801879

18811880
endif # VERBOSE
18821881

deps/Makefile

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ BUILDDIR := $(BUILDDIR)$(MAYBE_HOST)
2626
# custom Makefile rules: openlibm dsfmt libsuitesparse lapack blastrampoline openblas utf8proc objconv libwhich
2727
# CMake libs: llvm llvmunwind libgit2 libssh2 mbedtls libtracyclient
2828
#
29-
# downloadable via git: llvm-svn, libuv, libopenlibm, utf8proc, libgit2, libssh2, libtracyclient
29+
# downloadable via git: llvm-svn, libuv, libopenlibm, utf8proc, libgit2, libssh2, libtracyclient, mmtk_julia
3030
#
3131
# to debug 'define' rules, replace eval at the usage site with info or error
3232

@@ -195,14 +195,18 @@ DEP_LIBS += libwhich
195195
endif
196196
endif
197197

198+
ifneq (${MMTK_PLAN},None)
199+
DEP_LIBS += mmtk_julia
200+
endif
201+
198202
DEP_LIBS_STAGED := $(DEP_LIBS)
199203

200204
# list all targets
201205
DEP_LIBS_STAGED_ALL := llvm llvm-tools clang llvmunwind unwind libuv pcre \
202206
openlibm dsfmt blastrampoline openblas lapack gmp mpfr patchelf utf8proc \
203207
objconv mbedtls libssh2 nghttp2 curl libgit2 libwhich zlib p7zip csl \
204208
sanitizers libsuitesparse lld libtracyclient ittapi nvtx JuliaSyntax \
205-
terminfo
209+
terminfo mmtk_julia
206210
DEP_LIBS_ALL := $(DEP_LIBS_STAGED_ALL)
207211

208212
ifneq ($(USE_BINARYBUILDER_OPENBLAS),0)
@@ -266,6 +270,9 @@ include $(SRCDIR)/p7zip.mk
266270
include $(SRCDIR)/libtracyclient.mk
267271
include $(SRCDIR)/terminfo.mk
268272

273+
# MMTk
274+
include $(SRCDIR)/mmtk_julia.mk
275+
269276
# vendored Julia libs
270277
include $(SRCDIR)/JuliaSyntax.mk
271278

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
4b2bc06421faf022ee6bda09a7c87f7a
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1d9d500239fa9f3eb60404458fa5fe4e31d0dd4defbbf32ce84769b33a6c21e676a48be4f3b6dd3e114f367a2bd278c5ff03bb25f0617fa0101f470701fd2b8a

deps/mmtk_julia.mk

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
## MMTK ##
2+
3+
# Both MMTK_MOVING and MMTK_PLAN should be specified in the Make.user file.
4+
# At this point, since we only support non-moving this is always set to 0
5+
# FIXME: change it to `?:` when introducing moving plans
6+
MMTK_MOVING := 0
7+
MMTK_VARS := MMTK_PLAN=$(MMTK_PLAN) MMTK_MOVING=$(MMTK_MOVING)
8+
9+
# Download the binding, build it from source
10+
ifeq (${MMTK_JULIA_DIR},$(BUILDROOT)/usr/lib/mmtk_julia)
11+
$(eval $(call git-external,mmtk_julia,MMTK_JULIA,,,$(BUILDDIR)))
12+
13+
MMTK_JULIA_DIR=$(BUILDROOT)/deps/$(BUILDDIR)/$(MMTK_JULIA_SRC_DIR)
14+
MMTK_JULIA_LIB_PATH=$(MMTK_JULIA_DIR)/mmtk/target/$(MMTK_BUILD)
15+
PROJECT_DIRS := JULIA_PATH=$(JULIAHOME) JULIA_BUILDROOT=$(BUILDROOT) MMTK_JULIA_DIR=$(MMTK_JULIA_DIR)
16+
17+
$(BUILDDIR)/$(MMTK_JULIA_SRC_DIR)/build-compiled: $(BUILDROOT)/usr/lib/libmmtk_julia.so
18+
@echo 1 > $@
19+
20+
# NB: use the absolute dir when creating the symlink
21+
$(BUILDROOT)/usr/lib/libmmtk_julia.so: $(MMTK_JULIA_LIB_PATH)/libmmtk_julia.so
22+
@ln -sf $(MMTK_JULIA_LIB_PATH)/libmmtk_julia.so $@
23+
24+
$(MMTK_JULIA_LIB_PATH)/libmmtk_julia.so: $(BUILDDIR)/$(MMTK_JULIA_SRC_DIR)/source-extracted
25+
@$(PROJECT_DIRS) $(MMTK_VARS) $(MAKE) -C $(MMTK_JULIA_DIR) $(MMTK_BUILD)
26+
27+
get-mmtk_julia: $(MMTK_JULIA_SRC_FILE)
28+
extract-mmtk_julia: $(BUILDDIR)/$(MMTK_JULIA_SRC_DIR)/source-extracted
29+
configure-mmtk_julia: extract-mmtk_julia
30+
compile-mmtk_julia: $(BUILDROOT)/usr/lib/libmmtk_julia.so
31+
fastcheck-mmtk_julia: #none
32+
check-mmtk_julia: compile-mmtk_julia
33+
34+
$(eval $(call symlink_install,mmtk_julia,$$(MMTK_JULIA_SRC_DIR),$$(BUILDROOT)/usr/lib))
35+
36+
# In this case, there is a custom version of the binding in MMTK_JULIA_DIR
37+
# Build it and symlink libmmtk_julia.so file into $(BUILDROOT)/usr/lib
38+
else
39+
40+
PROJECT_DIRS := JULIA_PATH=$(JULIAHOME) JULIA_BUILDROOT=$(BUILDROOT) MMTK_JULIA_DIR=$(MMTK_JULIA_DIR)
41+
MMTK_JULIA_LIB_PATH=$(MMTK_JULIA_DIR)/mmtk/target/$(MMTK_BUILD)
42+
43+
install-mmtk_julia: compile-mmtk_julia $(build_prefix)/manifest/mmtk_julia
44+
45+
compile-mmtk_julia: $(BUILDROOT)/usr/lib/libmmtk_julia.so
46+
47+
version-check-mmtk_julia: $(MMTK_JULIA_DIR)/mmtk/target/$(MMTK_BUILD)/libmmtk_julia.so
48+
49+
# NB: This will NOT run `cargo build` if there are changes in the Rust source files
50+
# inside the binding repo. However the target below should remake the symlink if there
51+
# are changes in the libmmtk_julia.so from the custom MMTK_JULIA_DIR folder
52+
$(BUILDROOT)/usr/lib/libmmtk_julia.so: $(MMTK_JULIA_DIR)/mmtk/target/$(MMTK_BUILD)/libmmtk_julia.so
53+
@ln -sf $(MMTK_JULIA_DIR)/mmtk/target/$(MMTK_BUILD)/libmmtk_julia.so $@
54+
55+
$(MMTK_JULIA_DIR)/mmtk/target/$(MMTK_BUILD)/libmmtk_julia.so:
56+
@$(PROJECT_DIRS) $(MMTK_VARS) $(MAKE) -C $(MMTK_JULIA_DIR) $(MMTK_BUILD)
57+
58+
MMTK_JULIA_VER := mmtk_julia_custom
59+
60+
UNINSTALL_mmtk_julia := $(MMTK_JULIA_VER) manual_mmtk_julia
61+
62+
define manual_mmtk_julia
63+
uninstall-mmtk_julia:
64+
-rm -f $(build_prefix)/manifest/mmtk_julia
65+
-rm -f $(BUILDROOT)/usr/lib/libmmtk_julia.so
66+
endef
67+
68+
$(build_prefix)/manifest/mmtk_julia: $(BUILDROOT)/usr/lib/libmmtk_julia.so
69+
@echo $(UNINSTALL_mmtk_julia) > $@
70+
71+
endif # MMTK_JULIA_DIR

deps/mmtk_julia.version

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
MMTK_JULIA_BRANCH = master
2+
MMTK_JULIA_SHA1 = 05fb25cb03dfdf082e5023dd11bbcbb23a2b75d8
3+
MMTK_JULIA_GIT_URL := https://github.com/mmtk/mmtk-julia.git
4+
MMTK_JULIA_TAR_URL = https://github.com/mmtk/mmtk-julia/archive/refs/tags/v0.29.0.tar.gz

src/Makefile

Lines changed: 3 additions & 9 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-
ifeq ($(WITH_MMTK), 1)
32+
ifneq (${MMTK_PLAN},None)
3333
FLAGS += -I$(MMTK_API_INC)
3434
endif
3535

@@ -249,12 +249,6 @@ $(BUILDDIR)/%.h.gen : $(SRCDIR)/%.d
249249
sed 's/JULIA_/JL_PROBE_/' $@ > $@.tmp
250250
mv $@.tmp $@
251251

252-
# Compile files from the binding side and copy so file into lib folder
253-
ifneq (${MMTK_PLAN},None)
254-
$(MMTK_LIB_DST): $(MMTK_LIB_SRC)
255-
@$(call PRINT_MMTK, cp $< $@)
256-
endif
257-
258252
$(BUILDDIR)/jl_internal_funcs.inc: $(SRCDIR)/jl_exported_funcs.inc
259253
# Generate `.inc` file that contains a list of `#define` macros to rename functions defined in `libjulia-internal`
260254
# to have a `ijl_` prefix instead of `jl_`, to denote that they are coming from `libjulia-internal`. This avoids
@@ -420,13 +414,13 @@ $(BUILDDIR)/julia.expmap: $(SRCDIR)/julia.expmap.in $(JULIAHOME)/VERSION $(LLVM_
420414
sed <'$<' >'$@' -e "s/@JULIA_SHLIB_SYMBOL_VERSION@/JL_LIBJULIA_$(SOMAJOR)/" \
421415
-e "s/@LLVM_SHLIB_SYMBOL_VERSION@/$(LLVM_SHLIB_SYMBOL_VERSION)/"
422416

423-
$(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)
417+
$(build_shlibdir)/libjulia-internal.$(JL_MAJOR_MINOR_SHLIB_EXT): $(BUILDDIR)/julia.expmap $(OBJS) $(BUILDDIR)/flisp/libflisp.a $(BUILDDIR)/support/libsupport.a $(LIBUV)
424418
@$(call PRINT_LINK, $(CXXLD) $(call IMPLIB_FLAGS,$@) $(JCXXFLAGS) $(JL_CXXFLAGS) $(CXXLDFLAGS) $(SHIPFLAGS) $(OBJS) $(RPATH_LIB) -o $@ \
425419
$(JLDFLAGS) $(BOLT_LDFLAGS) $(JLIBLDFLAGS) $(RT_RELEASE_LIBS) $(call SONAME_FLAGS,libjulia-internal.$(JL_MAJOR_SHLIB_EXT)))
426420
@$(INSTALL_NAME_CMD)libjulia-internal.$(SHLIB_EXT) $@
427421
$(DSYMUTIL) $@
428422

429-
$(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)
423+
$(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)
430424
@$(call PRINT_LINK, $(CXXLD) $(call IMPLIB_FLAGS,$@) $(JCXXFLAGS) $(JL_CXXFLAGS) $(CXXLDFLAGS) $(DEBUGFLAGS) $(DOBJS) $(RPATH_LIB) -o $@ \
431425
$(JLDFLAGS) $(JLIBLDFLAGS) $(RT_DEBUG_LIBS) $(call SONAME_FLAGS,libjulia-internal-debug.$(JL_MAJOR_SHLIB_EXT)))
432426
@$(INSTALL_NAME_CMD)libjulia-internal-debug.$(SHLIB_EXT) $@

src/gc-mmtk.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ JL_DLLEXPORT void jl_gc_set_max_memory(uint64_t max_mem) {
162162
// MMTk currently does not allow setting the heap size at runtime
163163
}
164164

165-
inline void maybe_collect(jl_ptls_t ptls)
165+
STATIC_INLINE void maybe_collect(jl_ptls_t ptls)
166166
{
167167
// Just do a safe point for general maybe_collect
168168
jl_gc_safepoint_(ptls);
@@ -792,12 +792,12 @@ int jl_gc_classify_pools(size_t sz, int *osize)
792792

793793
#define MMTK_MIN_ALIGNMENT 4
794794
// MMTk assumes allocation size is aligned to min alignment.
795-
inline size_t mmtk_align_alloc_sz(size_t sz) JL_NOTSAFEPOINT
795+
STATIC_INLINE size_t mmtk_align_alloc_sz(size_t sz) JL_NOTSAFEPOINT
796796
{
797797
return (sz + MMTK_MIN_ALIGNMENT - 1) & ~(MMTK_MIN_ALIGNMENT - 1);
798798
}
799799

800-
inline void* bump_alloc_fast(MMTkMutatorContext* mutator, uintptr_t* cursor, uintptr_t limit, size_t size, size_t align, size_t offset, int allocator) {
800+
STATIC_INLINE void* bump_alloc_fast(MMTkMutatorContext* mutator, uintptr_t* cursor, uintptr_t limit, size_t size, size_t align, size_t offset, int allocator) {
801801
intptr_t delta = (-offset - *cursor) & (align - 1);
802802
uintptr_t result = *cursor + (uintptr_t)delta;
803803

@@ -809,7 +809,7 @@ inline void* bump_alloc_fast(MMTkMutatorContext* mutator, uintptr_t* cursor, uin
809809
}
810810
}
811811

812-
inline void* mmtk_immix_alloc_fast(MMTkMutatorContext* mutator, size_t size, size_t align, size_t offset) {
812+
STATIC_INLINE void* mmtk_immix_alloc_fast(MMTkMutatorContext* mutator, size_t size, size_t align, size_t offset) {
813813
ImmixAllocator* allocator = &mutator->allocators.immix[MMTK_DEFAULT_IMMIX_ALLOCATOR];
814814
return bump_alloc_fast(mutator, (uintptr_t*)&allocator->cursor, (intptr_t)allocator->limit, size, align, offset, 0);
815815
}
@@ -818,17 +818,17 @@ inline void mmtk_immix_post_alloc_slow(MMTkMutatorContext* mutator, void* obj, s
818818
mmtk_post_alloc(mutator, obj, size, 0);
819819
}
820820

821-
inline void mmtk_immix_post_alloc_fast(MMTkMutatorContext* mutator, void* obj, size_t size) {
821+
STATIC_INLINE void mmtk_immix_post_alloc_fast(MMTkMutatorContext* mutator, void* obj, size_t size) {
822822
// FIXME: for now, we do nothing
823823
// but when supporting moving, this is where we set the valid object (VO) bit
824824
}
825825

826-
inline void* mmtk_immortal_alloc_fast(MMTkMutatorContext* mutator, size_t size, size_t align, size_t offset) {
826+
STATIC_INLINE void* mmtk_immortal_alloc_fast(MMTkMutatorContext* mutator, size_t size, size_t align, size_t offset) {
827827
BumpAllocator* allocator = &mutator->allocators.bump_pointer[MMTK_IMMORTAL_BUMP_ALLOCATOR];
828828
return bump_alloc_fast(mutator, (uintptr_t*)&allocator->cursor, (uintptr_t)allocator->limit, size, align, offset, 1);
829829
}
830830

831-
inline void mmtk_immortal_post_alloc_fast(MMTkMutatorContext* mutator, void* obj, size_t size) {
831+
STATIC_INLINE void mmtk_immortal_post_alloc_fast(MMTkMutatorContext* mutator, void* obj, size_t size) {
832832
// FIXME: Similarly, for now, we do nothing
833833
// but when supporting moving, this is where we set the valid object (VO) bit
834834
// and log (old gen) bit

0 commit comments

Comments
 (0)