Skip to content

Commit

Permalink
Add marking functions for Julia objects.
Browse files Browse the repository at this point in the history
  • Loading branch information
rbehrends committed Apr 18, 2019
1 parent df48487 commit 9822c00
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/julia_gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

#include "julia.h"
#include "julia_gcext.h"
#include "julia_gc.h"


/****************************************************************************
Expand Down Expand Up @@ -482,6 +483,31 @@ static inline int JMark(void * obj)
return jl_gc_mark_queue_obj(JuliaTLS, (jl_value_t *)obj);
}

void MarkJuliaObjSafe(void * obj)
{
if (!obj)
return;
// Validate that `obj` is still allocated and not on a
// free list already. We verify this by checking that the
// type is a pool object of type `jl_datatype_type`.
jl_value_t *ty = jl_typeof(obj);
if (jl_gc_internal_obj_base_ptr(ty) != ty)
return;
if (!jl_typeis(ty, jl_datatype_type))
return;
if (jl_gc_mark_queue_obj(JuliaTLS, (jl_value_t *)obj))
YoungRef++;
}


void MarkJuliaObj(void * obj)
{
if (!obj)
return;
if (jl_gc_mark_queue_obj(JuliaTLS, (jl_value_t *)obj))
YoungRef++;
}


// Overview of conservative stack scanning
//
Expand Down
35 changes: 35 additions & 0 deletions src/julia_gc.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/****************************************************************************
**
** This file is part of GAP, a system for computational discrete algebra.
**
** Copyright of GAP belongs to its developers, whose names are too numerous
** to list here. Please refer to the COPYRIGHT file for details.
**
** SPDX-License-Identifier: GPL-2.0-or-later
**
** This file declares functions of the Julia GC interface.
*/

#ifndef GAP_JULIA_GC_H
#define GAP_JULIA_GC_H

/****************************************************************************
**
*F MarkJuliaObj(<obj>) . . . . . . . . . . . . . . . . mark Julia object
**
** 'MarkJuliaObjSafe' marks a Julia object; the argument can be NULL.
*/

void MarkJuliaObj(void * obj);

/****************************************************************************
**
*F MarkJuliaObjSafe(<obj>) . . . . . . . . . . . . . . mark Julia object
**
** 'MarkJuliaObjSafe' marks a Julia object, verifying that it is a valid
** object.
*/

void MarkJuliaObjSafe(void * obj);

#endif

0 comments on commit 9822c00

Please sign in to comment.