Skip to content

Commit

Permalink
Add new garbage collector based on Julia
Browse files Browse the repository at this point in the history
Use `--with-gc=julia` to switch to this alternative garbage
collector. There is also a new `--with-julia=` option which
can be used to point GAP at the correct Julia version (which
currently still needs some patches to add APIs we need).

The main work is in the new file src/julia_gc.c
  • Loading branch information
rbehrends authored and fingolfin committed May 14, 2018
1 parent 4b6b55b commit 3dc0186
Show file tree
Hide file tree
Showing 5 changed files with 827 additions and 5 deletions.
4 changes: 4 additions & 0 deletions GNUmakefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ READLINE_CPPFLAGS = @READLINE_CPPFLAGS@
READLINE_LDFLAGS = @READLINE_LDFLAGS@
READLINE_LIBS = @READLINE_LIBS@

JULIA_CPPFLAGS = @JULIA_CPPFLAGS@
JULIA_LDFLAGS = @JULIA_LDFLAGS@
JULIA_LIBS = @JULIA_LIBS@

BUILD_BOEHM_GC = @BUILD_BOEHM_GC@
BOEHM_GC_CPPFLAGS = @BOEHM_GC_CPPFLAGS@
BOEHM_GC_LDFLAGS = @BOEHM_GC_LDFLAGS@
Expand Down
4 changes: 4 additions & 0 deletions Makefile.rules
Original file line number Diff line number Diff line change
Expand Up @@ -151,11 +151,13 @@ GAP_PKG_CPPFLAGS += $(DEFS)
# Add flags for dependencies
GAP_CPPFLAGS += $(GMP_CPPFLAGS)
GAP_CPPFLAGS += $(READLINE_CPPFLAGS)
GAP_CPPFLAGS += $(JULIA_CPPFLAGS)
GAP_CPPFLAGS += $(BOEHM_GC_CPPFLAGS)
GAP_CPPFLAGS += $(LIBATOMIC_OPS_CPPFLAGS)

GAP_PKG_CPPFLAGS += $(GMP_CPPFLAGS)
GAP_PKG_CPPFLAGS += $(READLINE_CPPFLAGS)
GAP_PKG_CPPFLAGS += $(JULIA_CPPFLAGS)
GAP_PKG_CPPFLAGS += $(BOEHM_GC_CPPFLAGS)
GAP_PKG_CPPFLAGS += $(LIBATOMIC_OPS_CPPFLAGS)

Expand Down Expand Up @@ -188,6 +190,7 @@ GAP_LDFLAGS = $(ABI_CFLAGS)
# Add flags for dependencies
GAP_LDFLAGS += $(GMP_LDFLAGS)
GAP_LDFLAGS += $(READLINE_LDFLAGS)
GAP_LDFLAGS += $(JULIA_LDFLAGS)
GAP_LDFLAGS += $(BOEHM_GC_LDFLAGS)
GAP_LDFLAGS += $(LIBATOMIC_OPS_LDFLAGS)

Expand All @@ -205,6 +208,7 @@ GAP_LIBS =
# Add flags for dependencies
GAP_LIBS += $(GMP_LIBS)
GAP_LIBS += $(READLINE_LIBS)
GAP_LIBS += $(JULIA_LIBS)
GAP_LIBS += $(BOEHM_GC_LIBS)
GAP_LIBS += $(LIBATOMIC_OPS_LIBS)

Expand Down
50 changes: 48 additions & 2 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ dnl
dnl User setting: garbage collector to use
dnl
AC_ARG_WITH([gc],
[AS_HELP_STRING([--with-gc@<:@=default|gasman|boehm@:>@],
[AS_HELP_STRING([--with-gc@<:@=default|gasman|boehm|julia@:>@],
[specify which garbage collector to use (default: gasman; for HPC-GAP: boehm)])],
[],
[with_gc=default])
Expand All @@ -223,7 +223,10 @@ AS_CASE([$with_gc],
AC_SUBST([GC_SOURCES], [src/gasman.c])
AC_DEFINE([USE_GASMAN], [1], [define as 1 if GASMAN is used])
],
[*], [AC_MSG_ERROR([Invalid gc method '$with_gc', use default|none|gasman|boehm])],
[julia], [AC_SUBST([GC_SOURCES], [src/julia_gc.c])
AC_DEFINE([USE_JULIA_GC], [1], [define as 1 if the Julia GC is used])
],
[*], [AC_MSG_ERROR([Invalid gc method '$with_gc', use default|none|gasman|boehm|julia])],
)
AC_MSG_RESULT([$with_gc])

Expand Down Expand Up @@ -389,6 +392,49 @@ AC_SUBST([READLINE_CPPFLAGS])
AC_SUBST([READLINE_LDFLAGS])
AC_SUBST([READLINE_LIBS])


dnl Find julia
AC_ARG_WITH([julia],
[AS_HELP_STRING([--with-julia@<:@=PREFIX@:>@],
[specify a prefix where julia can be found])])

AS_IF([test "x$with_julia" != xno],[
JULIA_LIBS="-ljulia"
AS_CASE([x"$with_julia"],
[xyes|x],[
JULIA_CPPFLAGS=
JULIA_LDFLAGS=
],
[*],[
JULIA_CPPFLAGS="-I$with_julia/include/julia"
JULIA_LDFLAGS="-L$with_julia/lib -Wl,-rpath,$with_julia/lib"
JULIA_LIBS="-ljulia"
]
)
AX_CHECK_LIBRARY([JULIA], [julia.h], [julia], [jl_gc_alloc], [], [], [])
# TODO: also check for gcext.h, so that we can be sure the user is pointing
# at a modified version of Julia.
AS_IF([test $ax_cv_have_JULIA = yes],[
AC_DEFINE([HAVE_LIBJULIA], [1], [Define if you have libjulia])
],[
AS_CASE([x"$with_julia"],
[x], [JULIA_CPPFLAGS= JULIA_LDFLAGS= JULIA_LIBS=],
[*], [AC_MSG_FAILURE([--with-julia was given, but test for julia failed])]
)
])
])

dnl TODO: check if $with_gc = julia; if so, error out if julia is not found


AC_SUBST([JULIA_CPPFLAGS])
AC_SUBST([JULIA_LDFLAGS])
AC_SUBST([JULIA_LIBS])


dnl Find ward (if HPC-GAP mode is enabled)
AC_ARG_WITH([ward],
[AS_HELP_STRING([--with-ward@<:@=PREFIX@:>@],
Expand Down
23 changes: 20 additions & 3 deletions src/gasman.h
Original file line number Diff line number Diff line change
Expand Up @@ -338,10 +338,20 @@ static inline void SET_PTR_BAG(Bag bag, Bag *val)

#if !defined(USE_GASMAN)

#ifndef USE_JULIA_GC

static inline void CHANGED_BAG(Bag bag)
{
}

#else

// Julia
//
void CHANGED_BAG(Bag bag);

#endif

#elif defined(MEMORY_CANARY)

/****************************************************************************
Expand Down Expand Up @@ -822,10 +832,10 @@ extern void MarkAllButFirstSubBags( Bag bag );
** identifier.
*/
#ifdef USE_GASMAN
extern void MarkBag( Bag bag );
#else
#ifdef USE_BOEHM_GC
static inline void MarkBag( Bag bag ) {}
#else
extern void MarkBag( Bag bag );
#endif


Expand Down Expand Up @@ -889,6 +899,13 @@ extern Bag * AllocBags;
#define FORGET_WP(loc) \
GC_unregister_disappearing_link((void **)(loc))

#else

#define IS_WEAK_DEAD_BAG(bag) (0)

#define REGISTER_WP(loc, obj) ((void) 0)
#define FORGET_WP(loc) ((void) 0)

#endif

/****************************************************************************
Expand Down
Loading

0 comments on commit 3dc0186

Please sign in to comment.