Skip to content

Commit

Permalink
Adding a few comments; Moving some functions to be closer together
Browse files Browse the repository at this point in the history
  • Loading branch information
udesou committed Sep 25, 2024
1 parent 9469eb9 commit 5c83754
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 289 deletions.
70 changes: 0 additions & 70 deletions src/gc-common.c
Original file line number Diff line number Diff line change
Expand Up @@ -709,76 +709,6 @@ JL_DLLEXPORT void jl_throw_out_of_memory_error(void)
jl_throw(jl_memory_exception);
}

size_t jl_genericmemory_nbytes(jl_genericmemory_t *m) JL_NOTSAFEPOINT
{
const jl_datatype_layout_t *layout = ((jl_datatype_t*)jl_typetagof(m))->layout;
size_t sz = layout->size * m->length;
if (layout->flags.arrayelem_isunion)
// account for isbits Union array selector bytes
sz += m->length;
return sz;
}

// tracking Memorys with malloc'd storage
void jl_gc_track_malloced_genericmemory(jl_ptls_t ptls, jl_genericmemory_t *m, int isaligned){
// This is **NOT** a GC safe point.
mallocmemory_t *ma;
if (ptls->gc_tls.heap.mafreelist == NULL) {
ma = (mallocmemory_t*)malloc_s(sizeof(mallocmemory_t));
}
else {
ma = ptls->gc_tls.heap.mafreelist;
ptls->gc_tls.heap.mafreelist = ma->next;
}
ma->a = (jl_genericmemory_t*)((uintptr_t)m | !!isaligned);
ma->next = ptls->gc_tls.heap.mallocarrays;
ptls->gc_tls.heap.mallocarrays = ma;
}

int gc_logging_enabled = 0;

JL_DLLEXPORT void jl_enable_gc_logging(int enable) {
gc_logging_enabled = enable;
}

JL_DLLEXPORT int jl_is_gc_logging_enabled(void) {
return gc_logging_enabled;
}

// gc-debug common functions
// ---

int gc_slot_to_fieldidx(void *obj, void *slot, jl_datatype_t *vt) JL_NOTSAFEPOINT
{
int nf = (int)jl_datatype_nfields(vt);
for (int i = 1; i < nf; i++) {
if (slot < (void*)((char*)obj + jl_field_offset(vt, i)))
return i - 1;
}
return nf - 1;
}

int gc_slot_to_arrayidx(void *obj, void *_slot) JL_NOTSAFEPOINT
{
char *slot = (char*)_slot;
jl_datatype_t *vt = (jl_datatype_t*)jl_typeof(obj);
char *start = NULL;
size_t len = 0;
size_t elsize = sizeof(void*);
if (vt == jl_module_type) {
jl_module_t *m = (jl_module_t*)obj;
start = (char*)m->usings.items;
len = m->usings.len;
}
else if (vt == jl_simplevector_type) {
start = (char*)jl_svec_data(obj);
len = jl_svec_len(obj);
}
if (slot < start || slot >= start + elsize * len)
return -1;
return (slot - start) / elsize;
}

#ifdef __cplusplus
}
#endif
Loading

0 comments on commit 5c83754

Please sign in to comment.