aboutsummaryrefslogtreecommitdiffstats
path: root/mjit_compile.c
diff options
context:
space:
mode:
authork0kubun <k0kubun@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2019-03-18 17:20:21 +0000
committerk0kubun <k0kubun@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2019-03-18 17:20:21 +0000
commita75ae6faa931e8b9d32c99039a06b950df391a06 (patch)
tree967f7f2d95124d5b7ba2b1793d214b49bdad25c7 /mjit_compile.c
parent4d426e28d2cbbc09208987c6cf86180ea3ba3522 (diff)
downloadruby-a75ae6faa931e8b9d32c99039a06b950df391a06.tar.gz
Use alloca again instead of malloc and free
by changing interface of `mjit_copy_cache_from_main_thread`. This is also fixing deadlock introduced by r67299. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67300 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'mjit_compile.c')
-rw-r--r--mjit_compile.c16
1 files changed, 12 insertions, 4 deletions
diff --git a/mjit_compile.c b/mjit_compile.c
index 4ad083694e..7e3d4913a8 100644
--- a/mjit_compile.c
+++ b/mjit_compile.c
@@ -196,7 +196,7 @@ compile_cancel_handler(FILE *f, const struct rb_iseq_constant_body *body, struct
fprintf(f, " return Qundef;\n");
}
-extern bool mjit_copy_cache_from_main_thread(const rb_iseq_t *iseq, struct rb_call_cache **cc_entries, union iseq_inline_storage_entry **is_entries);
+extern bool mjit_copy_cache_from_main_thread(const rb_iseq_t *iseq, struct rb_call_cache *cc_entries, union iseq_inline_storage_entry *is_entries);
// Compile ISeq to C code in `f`. It returns true if it succeeds to compile.
bool
@@ -211,8 +211,18 @@ mjit_compile(FILE *f, const rb_iseq_t *iseq, const char *funcname)
if (status.stack_size_for_pos == NULL)
return false;
memset(status.stack_size_for_pos, NOT_COMPILED_STACK_SIZE, sizeof(int) * body->iseq_size);
- if (mjit_copy_cache_from_main_thread(iseq, &status.cc_entries, &status.is_entries) == false)
+
+ status.cc_entries = NULL;
+ if ((body->ci_size + body->ci_kw_size) > 0)
+ status.cc_entries = alloca(sizeof(struct rb_call_cache) * (body->ci_size + body->ci_kw_size));
+ status.is_entries = NULL;
+ if (body->is_size > 0)
+ status.is_entries = alloca(sizeof(union iseq_inline_storage_entry) * body->is_size);
+
+ if ((status.cc_entries != NULL || status.is_entries != NULL)
+ && !mjit_copy_cache_from_main_thread(iseq, status.cc_entries, status.is_entries)) {
return false;
+ }
/* For performance, we verify stack size only on compilation time (mjit_compile.inc.erb) without --jit-debug */
if (!mjit_opts.debug) {
@@ -252,8 +262,6 @@ mjit_compile(FILE *f, const rb_iseq_t *iseq, const char *funcname)
fprintf(f, "\n} /* end of %s */\n", funcname);
free(status.stack_size_for_pos);
- free(status.cc_entries);
- free(status.is_entries);
return status.success;
}