Skip to content

Commit

Permalink
Fix comp units using obsolete pointers to their filename
Browse files Browse the repository at this point in the history
CompUnits are allocated directly in gen2 while the filename that ends up in
cu->body.filename usually starts out in the nursery. So in every place we set
that filename property we need a write barrier. Otherwise the reference won't
get updated when the filename will be moved by the GC.
  • Loading branch information
niner committed Jul 30, 2019
1 parent 4227c71 commit 2dbf622
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/core/loadbytecode.c
Expand Up @@ -101,13 +101,14 @@ void MVM_load_bytecode(MVMThreadContext *tc, MVMString *filename) {
}

/* Otherwise, load from disk. */
MVMROOT(tc, filename, {
MVMROOT2(tc, cu, filename, {
char *c_filename = MVM_string_utf8_c8_encode_C_string(tc, filename);
/* XXX any exception from MVM_cu_map_from_file needs to be handled
* and c_filename needs to be freed */
cu = MVM_cu_map_from_file(tc, c_filename);
MVM_free(c_filename);
cu->body.filename = filename;
MVM_gc_write_barrier_hit(tc, (MVMCollectable *)cu);

run_comp_unit(tc, cu);

Expand All @@ -126,10 +127,11 @@ void MVM_load_bytecode_fh(MVMThreadContext *tc, MVMObject *oshandle, MVMString *
if (REPR(oshandle)->ID != MVM_REPR_ID_MVMOSHandle)
MVM_exception_throw_adhoc(tc, "loadbytecodefh requires an object with REPR MVMOSHandle");

MVMROOT(tc, filename, {
MVMROOT2(tc, cu, filename, {
MVMuint64 pos = MVM_io_tell(tc, oshandle);
cu = MVM_cu_map_from_file_handle(tc, MVM_io_fileno(tc, oshandle), pos);
cu->body.filename = filename;
MVM_gc_write_barrier_hit(tc, (MVMCollectable *)cu);

run_comp_unit(tc, cu);
});
Expand Down
1 change: 1 addition & 0 deletions src/moar.c
Expand Up @@ -428,6 +428,7 @@ void MVM_vm_run_file(MVMInstance *instance, const char *filename) {
location cu->body.filename */
MVMString *const str = MVM_string_utf8_c8_decode(tc, instance->VMString, filename, strlen(filename));
cu->body.filename = str;
MVM_gc_write_barrier_hit(tc, (MVMCollectable *)cu);

/* Run deserialization frame, if there is one. Disable specialization
* during this time, so we don't waste time logging one-shot setup
Expand Down

0 comments on commit 2dbf622

Please sign in to comment.