Skip to content

Commit

Permalink
build: update wee8 to 7.8.188. (envoyproxy#155)
Browse files Browse the repository at this point in the history
Signed-off-by: Piotr Sikora <piotrsikora@google.com>
  • Loading branch information
PiotrSikora authored Aug 26, 2019
1 parent 89a2b81 commit 42c0929
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 72 deletions.
7 changes: 5 additions & 2 deletions bazel/external/wee8.genrule_cmd
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ fi
WEE8_BUILD_ARGS+=" is_debug=false"
# Clang or not Clang, that is the question.
WEE8_BUILD_ARGS+=" is_clang=$$IS_CLANG"
# Disable custom compiler plugins.
WEE8_BUILD_ARGS+=" clang_use_chrome_plugins=false"
# Hack to disable bleeding-edge compiler flags.
WEE8_BUILD_ARGS+=" use_xcode_clang=true"
# Use local toolchain.
WEE8_BUILD_ARGS+=" custom_toolchain=\"//build/toolchain/linux/unbundle:default\""
# Use local stdlibc++ / libc++.
Expand All @@ -62,6 +62,9 @@ WEE8_BUILD_ARGS+=" is_component_build=false"
WEE8_BUILD_ARGS+=" v8_enable_i18n_support=false"
WEE8_BUILD_ARGS+=" v8_enable_gdbjit=false"
WEE8_BUILD_ARGS+=" v8_use_external_startup_data=false"
# Disable read-only heap, since it's leaky and HEAPCHECK complains about it.
# TODO(PiotrSikora): remove when fixed upstream.
WEE8_BUILD_ARGS+=" v8_enable_shared_ro_heap=false"

# Build wee8.
third_party/depot_tools/gn gen out/wee8 --args="$$WEE8_BUILD_ARGS"
Expand Down
57 changes: 4 additions & 53 deletions bazel/external/wee8.patch
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# 1. Force full GC when destroying VMs.
# 2. Fix build with -DDEBUG.
# 3. Fix for VMs with overlapping lifetimes (https://crrev.com/c/1698387).
# 4. Fix linking with unbundled toolchain on macOS.
# 5. Increase VSZ limit to 4TiB (allows us to start up to 370 VMs).
# 3. Fix linking with unbundled toolchain on macOS.
# 4. Increase VSZ limit to 4TiB (allows us to start up to 370 VMs).
--- a/wee8/build/toolchain/gcc_toolchain.gni
+++ b/wee8/build/toolchain/gcc_toolchain.gni
@@ -355,6 +355,8 @@ template("gcc_toolchain") {
Expand All @@ -25,16 +23,7 @@
end_group_flag = "-Wl,--end-group "
--- a/wee8/src/wasm/c-api.cc
+++ b/wee8/src/wasm/c-api.cc
@@ -633,7 +633,7 @@ auto seal(const typename implement<C>::type* x) -> const C* {
return reinterpret_cast<const C*>(x);
}

-#ifdef DEBUG
+#if 0
template <class T>
void vec<T>::make_data() {}

@@ -708,13 +708,12 @@ auto Engine::make(own<Config*>&& config) -> own<Engine*> {
@@ -260,7 +260,7 @@ auto Engine::make(own<Config>&& config) -> own<Engine> {
// Stores

StoreImpl::~StoreImpl() {
Expand All @@ -43,36 +32,9 @@
reinterpret_cast<i::Isolate*>(isolate_)->heap()->PreciseCollectAllGarbage(
i::Heap::kNoGCFlags, i::GarbageCollectionReason::kTesting,
v8::kGCCallbackFlagForced);
#endif
context()->Exit();
- isolate_->Exit();
isolate_->Dispose();
delete create_params_.array_buffer_allocator;
}
@@ -739,7 +738,6 @@ auto Store::make(Engine*) -> own<Store*> {
if (!isolate) return own<Store*>();

{
- v8::Isolate::Scope isolate_scope(isolate);
v8::HandleScope handle_scope(isolate);

// Create context.
@@ -750,8 +748,10 @@ auto Store::make(Engine*) -> own<Store*> {
store->isolate_ = isolate;
store->context_ = v8::Eternal<v8::Context>(isolate, context);
}
-
- store->isolate()->Enter();
+ // We intentionally do not call isolate->Enter() here, because that would
+ // prevent embedders from using stores with overlapping but non-nested
+ // lifetimes. The consequence is that Isolate::Current() is dysfunctional
+ // and hence must not be called by anything reachable via this file.
store->context()->Enter();
isolate->SetData(0, store.get());

--- a/wee8/src/wasm/wasm-memory.cc
+++ b/wee8/src/wasm/wasm-memory.cc
@@ -139,7 +139,7 @@ void* TryAllocateBackingStore(WasmMemoryTracker* memory_tracker, Heap* heap,
@@ -142,7 +142,7 @@ void* TryAllocateBackingStore(WasmMemoryTracker* memory_tracker, Heap* heap,
// address space limits needs to be smaller.
constexpr size_t kAddressSpaceLimit = 0x8000000000L; // 512 GiB
#elif V8_TARGET_ARCH_64_BIT
Expand All @@ -81,14 +43,3 @@
#else
constexpr size_t kAddressSpaceLimit = 0xC0000000; // 3 GiB
#endif
--- a/wee8/third_party/wasm-api/wasm.hh
+++ b/wee8/third_party/wasm-api/wasm.hh
@@ -111,7 +111,7 @@ class vec {
size_t size_;
std::unique_ptr<T[]> data_;

-#ifdef DEBUG
+#if 0
void make_data();
void free_data();
#else
4 changes: 2 additions & 2 deletions bazel/repository_locations.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,8 @@ REPOSITORY_LOCATIONS = dict(
com_googlesource_chromium_v8 = dict(
# This archive was created using https://storage.googleapis.com/envoyproxy-wee8/wee8-archive.sh
# and contains complete checkout of v8 with all dependencies necessary to build wee8.
sha256 = "690ca8e3460362fba8e95d94c9325211ad477a4d71a392461f899ec91afd1292",
urls = ["https://storage.googleapis.com/envoyproxy-wee8/wee8-7.6.303.20.tar.gz"],
sha256 = "c1249a98036861f0fd1a200d0dd18f0d6f681a7c5221dcf25764d58053fbf380",
urls = ["https://storage.googleapis.com/envoyproxy-wee8/wee8-7.8.188.tar.gz"],
),
io_opencensus_cpp = dict(
sha256 = "8d6016e47c2e19e7acbadb6f905b8c422748c64299d71101ac8f28151677e195",
Expand Down
30 changes: 15 additions & 15 deletions source/extensions/common/wasm/v8/v8.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ struct FuncData {
FuncData(std::string name) : name(name) {}

std::string name;
wasm::own<wasm::Func*> callback;
wasm::own<wasm::Func> callback;
void* raw_func;
};

Expand Down Expand Up @@ -112,15 +112,15 @@ class V8 : public WasmVm {
std::function<R(Context*, Args...)>* function);

wasm::vec<byte_t> source_ = wasm::vec<byte_t>::invalid();
wasm::own<wasm::Store*> store_;
wasm::own<wasm::Module*> module_;
wasm::own<wasm::Instance*> instance_;
wasm::own<wasm::Memory*> memory_;
wasm::own<wasm::Table*> table_;
wasm::own<wasm::Store> store_;
wasm::own<wasm::Module> module_;
wasm::own<wasm::Instance> instance_;
wasm::own<wasm::Memory> memory_;
wasm::own<wasm::Table> table_;

absl::flat_hash_map<std::string, wasm::own<wasm::Global*>> host_globals_;
absl::flat_hash_map<std::string, wasm::own<wasm::Global>> host_globals_;
absl::flat_hash_map<std::string, FuncDataPtr> host_functions_;
absl::flat_hash_map<std::string, wasm::own<wasm::Func*>> module_functions_;
absl::flat_hash_map<std::string, wasm::own<wasm::Func>> module_functions_;

uint32_t memory_stack_base_;
uint32_t memory_heap_base_;
Expand Down Expand Up @@ -150,7 +150,7 @@ static const char* printValKind(wasm::ValKind kind) {
}
}

static std::string printValTypes(const wasm::vec<wasm::ValType*>& types) {
static std::string printValTypes(const wasm::ownvec<wasm::ValType>& types) {
if (types.size() == 0) {
return "void";
}
Expand All @@ -166,8 +166,8 @@ static std::string printValTypes(const wasm::vec<wasm::ValType*>& types) {
return s;
}

static bool equalValTypes(const wasm::vec<wasm::ValType*>& left,
const wasm::vec<wasm::ValType*>& right) {
static bool equalValTypes(const wasm::ownvec<wasm::ValType>& left,
const wasm::ownvec<wasm::ValType>& right) {
if (left.size() != right.size()) {
return false;
}
Expand Down Expand Up @@ -222,7 +222,7 @@ template <typename T> struct V8ProxyForGlobal : Global<T> {

template <typename T, std::size_t... I>
constexpr auto convertArgsTupleToValTypesImpl(absl::index_sequence<I...>) {
return wasm::vec<wasm::ValType*>::make(
return wasm::ownvec<wasm::ValType>::make(
wasm::ValType::make(convertArgToValKind<typename std::tuple_element<I, T>::type>())...);
}

Expand Down Expand Up @@ -396,7 +396,7 @@ void V8::link(absl::string_view debug_name, bool needs_emscripten) {
for (size_t i = 0; i < export_types.size(); i++) {
absl::string_view name(export_types[i]->name().get(), export_types[i]->name().size());
auto export_type = export_types[i]->type();
auto export_item = exports[i];
auto export_item = exports[i].get();
ASSERT(export_type->kind() == export_item->kind());

switch (export_type->kind()) {
Expand Down Expand Up @@ -556,7 +556,7 @@ void V8::registerHostFunctionImpl(absl::string_view moduleName, absl::string_vie
convertArgsTupleToValTypes<std::tuple<>>());
auto func = wasm::Func::make(
store_.get(), type.get(),
[](void* data, const wasm::Val params[], wasm::Val[]) -> wasm::own<wasm::Trap*> {
[](void* data, const wasm::Val params[], wasm::Val[]) -> wasm::own<wasm::Trap> {
auto func_data = reinterpret_cast<FuncData*>(data);
ENVOY_LOG(trace, "[wasm] callHostFunction(\"{}\")", func_data->name);
auto args_tuple = convertValTypesToArgsTuple<std::tuple<Args...>>(params);
Expand All @@ -580,7 +580,7 @@ void V8::registerHostFunctionImpl(absl::string_view moduleName, absl::string_vie
convertArgsTupleToValTypes<std::tuple<R>>());
auto func = wasm::Func::make(
store_.get(), type.get(),
[](void* data, const wasm::Val params[], wasm::Val results[]) -> wasm::own<wasm::Trap*> {
[](void* data, const wasm::Val params[], wasm::Val results[]) -> wasm::own<wasm::Trap> {
auto func_data = reinterpret_cast<FuncData*>(data);
ENVOY_LOG(trace, "[wasm] callHostFunction(\"{}\")", func_data->name);
auto args_tuple = convertValTypesToArgsTuple<std::tuple<Args...>>(params);
Expand Down

0 comments on commit 42c0929

Please sign in to comment.