Skip to content

Commit 72ce32f

Browse files
authored
WAMR: adds support for clone. (#317)
Signed-off-by: [email protected] <[email protected]>
1 parent 624ef2e commit 72ce32f

File tree

5 files changed

+49
-13
lines changed

5 files changed

+49
-13
lines changed

bazel/external/wamr.BUILD

+7-5
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,17 @@ filegroup(
1212
cmake(
1313
name = "wamr_lib",
1414
cache_entries = {
15-
"WAMR_BUILD_INTERP": "1",
15+
"WAMR_BUILD_AOT": "0",
1616
"WAMR_BUILD_FAST_INTERP": "1",
17+
"WAMR_BUILD_INTERP": "1",
1718
"WAMR_BUILD_JIT": "0",
18-
"WAMR_BUILD_LAZY_JIT": "0",
19-
"WAMR_BUILD_AOT": "0",
20-
"WAMR_BUILD_SIMD": "0",
21-
"WAMR_BUILD_MULTI_MODULE": "1",
2219
"WAMR_BUILD_LIBC_WASI": "0",
20+
"WAMR_BUILD_MULTI_MODULE": "0",
21+
"WAMR_BUILD_SIMD": "0",
2322
"WAMR_BUILD_TAIL_CALL": "1",
23+
"WAMR_BUILD_WASM_CACHE": "0",
24+
"WAMR_DISABLE_HW_BOUND_CHECK": "0",
25+
"WAMR_DISABLE_STACK_HW_BOUND_CHECK": "1",
2426
},
2527
generate_args = ["-GNinja"],
2628
lib_source = ":srcs",

bazel/repositories.bzl

+4-4
Original file line numberDiff line numberDiff line change
@@ -159,10 +159,10 @@ def proxy_wasm_cpp_host_repositories():
159159
http_archive,
160160
name = "com_github_bytecodealliance_wasm_micro_runtime",
161161
build_file = "@proxy_wasm_cpp_host//bazel/external:wamr.BUILD",
162-
# WAMR-05-18-2022
163-
sha256 = "350736fffdc49533f5f372221d01e3b570ecd7b85f4429b22f5d89594eb99d9c",
164-
strip_prefix = "wasm-micro-runtime-d7a2888b18c478d87ce8094e1419b4e061db289f",
165-
url = "https://github.com/bytecodealliance/wasm-micro-runtime/archive/d7a2888b18c478d87ce8094e1419b4e061db289f.tar.gz",
162+
# WAMR-2022-12-07
163+
sha256 = "6a5263ad022176257a93b39b02f95f615c0c590da1798c86c935f501a51c30c4",
164+
strip_prefix = "wasm-micro-runtime-c3d66f916ef8093e5c8cacf3329ed968f807cf58",
165+
url = "https://github.com/bytecodealliance/wasm-micro-runtime/archive/c3d66f916ef8093e5c8cacf3329ed968f807cf58.tar.gz",
166166
)
167167

168168
native.bind(

src/wamr/types.h

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ using WasmEnginePtr = common::CSmartPtr<wasm_engine_t, wasm_engine_delete>;
2121
using WasmFuncPtr = common::CSmartPtr<wasm_func_t, wasm_func_delete>;
2222
using WasmStorePtr = common::CSmartPtr<wasm_store_t, wasm_store_delete>;
2323
using WasmModulePtr = common::CSmartPtr<wasm_module_t, wasm_module_delete>;
24+
using WasmSharedModulePtr = common::CSmartPtr<wasm_shared_module_t, wasm_shared_module_delete>;
2425
using WasmMemoryPtr = common::CSmartPtr<wasm_memory_t, wasm_memory_delete>;
2526
using WasmTablePtr = common::CSmartPtr<wasm_table_t, wasm_table_delete>;
2627
using WasmInstancePtr = common::CSmartPtr<wasm_instance_t, wasm_instance_delete>;

src/wamr/wamr.cc

+35-2
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ class Wamr : public WasmVm {
5858
std::string_view getEngineName() override { return "wamr"; }
5959
std::string_view getPrecompiledSectionName() override { return ""; }
6060

61-
Cloneable cloneable() override { return Cloneable::NotCloneable; }
62-
std::unique_ptr<WasmVm> clone() override { return nullptr; }
61+
Cloneable cloneable() override { return Cloneable::CompiledBytecode; }
62+
std::unique_ptr<WasmVm> clone() override;
6363

6464
bool load(std::string_view bytecode, std::string_view precompiled,
6565
const std::unordered_map<uint32_t, std::string> &function_names) override;
@@ -108,6 +108,7 @@ class Wamr : public WasmVm {
108108

109109
WasmStorePtr store_;
110110
WasmModulePtr module_;
111+
WasmSharedModulePtr shared_module_;
111112
WasmInstancePtr instance_;
112113

113114
WasmMemoryPtr memory_;
@@ -132,9 +133,41 @@ bool Wamr::load(std::string_view bytecode, std::string_view /*precompiled*/,
132133
return false;
133134
}
134135

136+
shared_module_ = wasm_module_share(module_.get());
137+
if (shared_module_ == nullptr) {
138+
return false;
139+
}
140+
135141
return true;
136142
}
137143

144+
std::unique_ptr<WasmVm> Wamr::clone() {
145+
assert(module_ != nullptr);
146+
147+
auto vm = std::make_unique<Wamr>();
148+
if (vm == nullptr) {
149+
return nullptr;
150+
}
151+
152+
vm->store_ = wasm_store_new(engine());
153+
if (vm->store_ == nullptr) {
154+
return nullptr;
155+
}
156+
157+
vm->module_ = wasm_module_obtain(vm->store_.get(), shared_module_.get());
158+
if (vm->module_ == nullptr) {
159+
return nullptr;
160+
}
161+
162+
auto *integration_clone = integration()->clone();
163+
if (integration_clone == nullptr) {
164+
return nullptr;
165+
}
166+
vm->integration().reset(integration_clone);
167+
168+
return vm;
169+
}
170+
138171
static bool equalValTypes(const wasm_valtype_vec_t *left, const wasm_valtype_vec_t *right) {
139172
if (left->size != right->size) {
140173
return false;

test/wasm_vm_test.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ INSTANTIATE_TEST_SUITE_P(WasmEngines, TestVm, testing::ValuesIn(getWasmEngines()
3131
});
3232

3333
TEST_P(TestVm, Basic) {
34-
if (engine_ == "wamr" || engine_ == "wasmedge") {
34+
if (engine_ == "wasmedge") {
3535
EXPECT_EQ(vm_->cloneable(), proxy_wasm::Cloneable::NotCloneable);
36-
} else if (engine_ == "wasmtime" || engine_ == "v8") {
36+
} else if (engine_ == "wasmtime" || engine_ == "v8" || engine_ == "wamr") {
3737
EXPECT_EQ(vm_->cloneable(), proxy_wasm::Cloneable::CompiledBytecode);
3838
} else if (engine_ == "wavm") {
3939
EXPECT_EQ(vm_->cloneable(), proxy_wasm::Cloneable::InstantiatedModule);

0 commit comments

Comments
 (0)