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 6e09cb5 commit 7590998
Show file tree
Hide file tree
Showing 2 changed files with 62 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 @@ -483,6 +484,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 (JMark(obj))
YoungRef++;
}


// Overview of conservative stack scanning
//
Expand Down
36 changes: 36 additions & 0 deletions src/julia_gc.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/****************************************************************************
**
** 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; the argument may be NULL.
** Extra validation steps are performed to determine whether <obj> is
** a valid Julia object. If not, it is silently ignored.
*/

void MarkJuliaObjSafe(void * obj);

#endif

0 comments on commit 7590998

Please sign in to comment.