Skip to content

Commit

Permalink
Add tool for deopt count dump, repeated deopt silencing
Browse files Browse the repository at this point in the history
  • Loading branch information
semoro committed Dec 5, 2021
1 parent da41ee8 commit ac81933
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#![feature(asm)]

mod compile;
mod pads;
pub(crate) mod pads;
mod dmir;
mod codegen;
mod ref_count;
Expand Down
24 changes: 21 additions & 3 deletions src/pads/deopt.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
extern crate libc;

use std::cell::RefCell;
use std::collections::HashMap;
use auxtools::raw_types::funcs::CURRENT_EXECUTION_CONTEXT;
use auxtools::raw_types::values::{ValueData, ValueTag, Value};
use auxtools::raw_types::strings::StringId;
Expand Down Expand Up @@ -30,6 +32,10 @@ fn do_call_trampoline(proc_instance: *mut ProcInstance) -> Value {
*out = DO_CALL.unwrap()(proc);
}

thread_local! {
pub static DEOPT_COUNT: RefCell<HashMap<(ProcId, u32), u32>> = RefCell::new(HashMap::new());
}

#[no_mangle]
pub extern "C" fn handle_deopt(
out: *mut Value,
Expand All @@ -46,8 +52,20 @@ pub extern "C" fn handle_deopt(
locals: *const Value,
locals_count: u32
) {
let deopt_count = DEOPT_COUNT.with(|deopt_data| {
*deopt_data.borrow_mut().entry((proc_id, offset))
.and_modify(|prev| *prev += 1)
.or_insert(1)
});

let log_deopt =
if cfg!(deopt_print_debug) {
true
} else {
deopt_count < 10
};

log::debug!("Deopt called entry {:?}", proc_id);
if log_deopt { log::debug!("Deopt called entry {:?}", proc_id); }
unsafe {
let context = {
let size = std::mem::size_of::<ExecutionContext>() as libc::size_t;
Expand Down Expand Up @@ -159,11 +177,11 @@ pub extern "C" fn handle_deopt(
pub some_time4: Timeval,
*/

log::debug!("Deopt called: context {:?}, proc {:?}", *context, *proc);
if log_deopt { log::debug!("Deopt called: context {:?}, proc {:?}", *context, *proc); }

*out = do_call_trampoline(proc);

log::debug!("Deopt return: {:?}", *out);
if log_deopt { log::debug!("Deopt return: {:?}", *out); }
};
}

Expand Down
12 changes: 12 additions & 0 deletions src/tools.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use dmasm::Instruction;
use dmasm::format_disassembly;
use dmasm::operands::Variable;
use crate::DisassembleEnv;
use crate::pads::deopt::DEOPT_COUNT;

pub fn var_desc(v: &Variable) -> String {
match v {
Expand Down Expand Up @@ -120,3 +121,14 @@ pub fn dump_opcodes(list: Value) {
}
Ok(Value::null())
}

#[hook("/proc/dmjit_dump_deopts")]
fn dump_deopts() {
DEOPT_COUNT.with(|deopt_data| {
log::info!("Dump deopt statistics");
for ((proc_id, offset), count) in deopt_data.borrow().iter() {
log::info!("{:?} {}@{:X} -- {}", proc_id, Proc::from_id(*proc_id).map_or("_unk".to_string(), |proc| proc.path), offset, count)
}
});
Ok(Value::null())
}
3 changes: 3 additions & 0 deletions tests/testData/hook.dm
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,7 @@
DMJIT_NATIVE

/proc/dmjit_report_time(name)
DMJIT_NATIVE

/proc/dmjit_dump_deopts()
DMJIT_NATIVE

0 comments on commit ac81933

Please sign in to comment.