-
Notifications
You must be signed in to change notification settings - Fork 73
Extract common bytecode operations into WasmBase. #161
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
Changes from 1 commit
2700591
a4cffd8
5e61151
a1135d9
fc1afd9
be7ddb5
6066894
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,7 +58,8 @@ class WasmBase : public std::enable_shared_from_this<WasmBase> { | |
WasmBase(const std::shared_ptr<WasmHandleBase> &other, WasmVmFactory factory); | ||
virtual ~WasmBase(); | ||
|
||
bool initialize(const std::string &code, bool allow_precompiled = false); | ||
bool load(const std::string &code, bool allow_precompiled = false); | ||
bool initialize(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
void startVm(ContextBase *root_context); | ||
bool configure(ContextBase *root_context, std::shared_ptr<PluginBase> plugin); | ||
// Returns the root ContextBase or nullptr if onStart returns false. | ||
|
@@ -79,9 +80,11 @@ class WasmBase : public std::enable_shared_from_this<WasmBase> { | |
bool isFailed() { return failed_ != FailState::Ok; } | ||
FailState fail_state() { return failed_; } | ||
|
||
const std::string &code() const { return code_; } | ||
const std::string &vm_configuration() const; | ||
bool allow_precompiled() const { return allow_precompiled_; } | ||
|
||
const std::string &module() const { return module_; } | ||
bool moduleIsPrecompiled() const { return module_is_precompiled_; } | ||
std::unordered_map<uint32_t, std::string> functionNames() const { return function_names_; } | ||
|
||
void timerReady(uint32_t root_context_id); | ||
void queueReady(uint32_t root_context_id, uint32_t token); | ||
|
@@ -135,7 +138,7 @@ class WasmBase : public std::enable_shared_from_this<WasmBase> { | |
virtual void error(std::string_view message) { std::cerr << message << "\n"; } | ||
virtual void unimplemented() { error("unimplemented proxy-wasm API"); } | ||
|
||
AbiVersion abiVersion() { return abi_version_; } | ||
AbiVersion abiVersion() const { return abi_version_; } | ||
|
||
const std::unordered_map<std::string, std::string> &envs() { return envs_; } | ||
|
||
|
@@ -182,7 +185,7 @@ class WasmBase : public std::enable_shared_from_this<WasmBase> { | |
std::string vm_id_; // User-provided vm_id. | ||
std::string vm_key_; // vm_id + hash of code. | ||
std::unique_ptr<WasmVm> wasm_vm_; | ||
Cloneable started_from_{Cloneable::NotCloneable}; | ||
std::optional<Cloneable> started_from_; | ||
|
||
uint32_t next_context_id_ = 1; // 0 is reserved for the VM context. | ||
std::shared_ptr<ContextBase> vm_context_; // Context unrelated to any specific root or stream | ||
|
@@ -260,15 +263,17 @@ class WasmBase : public std::enable_shared_from_this<WasmBase> { | |
std::shared_ptr<WasmHandleBase> base_wasm_handle_; | ||
|
||
// Used by the base_wasm to enable non-clonable thread local Wasm(s) to be constructed. | ||
std::string code_; | ||
std::string vm_configuration_; | ||
bool allow_precompiled_ = false; | ||
bool stop_iteration_ = false; | ||
FailState failed_ = FailState::Ok; // Wasm VM fatal error. | ||
std::string module_; | ||
bool module_is_precompiled_ = false; | ||
std::unordered_map<uint32_t, std::string> function_names_; | ||
|
||
// ABI version. | ||
AbiVersion abi_version_ = AbiVersion::Unknown; | ||
|
||
std::string vm_configuration_; | ||
bool stop_iteration_ = false; | ||
FailState failed_ = FailState::Ok; // Wasm VM fatal error. | ||
|
||
// Plugin Stats/Metrics | ||
uint32_t next_counter_metric_id_ = static_cast<uint32_t>(MetricType::Counter); | ||
uint32_t next_gauge_metric_id_ = static_cast<uint32_t>(MetricType::Gauge); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ | |
#include <memory> | ||
#include <optional> | ||
#include <string> | ||
#include <unordered_map> | ||
|
||
#include "include/proxy-wasm/word.h" | ||
|
||
|
@@ -174,14 +175,13 @@ class WasmVm { | |
* Load the WASM code from a file. Return true on success. Once the module is loaded it can be | ||
* queried, e.g. to see which version of emscripten support is required. After loading, the | ||
* appropriate ABI callbacks can be registered and then the module can be link()ed (see below). | ||
* @param code the WASM binary code (or registered NullVm plugin name). | ||
* @param allow_precompiled if true, allows supporting VMs (e.g. WAVM) to load the binary | ||
* machine code from a user-defined section of the WASM file. Because that code is not verified by | ||
* the proxy process it is up to the user to ensure that the code is both safe and is built for | ||
* the linked in version of WAVM. | ||
* @param module the WASM binary code (bytecode or precompiled) or registered NullVm plugin name. | ||
* @param is_precompiled if true, the module is precompiled. | ||
* @param function_names an index-to-name mapping for the exported functions. | ||
PiotrSikora marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* @return whether or not the load was successful. | ||
*/ | ||
virtual bool load(const std::string &code, bool allow_precompiled) = 0; | ||
virtual bool load(std::string_view module, bool is_precompiled, | ||
std::unordered_map<uint32_t, std::string> function_names) = 0; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this seems premature optimization but we could share a single function_names map and pass here by reference to it so that we don't copy it to all the thread local VMs.. |
||
|
||
/** | ||
* Link the WASM code to the host-provided functions, e.g. the ABI. Prior to linking, the module | ||
|
@@ -192,12 +192,6 @@ class WasmVm { | |
*/ | ||
virtual bool link(std::string_view debug_name) = 0; | ||
|
||
/** | ||
* Get ABI version of the module. | ||
* @return the ABI version. | ||
*/ | ||
virtual AbiVersion getAbiVersion() = 0; | ||
PiotrSikora marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
/** | ||
* Get size of the currently allocated memory in the VM. | ||
* @return the size of memory in bytes. | ||
|
Uh oh!
There was an error while loading. Please reload this page.