Skip to content

Commit

Permalink
MJIT: Get rid of is_entries copy
Browse files Browse the repository at this point in the history
MJIT worker no longer exists, so we don't need this safeguard anymore.
  • Loading branch information
k0kubun committed Nov 29, 2022
1 parent 9c13fc6 commit bb6f933
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 32 deletions.
11 changes: 3 additions & 8 deletions lib/mjit/compiler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -330,10 +330,10 @@ def compile_send(insn, stack_size, sp_inc, local_stack_p, pos, next_pos, status,
end

def compile_ivar(insn_name, stack_size, pos, status, operands, body)
ic_copy = (status.is_entries + (C.iseq_inline_storage_entry.new(operands[1]) - body.is_entries)).iv_cache
dest_shape_id = ic_copy.value >> C.SHAPE_FLAG_SHIFT
iv_cache = C.iseq_inline_storage_entry.new(operands[1]).iv_cache
dest_shape_id = iv_cache.value >> C.SHAPE_FLAG_SHIFT
source_shape_id = parent_shape_id(dest_shape_id)
attr_index = ic_copy.value & ((1 << C.SHAPE_FLAG_SHIFT) - 1)
attr_index = iv_cache.value & ((1 << C.SHAPE_FLAG_SHIFT) - 1)

src = +''
if !status.compile_info.disable_ivar_cache && source_shape_id != C.INVALID_SHAPE_ID
Expand Down Expand Up @@ -769,9 +769,6 @@ def init_compile_status(status, body, compile_root_p)
status.inlined_iseqs[i] = nil
end
end
if ISEQ_IS_SIZE(body) > 0
status.is_entries = Fiddle.malloc(C.iseq_inline_storage_entry.sizeof * ISEQ_IS_SIZE(body))
end
if body.ci_size > 0
status.cc_entries_index = C.mjit_capture_cc_entries(status.compiled_iseq, body)
else
Expand All @@ -790,8 +787,6 @@ def init_compile_status(status, body, compile_root_p)
end

def init_ivar_compile_status(body, status)
C.mjit_capture_is_entries(body, status.is_entries)

pos = 0

while pos < body.iseq_size
Expand Down
2 changes: 0 additions & 2 deletions mjit_c.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ struct compile_status {
// If true, JIT-ed code will use local variables to store pushed values instead of
// using VM's stack and moving stack pointer.
bool local_stack_p;
// Safely-accessible ivar cache entries copied from main thread.
union iseq_inline_storage_entry *is_entries;
// Index of call cache entries captured to compiled_iseq to be marked on GC
int cc_entries_index;
// A pointer to root (i.e. not inlined) iseq being compiled.
Expand Down
11 changes: 0 additions & 11 deletions mjit_c.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,16 +77,6 @@ def mjit_capture_cc_entries(compiled_body, captured_body)
Primitive.cexpr! 'INT2NUM(mjit_capture_cc_entries((struct rb_iseq_constant_body *)NUM2PTR(_compiled_body_addr), (struct rb_iseq_constant_body *)NUM2PTR(_captured_body_addr)))'
end

#const struct rb_iseq_constant_body *body, union iseq_inline_storage_entry *is_entries
def mjit_capture_is_entries(body, is_entries)
_body_addr = body.to_i
_is_entries_addr = is_entries.to_i
Primitive.cstmt! %{
mjit_capture_is_entries((struct rb_iseq_constant_body *)NUM2PTR(_body_addr), (union iseq_inline_storage_entry *)NUM2PTR(_is_entries_addr));
return Qnil;
}
end

# Convert encoded VM pointers to insn BINs.
def rb_vm_insn_decode(encoded)
Primitive.cexpr! 'INT2NUM(rb_vm_insn_decode(NUM2PTR(encoded)))'
Expand Down Expand Up @@ -246,7 +236,6 @@ def C.compile_status
success: [self._Bool, Primitive.cexpr!("OFFSETOF((*((struct compile_status *)NULL)), success)")],
stack_size_for_pos: [CType::Pointer.new { CType::Immediate.parse("int") }, Primitive.cexpr!("OFFSETOF((*((struct compile_status *)NULL)), stack_size_for_pos)")],
local_stack_p: [self._Bool, Primitive.cexpr!("OFFSETOF((*((struct compile_status *)NULL)), local_stack_p)")],
is_entries: [CType::Pointer.new { self.iseq_inline_storage_entry }, Primitive.cexpr!("OFFSETOF((*((struct compile_status *)NULL)), is_entries)")],
cc_entries_index: [CType::Immediate.parse("int"), Primitive.cexpr!("OFFSETOF((*((struct compile_status *)NULL)), cc_entries_index)")],
compiled_iseq: [CType::Pointer.new { self.rb_iseq_constant_body }, Primitive.cexpr!("OFFSETOF((*((struct compile_status *)NULL)), compiled_iseq)")],
compiled_id: [CType::Immediate.parse("int"), Primitive.cexpr!("OFFSETOF((*((struct compile_status *)NULL)), compiled_id)")],
Expand Down
11 changes: 0 additions & 11 deletions mjit_compiler.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,17 +104,6 @@ cdhash_each(VALUE key, VALUE value, VALUE hash)
extern int
mjit_capture_cc_entries(const struct rb_iseq_constant_body *compiled_iseq, const struct rb_iseq_constant_body *captured_iseq);

// Copy current is_entries and use it throughout the current compilation consistently.
// While ic->entry has been immutable since https://github.com/ruby/ruby/pull/3662,
// we still need this to avoid a race condition between entries and ivar_serial/max_ivar_index.
static void
mjit_capture_is_entries(const struct rb_iseq_constant_body *body, union iseq_inline_storage_entry *is_entries)
{
if (is_entries == NULL)
return;
memcpy(is_entries, body->is_entries, sizeof(union iseq_inline_storage_entry) * ISEQ_IS_SIZE(body));
}

// Compile ISeq to C code in `f`. It returns true if it succeeds to compile.
bool
mjit_compile(FILE *f, const rb_iseq_t *iseq, const char *funcname, int id)
Expand Down

0 comments on commit bb6f933

Please sign in to comment.