Commit c35c54bb authored by Ben L. Titzer's avatar Ben L. Titzer Committed by Commit Bot

[wasm] Naming consistency for min/max pages and sizes in wasm-module.h

This is a pure renaming CL; no functionality changes.

R=mtrofin@chromium.org

Bug: 
Change-Id: I2f8262bdb17b9256d5b66fad56a7e51063f6f0d9
Reviewed-on: https://chromium-review.googlesource.com/610007Reviewed-by: 's avatarMircea Trofin <mtrofin@chromium.org>
Commit-Queue: Ben Titzer <titzer@chromium.org>
Cr-Commit-Position: refs/heads/master@{#47282}
parent cf4adddb
......@@ -3045,7 +3045,8 @@ void WasmGraphBuilder::EnsureFunctionTableNodes() {
auto signature_handle = module_env_->signature_tables()[i];
function_tables_.push_back(HeapConstant(function_handle));
signature_tables_.push_back(HeapConstant(signature_handle));
uint32_t table_size = module_env_->module()->function_tables[i].min_size;
uint32_t table_size =
module_env_->module()->function_tables[i].initial_size;
function_table_sizes_.push_back(jsgraph()->RelocatableInt32Constant(
static_cast<uint32_t>(table_size),
RelocInfo::WASM_FUNCTION_TABLE_SIZE_REFERENCE));
......
......@@ -879,10 +879,10 @@ MaybeHandle<WasmInstanceObject> InstanceBuilder::Build() {
//--------------------------------------------------------------------------
// Set up the memory for the new instance.
//--------------------------------------------------------------------------
uint32_t min_mem_pages = module_->min_mem_pages;
uint32_t initial_pages = module_->initial_pages;
(module_->is_wasm() ? counters()->wasm_wasm_min_mem_pages_count()
: counters()->wasm_asm_min_mem_pages_count())
->AddSample(min_mem_pages);
->AddSample(initial_pages);
if (!memory_.is_null()) {
Handle<JSArrayBuffer> memory = memory_.ToHandleChecked();
......@@ -892,8 +892,8 @@ MaybeHandle<WasmInstanceObject> InstanceBuilder::Build() {
DCHECK_IMPLIES(EnableGuardRegions(),
module_->is_asm_js() || memory->has_guard_region());
} else if (min_mem_pages > 0) {
memory_ = AllocateMemory(min_mem_pages);
} else if (initial_pages > 0) {
memory_ = AllocateMemory(initial_pages);
if (memory_.is_null()) return {}; // failed to allocate memory
}
......@@ -1300,27 +1300,27 @@ int InstanceBuilder::ProcessImports(Handle<FixedArray> code_table,
table_instance.table_object->functions(), isolate_);
int imported_cur_size = table_instance.js_wrappers->length();
if (imported_cur_size < static_cast<int>(table.min_size)) {
if (imported_cur_size < static_cast<int>(table.initial_size)) {
thrower_->LinkError(
"table import %d is smaller than minimum %d, got %u", index,
table.min_size, imported_cur_size);
"table import %d is smaller than initial %d, got %u", index,
table.initial_size, imported_cur_size);
return -1;
}
if (table.has_max) {
int64_t imported_max_size =
if (table.has_maximum_size) {
int64_t imported_maximum_size =
table_instance.table_object->maximum_length()->Number();
if (imported_max_size < 0) {
if (imported_maximum_size < 0) {
thrower_->LinkError(
"table import %d has no maximum length, expected %d", index,
table.max_size);
table.maximum_size);
return -1;
}
if (imported_max_size > table.max_size) {
if (imported_maximum_size > table.maximum_size) {
thrower_->LinkError(
"memory import %d has a larger maximum size %" PRIx64
" than the module's declared maximum %u",
index, imported_max_size, table.max_size);
index, imported_maximum_size, table.maximum_size);
return -1;
}
}
......@@ -1370,25 +1370,25 @@ int InstanceBuilder::ProcessImports(Handle<FixedArray> code_table,
memory_ = buffer;
uint32_t imported_cur_pages = static_cast<uint32_t>(
buffer->byte_length()->Number() / WasmModule::kPageSize);
if (imported_cur_pages < module_->min_mem_pages) {
if (imported_cur_pages < module_->initial_pages) {
thrower_->LinkError(
"memory import %d is smaller than maximum %u, got %u", index,
module_->min_mem_pages, imported_cur_pages);
"memory import %d is smaller than initial %u, got %u", index,
module_->initial_pages, imported_cur_pages);
}
int32_t imported_max_pages = memory->maximum_pages();
if (module_->has_max_mem) {
if (imported_max_pages < 0) {
int32_t imported_maximum_pages = memory->maximum_pages();
if (module_->has_maximum_pages) {
if (imported_maximum_pages < 0) {
thrower_->LinkError(
"memory import %d has no maximum limit, expected at most %u",
index, imported_max_pages);
index, imported_maximum_pages);
return -1;
}
if (static_cast<uint32_t>(imported_max_pages) >
module_->max_mem_pages) {
if (static_cast<uint32_t>(imported_maximum_pages) >
module_->maximum_pages) {
thrower_->LinkError(
"memory import %d has a larger maximum size %u than the "
"module's declared maximum %u",
index, imported_max_pages, module_->max_mem_pages);
index, imported_maximum_pages, module_->maximum_pages);
return -1;
}
}
......@@ -1492,14 +1492,14 @@ void InstanceBuilder::InitGlobals() {
}
// Allocate memory for a module instance as a new JSArrayBuffer.
Handle<JSArrayBuffer> InstanceBuilder::AllocateMemory(uint32_t min_mem_pages) {
if (min_mem_pages > FLAG_wasm_max_mem_pages) {
Handle<JSArrayBuffer> InstanceBuilder::AllocateMemory(uint32_t num_pages) {
if (num_pages > FLAG_wasm_max_mem_pages) {
thrower_->RangeError("Out of memory: wasm memory too large");
return Handle<JSArrayBuffer>::null();
}
const bool enable_guard_regions = EnableGuardRegions();
Handle<JSArrayBuffer> mem_buffer = NewArrayBuffer(
isolate_, min_mem_pages * WasmModule::kPageSize, enable_guard_regions);
isolate_, num_pages * WasmModule::kPageSize, enable_guard_regions);
if (mem_buffer.is_null()) {
thrower_->RangeError("Out of memory: wasm memory");
......@@ -1613,10 +1613,11 @@ void InstanceBuilder::ProcessExports(
TableInstance& table_instance = table_instances_[exp.index];
WasmIndirectFunctionTable& table = module_->function_tables[exp.index];
if (table_instance.table_object.is_null()) {
uint32_t maximum =
table.has_max ? table.max_size : FLAG_wasm_max_table_size;
table_instance.table_object = WasmTableObject::New(
isolate_, table.min_size, maximum, &table_instance.js_wrappers);
uint32_t maximum = table.has_maximum_size ? table.maximum_size
: FLAG_wasm_max_table_size;
table_instance.table_object =
WasmTableObject::New(isolate_, table.initial_size, maximum,
&table_instance.js_wrappers);
}
desc.set_value(table_instance.table_object);
break;
......@@ -1631,7 +1632,7 @@ void InstanceBuilder::ProcessExports(
(instance->has_memory_buffer())
? handle(instance->memory_buffer())
: Handle<JSArrayBuffer>::null(),
(module_->max_mem_pages != 0) ? module_->max_mem_pages : -1);
(module_->maximum_pages != 0) ? module_->maximum_pages : -1);
instance->set_memory_object(*memory_object);
} else {
memory_object =
......@@ -1700,7 +1701,7 @@ void InstanceBuilder::InitializeTables(
for (int index = 0; index < function_table_count; ++index) {
WasmIndirectFunctionTable& table = module_->function_tables[index];
TableInstance& table_instance = table_instances_[index];
int table_size = static_cast<int>(table.min_size);
int table_size = static_cast<int>(table.initial_size);
if (table_instance.function_table.is_null()) {
// Create a new dispatch table if necessary.
......
......@@ -290,7 +290,7 @@ class InstanceBuilder {
void InitGlobals();
// Allocate memory for a module instance as a new JSArrayBuffer.
Handle<JSArrayBuffer> AllocateMemory(uint32_t min_mem_pages);
Handle<JSArrayBuffer> AllocateMemory(uint32_t num_pages);
bool NeedsWrappers() const;
......
......@@ -286,8 +286,8 @@ class ModuleDecoder : public Decoder {
SetCounters(isolate->counters());
module_.reset(new WasmModule(
base::make_unique<Zone>(isolate->allocator(), "signatures")));
module_->min_mem_pages = 0;
module_->max_mem_pages = 0;
module_->initial_pages = 0;
module_->maximum_pages = 0;
module_->mem_export = false;
module_->set_origin(origin_);
}
......@@ -465,10 +465,10 @@ class ModuleDecoder : public Decoder {
WasmIndirectFunctionTable* table = &module_->function_tables.back();
table->imported = true;
expect_u8("element type", kWasmAnyFunctionTypeForm);
consume_resizable_limits("element count", "elements",
FLAG_wasm_max_table_size, &table->min_size,
&table->has_max, FLAG_wasm_max_table_size,
&table->max_size);
consume_resizable_limits(
"element count", "elements", FLAG_wasm_max_table_size,
&table->initial_size, &table->has_maximum_size,
FLAG_wasm_max_table_size, &table->maximum_size);
break;
}
case kExternalMemory: {
......@@ -476,8 +476,8 @@ class ModuleDecoder : public Decoder {
if (!AddMemory(module_.get())) break;
consume_resizable_limits(
"memory", "pages", FLAG_wasm_max_mem_pages,
&module_->min_mem_pages, &module_->has_max_mem,
kSpecMaxWasmMemoryPages, &module_->max_mem_pages);
&module_->initial_pages, &module_->has_maximum_pages,
kSpecMaxWasmMemoryPages, &module_->maximum_pages);
break;
}
case kExternalGlobal: {
......@@ -531,9 +531,9 @@ class ModuleDecoder : public Decoder {
WasmIndirectFunctionTable* table = &module_->function_tables.back();
expect_u8("table type", kWasmAnyFunctionTypeForm);
consume_resizable_limits("table elements", "elements",
FLAG_wasm_max_table_size, &table->min_size,
&table->has_max, FLAG_wasm_max_table_size,
&table->max_size);
FLAG_wasm_max_table_size, &table->initial_size,
&table->has_maximum_size,
FLAG_wasm_max_table_size, &table->maximum_size);
}
}
......@@ -542,10 +542,10 @@ class ModuleDecoder : public Decoder {
for (uint32_t i = 0; ok() && i < memory_count; i++) {
if (!AddMemory(module_.get())) break;
consume_resizable_limits("memory", "pages", FLAG_wasm_max_mem_pages,
&module_->min_mem_pages, &module_->has_max_mem,
kSpecMaxWasmMemoryPages,
&module_->max_mem_pages);
consume_resizable_limits(
"memory", "pages", FLAG_wasm_max_mem_pages, &module_->initial_pages,
&module_->has_maximum_pages, kSpecMaxWasmMemoryPages,
&module_->maximum_pages);
}
}
......
......@@ -136,9 +136,9 @@ struct WasmDataSegment {
struct WasmIndirectFunctionTable {
MOVE_ONLY_WITH_DEFAULT_CONSTRUCTORS(WasmIndirectFunctionTable);
uint32_t min_size = 0; // minimum table size.
uint32_t max_size = 0; // maximum table size.
bool has_max = false; // true if there is a maximum size.
uint32_t initial_size = 0; // initial table size.
uint32_t maximum_size = 0; // maximum table size.
bool has_maximum_size = false; // true if there is a maximum size.
// TODO(titzer): Move this to WasmInstance. Needed by interpreter only.
std::vector<int32_t> values; // function table, -1 indicating invalid.
bool imported = false; // true if imported.
......@@ -185,9 +185,9 @@ struct V8_EXPORT_PRIVATE WasmModule {
static const uint32_t kMinMemPages = 1; // Minimum memory size = 64kb
std::unique_ptr<Zone> signature_zone;
uint32_t min_mem_pages = 0; // minimum size of the memory in 64k pages
uint32_t max_mem_pages = 0; // maximum size of the memory in 64k pages
bool has_max_mem = false; // try if a maximum memory size exists
uint32_t initial_pages = 0; // initial size of the memory in 64k pages
uint32_t maximum_pages = 0; // maximum size of the memory in 64k pages
bool has_maximum_pages = false; // true if there is a maximum memory size
bool has_memory = false; // true if the memory was defined or imported
bool mem_export = false; // true if the memory is exported
int start_function_index = -1; // start function, >= 0 if any
......@@ -294,7 +294,7 @@ class V8_EXPORT_PRIVATE ModuleEnv {
function_tables_(module->function_tables.size()),
signature_tables_(module->function_tables.size()),
function_code_(module->functions.size(), default_function_code),
mem_size_(module->min_mem_pages * WasmModule::kPageSize) {}
mem_size_(module->initial_pages * WasmModule::kPageSize) {}
WasmModule* module() const { return module_; }
......
......@@ -263,7 +263,7 @@ namespace {
Handle<JSArrayBuffer> GrowMemoryBuffer(Isolate* isolate,
Handle<JSArrayBuffer> old_buffer,
uint32_t pages, uint32_t max_pages) {
uint32_t pages, uint32_t maximum_pages) {
Address old_mem_start = nullptr;
uint32_t old_size = 0;
if (!old_buffer.is_null()) {
......@@ -274,7 +274,7 @@ Handle<JSArrayBuffer> GrowMemoryBuffer(Isolate* isolate,
uint32_t old_pages = old_size / WasmModule::kPageSize;
DCHECK_GE(std::numeric_limits<uint32_t>::max(),
old_size + pages * WasmModule::kPageSize);
if (old_pages > max_pages || pages > max_pages - old_pages) {
if (old_pages > maximum_pages || pages > maximum_pages - old_pages) {
return Handle<JSArrayBuffer>::null();
}
......@@ -385,14 +385,14 @@ int32_t WasmMemoryObject::Grow(Isolate* isolate,
return old_size / WasmModule::kPageSize;
}
uint32_t max_pages;
uint32_t maximum_pages;
if (memory_object->has_maximum_pages()) {
max_pages = static_cast<uint32_t>(memory_object->maximum_pages());
if (FLAG_wasm_max_mem_pages < max_pages) return -1;
maximum_pages = static_cast<uint32_t>(memory_object->maximum_pages());
if (FLAG_wasm_max_mem_pages < maximum_pages) return -1;
} else {
max_pages = FLAG_wasm_max_mem_pages;
maximum_pages = FLAG_wasm_max_mem_pages;
}
new_buffer = GrowMemoryBuffer(isolate, old_buffer, pages, max_pages);
new_buffer = GrowMemoryBuffer(isolate, old_buffer, pages, maximum_pages);
if (new_buffer.is_null()) return -1;
if (memory_object->has_instances()) {
......@@ -466,9 +466,9 @@ int32_t WasmInstanceObject::GrowMemory(Isolate* isolate,
old_size = old_buffer->byte_length()->Number();
old_mem_start = static_cast<Address>(old_buffer->backing_store());
}
uint32_t max_pages = instance->GetMaxMemoryPages();
uint32_t maximum_pages = instance->GetMaxMemoryPages();
Handle<JSArrayBuffer> buffer =
GrowMemoryBuffer(isolate, old_buffer, pages, max_pages);
GrowMemoryBuffer(isolate, old_buffer, pages, maximum_pages);
if (buffer.is_null()) return -1;
SetInstanceMemory(isolate, instance, buffer);
UncheckedUpdateInstanceMemory(isolate, instance, old_mem_start, old_size);
......@@ -484,12 +484,12 @@ uint32_t WasmInstanceObject::GetMaxMemoryPages() {
if (maximum < FLAG_wasm_max_mem_pages) return maximum;
}
}
uint32_t compiled_max_pages = compiled_module()->module()->max_mem_pages;
uint32_t compiled_maximum_pages = compiled_module()->module()->maximum_pages;
Isolate* isolate = GetIsolate();
assert(compiled_module()->module()->is_wasm());
isolate->counters()->wasm_wasm_max_mem_pages_count()->AddSample(
compiled_max_pages);
if (compiled_max_pages != 0) return compiled_max_pages;
compiled_maximum_pages);
if (compiled_maximum_pages != 0) return compiled_maximum_pages;
return FLAG_wasm_max_mem_pages;
}
......@@ -829,7 +829,7 @@ Handle<WasmCompiledModule> WasmCompiledModule::New(
// reliable, and we need these at Reset (which is called at
// finalization). If the order were reliable, and top-down, we could instead
// just get them from shared().
compiled_module->set_min_mem_pages(shared->module()->min_mem_pages);
compiled_module->set_initial_pages(shared->module()->initial_pages);
compiled_module->set_num_imported_functions(
shared->module()->num_imported_functions);
// TODO(mtrofin): copy the rest of the specialization parameters over.
......@@ -1075,7 +1075,7 @@ uint32_t WasmCompiledModule::mem_size() const {
}
uint32_t WasmCompiledModule::default_mem_size() const {
return min_mem_pages() * WasmModule::kPageSize;
return initial_pages() * WasmModule::kPageSize;
}
MaybeHandle<String> WasmCompiledModule::GetModuleNameOrNull(
......
......@@ -390,7 +390,7 @@ class WasmCompiledModule : public FixedArray {
MACRO(LARGE_NUMBER, size_t, embedded_mem_start) \
MACRO(LARGE_NUMBER, size_t, globals_start) \
MACRO(LARGE_NUMBER, uint32_t, embedded_mem_size) \
MACRO(SMALL_CONST_NUMBER, uint32_t, min_mem_pages) \
MACRO(SMALL_CONST_NUMBER, uint32_t, initial_pages) \
MACRO(WEAK_LINK, WasmCompiledModule, next_instance) \
MACRO(WEAK_LINK, WasmCompiledModule, prev_instance) \
MACRO(WEAK_LINK, JSObject, owning_instance) \
......
......@@ -196,8 +196,8 @@ class TestingModule : public ModuleEnv {
rng.NextBytes(raw, end - raw);
}
void SetMaxMemPages(uint32_t max_mem_pages) {
test_module_.max_mem_pages = max_mem_pages;
void SetMaxMemPages(uint32_t maximum_pages) {
test_module_.maximum_pages = maximum_pages;
}
uint32_t AddFunction(FunctionSig* sig, Handle<Code> code, const char* name) {
......@@ -266,9 +266,9 @@ class TestingModule : public ModuleEnv {
uint32_t table_size) {
test_module_.function_tables.emplace_back();
WasmIndirectFunctionTable& table = test_module_.function_tables.back();
table.min_size = table_size;
table.max_size = table_size;
table.has_max = true;
table.initial_size = table_size;
table.maximum_size = table_size;
table.has_maximum_size = true;
for (uint32_t i = 0; i < table_size; ++i) {
table.values.push_back(function_indexes[i]);
table.map.FindOrInsert(test_module_.functions[function_indexes[i]].sig);
......
......@@ -21,8 +21,8 @@ namespace internal {
namespace wasm {
namespace testing {
uint32_t GetMinModuleMemSize(const WasmModule* module) {
return WasmModule::kPageSize * module->min_mem_pages;
uint32_t GetInitialMemSize(const WasmModule* module) {
return WasmModule::kPageSize * module->initial_pages;
}
std::unique_ptr<WasmModule> DecodeWasmModuleForTesting(
......
......@@ -231,8 +231,8 @@ class TestModuleEnv : public ModuleEnv {
void InitializeMemory() {
mod.has_memory = true;
mod.min_mem_pages = 1;
mod.max_mem_pages = 100;
mod.initial_pages = 1;
mod.maximum_pages = 100;
}
void InitializeFunctionTable() { mod.function_tables.emplace_back(); }
......
......@@ -726,7 +726,7 @@ TEST_F(WasmModuleVerifyTest, OneIndirectFunction) {
EXPECT_EQ(1u, result.val->signatures.size());
EXPECT_EQ(1u, result.val->functions.size());
EXPECT_EQ(1u, result.val->function_tables.size());
EXPECT_EQ(1u, result.val->function_tables[0].min_size);
EXPECT_EQ(1u, result.val->function_tables[0].initial_size);
}
}
......@@ -771,7 +771,7 @@ TEST_F(WasmModuleVerifyTest, OneIndirectFunction_one_entry) {
EXPECT_EQ(1u, result.val->signatures.size());
EXPECT_EQ(1u, result.val->functions.size());
EXPECT_EQ(1u, result.val->function_tables.size());
EXPECT_EQ(1u, result.val->function_tables[0].min_size);
EXPECT_EQ(1u, result.val->function_tables[0].initial_size);
}
}
......@@ -807,7 +807,7 @@ TEST_F(WasmModuleVerifyTest, MultipleIndirectFunctions) {
EXPECT_EQ(2u, result.val->signatures.size());
EXPECT_EQ(4u, result.val->functions.size());
EXPECT_EQ(1u, result.val->function_tables.size());
EXPECT_EQ(8u, result.val->function_tables[0].min_size);
EXPECT_EQ(8u, result.val->function_tables[0].initial_size);
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment