Allow disabling state tracking for faster startup.

This commit is contained in:
losfair 2019-07-12 23:33:54 +08:00
parent f327feccef
commit 08cdc9a42f
4 changed files with 21 additions and 1 deletions

View File

@ -117,6 +117,7 @@ pub struct CompilerConfig {
pub symbol_map: Option<HashMap<u32, String>>, pub symbol_map: Option<HashMap<u32, String>>,
pub memory_bound_check_mode: MemoryBoundCheckMode, pub memory_bound_check_mode: MemoryBoundCheckMode,
pub enforce_stack_check: bool, pub enforce_stack_check: bool,
pub track_state: bool,
} }
pub trait Compiler { pub trait Compiler {

View File

@ -317,6 +317,7 @@ pub struct CodegenError {
struct CodegenConfig { struct CodegenConfig {
memory_bound_check_mode: MemoryBoundCheckMode, memory_bound_check_mode: MemoryBoundCheckMode,
enforce_stack_check: bool, enforce_stack_check: bool,
track_state: bool,
} }
impl ModuleCodeGenerator<X64FunctionCode, X64ExecutionContext, CodegenError> impl ModuleCodeGenerator<X64FunctionCode, X64ExecutionContext, CodegenError>
@ -366,7 +367,8 @@ impl ModuleCodeGenerator<X64FunctionCode, X64ExecutionContext, CodegenError>
begin_label_info.1 = Some(begin_offset); begin_label_info.1 = Some(begin_offset);
let begin_label = begin_label_info.0; let begin_label = begin_label_info.0;
let machine = Machine::new(); let mut machine = Machine::new();
machine.track_state = self.config.as_ref().unwrap().track_state;
dynasm!( dynasm!(
assembler assembler
@ -532,6 +534,7 @@ impl ModuleCodeGenerator<X64FunctionCode, X64ExecutionContext, CodegenError>
self.config = Some(Arc::new(CodegenConfig { self.config = Some(Arc::new(CodegenConfig {
memory_bound_check_mode: config.memory_bound_check_mode, memory_bound_check_mode: config.memory_bound_check_mode,
enforce_stack_check: config.enforce_stack_check, enforce_stack_check: config.enforce_stack_check,
track_state: config.track_state,
})); }));
Ok(()) Ok(())
} }
@ -1594,6 +1597,9 @@ impl X64FunctionCode {
fsm: &mut FunctionStateMap, fsm: &mut FunctionStateMap,
control_stack: &mut [ControlFrame], control_stack: &mut [ControlFrame],
) -> usize { ) -> usize {
if !m.track_state {
return ::std::usize::MAX;
}
let last_frame = control_stack.last_mut().unwrap(); let last_frame = control_stack.last_mut().unwrap();
let mut diff = m.state.diff(&last_frame.state); let mut diff = m.state.diff(&last_frame.state);
diff.last = Some(last_frame.state_diff_id); diff.last = Some(last_frame.state_diff_id);

View File

@ -13,6 +13,7 @@ pub struct Machine {
stack_offset: MachineStackOffset, stack_offset: MachineStackOffset,
save_area_offset: Option<MachineStackOffset>, save_area_offset: Option<MachineStackOffset>,
pub state: MachineState, pub state: MachineState,
pub(crate) track_state: bool,
} }
impl Machine { impl Machine {
@ -23,6 +24,7 @@ impl Machine {
stack_offset: MachineStackOffset(0), stack_offset: MachineStackOffset(0),
save_area_offset: None, save_area_offset: None,
state: x64::new_machine_state(), state: x64::new_machine_state(),
track_state: true,
} }
} }

View File

@ -112,10 +112,16 @@ struct Run {
)] )]
loader: Option<LoaderName>, loader: Option<LoaderName>,
/// Path to previously saved instance image to resume.
#[cfg(feature = "backend-singlepass")] #[cfg(feature = "backend-singlepass")]
#[structopt(long = "resume")] #[structopt(long = "resume")]
resume: Option<String>, resume: Option<String>,
/// Whether or not state tracking should be disabled during compilation.
/// State tracking is necessary for tier switching and backtracing.
#[structopt(long = "no-track-state")]
no_track_state: bool,
/// The command name is a string that will override the first argument passed /// The command name is a string that will override the first argument passed
/// to the wasm program. This is used in wapm to provide nicer output in /// to the wasm program. This is used in wapm to provide nicer output in
/// help commands and error messages of the running wasm program /// help commands and error messages of the running wasm program
@ -326,6 +332,8 @@ fn execute_wasm(options: &Run) -> Result<(), String> {
Backend::LLVM => return Err("the llvm backend is not enabled".to_string()), Backend::LLVM => return Err("the llvm backend is not enabled".to_string()),
}; };
let track_state = !options.no_track_state;
#[cfg(feature = "loader:kernel")] #[cfg(feature = "loader:kernel")]
let is_kernel_loader = if let Some(LoaderName::Kernel) = options.loader { let is_kernel_loader = if let Some(LoaderName::Kernel) = options.loader {
true true
@ -343,6 +351,7 @@ fn execute_wasm(options: &Run) -> Result<(), String> {
symbol_map: em_symbol_map, symbol_map: em_symbol_map,
memory_bound_check_mode: MemoryBoundCheckMode::Disable, memory_bound_check_mode: MemoryBoundCheckMode::Disable,
enforce_stack_check: true, enforce_stack_check: true,
track_state,
}, },
&*compiler, &*compiler,
) )
@ -352,6 +361,7 @@ fn execute_wasm(options: &Run) -> Result<(), String> {
&wasm_binary[..], &wasm_binary[..],
CompilerConfig { CompilerConfig {
symbol_map: em_symbol_map, symbol_map: em_symbol_map,
track_state,
..Default::default() ..Default::default()
}, },
&*compiler, &*compiler,
@ -397,6 +407,7 @@ fn execute_wasm(options: &Run) -> Result<(), String> {
&wasm_binary[..], &wasm_binary[..],
CompilerConfig { CompilerConfig {
symbol_map: em_symbol_map, symbol_map: em_symbol_map,
track_state,
..Default::default() ..Default::default()
}, },
&*compiler, &*compiler,