Skip to content

Feat: Support creating warmed VM in the proxy wasm V8 VM API. #447

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

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions include/proxy-wasm/null_vm.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ struct NullVm : public WasmVm {
void terminate() override {}
bool usesWasmByteOrder() override { return false; }

void warm() override {}

std::string plugin_name_;
std::unique_ptr<NullVmPlugin> plugin_;
};
Expand Down
5 changes: 5 additions & 0 deletions include/proxy-wasm/wasm_vm.h
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,11 @@ class WasmVm {
*/
virtual bool usesWasmByteOrder() = 0;

/**
* Warm the VM such as engine and runtime.
*/
virtual void warm() = 0;

bool isFailed() { return failed_ != FailState::Ok; }
void fail(FailState fail_state, std::string_view message) {
integration()->error(message);
Expand Down
16 changes: 15 additions & 1 deletion src/v8/v8.cc
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ class V8 : public WasmVm {
void terminate() override;
bool usesWasmByteOrder() override { return true; }

void warm() override;

private:
wasm::own<wasm::Trap> trap(std::string message);

Expand All @@ -124,6 +126,9 @@ class V8 : public WasmVm {
void getModuleFunctionImpl(std::string_view function_name,
std::function<R(ContextBase *, Args...)> *function);

// Initialize the V8 engine and store if necessary.
void initStore();

wasm::own<wasm::Store> store_;
wasm::own<wasm::Module> module_;
wasm::own<wasm::Shared<wasm::Module>> shared_module_;
Expand Down Expand Up @@ -260,9 +265,16 @@ template <typename T, typename U> constexpr T convertValTypesToArgsTuple(const U

// V8 implementation.

void V8::initStore() {
if (store_ != nullptr) {
return;
}
store_ = wasm::Store::make(engine());
}

bool V8::load(std::string_view bytecode, std::string_view precompiled,
const std::unordered_map<uint32_t, std::string> &function_names) {
store_ = wasm::Store::make(engine());
initStore();
if (store_ == nullptr) {
return false;
}
Expand Down Expand Up @@ -708,6 +720,8 @@ void V8::terminate() {
isolate->TerminateExecution();
}

void V8::warm() { initStore(); }

std::string V8::getFailMessage(std::string_view function_name, wasm::own<wasm::Trap> trap) {
auto message = "Function: " + std::string(function_name) + " failed: ";
message += std::string(trap->message().get(), trap->message().size());
Expand Down
Loading