Skip to content

Commit

Permalink
various memory cleanup cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
diakopter committed Sep 5, 2013
1 parent 98b2f4e commit 0c8cf07
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 26 deletions.
5 changes: 1 addition & 4 deletions src/6model/reprs/MVMArray.c
Expand Up @@ -92,10 +92,7 @@ static void gc_mark(MVMThreadContext *tc, MVMSTable *st, void *data, MVMGCWorkli
/* Called by the VM in order to free memory associated with this object. */
static void gc_free(MVMThreadContext *tc, MVMObject *obj) {
MVMArray *arr = (MVMArray *)obj;
if (arr->body.slots.any) {
free(arr->body.slots.any);
arr->body.slots.any = NULL;
}
MVM_checked_free_null(arr->body.slots.any);
}

/* Gets the storage specification for this representation. */
Expand Down
8 changes: 2 additions & 6 deletions src/6model/reprs/MVMCallCapture.c
Expand Up @@ -62,12 +62,8 @@ static void gc_free(MVMThreadContext *tc, MVMObject *obj) {
/* We made our own copy of the args buffer and processing context, so
* free them both. */
if (ctx->body.apc) {
if (ctx->body.apc->args) {
free(ctx->body.apc->args);
ctx->body.apc->args = NULL;
}
free(ctx->body.apc);
ctx->body.apc = NULL;
MVM_checked_free_null(ctx->body.apc->args);
MVM_checked_free_null(ctx->body.apc);
}
}
}
Expand Down
4 changes: 1 addition & 3 deletions src/6model/reprs/MVMString.c
Expand Up @@ -75,9 +75,7 @@ static void gc_mark(MVMThreadContext *tc, MVMSTable *st, void *data, MVMGCWorkli
/* Called by the VM in order to free memory associated with this object. */
static void gc_free(MVMThreadContext *tc, MVMObject *obj) {
MVMString *str = (MVMString *)obj;
if (str->body.storage)
free(str->body.storage);
str->body.storage = NULL;
MVM_checked_free_null(str->body.storage);
str->body.graphs = str->body.codes = str->body.flags = 0;
}

Expand Down
8 changes: 4 additions & 4 deletions src/6model/reprs/NFA.c
Expand Up @@ -57,10 +57,10 @@ static void gc_free(MVMThreadContext *tc, MVMObject *obj) {
MVMNFA *nfa = (MVMNFA *)obj;
MVMint64 i;
for (i = 0; i < nfa->body.num_states; i++)
if (nfa->body.states[i])
free(nfa->body.states[i]);
free(nfa->body.states);
free(nfa->body.num_state_edges);
if (nfa->body.num_state_edges[i])
MVM_checked_free_null(nfa->body.states[i]);
MVM_checked_free_null(nfa->body.states);
MVM_checked_free_null(nfa->body.num_state_edges);
}

/* Gets the storage specification for this representation. */
Expand Down
3 changes: 2 additions & 1 deletion src/6model/reprs/P6opaque.c
Expand Up @@ -977,7 +977,8 @@ void change_type(MVMThreadContext *tc, MVMObject *obj, MVMObject *new_type) {
/* Allocate new memory. */
size_t new_size = STABLE(new_type)->size - sizeof(MVMObject);
void *new = malloc(new_size);
memset(new, 0, new_size);
memset((char *)new + (STABLE(obj)->size - sizeof(MVMObject)),
0, new_size - (STABLE(obj)->size - sizeof(MVMObject)));

/* Copy existing to new.
* XXX Need more care here, as may have to re-barrier pointers. */
Expand Down
4 changes: 1 addition & 3 deletions src/6model/reprs/SCRef.c
Expand Up @@ -63,8 +63,6 @@ static void gc_mark(MVMThreadContext *tc, MVMSTable *st, void *data, MVMGCWorkli
for (i = 0; i < sc->num_stables; i++)
MVM_gc_worklist_add(tc, worklist, &sc->root_stables[i]);

/* Maintain backlink (yes, this is ugly). */
sc->sc = (MVMSerializationContext *)((char *)data - sizeof(MVMObject));
MVM_gc_worklist_add(tc, worklist, &sc->sc);
}

Expand All @@ -79,7 +77,7 @@ static void gc_free(MVMThreadContext *tc, MVMObject *obj) {

/* Free manually managed STable list memory and body. */
MVM_checked_free_null(sc->body->root_stables);
free(sc->body);
MVM_checked_free_null(sc->body);
}

/* Gets the storage specification for this representation. */
Expand Down
8 changes: 4 additions & 4 deletions src/gc/collect.c
Expand Up @@ -513,7 +513,7 @@ void MVM_gc_collect_free_nursery_uncopied(MVMThreadContext *tc, void *limit) {
/* Object instance. If dead, call gc_free if needed. Scan is
* incremented by object size. */
MVMObject *obj = (MVMObject *)item;
/* GCCOLL_LOG(tc, "Thread %d run %d : collecting an object %d in the nursery\n", item);*/
GCCOLL_LOG(tc, "Thread %d run %d : collecting an object %d in the nursery with reprid %d\n", item, REPR(obj)->ID);
if (dead && REPR(obj)->gc_free)
REPR(obj)->gc_free(tc, obj);
}
Expand Down Expand Up @@ -609,7 +609,7 @@ void MVM_gc_collect_free_gen2_unmarked(MVMThreadContext *tc) {
}
else if (col->flags & MVM_CF_STABLE) {
if (col->sc == (MVMSerializationContext *)1) {
/* we marked it dead last time, kill it. */
/* We marked it dead last time, kill it. */
MVM_6model_stable_gc_free(tc, (MVMSTable *)col);
}
else {
Expand All @@ -621,7 +621,8 @@ void MVM_gc_collect_free_gen2_unmarked(MVMThreadContext *tc) {
/* There will definitely be another gc run, so mark it as "died last time". */
col->sc = (MVMSerializationContext *)1;
}
goto skip_freelist_update;
/* Skip the freelist updating. */
continue;
}
}
else {
Expand All @@ -635,7 +636,6 @@ void MVM_gc_collect_free_gen2_unmarked(MVMThreadContext *tc) {

/* Update the pointer to the insert position to point to us */
freelist_insert_pos = (char ***)cur_ptr;
skip_freelist_update: ;
}

/* Move to the next object. */
Expand Down
2 changes: 1 addition & 1 deletion src/moarvm.c
Expand Up @@ -150,7 +150,7 @@ void MVM_vm_destroy_instance(MVMInstance *instance) {

/* Run the GC global destruction phase. After this,
* no 6model object pointers should be accessed. */
//MVM_gc_global_destruction(instance->main_thread);
MVM_gc_global_destruction(instance->main_thread);

/* Free various instance-wide storage. */
MVM_checked_free_null(instance->boot_types);
Expand Down

0 comments on commit 0c8cf07

Please sign in to comment.