Stop incrementing `jit_entry_calls` once threshold is hit

Otherwise the ISeq page will constantly be written
into preventing it from being shared.
This commit is contained in:
Jean Boussier 2023-08-22 07:46:03 +02:00
Родитель 24bcd49473
Коммит cedb333063
1 изменённых файлов: 10 добавлений и 14 удалений

22
vm.c
Просмотреть файл

@ -381,19 +381,16 @@ static VALUE vm_invoke_proc(rb_execution_context_t *ec, rb_proc_t *proc, VALUE s
static inline rb_jit_func_t
jit_compile(rb_execution_context_t *ec)
{
// Increment the ISEQ's call counter
const rb_iseq_t *iseq = ec->cfp->iseq;
struct rb_iseq_constant_body *body = ISEQ_BODY(iseq);
bool yjit_enabled = rb_yjit_compile_new_iseqs();
if (yjit_enabled || rb_rjit_call_p) {
body->jit_entry_calls++;
}
else {
if (!(yjit_enabled || rb_rjit_call_p)) {
return NULL;
}
// Trigger JIT compilation if not compiled
// Increment the ISEQ's call counter and trigger JIT compilation if not compiled
if (body->jit_entry == NULL) {
body->jit_entry_calls++;
if (yjit_enabled) {
if (rb_yjit_threshold_hit(iseq, body->jit_entry_calls)) {
rb_yjit_compile_iseq(iseq, ec, false);
@ -436,20 +433,19 @@ jit_exec(rb_execution_context_t *ec)
static inline rb_jit_func_t
jit_compile_exception(rb_execution_context_t *ec)
{
// Increment the ISEQ's call counter
const rb_iseq_t *iseq = ec->cfp->iseq;
struct rb_iseq_constant_body *body = ISEQ_BODY(iseq);
if (rb_yjit_compile_new_iseqs()) {
body->jit_exception_calls++;
}
else {
if (!rb_yjit_compile_new_iseqs()) {
return NULL;
}
// Trigger JIT compilation if not compiled
if (body->jit_exception == NULL && rb_yjit_threshold_hit(iseq, body->jit_exception_calls)) {
// Increment the ISEQ's call counter and trigger JIT compilation if not compiled
if (body->jit_exception == NULL) {
body->jit_exception_calls++;
if (rb_yjit_threshold_hit(iseq, body->jit_exception_calls)) {
rb_yjit_compile_iseq(iseq, ec, true);
}
}
return body->jit_exception;
}