Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix exported names from gc.c to have jl_gc_ prefix #11741

Merged
merged 4 commits into from
Jun 20, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,21 @@ Deprecated or removed

* `start_timer` and `stop_timer` are replaced by `Timer` and `close`.

* The following internal julia C functions have been renamed, in order to prevent
potential naming conflicts with C libraries: ([#11741])

* `gc_wb*` -> `jl_gc_wb*`

* `gc_queue_root` -> `jl_gc_queue_root`

* `allocobj` -> `jl_gc_allocobj`

* `alloc_[0-3]w` -> `jl_gc_alloc_*w`

* `diff_gc_total_bytes` -> `jl_gc_diff_total_bytes`

* `sync_gc_total_bytes` -> `jl_gc_sync_total_bytes`

Julia v0.3.0 Release Notes
==========================

Expand Down Expand Up @@ -1462,3 +1477,4 @@ Too numerous to mention.
[#11347]: https://github.com/JuliaLang/julia/issues/11347
[#11379]: https://github.com/JuliaLang/julia/issues/11379
[#11432]: https://github.com/JuliaLang/julia/issues/11432
[#11741]: https://github.com/JuliaLang/julia/issues/11741
4 changes: 2 additions & 2 deletions doc/devdocs/object.rst
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ The mutability property of a value can be queried for with::

If the object being stored is a :c:type:`jl_value_t`, the Julia garbage collector must be notified also::

void gc_wb(jl_value_t *parent, jl_value_t *ptr);
void jl_gc_wb(jl_value_t *parent, jl_value_t *ptr);

However, the :ref:`man-embedding` section of the manual is also required reading at this point,

Expand Down Expand Up @@ -163,7 +163,7 @@ Internal to Julia, storage is typically allocated by :c:func:`newstruct` (or :fu
And at the lowest level, memory is getting allocated by a call to the garbage collector (in ``gc.c``),
then tagged with its type::

jl_value_t *allocobj(size_t nbytes);
jl_value_t *jl_gc_allocobj(size_t nbytes);
void jl_set_typeof(jl_value_t *v, jl_datatype_t *type);

.. sidebar:: :ref:`man-singleton-types`
Expand Down
17 changes: 9 additions & 8 deletions doc/manual/embedding.rst
Original file line number Diff line number Diff line change
Expand Up @@ -172,11 +172,11 @@ Several Julia values can be pushed at once using the ``JL_GC_PUSH2`` , ``JL_GC_P
// Do something with args (e.g. call jl_... functions)
JL_GC_POP();

The garbage collector also operates under the assumption that it is aware of every old-generation object pointing to a young-generation one. Any time a pointer is updated breaking that assumption, it must be signaled to the collector with the ``gc_wb`` (write barrier) function like so::
The garbage collector also operates under the assumption that it is aware of every old-generation object pointing to a young-generation one. Any time a pointer is updated breaking that assumption, it must be signaled to the collector with the ``jl_gc_wb`` (write barrier) function like so::

jl_value_t *parent = some_old_value, *child = some_young_value;
((some_specific_type*)parent)->field = child;
gc_wb(parent, child);
jl_gc_wb(parent, child);

It is in general impossible to predict which values will be old at runtime, so the write barrier must be inserted after all explicit stores. One notable exception is if the ``parent`` object was just allocated and garbage collection was not run since then. Remember that most ``jl_...`` functions can sometimes invoke garbage collection.

Expand All @@ -186,19 +186,20 @@ The write barrier is also necessary for arrays of pointers when updating their d
void **data = (void**)jl_array_data(some_array);
jl_value_t *some_value = ...;
data[0] = some_value;
gc_wb(some_array, some_value);
jl_gc_wb(some_array, some_value);


Manipulating the Garbage Collector
---------------------------------------------------

There are some functions to control the GC. In normal use cases, these should not be necessary.

========================= ==============================================================================
``void jl_gc_collect()`` Force a GC run
``void jl_gc_disable()`` Disable the GC
``void jl_gc_enable()`` Enable the GC
========================= ==============================================================================
======================= =====================================================
``jl_gc_collect()`` Force a GC run
``jl_gc_enable(0)`` Disable the GC, return previous state as int
``jl_gc_enable(1)`` Enable the GC, return previous state as int
``jl_gc_is_enabled()`` Return current state as int
======================= =====================================================

Working with Arrays
========================
Expand Down
30 changes: 15 additions & 15 deletions src/alloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ void jl_set_nth_field(jl_value_t *v, size_t i, jl_value_t *rhs)
size_t offs = jl_field_offset(st,i);
if (jl_field_isptr(st,i)) {
*(jl_value_t**)((char*)v + offs) = rhs;
if (rhs != NULL) gc_wb(v, rhs);
if (rhs != NULL) jl_gc_wb(v, rhs);
}
else {
jl_assign_bits((char*)v + offs, rhs);
Expand Down Expand Up @@ -315,7 +315,7 @@ DLLEXPORT jl_value_t *jl_new_struct_uninit(jl_datatype_t *type)
DLLEXPORT jl_function_t *jl_new_closure(jl_fptr_t fptr, jl_value_t *env,
jl_lambda_info_t *linfo)
{
jl_function_t *f = (jl_function_t*)alloc_3w(); assert(NWORDS(sizeof(jl_function_t))==3);
jl_function_t *f = (jl_function_t*)jl_gc_alloc_3w(); assert(NWORDS(sizeof(jl_function_t))==3);
jl_set_typeof(f, jl_function_type);
f->fptr = (fptr!=NULL ? fptr : linfo->fptr);
f->env = env;
Expand Down Expand Up @@ -445,7 +445,7 @@ jl_sym_t *jl_symbol(const char *str)
if (*pnode == NULL) {
*pnode = mk_symbol(str);
if (parent != NULL)
gc_wb(parent, *pnode);
jl_gc_wb(parent, *pnode);
}
return *pnode;
}
Expand Down Expand Up @@ -594,11 +594,11 @@ jl_datatype_t *jl_new_datatype(jl_sym_t *name, jl_datatype_t *super,
tn = t->name;
// init before possibly calling jl_new_typename
t->super = super;
if (super != NULL) gc_wb(t, t->super);
if (super != NULL) jl_gc_wb(t, t->super);
t->parameters = parameters;
gc_wb(t, t->parameters);
jl_gc_wb(t, t->parameters);
t->types = ftypes;
if (ftypes != NULL) gc_wb(t, t->types);
if (ftypes != NULL) jl_gc_wb(t, t->types);
t->abstract = abstract;
t->mutabl = mutabl;
t->pointerfree = 0;
Expand All @@ -616,14 +616,14 @@ jl_datatype_t *jl_new_datatype(jl_sym_t *name, jl_datatype_t *super,
else
tn = jl_new_typename((jl_sym_t*)name);
t->name = tn;
gc_wb(t, t->name);
jl_gc_wb(t, t->name);
}
t->name->names = fnames;
gc_wb(t->name, t->name->names);
jl_gc_wb(t->name, t->name->names);

if (t->name->primary == NULL) {
t->name->primary = (jl_value_t*)t;
gc_wb(t->name, t);
jl_gc_wb(t->name, t);
}

if (abstract || jl_svec_len(parameters) > 0) {
Expand Down Expand Up @@ -668,7 +668,7 @@ jl_value_t *jl_box##nb(jl_datatype_t *t, int##nb##_t x) \
{ \
assert(jl_isbits(t)); \
assert(jl_datatype_size(t) == sizeof(x)); \
jl_value_t *v = (jl_value_t*)alloc_##nw##w(); \
jl_value_t *v = (jl_value_t*)jl_gc_alloc_##nw##w(); \
jl_set_typeof(v, t); \
*(int##nb##_t*)jl_data_ptr(v) = x; \
return v; \
Expand Down Expand Up @@ -706,7 +706,7 @@ UNBOX_FUNC(gensym, ssize_t)
#define BOX_FUNC(typ,c_type,pfx,nw) \
jl_value_t *pfx##_##typ(c_type x) \
{ \
jl_value_t *v = (jl_value_t*)alloc_##nw##w(); \
jl_value_t *v = (jl_value_t*)jl_gc_alloc_##nw##w(); \
jl_set_typeof(v, jl_##typ##_type); \
*(c_type*)jl_data_ptr(v) = x; \
return v; \
Expand All @@ -728,7 +728,7 @@ jl_value_t *jl_box_##typ(c_type x) \
c_type idx = x+NBOX_C/2; \
if ((u##c_type)idx < (u##c_type)NBOX_C) \
return boxed_##typ##_cache[idx]; \
jl_value_t *v = (jl_value_t*)alloc_##nw##w(); \
jl_value_t *v = (jl_value_t*)jl_gc_alloc_##nw##w(); \
jl_set_typeof(v, jl_##typ##_type); \
*(c_type*)jl_data_ptr(v) = x; \
return v; \
Expand All @@ -739,7 +739,7 @@ jl_value_t *jl_box_##typ(c_type x) \
{ \
if (x < NBOX_C) \
return boxed_##typ##_cache[x]; \
jl_value_t *v = (jl_value_t*)alloc_##nw##w(); \
jl_value_t *v = (jl_value_t*)jl_gc_alloc_##nw##w(); \
jl_set_typeof(v, jl_##typ##_type); \
*(c_type*)jl_data_ptr(v) = x; \
return v; \
Expand Down Expand Up @@ -833,7 +833,7 @@ jl_expr_t *jl_exprn(jl_sym_t *head, size_t n)
{
jl_array_t *ar = n==0 ? (jl_array_t*)jl_an_empty_cell : jl_alloc_cell_1d(n);
JL_GC_PUSH1(&ar);
jl_expr_t *ex = (jl_expr_t*)alloc_3w(); assert(NWORDS(sizeof(jl_expr_t))==3);
jl_expr_t *ex = (jl_expr_t*)jl_gc_alloc_3w(); assert(NWORDS(sizeof(jl_expr_t))==3);
jl_set_typeof(ex, jl_expr_type);
ex->head = head;
ex->args = ar;
Expand All @@ -850,7 +850,7 @@ JL_CALLABLE(jl_f_new_expr)
JL_GC_PUSH1(&ar);
for(size_t i=0; i < nargs-1; i++)
jl_cellset(ar, i, args[i+1]);
jl_expr_t *ex = (jl_expr_t*)alloc_3w(); assert(NWORDS(sizeof(jl_expr_t))==3);
jl_expr_t *ex = (jl_expr_t*)jl_gc_alloc_3w(); assert(NWORDS(sizeof(jl_expr_t))==3);
jl_set_typeof(ex, jl_expr_type);
ex->head = (jl_sym_t*)args[0];
ex->args = ar;
Expand Down
16 changes: 8 additions & 8 deletions src/array.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ static jl_array_t *_new_array_(jl_value_t *atype, uint32_t ndims, size_t *dims,
size_t doffs = tsz;
tsz += tot;
tsz = JL_ARRAY_ALIGN(tsz, 16); // align whole object 16
a = (jl_array_t*)allocobj(tsz);
a = (jl_array_t*)jl_gc_allocobj(tsz);
jl_set_typeof(a, atype);
a->how = 0;
data = (char*)a + doffs;
Expand All @@ -91,7 +91,7 @@ static jl_array_t *_new_array_(jl_value_t *atype, uint32_t ndims, size_t *dims,
}
else {
tsz = JL_ARRAY_ALIGN(tsz, 16); // align whole object 16
a = (jl_array_t*)allocobj(tsz);
a = (jl_array_t*)jl_gc_allocobj(tsz);
JL_GC_PUSH1(&a);
jl_set_typeof(a, atype);
// temporarily initialize to make gc-safe
Expand Down Expand Up @@ -153,7 +153,7 @@ jl_array_t *jl_reshape_array(jl_value_t *atype, jl_array_t *data, jl_value_t *di

int ndimwords = jl_array_ndimwords(ndims);
int tsz = JL_ARRAY_ALIGN(sizeof(jl_array_t) + ndimwords*sizeof(size_t) + sizeof(void*), 16);
a = (jl_array_t*)allocobj(tsz);
a = (jl_array_t*)jl_gc_allocobj(tsz);
jl_set_typeof(a, atype);
a->pooled = tsz <= GC_MAX_SZCLASS;
a->ndims = ndims;
Expand Down Expand Up @@ -229,7 +229,7 @@ jl_array_t *jl_ptr_to_array_1d(jl_value_t *atype, void *data, size_t nel,

int ndimwords = jl_array_ndimwords(1);
int tsz = JL_ARRAY_ALIGN(sizeof(jl_array_t) + ndimwords*sizeof(size_t), 16);
a = (jl_array_t*)allocobj(tsz);
a = (jl_array_t*)jl_gc_allocobj(tsz);
jl_set_typeof(a, atype);
a->pooled = tsz <= GC_MAX_SZCLASS;
a->data = data;
Expand Down Expand Up @@ -280,7 +280,7 @@ jl_array_t *jl_ptr_to_array(jl_value_t *atype, void *data, jl_value_t *dims,

int ndimwords = jl_array_ndimwords(ndims);
int tsz = JL_ARRAY_ALIGN(sizeof(jl_array_t) + ndimwords*sizeof(size_t), 16);
a = (jl_array_t*)allocobj(tsz);
a = (jl_array_t*)jl_gc_allocobj(tsz);
jl_set_typeof(a, atype);
a->pooled = tsz <= GC_MAX_SZCLASS;
a->data = data;
Expand Down Expand Up @@ -354,7 +354,7 @@ jl_value_t *jl_array_to_string(jl_array_t *a)
// TODO: check type of array?
jl_datatype_t *string_type = u8_isvalid((char*)a->data, jl_array_len(a)) == 1 ? // ASCII
jl_ascii_string_type : jl_utf8_string_type;
jl_value_t *s = (jl_value_t*)alloc_1w();
jl_value_t *s = (jl_value_t*)jl_gc_alloc_1w();
jl_set_typeof(s, string_type);
jl_set_nth_field(s, 0, (jl_value_t*)a);
return s;
Expand Down Expand Up @@ -524,7 +524,7 @@ void jl_arrayset(jl_array_t *a, jl_value_t *rhs, size_t i)
if (a->how == 3) {
owner = jl_array_data_owner(a);
}
gc_wb(owner, rhs);
jl_gc_wb(owner, rhs);
}
}

Expand Down Expand Up @@ -598,7 +598,7 @@ static void array_resize_buffer(jl_array_t *a, size_t newlen, size_t oldlen, siz
if (a->ptrarray || es==1)
memset(newdata+offsnb+oldnbytes, 0, nbytes-oldnbytes-offsnb);
if (a->how == 1)
gc_wb_buf(a, newdata);
jl_gc_wb_buf(a, newdata);
a->maxsize = newlen;
}

Expand Down
4 changes: 2 additions & 2 deletions src/ast.c
Original file line number Diff line number Diff line change
Expand Up @@ -770,7 +770,7 @@ static jl_value_t *copy_ast(jl_value_t *expr, jl_svec_t *sp, int do_sp)
// of a top-level thunk that gets type inferred.
li->def = li;
li->ast = jl_prepare_ast(li, li->sparams);
gc_wb(li, li->ast);
jl_gc_wb(li, li->ast);
JL_GC_POP();
return (jl_value_t*)li;
}
Expand Down Expand Up @@ -821,7 +821,7 @@ DLLEXPORT jl_value_t *jl_copy_ast(jl_value_t *expr)
ne = jl_exprn(e->head, l);
if (l == 0) {
ne->args = jl_alloc_cell_1d(0);
gc_wb(ne, ne->args);
jl_gc_wb(ne, ne->args);
}
else {
for(i=0; i < l; i++) {
Expand Down
4 changes: 2 additions & 2 deletions src/builtins.c
Original file line number Diff line number Diff line change
Expand Up @@ -938,7 +938,7 @@ void jl_trampoline_compile_function(jl_function_t *f, int always_infer, jl_tuple
if (!jl_in_inference) {
if (!jl_is_expr(f->linfo->ast)) {
f->linfo->ast = jl_uncompress_ast(f->linfo, f->linfo->ast);
gc_wb(f->linfo, f->linfo->ast);
jl_gc_wb(f->linfo, f->linfo->ast);
}
if (always_infer || jl_eval_with_compiler_p(jl_lam_body((jl_expr_t*)f->linfo->ast),1,f->linfo->module)) {
jl_type_infer(f->linfo, sig, f->linfo);
Expand All @@ -952,7 +952,7 @@ void jl_trampoline_compile_function(jl_function_t *f, int always_infer, jl_tuple
jl_generate_fptr(f);
if (jl_boot_file_loaded && jl_is_expr(f->linfo->ast)) {
f->linfo->ast = jl_compress_ast(f->linfo, f->linfo->ast);
gc_wb(f->linfo, f->linfo->ast);
jl_gc_wb(f->linfo, f->linfo->ast);
}
}

Expand Down
Loading