Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
compunit->update_mutex is now a MVMReentrantMutex.
There is also a BOOTReentrantMutex now.
  • Loading branch information
timo committed Aug 5, 2014
1 parent a4b0381 commit ef00cc5
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 16 deletions.
5 changes: 4 additions & 1 deletion src/6model/bootstrap.c
Expand Up @@ -576,7 +576,8 @@ void MVM_6model_bootstrap(MVMThreadContext *tc) {

/* Create stub VMNull, BOOTInt, BOOTNum, BOOTStr, BOOTArray, BOOTHash,
* BOOTCCode, BOOTCode, BOOTThread, BOOTIter, BOOTContext, SCRef, Lexotic,
* CallCapture, BOOTIO, BOOTException, BOOTQueue, and BOOTAsync types. */
* CallCapture, BOOTIO, BOOTException, BOOTQueue, BOOTAsync,
* and BOOTReentrantMutex types. */
#define create_stub_boot_type(tc, reprid, slot, makeboolspec, boolspec) do { \
const MVMREPROps *repr = MVM_repr_get_by_id(tc, reprid); \
MVMObject *type = tc->instance->slot = repr->type_object_for(tc, NULL); \
Expand Down Expand Up @@ -611,6 +612,7 @@ void MVM_6model_bootstrap(MVMThreadContext *tc) {
create_stub_boot_type(tc, MVM_REPR_ID_MVMThread, Thread, 0, MVM_BOOL_MODE_NOT_TYPE_OBJECT);
create_stub_boot_type(tc, MVM_REPR_ID_ConcBlockingQueue, boot_types.BOOTQueue, 0, MVM_BOOL_MODE_NOT_TYPE_OBJECT);
create_stub_boot_type(tc, MVM_REPR_ID_MVMAsyncTask, boot_types.BOOTAsync, 0, MVM_BOOL_MODE_NOT_TYPE_OBJECT);
create_stub_boot_type(tc, MVM_REPR_ID_ReentrantMutex, boot_types.BOOTReentrantMutex, 0, MVM_BOOL_MODE_NOT_TYPE_OBJECT);

/* Bootstrap the KnowHOW type, giving it a meta-object. */
bootstrap_KnowHOW(tc);
Expand Down Expand Up @@ -644,6 +646,7 @@ void MVM_6model_bootstrap(MVMThreadContext *tc) {
meta_objectifier(tc, Thread, "Thread");
meta_objectifier(tc, boot_types.BOOTQueue, "BOOTQueue");
meta_objectifier(tc, boot_types.BOOTAsync, "BOOTAsync");
meta_objectifier(tc, boot_types.BOOTReentrantMutex, "BOOTReentrantMutex");

/* Create the KnowHOWAttribute type. */
create_KnowHOWAttribute(tc);
Expand Down
9 changes: 5 additions & 4 deletions src/6model/reprs/MVMCompUnit.c
Expand Up @@ -27,8 +27,9 @@ static MVMObject * type_object_for(MVMThreadContext *tc, MVMObject *HOW) {
/* Initializes a new instance. */
static void initialize(MVMThreadContext *tc, MVMSTable *st, MVMObject *root, void *data) {
MVMCompUnitBody *body = (MVMCompUnitBody *)data;
body->update_pools_mutex = malloc(sizeof(uv_mutex_t));
uv_mutex_init(body->update_pools_mutex);
MVMObject *mutextype = tc->instance->boot_types.BOOTReentrantMutex;
body->update_mutex = REPR(mutextype)->allocate(tc, STABLE(mutextype));
REPR(mutextype)->initialize(tc, STABLE(mutextype), body->update_mutex, OBJECT_BODY(body->update_mutex));
}

/* Copies the body of one object to another. */
Expand Down Expand Up @@ -65,6 +66,8 @@ static void gc_mark(MVMThreadContext *tc, MVMSTable *st, void *data, MVMGCWorkli
/* Unresolved sc bodies' handles are marked by the GC instance root marking. */
}

MVM_gc_worklist_add(tc, worklist, &body->update_mutex);

/* Add various other referenced strings, etc. */
MVM_gc_worklist_add(tc, worklist, &body->hll_name);
MVM_gc_worklist_add(tc, worklist, &body->filename);
Expand Down Expand Up @@ -98,8 +101,6 @@ static void gc_free(MVMThreadContext *tc, MVMObject *obj) {
default:
MVM_panic(MVM_exitcode_NYI, "Invalid deallocate of %u during MVMCompUnit gc_free", body->deallocate);
}
uv_mutex_destroy(body->update_pools_mutex);
free(body->update_pools_mutex);
}

/* Gets the storage specification for this representation. */
Expand Down
8 changes: 5 additions & 3 deletions src/6model/reprs/MVMCompUnit.h
Expand Up @@ -94,9 +94,11 @@ struct MVMCompUnitBody {
/* Handle, if any, associated with a mapped file. */
void *handle;

/* Lock to be taken if we want to add extra string, callsite, or coderef
* constants to the pools (done during inlining). */
uv_mutex_t *update_pools_mutex;
/* MVMReentrantLock to be taken if we want to add extra string,
* callsite, or coderef constants to the pools (done during
* inlining) or when we finish deserializing a frame, thus
* vivifying its lexicals. */
MVMObject *update_mutex;

/* Version of the bytecode format we deserialized this comp unit from. */
MVMuint16 bytecode_version;
Expand Down
12 changes: 12 additions & 0 deletions src/core/bytecode.c
Expand Up @@ -616,6 +616,15 @@ void MVM_bytecode_finish_frame(MVMThreadContext *tc, MVMCompUnit *cu, MVMStaticF
if (sf->body.fully_deserialized)
return;

/* Acquire the update mutex on the CompUnit. */
MVM_reentrantmutex_lock(tc, (MVMReentrantMutex *)cu->body.update_mutex);

/* Ensure no other thread has done this for us in the mean time. */
if (sf->body.fully_deserialized) {
MVM_reentrantmutex_unlock(tc, (MVMReentrantMutex *)cu->body.update_mutex);
return;
}

/* Locate start of frame body. */
pos = sf->body.frame_data_pos;

Expand Down Expand Up @@ -699,6 +708,9 @@ void MVM_bytecode_finish_frame(MVMThreadContext *tc, MVMCompUnit *cu, MVMStaticF

/* Mark the frame fully deserialized. */
sf->body.fully_deserialized = 1;

/* Release the update mutex again */
MVM_reentrantmutex_unlock(tc, (MVMReentrantMutex *)cu->body.update_mutex);
}

/* Loads the callsites. */
Expand Down
8 changes: 4 additions & 4 deletions src/core/compunit.c
Expand Up @@ -66,7 +66,7 @@ MVMuint16 MVM_cu_callsite_add(MVMThreadContext *tc, MVMCompUnit *cu, MVMCallsite
MVMuint16 found = 0;
MVMuint16 idx;

uv_mutex_lock(cu->body.update_pools_mutex);
MVM_reentrantmutex_lock(tc, (MVMReentrantMutex *)cu->body.update_mutex);

/* See if we already know this callsite. */
for (idx = 0; idx < cu->body.num_callsites; idx++)
Expand All @@ -83,7 +83,7 @@ MVMuint16 MVM_cu_callsite_add(MVMThreadContext *tc, MVMCompUnit *cu, MVMCallsite
cu->body.num_callsites++;
}

uv_mutex_unlock(cu->body.update_pools_mutex);
MVM_reentrantmutex_unlock(tc, (MVMReentrantMutex *)cu->body.update_mutex);

return idx;
}
Expand All @@ -93,7 +93,7 @@ MVMuint32 MVM_cu_string_add(MVMThreadContext *tc, MVMCompUnit *cu, MVMString *st
MVMuint32 found = 0;
MVMuint32 idx;

uv_mutex_lock(cu->body.update_pools_mutex);
MVM_reentrantmutex_lock(tc, (MVMReentrantMutex *)cu->body.update_mutex);

/* See if we already know this string; only consider those added already by
* inline, since we don't intern and don't want this to be costly to hunt. */
Expand All @@ -111,7 +111,7 @@ MVMuint32 MVM_cu_string_add(MVMThreadContext *tc, MVMCompUnit *cu, MVMString *st
cu->body.num_strings++;
}

uv_mutex_unlock(cu->body.update_pools_mutex);
MVM_reentrantmutex_unlock(tc, (MVMReentrantMutex *)cu->body.update_mutex);

return idx;
}
1 change: 1 addition & 0 deletions src/core/instance.h
Expand Up @@ -22,6 +22,7 @@ struct MVMBootTypes {
MVMObject *BOOTContinuation;
MVMObject *BOOTQueue;
MVMObject *BOOTAsync;
MVMObject *BOOTReentrantMutex;
};

/* Various raw types that don't need a HOW */
Expand Down
8 changes: 4 additions & 4 deletions src/spesh/inline.c
Expand Up @@ -6,14 +6,14 @@ static void demand_extop(MVMThreadContext *tc, MVMCompUnit *target_cu, MVMCompUn
MVMExtOpRecord *extops;
MVMuint16 i, num_extops;

uv_mutex_lock(target_cu->body.update_pools_mutex);
MVM_reentrantmutex_lock(tc, (MVMReentrantMutex *)target_cu->body.update_mutex);

/* See if the target compunit already has the extop. */
extops = target_cu->body.extops;
num_extops = target_cu->body.num_extops;
for (i = 0; i < num_extops; i++)
if (extops[i].info == info) {
uv_mutex_unlock(target_cu->body.update_pools_mutex);
MVM_reentrantmutex_unlock(tc, (MVMReentrantMutex *)target_cu->body.update_mutex);
return;
}

Expand All @@ -29,13 +29,13 @@ static void demand_extop(MVMThreadContext *tc, MVMCompUnit *target_cu, MVMCompUn
memcpy(&target_cu->body.extops[target_cu->body.num_extops],
&extops[i], sizeof(MVMExtOpRecord));
target_cu->body.num_extops++;
uv_mutex_unlock(target_cu->body.update_pools_mutex);
MVM_reentrantmutex_unlock(tc, (MVMReentrantMutex *)target_cu->body.update_mutex);
return;
}
}

/* Didn't find it; should be impossible. */
uv_mutex_unlock(target_cu->body.update_pools_mutex);
MVM_reentrantmutex_unlock(tc, (MVMReentrantMutex *)target_cu->body.update_mutex);
MVM_exception_throw_adhoc(tc, "Spesh: inline failed to find source CU extop entry");
}

Expand Down

0 comments on commit ef00cc5

Please sign in to comment.