Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions concurrent_set.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,26 @@ concurrent_set_size(const void *ptr)
(set->capacity * sizeof(struct concurrent_set_entry));
}

/* Hack: Though it would be trivial, we're intentionally avoiding WB-protecting
* this object. This prevents the object from aging and ensures it can always be
* collected in a minor GC.
* Longer term this deserves a better way to reclaim memory promptly.
*/
static void
concurrent_set_mark(void *ptr)
{
(void)ptr;
}

static const rb_data_type_t concurrent_set_type = {
.wrap_struct_name = "VM/concurrent_set",
.function = {
.dmark = NULL,
.dmark = concurrent_set_mark,
.dfree = concurrent_set_free,
.dsize = concurrent_set_size,
},
.flags = RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED | RUBY_TYPED_EMBEDDABLE
/* Hack: NOT WB_PROTECTED on purpose (see above) */
.flags = RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_EMBEDDABLE
};

VALUE
Expand Down
10 changes: 5 additions & 5 deletions template/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -664,14 +664,14 @@ $(INSNS): $(srcdir)/insns.def vm_opts.h \
$(tooldir)/ruby_vm/loaders/opt_operand_def.rb \
$(tooldir)/ruby_vm/loaders/vm_opts_h.rb \
$(tooldir)/ruby_vm/models/attribute.rb \
$(tooldir)/ruby_vm/models/bare_instructions.rb \
$(tooldir)/ruby_vm/models/bare_instruction.rb \
$(tooldir)/ruby_vm/models/c_expr.rb \
$(tooldir)/ruby_vm/models/instructions.rb \
$(tooldir)/ruby_vm/models/instructions_unifications.rb \
$(tooldir)/ruby_vm/models/operands_unifications.rb \
$(tooldir)/ruby_vm/models/trace_instructions.rb \
$(tooldir)/ruby_vm/models/instructions_unification.rb \
$(tooldir)/ruby_vm/models/operands_unification.rb \
$(tooldir)/ruby_vm/models/trace_instruction.rb \
$(tooldir)/ruby_vm/models/typemap.rb \
$(tooldir)/ruby_vm/models/zjit_instructions.rb \
$(tooldir)/ruby_vm/models/zjit_instruction.rb \
$(tooldir)/ruby_vm/scripts/converter.rb \
$(tooldir)/ruby_vm/scripts/insns2vm.rb \
$(tooldir)/ruby_vm/views/_attributes.erb \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
require_relative 'typemap'
require_relative 'attribute'

class RubyVM::BareInstructions
class RubyVM::BareInstruction
attr_reader :template, :name, :operands, :pops, :rets, :decls, :expr

def initialize opts = {}
Expand Down Expand Up @@ -224,13 +224,13 @@ def typesplit a
new h.merge(:template => h)
}

def self.fetch name
def self.find(name)
@instances.find do |insn|
insn.name == name
end or raise IndexError, "instruction not found: #{name}"
end

def self.to_a
def self.all
@instances
end
end
19 changes: 10 additions & 9 deletions tool/ruby_vm/models/instructions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@
# conditions mentioned in the file COPYING are met. Consult the file for
# details.

require_relative 'bare_instructions'
require_relative 'operands_unifications'
require_relative 'instructions_unifications'
require_relative 'bare_instruction'
require_relative 'operands_unification'
require_relative 'instructions_unification'
require_relative 'trace_instruction'
require_relative 'zjit_instruction'

RubyVM::Instructions = RubyVM::BareInstructions.to_a + \
RubyVM::OperandsUnifications.to_a + \
RubyVM::InstructionsUnifications.to_a

require_relative 'trace_instructions'
require_relative 'zjit_instructions'
RubyVM::Instructions = RubyVM::BareInstruction.all +
RubyVM::OperandsUnification.all +
RubyVM::InstructionsUnification.all +
RubyVM::TraceInstruction.all +
RubyVM::ZJITInstruction.all
RubyVM::Instructions.freeze
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@

require_relative '../helpers/c_escape'
require_relative '../loaders/opt_insn_unif_def'
require_relative 'bare_instructions'
require_relative 'bare_instruction'

class RubyVM::InstructionsUnifications
class RubyVM::InstructionsUnification
include RubyVM::CEscape

attr_reader :name
Expand All @@ -22,7 +22,7 @@ def initialize opts = {}
@location = opts[:location]
@name = namegen opts[:signature]
@series = opts[:signature].map do |i|
RubyVM::BareInstructions.fetch i # Misshit is fatal
RubyVM::BareInstruction.find(i) # Misshit is fatal
end
end

Expand All @@ -36,7 +36,7 @@ def namegen signature
new h
end

def self.to_a
def self.all
@instances
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@

require_relative '../helpers/c_escape'
require_relative '../loaders/opt_operand_def'
require_relative 'bare_instructions'
require_relative 'bare_instruction'

class RubyVM::OperandsUnifications < RubyVM::BareInstructions
class RubyVM::OperandsUnification < RubyVM::BareInstruction
include RubyVM::CEscape

attr_reader :preamble, :original, :spec

def initialize opts = {}
name = opts[:signature][0]
@original = RubyVM::BareInstructions.fetch name
@original = RubyVM::BareInstruction.find(name)
template = @original.template
parts = compose opts[:location], opts[:signature], template[:signature]
json = template.dup
Expand Down Expand Up @@ -129,12 +129,12 @@ def compose location, spec, template
new h
end

def self.to_a
def self.all
@instances
end

def self.each_group
to_a.group_by(&:original).each_pair do |k, v|
all.group_by(&:original).each_pair do |k, v|
yield k, v
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
# details.

require_relative '../helpers/c_escape'
require_relative 'bare_instructions'
require_relative 'bare_instruction'

class RubyVM::TraceInstructions
class RubyVM::TraceInstruction
include RubyVM::CEscape

attr_reader :name
Expand Down Expand Up @@ -58,17 +58,13 @@ def has_attribute? *;
return false
end

def zjit_profile?
return false
end

private

@instances = RubyVM::Instructions.map {|i| new i }
@instances = (RubyVM::BareInstruction.all +
RubyVM::OperandsUnification.all +
RubyVM::InstructionsUnification.all).map {|i| new(i) }

def self.to_a
def self.all
@instances
end

RubyVM::Instructions.push(*to_a)
end
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
require_relative '../helpers/c_escape'
require_relative 'bare_instructions'
require_relative 'bare_instruction'

# Profile YARV instructions to optimize code generated by ZJIT
class RubyVM::ZJITInstructions
class RubyVM::ZJITInstruction
include RubyVM::CEscape

attr_reader :name
Expand Down Expand Up @@ -48,11 +48,9 @@ def has_attribute?(*)
return false
end

@instances = RubyVM::Instructions.filter(&:zjit_profile?).map {|i| new(i) }
@instances = RubyVM::BareInstruction.all.filter(&:zjit_profile?).map {|i| new(i) }

def self.to_a
def self.all
@instances
end

RubyVM::Instructions.push(*to_a)
end
2 changes: 1 addition & 1 deletion tool/ruby_vm/views/_insn_leaf_info.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ insn_leaf(int insn, const VALUE *opes)
{
switch (insn) {
% RubyVM::Instructions.each do |insn|
% next if insn.is_a?(RubyVM::TraceInstructions) || insn.is_a?(RubyVM::ZJITInstructions)
% next if insn.is_a?(RubyVM::TraceInstruction) || insn.is_a?(RubyVM::ZJITInstruction)
case <%= insn.bin %>:
return attr_leaf_<%= insn.name %>(<%=
insn.operands.map.with_index do |ope, i|
Expand Down
4 changes: 2 additions & 2 deletions tool/ruby_vm/views/_zjit_helpers.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ static int
vm_bare_insn_to_zjit_insn(int insn)
{
switch (insn) {
% RubyVM::ZJITInstructions.to_a.each do |insn|
% RubyVM::ZJITInstruction.all.each do |insn|
case BIN(<%= insn.jump_destination %>):
return <%= insn.bin %>;
% end
Expand All @@ -19,7 +19,7 @@ static int
vm_zjit_insn_to_bare_insn(int insn)
{
switch (insn) {
% RubyVM::ZJITInstructions.to_a.each do |insn|
% RubyVM::ZJITInstruction.all.each do |insn|
case <%= insn.bin %>:
return BIN(<%= insn.jump_destination %>);
% end
Expand Down
4 changes: 2 additions & 2 deletions tool/ruby_vm/views/optinsn.inc.erb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ insn_operands_unification(INSN *iobj)
/* do nothing */;
break;

% RubyVM::OperandsUnifications.each_group do |orig, unifs|
% RubyVM::OperandsUnification.each_group do |orig, unifs|
case <%= orig.bin %>:
% unifs.each do |insn|

Expand Down Expand Up @@ -56,7 +56,7 @@ rb_insn_unified_local_var_level(VALUE insn)
switch (insn) {
default:
return -1; /* do nothing */;
% RubyVM::OperandsUnifications.each_group do |orig, unifs|
% RubyVM::OperandsUnification.each_group do |orig, unifs|
% unifs.each do|insn|
case <%= insn.bin %>:
% insn.spec.map{|(var,val)|val}.reject{|i| i == '*' }.each do |val|
Expand Down
10 changes: 5 additions & 5 deletions tool/ruby_vm/views/vm.inc.erb
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,22 @@
} -%>

#include "vm_insnhelper.h"
% RubyVM::BareInstructions.to_a.each do |insn|
% RubyVM::BareInstruction.all.each do |insn|
<%= render 'insn_entry', locals: { insn: insn } -%>
% end
%
% RubyVM::OperandsUnifications.to_a.each do |insn|
% RubyVM::OperandsUnification.all.each do |insn|
<%= render 'insn_entry', locals: { insn: insn } -%>
% end
%
% RubyVM::InstructionsUnifications.to_a.each do |insn|
% RubyVM::InstructionsUnification.all.each do |insn|
<%= render 'insn_entry', locals: { insn: insn } -%>
% end
%
% RubyVM::ZJITInstructions.to_a.each do |insn|
% RubyVM::ZJITInstruction.all.each do |insn|
<%= render 'zjit_instruction', locals: { insn: insn } -%>
% end
%
% RubyVM::TraceInstructions.to_a.each do |insn|
% RubyVM::TraceInstruction.all.each do |insn|
<%= render 'trace_instruction', locals: { insn: insn } -%>
% end
3 changes: 2 additions & 1 deletion vm_callinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,8 @@ vm_cc_invalidate(const struct rb_callcache *cc)
{
VM_ASSERT(IMEMO_TYPE_P(cc, imemo_callcache));
VM_ASSERT(cc != vm_cc_empty());
VM_ASSERT(cc->klass != Qundef); // should be enable
// TODO: rb_multi_ractor_p() is a workaround to stabilize CI
VM_ASSERT(cc->klass != Qundef || rb_multi_ractor_p()); // should be enable

*(VALUE *)&cc->klass = Qundef;
RB_DEBUG_COUNTER_INC(cc_ent_invalidate);
Expand Down
4 changes: 2 additions & 2 deletions yjit/src/asm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -441,12 +441,12 @@ impl CodeBlock {

// Ignore empty code ranges
if start_addr == end_addr {
return (0..0).into_iter();
return 0..0;
}

let start_page = (start_addr.raw_addr(self) - mem_start) / self.page_size;
let end_page = (end_addr.raw_addr(self) - mem_start - 1) / self.page_size;
(start_page..end_page + 1).into_iter()
start_page..end_page + 1
}

/// Get a (possibly dangling) direct pointer to the current write position
Expand Down
2 changes: 1 addition & 1 deletion yjit/src/backend/ir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1602,7 +1602,7 @@ impl Assembler
if c_args.len() > 0 {
// Resolve C argument dependencies
let c_args_len = c_args.len() as isize;
let moves = Self::reorder_reg_moves(&c_args.drain(..).into_iter().collect());
let moves = Self::reorder_reg_moves(&c_args.drain(..).collect());
shift_live_ranges(&mut shifted_live_ranges, asm.insns.len(), moves.len() as isize - c_args_len);

// Push batched C arguments
Expand Down
16 changes: 5 additions & 11 deletions yjit/src/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -821,11 +821,11 @@ fn gen_stub_exit(ocb: &mut OutlinedCb) -> Option<CodePtr> {

/// Generate an exit to return to the interpreter
fn gen_exit(exit_pc: *mut VALUE, asm: &mut Assembler) {
#[cfg(all(feature = "disasm", not(test)))]
{
#[cfg(not(test))]
asm_comment!(asm, "exit to interpreter on {}", {
let opcode = unsafe { rb_vm_insn_addr2opcode((*exit_pc).as_ptr()) };
asm_comment!(asm, "exit to interpreter on {}", insn_name(opcode as usize));
}
insn_name(opcode as usize)
});

if asm.ctx.is_return_landing() {
asm.mov(SP, Opnd::mem(64, CFP, RUBY_OFFSET_CFP_SP));
Expand Down Expand Up @@ -1094,11 +1094,7 @@ pub fn gen_entry_prologue(
let code_ptr = cb.get_write_ptr();

let mut asm = Assembler::new(unsafe { get_iseq_body_local_table_size(iseq) });
if get_option_ref!(dump_disasm).is_some() {
asm_comment!(asm, "YJIT entry point: {}", iseq_get_location(iseq, 0));
} else {
asm_comment!(asm, "YJIT entry");
}
asm_comment!(asm, "YJIT entry point: {}", iseq_get_location(iseq, 0));

asm.frame_setup();

Expand Down Expand Up @@ -1296,7 +1292,6 @@ pub fn gen_single_block(
let mut asm = Assembler::new(jit.num_locals());
asm.ctx = ctx;

#[cfg(feature = "disasm")]
if get_option_ref!(dump_disasm).is_some() {
let blockid_idx = blockid.idx;
let chain_depth = if asm.ctx.get_chain_depth() > 0 { format!("(chain_depth: {})", asm.ctx.get_chain_depth()) } else { "".to_string() };
Expand Down Expand Up @@ -9051,7 +9046,6 @@ fn gen_send_general(
let recv_opnd: YARVOpnd = recv.into();

// Log the name of the method we're calling to
#[cfg(feature = "disasm")]
asm_comment!(asm, "call to {}", get_method_name(Some(comptime_recv_klass), mid));

// Gather some statistics about sends
Expand Down
2 changes: 1 addition & 1 deletion yjit/src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1099,7 +1099,7 @@ impl Context {
MapToLocal(local_idx) => {
bits.push_op(CtxOp::MapTempLocal);
bits.push_u3(stack_idx as u8);
bits.push_u3(local_idx as u8);
bits.push_u3(local_idx);
}

MapToSelf => {
Expand Down
5 changes: 1 addition & 4 deletions yjit/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,7 @@ pub fn ruby_str_to_rust(v: VALUE) -> String {
let str_ptr = unsafe { rb_RSTRING_PTR(v) } as *mut u8;
let str_len: usize = unsafe { rb_RSTRING_LEN(v) }.try_into().unwrap();
let str_slice: &[u8] = unsafe { slice::from_raw_parts(str_ptr, str_len) };
match String::from_utf8(str_slice.to_vec()) {
Ok(utf8) => utf8,
Err(_) => String::new(),
}
String::from_utf8(str_slice.to_vec()).unwrap_or_default()
}

// Location is the file defining the method, colon, method name.
Expand Down
Loading