mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Take VM lock in branch_stub_hit(), fix ractor deadlock.
This commit is contained in:
parent
dde69ab5c6
commit
cf4021ca78
4 changed files with 18 additions and 3 deletions
1
ujit.h
1
ujit.h
|
@ -41,6 +41,7 @@ bool rb_ujit_enabled_p(void)
|
||||||
return rb_ujit_enabled;
|
return rb_ujit_enabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Threshold==1 means compile on first execution
|
||||||
#define UJIT_CALL_THRESHOLD (2u)
|
#define UJIT_CALL_THRESHOLD (2u)
|
||||||
|
|
||||||
void rb_ujit_method_lookup_change(VALUE cme_or_cc);
|
void rb_ujit_method_lookup_change(VALUE cme_or_cc);
|
||||||
|
|
|
@ -912,7 +912,6 @@ gen_opt_send_without_block(jitstate_t* jit, ctx_t* ctx)
|
||||||
for (int32_t i = 0; i < argc + 1; ++i)
|
for (int32_t i = 0; i < argc + 1; ++i)
|
||||||
{
|
{
|
||||||
x86opnd_t stack_opnd = mem_opnd(64, RAX, -(argc + 1 - i) * 8);
|
x86opnd_t stack_opnd = mem_opnd(64, RAX, -(argc + 1 - i) * 8);
|
||||||
//print_ptr(cb, stack_opnd);
|
|
||||||
x86opnd_t c_arg_reg = C_ARG_REGS[i];
|
x86opnd_t c_arg_reg = C_ARG_REGS[i];
|
||||||
mov(cb, c_arg_reg, stack_opnd);
|
mov(cb, c_arg_reg, stack_opnd);
|
||||||
}
|
}
|
||||||
|
|
11
ujit_core.c
11
ujit_core.c
|
@ -3,6 +3,7 @@
|
||||||
#include "builtin.h"
|
#include "builtin.h"
|
||||||
#include "insns.inc"
|
#include "insns.inc"
|
||||||
#include "insns_info.inc"
|
#include "insns_info.inc"
|
||||||
|
#include "vm_sync.h"
|
||||||
#include "ujit_asm.h"
|
#include "ujit_asm.h"
|
||||||
#include "ujit_utils.h"
|
#include "ujit_utils.h"
|
||||||
#include "ujit_iface.h"
|
#include "ujit_iface.h"
|
||||||
|
@ -162,7 +163,7 @@ uint8_t* gen_entry_point(const rb_iseq_t *iseq, uint32_t insn_idx)
|
||||||
{
|
{
|
||||||
// The entry context makes no assumptions about types
|
// The entry context makes no assumptions about types
|
||||||
blockid_t blockid = { iseq, insn_idx };
|
blockid_t blockid = { iseq, insn_idx };
|
||||||
ctx_t ctx = { 0 };
|
ctx_t ctx = { { 0 }, 0 };
|
||||||
|
|
||||||
// Write the interpreter entry prologue
|
// Write the interpreter entry prologue
|
||||||
uint8_t* code_ptr = ujit_entry_prologue();
|
uint8_t* code_ptr = ujit_entry_prologue();
|
||||||
|
@ -183,6 +184,10 @@ uint8_t* gen_entry_point(const rb_iseq_t *iseq, uint32_t insn_idx)
|
||||||
// Triggers compilation of branches and code patching
|
// Triggers compilation of branches and code patching
|
||||||
uint8_t* branch_stub_hit(uint32_t branch_idx, uint32_t target_idx)
|
uint8_t* branch_stub_hit(uint32_t branch_idx, uint32_t target_idx)
|
||||||
{
|
{
|
||||||
|
uint8_t* dst_addr;
|
||||||
|
|
||||||
|
RB_VM_LOCK_ENTER();
|
||||||
|
|
||||||
assert (branch_idx < num_branches);
|
assert (branch_idx < num_branches);
|
||||||
assert (target_idx < 2);
|
assert (target_idx < 2);
|
||||||
branch_t *branch = &branch_entries[branch_idx];
|
branch_t *branch = &branch_entries[branch_idx];
|
||||||
|
@ -217,7 +222,7 @@ uint8_t* branch_stub_hit(uint32_t branch_idx, uint32_t target_idx)
|
||||||
add_incoming(p_block, branch_idx);
|
add_incoming(p_block, branch_idx);
|
||||||
|
|
||||||
// Update the branch target address
|
// Update the branch target address
|
||||||
uint8_t* dst_addr = cb_get_ptr(cb, p_block->start_pos);
|
dst_addr = cb_get_ptr(cb, p_block->start_pos);
|
||||||
branch->dst_addrs[target_idx] = dst_addr;
|
branch->dst_addrs[target_idx] = dst_addr;
|
||||||
|
|
||||||
// Rewrite the branch with the new jump target address
|
// Rewrite the branch with the new jump target address
|
||||||
|
@ -230,6 +235,8 @@ uint8_t* branch_stub_hit(uint32_t branch_idx, uint32_t target_idx)
|
||||||
branch->end_pos = cb->write_pos;
|
branch->end_pos = cb->write_pos;
|
||||||
cb_set_pos(cb, cur_pos);
|
cb_set_pos(cb, cur_pos);
|
||||||
|
|
||||||
|
RB_VM_LOCK_LEAVE();
|
||||||
|
|
||||||
// Return a pointer to the compiled block version
|
// Return a pointer to the compiled block version
|
||||||
return dst_addr;
|
return dst_addr;
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,9 +20,17 @@
|
||||||
// Maximum number of versions per block
|
// Maximum number of versions per block
|
||||||
#define MAX_VERSIONS 5
|
#define MAX_VERSIONS 5
|
||||||
|
|
||||||
|
// Maximum number of temp value types we keep track of
|
||||||
|
#define MAX_TEMP_TYPES 8
|
||||||
|
|
||||||
// Code generation context
|
// Code generation context
|
||||||
typedef struct CtxStruct
|
typedef struct CtxStruct
|
||||||
{
|
{
|
||||||
|
// Temporary variable types we keep track of
|
||||||
|
// Values are `ruby_value_type`
|
||||||
|
// T_NONE==0 is the unknown type
|
||||||
|
uint8_t temp_types[MAX_TEMP_TYPES];
|
||||||
|
|
||||||
// Number of values pushed on the temporary stack
|
// Number of values pushed on the temporary stack
|
||||||
uint32_t stack_size;
|
uint32_t stack_size;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue