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

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

Issue 2005933003: [wasm] globals size is not a per-instance property. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 7 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/compiler/wasm-compiler.cc ('k') | src/wasm/wasm-function-name-table.h » ('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/wasm/module-decoder.h" 5 #include "src/wasm/module-decoder.h"
6 6
7 #include "src/base/functional.h" 7 #include "src/base/functional.h"
8 #include "src/base/platform/platform.h" 8 #include "src/base/platform/platform.h"
9 #include "src/macro-assembler.h" 9 #include "src/macro-assembler.h"
10 #include "src/objects.h" 10 #include "src/objects.h"
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after
412 size_t actual_length = static_cast<size_t>(pc_ - section_start); 412 size_t actual_length = static_cast<size_t>(pc_ - section_start);
413 error(pc_, pc_, 413 error(pc_, pc_,
414 "section \"%s\" %s (%zu bytes) than specified (%zu bytes)", 414 "section \"%s\" %s (%zu bytes) than specified (%zu bytes)",
415 WasmSection::getName(section), diff, actual_length, 415 WasmSection::getName(section), diff, actual_length,
416 expected_length); 416 expected_length);
417 break; 417 break;
418 } 418 }
419 } 419 }
420 420
421 done: 421 done:
422 ModuleResult result = toResult(module); 422 CalculateGlobalsOffsets(module);
423 const WasmModule* finished_module = module;
424 ModuleResult result = toResult(finished_module);
423 if (FLAG_dump_wasm_module) { 425 if (FLAG_dump_wasm_module) {
424 DumpModule(module, result); 426 DumpModule(module, result);
425 } 427 }
426 return result; 428 return result;
427 } 429 }
428 430
429 uint32_t SafeReserve(uint32_t count) { 431 uint32_t SafeReserve(uint32_t count) {
430 // Avoid OOM by only reserving up to a certain size. 432 // Avoid OOM by only reserving up to a certain size.
431 const uint32_t kMaxReserve = 20000; 433 const uint32_t kMaxReserve = 20000;
432 return count < kMaxReserve ? count : kMaxReserve; 434 return count < kMaxReserve ? count : kMaxReserve;
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
563 WasmModule::kPageSize * (module ? module->min_mem_pages 565 WasmModule::kPageSize * (module ? module->min_mem_pages
564 : WasmModule::kMaxMemPages); 566 : WasmModule::kMaxMemPages);
565 if (!IsWithinLimit(memory_limit, segment->dest_addr, 567 if (!IsWithinLimit(memory_limit, segment->dest_addr,
566 segment->source_size)) { 568 segment->source_size)) {
567 error(start, "segment out of bounds of memory"); 569 error(start, "segment out of bounds of memory");
568 } 570 }
569 571
570 consume_bytes(segment->source_size); 572 consume_bytes(segment->source_size);
571 } 573 }
572 574
575 // Calculate individual global offsets and total size of globals table.
576 void CalculateGlobalsOffsets(WasmModule* module) {
577 uint32_t offset = 0;
578 if (module->globals.size() == 0) {
579 module->globals_size = 0;
580 return;
581 }
582 for (WasmGlobal& global : module->globals) {
583 byte size = WasmOpcodes::MemSize(global.type);
584 offset = (offset + size - 1) & ~(size - 1); // align
585 global.offset = offset;
586 offset += size;
587 }
588 module->globals_size = offset;
589 }
590
573 // Verifies the body (code) of a given function. 591 // Verifies the body (code) of a given function.
574 void VerifyFunctionBody(uint32_t func_num, ModuleEnv* menv, 592 void VerifyFunctionBody(uint32_t func_num, ModuleEnv* menv,
575 WasmFunction* function) { 593 WasmFunction* function) {
576 if (FLAG_trace_wasm_decoder || FLAG_trace_wasm_decode_time) { 594 if (FLAG_trace_wasm_decoder || FLAG_trace_wasm_decode_time) {
577 OFStream os(stdout); 595 OFStream os(stdout);
578 os << "Verifying WASM function " << WasmFunctionName(function, menv) 596 os << "Verifying WASM function " << WasmFunctionName(function, menv)
579 << std::endl; 597 << std::endl;
580 } 598 }
581 FunctionBody body = {menv, function->sig, start_, 599 FunctionBody body = {menv, function->sig, start_,
582 start_ + function->code_start_offset, 600 start_ + function->code_start_offset,
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
814 return FunctionError("size > maximum function size"); 832 return FunctionError("size > maximum function size");
815 isolate->counters()->wasm_function_size_bytes()->AddSample( 833 isolate->counters()->wasm_function_size_bytes()->AddSample(
816 static_cast<int>(size)); 834 static_cast<int>(size));
817 WasmFunction* function = new WasmFunction(); 835 WasmFunction* function = new WasmFunction();
818 ModuleDecoder decoder(zone, function_start, function_end, kWasmOrigin); 836 ModuleDecoder decoder(zone, function_start, function_end, kWasmOrigin);
819 return decoder.DecodeSingleFunction(module_env, function); 837 return decoder.DecodeSingleFunction(module_env, function);
820 } 838 }
821 } // namespace wasm 839 } // namespace wasm
822 } // namespace internal 840 } // namespace internal
823 } // namespace v8 841 } // namespace v8
OLDNEW
« no previous file with comments | « src/compiler/wasm-compiler.cc ('k') | src/wasm/wasm-function-name-table.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698