wasmtime: Pass around more contexts instead of fields (#1486)

* wasmtime: Pass around more contexts instead of fields

This commit refactors some wasmtime internals to pass around more
context-style structures rather than individual fields of each
structure. The intention here is to make the addition of fields to a
structure easier to plumb throughout the internals of wasmtime.
Currently you need to edit lots of functions to pass lots of parameters,
but ideally after this you'll only need to edit one or two struct fields
and then relevant locations have access to the information already.

Updates in this commit are:

* `debug_info` configuration is now folded into `Tunables`. Additionally
  a `wasmtime::Config` now holds a `Tunables` directly and is passed
  into an internal `Compiler`. Eventually this should allow for direct
  configuration of the `Tunables` attributes from the `wasmtime` API,
  but no new configuration is exposed at this time.

* `ModuleTranslation` is now passed around as a whole rather than
  passing individual components to allow access to all the fields,
  including `Tunables`.

This was motivated by investigating what it would take to optionally
allow loops and such to get interrupted, but that sort of codegen
setting was currently relatively difficult to plumb all the way through
and now it's hoped to be largely just an addition to `Tunables`.

* Fix lightbeam compile
This commit is contained in:
Alex Crichton
2020-04-08 19:02:49 -05:00
committed by GitHub
parent e29c224f24
commit c4e90f729c
14 changed files with 112 additions and 180 deletions

View File

@@ -2,6 +2,7 @@ use crate::externals::MemoryCreator;
use crate::trampoline::MemoryCreatorProxy;
use anyhow::Result;
use std::cell::RefCell;
use std::cmp::min;
use std::fmt;
use std::path::Path;
use std::rc::Rc;
@@ -9,6 +10,7 @@ use std::sync::Arc;
use wasmparser::{OperatorValidatorConfig, ValidatingParserConfig};
use wasmtime_environ::settings::{self, Configurable};
use wasmtime_environ::CacheConfig;
use wasmtime_environ::Tunables;
use wasmtime_jit::{native, CompilationStrategy, Compiler};
use wasmtime_profiling::{JitDumpAgent, NullProfilerAgent, ProfilingAgent, VTuneAgent};
use wasmtime_runtime::RuntimeMemoryCreator;
@@ -26,7 +28,7 @@ use wasmtime_runtime::RuntimeMemoryCreator;
pub struct Config {
pub(crate) flags: settings::Builder,
pub(crate) validating_config: ValidatingParserConfig,
pub(crate) debug_info: bool,
pub(crate) tunables: Tunables,
pub(crate) strategy: CompilationStrategy,
pub(crate) cache_config: CacheConfig,
pub(crate) profiler: Arc<dyn ProfilingAgent>,
@@ -37,6 +39,15 @@ impl Config {
/// Creates a new configuration object with the default configuration
/// specified.
pub fn new() -> Config {
let mut tunables = Tunables::default();
if cfg!(windows) {
// For now, use a smaller footprint on Windows so that we don't
// don't outstrip the paging file.
tunables.static_memory_bound = min(tunables.static_memory_bound, 0x100);
tunables.static_memory_offset_guard_size =
min(tunables.static_memory_offset_guard_size, 0x10000);
}
let mut flags = settings::builder();
// There are two possible traps for division, and this way
@@ -56,7 +67,7 @@ impl Config {
.expect("should be valid flag");
Config {
debug_info: false,
tunables,
validating_config: ValidatingParserConfig {
operator_config: OperatorValidatorConfig {
enable_threads: false,
@@ -79,7 +90,7 @@ impl Config {
///
/// By default this option is `false`.
pub fn debug_info(&mut self, enable: bool) -> &mut Self {
self.debug_info = enable;
self.tunables.debug_info = enable;
self
}
@@ -349,7 +360,7 @@ impl fmt::Debug for Config {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let features = &self.validating_config.operator_config;
f.debug_struct("Config")
.field("debug_info", &self.debug_info)
.field("debug_info", &self.tunables.debug_info)
.field("strategy", &self.strategy)
.field("wasm_threads", &features.enable_threads)
.field("wasm_reference_types", &features.enable_reference_types)
@@ -503,6 +514,7 @@ impl Store {
isa,
engine.config.strategy,
engine.config.cache_config.clone(),
engine.config.tunables.clone(),
);
Store {
inner: Rc::new(StoreInner {