[wasm] Remove --wasm-max-mem-pages-growth flag
This unifies {max_initial_mem_pages} and {max_maximum_mem_pages} into {max_mem_pages}. The {CompilationEnv} constructor was incorrectly using the former instead of the latter anyway. This did not really matter though, since they typically have the same value. Also, there is not a single test that sets --wasm-max-mem-pages-growth. R=manoskouk@chromium.org CC=jkummerow@chromium.org Bug: v8:10949 Change-Id: Ib7ab9b4c239d50b72013087eda5a214829c90369 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2426619 Reviewed-by: Manos Koukoutos <manoskouk@chromium.org> Commit-Queue: Clemens Backes <clemensb@chromium.org> Cr-Commit-Position: refs/heads/master@{#70114}
This commit is contained in:
parent
b77c63c0a6
commit
5f265c3379
@ -297,7 +297,7 @@ inline bool IsValidAsmjsMemorySize(size_t size) {
|
||||
// Enforce asm.js spec minimum size.
|
||||
if (size < (1u << 12u)) return false;
|
||||
// Enforce engine-limited and flag-limited maximum allocation size.
|
||||
if (size > wasm::max_initial_mem_pages() * uint64_t{wasm::kWasmPageSize}) {
|
||||
if (size > wasm::max_mem_pages() * uint64_t{wasm::kWasmPageSize}) {
|
||||
return false;
|
||||
}
|
||||
// Enforce power-of-2 sizes for 2^12 - 2^24.
|
||||
|
@ -767,9 +767,7 @@ DEFINE_BOOL(wasm_async_compilation, true,
|
||||
DEFINE_BOOL(wasm_test_streaming, false,
|
||||
"use streaming compilation instead of async compilation for tests")
|
||||
DEFINE_UINT(wasm_max_mem_pages, v8::internal::wasm::kSpecMaxMemoryPages,
|
||||
"maximum initial number of 64KiB memory pages of a wasm instance")
|
||||
DEFINE_UINT(wasm_max_mem_pages_growth, v8::internal::wasm::kSpecMaxMemoryPages,
|
||||
"maximum number of 64KiB pages a Wasm memory can grow to")
|
||||
"maximum number of 64KiB memory pages per wasm memory")
|
||||
DEFINE_UINT(wasm_max_table_size, v8::internal::wasm::kV8MaxWasmTableSize,
|
||||
"maximum table size of a wasm instance")
|
||||
DEFINE_UINT(wasm_max_code_space, v8::internal::kMaxWasmCodeMB,
|
||||
|
@ -276,9 +276,9 @@ std::unique_ptr<BackingStore> BackingStore::Allocate(
|
||||
}
|
||||
|
||||
// Trying to allocate 4 GiB on a 32-bit platform is guaranteed to fail.
|
||||
// We don't lower the official max_maximum_mem_pages() limit because that
|
||||
// would be observable upon instantiation; this way the effective limit
|
||||
// on 32-bit platforms is defined by the allocator.
|
||||
// We don't lower the official max_mem_pages() limit because that would be
|
||||
// observable upon instantiation; this way the effective limit on 32-bit
|
||||
// platforms is defined by the allocator.
|
||||
constexpr size_t kPlatformMaxPages =
|
||||
std::numeric_limits<size_t>::max() / wasm::kWasmPageSize;
|
||||
|
||||
@ -325,7 +325,7 @@ std::unique_ptr<BackingStore> BackingStore::TryAllocateWasmMemory(
|
||||
|
||||
// Compute size of reserved memory.
|
||||
|
||||
size_t engine_max_pages = wasm::max_maximum_mem_pages();
|
||||
size_t engine_max_pages = wasm::max_mem_pages();
|
||||
maximum_pages = std::min(engine_max_pages, maximum_pages);
|
||||
// If the platform doesn't support so many pages, attempting to allocate
|
||||
// is guaranteed to fail, so we don't even try.
|
||||
|
@ -1902,8 +1902,8 @@ auto Memory::make(Store* store_abs, const MemoryType* type) -> own<Memory> {
|
||||
|
||||
const Limits& limits = type->limits();
|
||||
uint32_t minimum = limits.min;
|
||||
// The max_initial_mem_pages limit is only spec'ed for JS embeddings,
|
||||
// so we'll directly use the maximum pages limit here.
|
||||
// The max_mem_pages limit is only spec'ed for JS embeddings, so we'll
|
||||
// directly use the maximum pages limit here.
|
||||
if (minimum > i::wasm::kSpecMaxMemoryPages) return nullptr;
|
||||
uint32_t maximum = limits.max;
|
||||
if (maximum != Limits(0).max) {
|
||||
|
@ -75,7 +75,7 @@ struct CompilationEnv {
|
||||
: 0),
|
||||
max_memory_size((module && module->has_maximum_pages
|
||||
? module->maximum_pages
|
||||
: max_initial_mem_pages()) *
|
||||
: max_mem_pages()) *
|
||||
uint64_t{kWasmPageSize}),
|
||||
enabled_features(enabled_features),
|
||||
lower_simd(lower_simd) {}
|
||||
|
@ -636,10 +636,10 @@ class ModuleDecoderImpl : public Decoder {
|
||||
// ===== Imported memory =============================================
|
||||
if (!AddMemory(module_.get())) break;
|
||||
uint8_t flags = validate_memory_flags(&module_->has_shared_memory);
|
||||
consume_resizable_limits(
|
||||
"memory", "pages", max_initial_mem_pages(),
|
||||
&module_->initial_pages, &module_->has_maximum_pages,
|
||||
max_maximum_mem_pages(), &module_->maximum_pages, flags);
|
||||
consume_resizable_limits("memory", "pages", max_mem_pages(),
|
||||
&module_->initial_pages,
|
||||
&module_->has_maximum_pages, max_mem_pages(),
|
||||
&module_->maximum_pages, flags);
|
||||
break;
|
||||
}
|
||||
case kExternalGlobal: {
|
||||
@ -736,10 +736,10 @@ class ModuleDecoderImpl : public Decoder {
|
||||
for (uint32_t i = 0; ok() && i < memory_count; i++) {
|
||||
if (!AddMemory(module_.get())) break;
|
||||
uint8_t flags = validate_memory_flags(&module_->has_shared_memory);
|
||||
consume_resizable_limits(
|
||||
"memory", "pages", max_initial_mem_pages(), &module_->initial_pages,
|
||||
&module_->has_maximum_pages, max_maximum_mem_pages(),
|
||||
&module_->maximum_pages, flags);
|
||||
consume_resizable_limits("memory", "pages", max_mem_pages(),
|
||||
&module_->initial_pages,
|
||||
&module_->has_maximum_pages, max_mem_pages(),
|
||||
&module_->maximum_pages, flags);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1675,10 +1675,9 @@ void InstanceBuilder::InitGlobals(Handle<WasmInstanceObject> instance) {
|
||||
// Allocate memory for a module instance as a new JSArrayBuffer.
|
||||
bool InstanceBuilder::AllocateMemory() {
|
||||
uint32_t initial_pages = module_->initial_pages;
|
||||
uint32_t maximum_pages = module_->has_maximum_pages
|
||||
? module_->maximum_pages
|
||||
: wasm::max_maximum_mem_pages();
|
||||
if (initial_pages > max_initial_mem_pages()) {
|
||||
uint32_t maximum_pages =
|
||||
module_->has_maximum_pages ? module_->maximum_pages : max_mem_pages();
|
||||
if (initial_pages > max_mem_pages()) {
|
||||
thrower_->RangeError("Out of memory: wasm memory too large");
|
||||
return false;
|
||||
}
|
||||
|
@ -1444,18 +1444,12 @@ std::shared_ptr<WasmEngine> WasmEngine::GetWasmEngine() {
|
||||
return *GetSharedWasmEngine();
|
||||
}
|
||||
|
||||
// {max_initial_mem_pages} is declared in wasm-limits.h.
|
||||
uint32_t max_initial_mem_pages() {
|
||||
// {max_mem_pages} is declared in wasm-limits.h.
|
||||
uint32_t max_mem_pages() {
|
||||
STATIC_ASSERT(kV8MaxWasmMemoryPages <= kMaxUInt32);
|
||||
return std::min(uint32_t{kV8MaxWasmMemoryPages}, FLAG_wasm_max_mem_pages);
|
||||
}
|
||||
|
||||
uint32_t max_maximum_mem_pages() {
|
||||
STATIC_ASSERT(kV8MaxWasmMemoryPages <= kMaxUInt32);
|
||||
return std::min(uint32_t{kV8MaxWasmMemoryPages},
|
||||
FLAG_wasm_max_mem_pages_growth);
|
||||
}
|
||||
|
||||
// {max_table_init_entries} is declared in wasm-limits.h.
|
||||
uint32_t max_table_init_entries() {
|
||||
return std::min(uint32_t{kV8MaxWasmTableInitEntries},
|
||||
|
@ -1134,15 +1134,14 @@ void WebAssemblyMemory(const v8::FunctionCallbackInfo<v8::Value>& args) {
|
||||
|
||||
int64_t initial = 0;
|
||||
if (!GetInitialOrMinimumProperty(isolate, &thrower, context, descriptor,
|
||||
&initial, 0,
|
||||
i::wasm::max_initial_mem_pages())) {
|
||||
&initial, 0, i::wasm::max_mem_pages())) {
|
||||
return;
|
||||
}
|
||||
// The descriptor's 'maximum'.
|
||||
int64_t maximum = -1;
|
||||
if (!GetOptionalIntegerProperty(isolate, &thrower, context, descriptor,
|
||||
v8_str(isolate, "maximum"), nullptr, &maximum,
|
||||
initial, i::wasm::max_maximum_mem_pages())) {
|
||||
initial, i::wasm::max_mem_pages())) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -1730,8 +1729,8 @@ void WebAssemblyMemoryGrow(const v8::FunctionCallbackInfo<v8::Value>& args) {
|
||||
}
|
||||
|
||||
uint64_t max_size64 = receiver->maximum_pages();
|
||||
if (max_size64 > uint64_t{i::wasm::max_maximum_mem_pages()}) {
|
||||
max_size64 = i::wasm::max_maximum_mem_pages();
|
||||
if (max_size64 > uint64_t{i::wasm::max_mem_pages()}) {
|
||||
max_size64 = i::wasm::max_mem_pages();
|
||||
}
|
||||
i::Handle<i::JSArrayBuffer> old_buffer(receiver->array_buffer(), i_isolate);
|
||||
|
||||
|
@ -31,8 +31,8 @@ constexpr size_t kV8MaxWasmExceptions = 1000000;
|
||||
constexpr size_t kV8MaxWasmExceptionTypes = 1000000;
|
||||
constexpr size_t kV8MaxWasmDataSegments = 100000;
|
||||
// This indicates the maximum memory size our implementation supports.
|
||||
// Don't use this limit directly; use {max_initial_mem_pages()} instead
|
||||
// to take the spec'ed limit as well as command line flag into account.
|
||||
// Don't use this limit directly; use {max_mem_pages()} instead to take the
|
||||
// spec'ed limit as well as command line flag into account.
|
||||
constexpr size_t kV8MaxWasmMemoryPages = 65536; // = 4 GiB
|
||||
constexpr size_t kV8MaxWasmStringSize = 100000;
|
||||
constexpr size_t kV8MaxWasmModuleSize = 1024 * 1024 * 1024; // = 1 GiB
|
||||
@ -65,13 +65,12 @@ constexpr uint64_t kWasmMaxHeapOffset =
|
||||
// Defined in wasm-engine.cc.
|
||||
// TODO(wasm): Make this size_t for wasm64. Currently the --wasm-max-mem-pages
|
||||
// flag is only uint32_t.
|
||||
V8_EXPORT_PRIVATE uint32_t max_initial_mem_pages();
|
||||
V8_EXPORT_PRIVATE uint32_t max_maximum_mem_pages();
|
||||
V8_EXPORT_PRIVATE uint32_t max_mem_pages();
|
||||
uint32_t max_table_init_entries();
|
||||
size_t max_module_size();
|
||||
|
||||
inline uint64_t max_mem_bytes() {
|
||||
return uint64_t{max_maximum_mem_pages()} * kWasmPageSize;
|
||||
return uint64_t{max_mem_pages()} * kWasmPageSize;
|
||||
}
|
||||
|
||||
} // namespace wasm
|
||||
|
@ -914,16 +914,15 @@ int32_t WasmMemoryObject::Grow(Isolate* isolate,
|
||||
if (old_buffer->is_asmjs_memory()) return -1;
|
||||
|
||||
// Checks for maximum memory size.
|
||||
uint32_t maximum_pages = wasm::max_maximum_mem_pages();
|
||||
uint32_t maximum_pages = wasm::max_mem_pages();
|
||||
if (memory_object->has_maximum_pages()) {
|
||||
maximum_pages = std::min(
|
||||
maximum_pages, static_cast<uint32_t>(memory_object->maximum_pages()));
|
||||
}
|
||||
DCHECK_GE(wasm::max_maximum_mem_pages(), maximum_pages);
|
||||
size_t old_size = old_buffer->byte_length();
|
||||
DCHECK_EQ(0, old_size % wasm::kWasmPageSize);
|
||||
size_t old_pages = old_size / wasm::kWasmPageSize;
|
||||
CHECK_GE(wasm::max_maximum_mem_pages(), old_pages);
|
||||
CHECK_GE(wasm::max_mem_pages(), old_pages);
|
||||
if (pages > maximum_pages - old_pages) return -1;
|
||||
std::shared_ptr<BackingStore> backing_store = old_buffer->GetBackingStore();
|
||||
if (!backing_store) return -1;
|
||||
|
@ -32,8 +32,6 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
|
||||
// We reduce the maximum memory size and table size of WebAssembly instances
|
||||
// to avoid OOMs in the fuzzer.
|
||||
i::FlagScope<uint32_t> max_mem_flag_scope(&i::FLAG_wasm_max_mem_pages, 32);
|
||||
i::FlagScope<uint32_t> max_mem_growth_flag_scope(
|
||||
&i::FLAG_wasm_max_mem_pages_growth, 32);
|
||||
i::FlagScope<uint32_t> max_table_size_scope(&i::FLAG_wasm_max_table_size,
|
||||
100);
|
||||
v8_fuzzer::FuzzerSupport* support = v8_fuzzer::FuzzerSupport::Get();
|
||||
|
Loading…
Reference in New Issue
Block a user