Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(51)

Side by Side Diff: src/wasm/wasm-module.cc

Issue 1597163002: wasm: change the module memory size to be multiples of the page size, 64k. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Rebase Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/wasm/wasm-module.h ('k') | test/mjsunit/wasm/calls.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 the V8 project authors. All rights reserved. 1 // Copyright 2015 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/macro-assembler.h" 5 #include "src/macro-assembler.h"
6 #include "src/objects.h" 6 #include "src/objects.h"
7 #include "src/v8.h" 7 #include "src/v8.h"
8 8
9 #include "src/simulator.h" 9 #include "src/simulator.h"
10 10
11 #include "src/wasm/ast-decoder.h" 11 #include "src/wasm/ast-decoder.h"
12 #include "src/wasm/module-decoder.h" 12 #include "src/wasm/module-decoder.h"
13 #include "src/wasm/wasm-module.h" 13 #include "src/wasm/wasm-module.h"
14 #include "src/wasm/wasm-result.h" 14 #include "src/wasm/wasm-result.h"
15 15
16 #include "src/compiler/wasm-compiler.h" 16 #include "src/compiler/wasm-compiler.h"
17 17
18 namespace v8 { 18 namespace v8 {
19 namespace internal { 19 namespace internal {
20 namespace wasm { 20 namespace wasm {
21 21
22 std::ostream& operator<<(std::ostream& os, const WasmModule& module) { 22 std::ostream& operator<<(std::ostream& os, const WasmModule& module) {
23 os << "WASM module with "; 23 os << "WASM module with ";
24 os << (1 << module.min_mem_size_log2) << " min mem"; 24 os << (module.min_mem_pages * module.kPageSize) << " min mem";
25 os << (1 << module.max_mem_size_log2) << " max mem"; 25 os << (module.max_mem_pages * module.kPageSize) << " max mem";
26 os << module.functions.size() << " functions"; 26 os << module.functions.size() << " functions";
27 os << module.functions.size() << " globals"; 27 os << module.functions.size() << " globals";
28 os << module.functions.size() << " data segments"; 28 os << module.functions.size() << " data segments";
29 return os; 29 return os;
30 } 30 }
31 31
32 32
33 std::ostream& operator<<(std::ostream& os, const WasmFunction& function) { 33 std::ostream& operator<<(std::ostream& os, const WasmFunction& function) {
34 os << "WASM function with signature " << *function.sig; 34 os << "WASM function with signature " << *function.sig;
35 35
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 global.offset = offset; 160 global.offset = offset;
161 offset += size; 161 offset += size;
162 } 162 }
163 return offset; 163 return offset;
164 } 164 }
165 165
166 166
167 void LoadDataSegments(WasmModule* module, byte* mem_addr, size_t mem_size) { 167 void LoadDataSegments(WasmModule* module, byte* mem_addr, size_t mem_size) {
168 for (const WasmDataSegment& segment : module->data_segments) { 168 for (const WasmDataSegment& segment : module->data_segments) {
169 if (!segment.init) continue; 169 if (!segment.init) continue;
170 if (!segment.source_size) continue;
170 CHECK_LT(segment.dest_addr, mem_size); 171 CHECK_LT(segment.dest_addr, mem_size);
171 CHECK_LE(segment.source_size, mem_size); 172 CHECK_LE(segment.source_size, mem_size);
172 CHECK_LE(segment.dest_addr + segment.source_size, mem_size); 173 CHECK_LE(segment.dest_addr + segment.source_size, mem_size);
173 byte* addr = mem_addr + segment.dest_addr; 174 byte* addr = mem_addr + segment.dest_addr;
174 memcpy(addr, module->module_start + segment.source_offset, 175 memcpy(addr, module->module_start + segment.source_offset,
175 segment.source_size); 176 segment.source_size);
176 } 177 }
177 } 178 }
178 179
179 180
180 Handle<FixedArray> BuildFunctionTable(Isolate* isolate, WasmModule* module) { 181 Handle<FixedArray> BuildFunctionTable(Isolate* isolate, WasmModule* module) {
181 if (module->function_table.size() == 0) { 182 if (module->function_table.size() == 0) {
182 return Handle<FixedArray>::null(); 183 return Handle<FixedArray>::null();
183 } 184 }
184 int table_size = static_cast<int>(module->function_table.size()); 185 int table_size = static_cast<int>(module->function_table.size());
185 Handle<FixedArray> fixed = isolate->factory()->NewFixedArray(2 * table_size); 186 Handle<FixedArray> fixed = isolate->factory()->NewFixedArray(2 * table_size);
186 for (int i = 0; i < table_size; i++) { 187 for (int i = 0; i < table_size; i++) {
187 WasmFunction* function = &module->functions[module->function_table[i]]; 188 WasmFunction* function = &module->functions[module->function_table[i]];
188 fixed->set(i, Smi::FromInt(function->sig_index)); 189 fixed->set(i, Smi::FromInt(function->sig_index));
189 } 190 }
190 return fixed; 191 return fixed;
191 } 192 }
192 193
193 Handle<JSArrayBuffer> NewArrayBuffer(Isolate* isolate, size_t size, 194 Handle<JSArrayBuffer> NewArrayBuffer(Isolate* isolate, size_t size,
194 byte** backing_store) { 195 byte** backing_store) {
195 if (size > (1 << WasmModule::kMaxMemSize)) { 196 if (size > (WasmModule::kMaxMemPages * WasmModule::kPageSize)) {
196 // TODO(titzer): lift restriction on maximum memory allocated here. 197 // TODO(titzer): lift restriction on maximum memory allocated here.
197 *backing_store = nullptr; 198 *backing_store = nullptr;
198 return Handle<JSArrayBuffer>::null(); 199 return Handle<JSArrayBuffer>::null();
199 } 200 }
200 void* memory = 201 void* memory =
201 isolate->array_buffer_allocator()->Allocate(static_cast<int>(size)); 202 isolate->array_buffer_allocator()->Allocate(static_cast<int>(size));
202 if (!memory) { 203 if (!memory) {
203 *backing_store = nullptr; 204 *backing_store = nullptr;
204 return Handle<JSArrayBuffer>::null(); 205 return Handle<JSArrayBuffer>::null();
205 } 206 }
(...skipping 21 matching lines...) Expand all
227 instance->mem_size = memory->byte_length()->Number(); 228 instance->mem_size = memory->byte_length()->Number();
228 instance->mem_buffer = memory; 229 instance->mem_buffer = memory;
229 } 230 }
230 231
231 // Allocate memory for a module instance as a new JSArrayBuffer. 232 // Allocate memory for a module instance as a new JSArrayBuffer.
232 bool AllocateMemory(ErrorThrower* thrower, Isolate* isolate, 233 bool AllocateMemory(ErrorThrower* thrower, Isolate* isolate,
233 WasmModuleInstance* instance) { 234 WasmModuleInstance* instance) {
234 DCHECK(instance->module); 235 DCHECK(instance->module);
235 DCHECK(instance->mem_buffer.is_null()); 236 DCHECK(instance->mem_buffer.is_null());
236 237
237 if (instance->module->min_mem_size_log2 > WasmModule::kMaxMemSize) { 238 if (instance->module->min_mem_pages > WasmModule::kMaxMemPages) {
238 thrower->Error("Out of memory: wasm memory too large"); 239 thrower->Error("Out of memory: wasm memory too large");
239 return false; 240 return false;
240 } 241 }
241 instance->mem_size = static_cast<size_t>(1) 242 instance->mem_size = WasmModule::kPageSize * instance->module->min_mem_pages;
242 << instance->module->min_mem_size_log2;
243 instance->mem_buffer = 243 instance->mem_buffer =
244 NewArrayBuffer(isolate, instance->mem_size, &instance->mem_start); 244 NewArrayBuffer(isolate, instance->mem_size, &instance->mem_start);
245 if (!instance->mem_start) { 245 if (!instance->mem_start) {
246 thrower->Error("Out of memory: wasm memory"); 246 thrower->Error("Out of memory: wasm memory");
247 instance->mem_size = 0; 247 instance->mem_size = 0;
248 return false; 248 return false;
249 } 249 }
250 return true; 250 return true;
251 } 251 }
252 252
(...skipping 11 matching lines...) Expand all
264 } 264 }
265 } 265 }
266 return true; 266 return true;
267 } 267 }
268 } // namespace 268 } // namespace
269 269
270 WasmModule::WasmModule() 270 WasmModule::WasmModule()
271 : shared_isolate(nullptr), 271 : shared_isolate(nullptr),
272 module_start(nullptr), 272 module_start(nullptr),
273 module_end(nullptr), 273 module_end(nullptr),
274 min_mem_size_log2(0), 274 min_mem_pages(0),
275 max_mem_size_log2(0), 275 max_mem_pages(0),
276 mem_export(false), 276 mem_export(false),
277 mem_external(false), 277 mem_external(false),
278 start_function_index(-1), 278 start_function_index(-1),
279 origin(kWasmOrigin) {} 279 origin(kWasmOrigin) {}
280 280
281 static MaybeHandle<JSFunction> LookupFunction(ErrorThrower& thrower, 281 static MaybeHandle<JSFunction> LookupFunction(ErrorThrower& thrower,
282 Handle<JSObject> ffi, 282 Handle<JSObject> ffi,
283 uint32_t index, 283 uint32_t index,
284 Handle<String> name, 284 Handle<String> name,
285 const char* cstr) { 285 const char* cstr) {
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after
606 } 606 }
607 if (result->IsHeapNumber()) { 607 if (result->IsHeapNumber()) {
608 return static_cast<int32_t>(HeapNumber::cast(*result)->value()); 608 return static_cast<int32_t>(HeapNumber::cast(*result)->value());
609 } 609 }
610 thrower.Error("WASM.compileRun() failed: Return value should be number"); 610 thrower.Error("WASM.compileRun() failed: Return value should be number");
611 return -1; 611 return -1;
612 } 612 }
613 } // namespace wasm 613 } // namespace wasm
614 } // namespace internal 614 } // namespace internal
615 } // namespace v8 615 } // namespace v8
OLDNEW
« no previous file with comments | « src/wasm/wasm-module.h ('k') | test/mjsunit/wasm/calls.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698