summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mjit.c15
-rw-r--r--mjit_worker.c14
2 files changed, 23 insertions, 6 deletions
diff --git a/mjit.c b/mjit.c
index d3cb063ff9..bcf773d2d7 100644
--- a/mjit.c
+++ b/mjit.c
@@ -54,13 +54,13 @@ mjit_copy_job_handler(void *data)
}
const struct rb_iseq_constant_body *body = job->iseq->body;
- unsigned int ci_size = body->ci_size;
+ const unsigned int ci_size = body->ci_size;
if (ci_size > 0) {
- const struct rb_callcache **cc_entries = ALLOC_N(const struct rb_callcache *, ci_size);
- if (body->jit_unit == NULL) {
- create_unit(job->iseq);
- }
- body->jit_unit->cc_entries = cc_entries;
+ VM_ASSERT(body->jit_unit != NULL);
+ VM_ASSERT(body->jit_unit->cc_entries != NULL);
+
+ const struct rb_callcache **cc_entries = body->jit_unit->cc_entries;
+
for (unsigned int i=0; i<ci_size; i++) {
cc_entries[i] = body->call_data[i].cc;
}
@@ -294,6 +294,9 @@ create_unit(const rb_iseq_t *iseq)
unit->id = current_unit_num++;
unit->iseq = (rb_iseq_t *)iseq;
+ if (iseq->body->ci_size > 0) {
+ unit->cc_entries = ALLOC_N(const struct rb_callcache *, iseq->body->ci_size);
+ }
iseq->body->jit_unit = unit;
}
diff --git a/mjit_worker.c b/mjit_worker.c
index 85411847d7..d074b7b957 100644
--- a/mjit_worker.c
+++ b/mjit_worker.c
@@ -1131,6 +1131,20 @@ mjit_copy_cache_from_main_thread(const rb_iseq_t *iseq, union iseq_inline_storag
CRITICAL_SECTION_FINISH(3, "in mjit_copy_cache_from_main_thread");
if (UNLIKELY(mjit_opts.wait)) {
+ // setup pseudo jit_unit
+ if (iseq->body->jit_unit == NULL) {
+ // This function is invoked in mjit worker thread, so GC should not be invoked.
+ // To prevent GC with xmalloc(), use malloc() directly here.
+ // However, mixing xmalloc() and malloc() will cause another issue.
+ // TODO: fix this allocation code.
+ iseq->body->jit_unit = (struct rb_mjit_unit *)malloc(sizeof(struct rb_mjit_unit));
+ if (iseq->body->jit_unit == NULL) rb_fatal("malloc failed");
+ if (iseq->body->ci_size > 0) {
+ iseq->body->jit_unit->cc_entries =
+ (const struct rb_callcache **)malloc(sizeof(const struct rb_callcache *) * iseq->body->ci_size);
+ if (iseq->body->jit_unit->cc_entries == NULL) rb_fatal("malloc failed");
+ }
+ }
mjit_copy_job_handler((void *)job);
}
else if (rb_workqueue_register(0, mjit_copy_job_handler, (void *)job)) {