Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

YJIT: Make iseq_get_location consistent with iseq.c #7074

Merged
merged 2 commits into from Jan 6, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion yjit/bindgen/src/main.rs
Expand Up @@ -318,7 +318,8 @@ fn main() {
// From iseq.h
.allowlist_function("rb_vm_insn_addr2opcode")
.allowlist_function("rb_iseqw_to_iseq")
.allowlist_function("rb_iseq_method_name")
.allowlist_function("rb_iseq_label")
.allowlist_function("rb_iseq_line_no")

// From builtin.h
.allowlist_type("rb_builtin_function.*")
Expand Down
4 changes: 2 additions & 2 deletions yjit/src/codegen.rs
Expand Up @@ -586,7 +586,7 @@ pub fn gen_entry_prologue(cb: &mut CodeBlock, iseq: IseqPtr, insn_idx: u32) -> O

let mut asm = Assembler::new();
if get_option_ref!(dump_disasm).is_some() {
asm.comment(&format!("YJIT entry: {}", iseq_get_location(iseq)));
asm.comment(&format!("YJIT entry point: {}", iseq_get_location(iseq, 0)));
} else {
asm.comment("YJIT entry");
}
Expand Down Expand Up @@ -720,7 +720,7 @@ pub fn gen_single_block(
#[cfg(feature = "disasm")]
if get_option_ref!(dump_disasm).is_some() {
let blockid_idx = blockid.idx;
asm.comment(&format!("Block: {} (ISEQ offset: {})", iseq_get_location(blockid.iseq), blockid_idx));
asm.comment(&format!("Block: {} (ISEQ offset: {})", iseq_get_location(blockid.iseq, blockid_idx), blockid_idx));
}

// For each instruction to compile
Expand Down
8 changes: 4 additions & 4 deletions yjit/src/core.rs
Expand Up @@ -1536,10 +1536,10 @@ fn gen_block_series_body(
// If dump_iseq_disasm is active, see if this iseq's location matches the given substring.
// If so, we print the new blocks to the console.
if let Some(substr) = get_option_ref!(dump_iseq_disasm).as_ref() {
let iseq_location = iseq_get_location(blockid.iseq);
let blockid_idx = blockid.idx;
let iseq_location = iseq_get_location(blockid.iseq, blockid_idx);
if iseq_location.contains(substr) {
let last_block = last_blockref.borrow();
let blockid_idx = blockid.idx;
println!("Compiling {} block(s) for {}, ISEQ offsets [{}, {})", batch.len(), iseq_location, blockid_idx, last_block.end_idx);
print!("{}", disasm_iseq_insn_range(blockid.iseq, blockid.idx, last_block.end_idx));
}
Expand Down Expand Up @@ -2191,9 +2191,9 @@ pub fn invalidate_block_version(blockref: &BlockRef) {
{
// If dump_iseq_disasm is specified, print to console that blocks for matching ISEQ names were invalidated.
if let Some(substr) = get_option_ref!(dump_iseq_disasm).as_ref() {
let iseq_location = iseq_get_location(block.blockid.iseq);
let blockid_idx = block.blockid.idx;
let iseq_location = iseq_get_location(block.blockid.iseq, blockid_idx);
if iseq_location.contains(substr) {
let blockid_idx = block.blockid.idx;
println!("Invalidating block from {}, ISEQ offsets [{}, {})", iseq_location, blockid_idx, block.end_idx);
}
}
Expand Down
3 changes: 2 additions & 1 deletion yjit/src/cruby_bindings.inc.rs
Expand Up @@ -1163,8 +1163,9 @@ extern "C" {
pub fn rb_ensure_iv_list_size(obj: VALUE, len: u32, newsize: u32);
pub fn rb_vm_insn_decode(encoded: VALUE) -> ::std::os::raw::c_int;
pub fn rb_vm_insn_addr2opcode(addr: *const ::std::os::raw::c_void) -> ::std::os::raw::c_int;
pub fn rb_iseq_line_no(iseq: *const rb_iseq_t, pos: usize) -> ::std::os::raw::c_uint;
pub fn rb_iseqw_to_iseq(iseqw: VALUE) -> *const rb_iseq_t;
pub fn rb_iseq_method_name(iseq: *const rb_iseq_t) -> VALUE;
pub fn rb_iseq_label(iseq: *const rb_iseq_t) -> VALUE;
pub fn rb_vm_barrier();
pub fn rb_profile_frames(
start: ::std::os::raw::c_int,
Expand Down
17 changes: 10 additions & 7 deletions yjit/src/utils.rs
Expand Up @@ -86,21 +86,24 @@ fn ruby_str_to_rust(v: VALUE) -> String {
// Location is the file defining the method, colon, method name.
// Filenames are sometimes internal strings supplied to eval,
// so be careful with them.
pub fn iseq_get_location(iseq: IseqPtr) -> String {
pub fn iseq_get_location(iseq: IseqPtr, pos: u32) -> String {
let iseq_label = unsafe { rb_iseq_label(iseq) };
let iseq_path = unsafe { rb_iseq_path(iseq) };
let iseq_method = unsafe { rb_iseq_method_name(iseq) };
let iseq_lineno = unsafe { rb_iseq_line_no(iseq, pos as usize) };

let mut s = if iseq_path == Qnil {
let mut s = if iseq_label == Qnil {
"None".to_string()
} else {
ruby_str_to_rust(iseq_path)
ruby_str_to_rust(iseq_label)
};
s.push_str(":");
if iseq_method == Qnil {
s.push_str("@");
if iseq_path == Qnil {
s.push_str("None");
} else {
s.push_str(& ruby_str_to_rust(iseq_method));
s.push_str(&ruby_str_to_rust(iseq_path));
}
s.push_str(":");
s.push_str(&iseq_lineno.to_string());
s
}

Expand Down