Skip to content

Commit 15166fc

Browse files
committed
Implemented the warm function for wamr, wasmedge, and wasmtime.
Signed-off-by: Rachel Green <[email protected]>
1 parent 1ddba49 commit 15166fc

File tree

3 files changed

+31
-6
lines changed

3 files changed

+31
-6
lines changed

src/wamr/wamr.cc

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,16 @@ class Wamr : public WasmVm {
121121
std::unordered_map<std::string, WasmFuncPtr> module_functions_;
122122
};
123123

124+
void Wamr::initStore() {
125+
if (store_ != nullptr) {
126+
return;
127+
}
128+
store_ = wasm_store_new(engine());
129+
}
130+
124131
bool Wamr::load(std::string_view bytecode, std::string_view precompiled,
125132
const std::unordered_map<uint32_t, std::string> & /*function_names*/) {
126-
store_ = wasm_store_new(engine());
133+
initStore();
127134
if (store_ == nullptr) {
128135
return false;
129136
}
@@ -699,9 +706,11 @@ void Wamr::getModuleFunctionImpl(std::string_view function_name,
699706
};
700707
};
701708

709+
void Wamr::warm() { initStore(); }
710+
702711
} // namespace wamr
703712

704-
bool initWamrEngine() { return wamr::engine() != nullptr; }
713+
bool initWamrEngine() { return wamr::engine() != nullptr; }
705714

706715
std::unique_ptr<WasmVm> createWamrVm() { return std::make_unique<wamr::Wamr>(); }
707716

src/wasmedge/wasmedge.cc

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -316,13 +316,18 @@ bool WasmEdge::load(std::string_view bytecode, std::string_view /*precompiled*/,
316316
return true;
317317
}
318318

319+
void WasmEdge::initStore() {
320+
if (store_ != nullptr) {
321+
return;
322+
}
323+
store_ = WasmEdge_StoreCreate();
324+
}
325+
319326
bool WasmEdge::link(std::string_view /*debug_name*/) {
320327
assert(ast_module_ != nullptr);
321328

322329
// Create store and register imports.
323-
if (store_ == nullptr) {
324-
store_ = WasmEdge_StoreCreate();
325-
}
330+
initStore();
326331
if (store_ == nullptr) {
327332
return false;
328333
}
@@ -611,6 +616,8 @@ void WasmEdge::getModuleFunctionImpl(std::string_view function_name,
611616
};
612617
}
613618

619+
void WasmEdge::warm() { initStore(); }
620+
614621
} // namespace WasmEdge
615622

616623
std::unique_ptr<WasmVm> createWasmEdgeVm() { return std::make_unique<WasmEdge::WasmEdge>(); }

src/wasmtime/wasmtime.cc

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,16 @@ class Wasmtime : public WasmVm {
113113
std::unordered_map<std::string, WasmFuncPtr> module_functions_;
114114
};
115115

116+
void Wasmtime::initStore() {
117+
if (store_ != nullptr)
118+
return;
119+
}
120+
store_ = wasm_store_new(engine());
121+
}
122+
116123
bool Wasmtime::load(std::string_view bytecode, std::string_view /*precompiled*/,
117124
const std::unordered_map<uint32_t, std::string> & /*function_names*/) {
118-
store_ = wasm_store_new(engine());
125+
initStore();
119126
if (store_ == nullptr) {
120127
return false;
121128
}
@@ -695,6 +702,8 @@ void Wasmtime::getModuleFunctionImpl(std::string_view function_name,
695702
};
696703
};
697704

705+
void Wasmtime::warm() { initStore(); }
706+
698707
} // namespace wasmtime
699708

700709
bool initWasmtimeEngine() { return wasmtime::engine() != nullptr; }

0 commit comments

Comments
 (0)