Skip to content

Commit

Permalink
WIP: add DISABLE_BIGVAL_TRACKING
Browse files Browse the repository at this point in the history
  • Loading branch information
fingolfin committed Jun 27, 2018
1 parent 5567eb3 commit 9df3b78
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/julia_gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@
#include "julia.h"
#include "julia_gcext.h"

// if DISABLE_BIGVAL_TRACKING is defined, we don't track the location of
// large bags; this speeds up some things, but may expose bugs in GAP code
// which incorrectly holds pointers into bags over a GC.
//#define DISABLE_BIGVAL_TRACKING

#define MARK_CACHE_BITS 16
#define MARK_CACHE_SIZE (1 << MARK_CACHE_BITS)

Expand Down Expand Up @@ -82,6 +87,8 @@ void JFinalizer(jl_value_t * obj)
TabFreeFuncBags[tnum]((Bag)&contents);
}

#if !defined(DISABLE_BIGVAL_TRACKING)

/****************************************************************************
**
** Treap functionality
Expand Down Expand Up @@ -114,6 +121,7 @@ static inline int cmp_ptr(void * p, void * q)
else
return 0;
}
#endif

static inline int lt_ptr(void * a, void * b)
{
Expand Down Expand Up @@ -151,6 +159,8 @@ static inline void * align_ptr(void * p)
return (void *)u;
}

#if !defined(DISABLE_BIGVAL_TRACKING)

typedef struct treap_t {
struct treap_t *left, *right;
size_t prio;
Expand Down Expand Up @@ -346,6 +356,8 @@ void free_bigval(void * p)
}
}

#endif

static jl_module_t * Module;
static jl_datatype_t * datatype_mptr;
static jl_datatype_t * datatype_bag;
Expand All @@ -354,7 +366,9 @@ static Bag * StackBottomBags;
static UInt StackAlignBags;
static jl_ptls_t JuliaTLS, SaveTLS;
static size_t max_pool_obj_size;
#if !defined(DISABLE_BIGVAL_TRACKING)
static size_t bigval_startoffset;
#endif
static UInt YoungRef;


Expand Down Expand Up @@ -431,6 +445,7 @@ static void TryMark(void * p)
{
jl_value_t * p2 = jl_gc_internal_obj_base_ptr(p);
if (!p2) {
#if !defined(DISABLE_BIGVAL_TRACKING)
// It is possible for p to point past the end of
// the object, so we subtract one word from the
// address. This is safe, as the object is preceded
Expand All @@ -450,6 +465,7 @@ static void TryMark(void * p)
if (hdr->type != jl_gc_internal_obj_base_ptr(hdr->type))
return;
}
#endif
}
else {
if (jl_typeis(p2, datatype_mptr))
Expand Down Expand Up @@ -579,9 +595,11 @@ void InitBags(UInt initial_size, Bag * stack_bottom, UInt stack_align)
TabMarkFuncBags[i] = MarkAllSubBags;
// These callbacks need to be set before initialization so
// that we can track objects allocated during `jl_init()`.
#if !defined(DISABLE_BIGVAL_TRACKING)
jl_gc_register_callback(notify_external_alloc, alloc_bigval);
jl_gc_register_callback(notify_external_free, free_bigval);
bigval_startoffset = jl_gc_external_obj_hdr_size();
#endif
max_pool_obj_size = jl_gc_max_internal_obj_size();
jl_init();
JuliaTLS = jl_get_ptls_states();
Expand Down Expand Up @@ -671,15 +689,27 @@ Bag NewBag(UInt type, UInt size)
if (size == 0)
alloc_size++;

#if defined(DISABLE_BIGVAL_TRACKING)
bag = jl_gc_alloc_typed(JuliaTLS, sizeof(void *), datatype_mptr);
SET_PTR_BAG(bag, 0);
#endif

BagHeader * header = AllocateBagMemory(type, alloc_size);

header->type = type;
header->flags = 0;
header->size = size;


#if !defined(DISABLE_BIGVAL_TRACKING)
// allocate the new masterpointer
bag = jl_gc_alloc_typed(JuliaTLS, sizeof(void *), datatype_mptr);
SET_PTR_BAG(bag, DATA(header));
#else
// change the masterpointer to reference the new bag memory
SET_PTR_BAG(bag, DATA(header));
jl_gc_wb_back((void *)bag);
#endif

// return the identifier of the new bag
return bag;
Expand Down

0 comments on commit 9df3b78

Please sign in to comment.