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

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

Issue 2551463002: [wasm] Move all V8-specific limitations to wasm-limits.h (Closed)
Patch Set: Created 4 years 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') | no next file » | 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 <memory> 5 #include <memory>
6 6
7 #include "src/base/atomic-utils.h" 7 #include "src/base/atomic-utils.h"
8 #include "src/code-stubs.h" 8 #include "src/code-stubs.h"
9 9
10 #include "src/macro-assembler.h" 10 #include "src/macro-assembler.h"
11 #include "src/objects.h" 11 #include "src/objects.h"
12 #include "src/property-descriptor.h" 12 #include "src/property-descriptor.h"
13 #include "src/simulator.h" 13 #include "src/simulator.h"
14 #include "src/snapshot/snapshot.h" 14 #include "src/snapshot/snapshot.h"
15 #include "src/v8.h" 15 #include "src/v8.h"
16 16
17 #include "src/wasm/ast-decoder.h" 17 #include "src/wasm/ast-decoder.h"
18 #include "src/wasm/module-decoder.h" 18 #include "src/wasm/module-decoder.h"
19 #include "src/wasm/wasm-js.h" 19 #include "src/wasm/wasm-js.h"
20 #include "src/wasm/wasm-limits.h"
20 #include "src/wasm/wasm-module.h" 21 #include "src/wasm/wasm-module.h"
21 #include "src/wasm/wasm-objects.h" 22 #include "src/wasm/wasm-objects.h"
22 #include "src/wasm/wasm-result.h" 23 #include "src/wasm/wasm-result.h"
23 24
24 #include "src/compiler/wasm-compiler.h" 25 #include "src/compiler/wasm-compiler.h"
25 26
26 using namespace v8::internal; 27 using namespace v8::internal;
27 using namespace v8::internal::wasm; 28 using namespace v8::internal::wasm;
28 namespace base = v8::base; 29 namespace base = v8::base;
29 30
(...skipping 650 matching lines...) Expand 10 before | Expand all | Expand 10 after
680 } 681 }
681 WasmFunction& func = module->functions[func_index]; 682 WasmFunction& func = module->functions[func_index];
682 return {static_cast<int>(func.code_start_offset), 683 return {static_cast<int>(func.code_start_offset),
683 static_cast<int>(func.code_end_offset - func.code_start_offset)}; 684 static_cast<int>(func.code_end_offset - func.code_start_offset)};
684 } 685 }
685 686
686 } // namespace 687 } // namespace
687 688
688 Handle<JSArrayBuffer> wasm::NewArrayBuffer(Isolate* isolate, size_t size, 689 Handle<JSArrayBuffer> wasm::NewArrayBuffer(Isolate* isolate, size_t size,
689 bool enable_guard_regions) { 690 bool enable_guard_regions) {
690 if (size > (WasmModule::kV8MaxPages * WasmModule::kPageSize)) { 691 if (size > (kV8MaxWasmMemoryPages * WasmModule::kPageSize)) {
691 // TODO(titzer): lift restriction on maximum memory allocated here. 692 // TODO(titzer): lift restriction on maximum memory allocated here.
692 return Handle<JSArrayBuffer>::null(); 693 return Handle<JSArrayBuffer>::null();
693 } 694 }
694 695
695 enable_guard_regions = enable_guard_regions && kGuardRegionsSupported; 696 enable_guard_regions = enable_guard_regions && kGuardRegionsSupported;
696 697
697 bool is_external; // Set by TryAllocateBackingStore 698 bool is_external; // Set by TryAllocateBackingStore
698 void* memory = 699 void* memory =
699 TryAllocateBackingStore(isolate, size, enable_guard_regions, is_external); 700 TryAllocateBackingStore(isolate, size, enable_guard_regions, is_external);
700 701
(...skipping 982 matching lines...) Expand 10 before | Expand all | Expand 10 after
1683 break; 1684 break;
1684 default: 1685 default:
1685 UNREACHABLE(); 1686 UNREACHABLE();
1686 break; 1687 break;
1687 } 1688 }
1688 } 1689 }
1689 } 1690 }
1690 1691
1691 // Allocate memory for a module instance as a new JSArrayBuffer. 1692 // Allocate memory for a module instance as a new JSArrayBuffer.
1692 Handle<JSArrayBuffer> AllocateMemory(uint32_t min_mem_pages) { 1693 Handle<JSArrayBuffer> AllocateMemory(uint32_t min_mem_pages) {
1693 if (min_mem_pages > WasmModule::kV8MaxPages) { 1694 if (min_mem_pages > kV8MaxWasmMemoryPages) {
1694 thrower_->RangeError("Out of memory: wasm memory too large"); 1695 thrower_->RangeError("Out of memory: wasm memory too large");
1695 return Handle<JSArrayBuffer>::null(); 1696 return Handle<JSArrayBuffer>::null();
1696 } 1697 }
1697 const bool enable_guard_regions = EnableGuardRegions(); 1698 const bool enable_guard_regions = EnableGuardRegions();
1698 Handle<JSArrayBuffer> mem_buffer = NewArrayBuffer( 1699 Handle<JSArrayBuffer> mem_buffer = NewArrayBuffer(
1699 isolate_, min_mem_pages * WasmModule::kPageSize, enable_guard_regions); 1700 isolate_, min_mem_pages * WasmModule::kPageSize, enable_guard_regions);
1700 1701
1701 if (mem_buffer.is_null()) { 1702 if (mem_buffer.is_null()) {
1702 thrower_->RangeError("Out of memory: wasm memory"); 1703 thrower_->RangeError("Out of memory: wasm memory");
1703 } 1704 }
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
1770 export_index++; 1771 export_index++;
1771 break; 1772 break;
1772 } 1773 }
1773 case kExternalTable: { 1774 case kExternalTable: {
1774 // Export a table as a WebAssembly.Table object. 1775 // Export a table as a WebAssembly.Table object.
1775 TableInstance& table_instance = table_instances_[exp.index]; 1776 TableInstance& table_instance = table_instances_[exp.index];
1776 WasmIndirectFunctionTable& table = 1777 WasmIndirectFunctionTable& table =
1777 module_->function_tables[exp.index]; 1778 module_->function_tables[exp.index];
1778 if (table_instance.table_object.is_null()) { 1779 if (table_instance.table_object.is_null()) {
1779 uint32_t maximum = 1780 uint32_t maximum =
1780 table.has_max ? table.max_size : WasmModule::kV8MaxTableSize; 1781 table.has_max ? table.max_size : kV8MaxWasmTableSize;
1781 table_instance.table_object = WasmTableObject::New( 1782 table_instance.table_object = WasmTableObject::New(
1782 isolate_, table.min_size, maximum, &table_instance.js_wrappers); 1783 isolate_, table.min_size, maximum, &table_instance.js_wrappers);
1783 } 1784 }
1784 desc.set_value(table_instance.table_object); 1785 desc.set_value(table_instance.table_object);
1785 break; 1786 break;
1786 } 1787 }
1787 case kExternalMemory: { 1788 case kExternalMemory: {
1788 // Export the memory as a WebAssembly.Memory object. 1789 // Export the memory as a WebAssembly.Memory object.
1789 Handle<WasmMemoryObject> memory_object; 1790 Handle<WasmMemoryObject> memory_object;
1790 if (!instance->has_memory_object()) { 1791 if (!instance->has_memory_object()) {
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after
2138 isolate); 2139 isolate);
2139 2140
2140 int maximum = memory_object->maximum_pages(); 2141 int maximum = memory_object->maximum_pages();
2141 if (maximum > 0) return static_cast<uint32_t>(maximum); 2142 if (maximum > 0) return static_cast<uint32_t>(maximum);
2142 } 2143 }
2143 uint32_t compiled_max_pages = 2144 uint32_t compiled_max_pages =
2144 instance->get_compiled_module()->max_mem_pages(); 2145 instance->get_compiled_module()->max_mem_pages();
2145 isolate->counters()->wasm_max_mem_pages_count()->AddSample( 2146 isolate->counters()->wasm_max_mem_pages_count()->AddSample(
2146 compiled_max_pages); 2147 compiled_max_pages);
2147 if (compiled_max_pages != 0) return compiled_max_pages; 2148 if (compiled_max_pages != 0) return compiled_max_pages;
2148 return WasmModule::kV8MaxPages; 2149 return kV8MaxWasmMemoryPages;
2149 } 2150 }
2150 2151
2151 Handle<JSArrayBuffer> GrowMemoryBuffer(Isolate* isolate, 2152 Handle<JSArrayBuffer> GrowMemoryBuffer(Isolate* isolate,
2152 MaybeHandle<JSArrayBuffer> buffer, 2153 MaybeHandle<JSArrayBuffer> buffer,
2153 uint32_t pages, uint32_t max_pages) { 2154 uint32_t pages, uint32_t max_pages) {
2154 Handle<JSArrayBuffer> old_buffer; 2155 Handle<JSArrayBuffer> old_buffer;
2155 Address old_mem_start = nullptr; 2156 Address old_mem_start = nullptr;
2156 uint32_t old_size = 0; 2157 uint32_t old_size = 0;
2157 if (buffer.ToHandle(&old_buffer) && old_buffer->backing_store() != nullptr) { 2158 if (buffer.ToHandle(&old_buffer) && old_buffer->backing_store() != nullptr) {
2158 old_mem_start = static_cast<Address>(old_buffer->backing_store()); 2159 old_mem_start = static_cast<Address>(old_buffer->backing_store());
2159 DCHECK_NOT_NULL(old_mem_start); 2160 DCHECK_NOT_NULL(old_mem_start);
2160 old_size = old_buffer->byte_length()->Number(); 2161 old_size = old_buffer->byte_length()->Number();
2161 } 2162 }
2162 DCHECK(old_size + pages * WasmModule::kPageSize <= 2163 DCHECK(old_size + pages * WasmModule::kPageSize <=
2163 std::numeric_limits<uint32_t>::max()); 2164 std::numeric_limits<uint32_t>::max());
2164 uint32_t new_size = old_size + pages * WasmModule::kPageSize; 2165 uint32_t new_size = old_size + pages * WasmModule::kPageSize;
2165 if (new_size <= old_size || max_pages * WasmModule::kPageSize < new_size || 2166 if (new_size <= old_size || max_pages * WasmModule::kPageSize < new_size ||
2166 WasmModule::kV8MaxPages * WasmModule::kPageSize < new_size) { 2167 kV8MaxWasmMemoryPages * WasmModule::kPageSize < new_size) {
2167 return Handle<JSArrayBuffer>::null(); 2168 return Handle<JSArrayBuffer>::null();
2168 } 2169 }
2169 2170
2170 Handle<JSArrayBuffer> new_buffer; 2171 Handle<JSArrayBuffer> new_buffer;
2171 if (!old_buffer.is_null() && old_buffer->has_guard_region()) { 2172 if (!old_buffer.is_null() && old_buffer->has_guard_region()) {
2172 // We don't move the backing store, we simply change the protection to make 2173 // We don't move the backing store, we simply change the protection to make
2173 // more of it accessible. 2174 // more of it accessible.
2174 base::OS::Unprotect(old_buffer->backing_store(), new_size); 2175 base::OS::Unprotect(old_buffer->backing_store(), new_size);
2175 reinterpret_cast<v8::Isolate*>(isolate) 2176 reinterpret_cast<v8::Isolate*>(isolate)
2176 ->AdjustAmountOfExternalAllocatedMemory(pages * WasmModule::kPageSize); 2177 ->AdjustAmountOfExternalAllocatedMemory(pages * WasmModule::kPageSize);
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
2357 MaybeHandle<String> WasmCompiledModule::GetFunctionName( 2358 MaybeHandle<String> WasmCompiledModule::GetFunctionName(
2358 Handle<WasmCompiledModule> compiled_module, uint32_t func_index) { 2359 Handle<WasmCompiledModule> compiled_module, uint32_t func_index) {
2359 DCHECK_LT(func_index, compiled_module->module()->functions.size()); 2360 DCHECK_LT(func_index, compiled_module->module()->functions.size());
2360 WasmFunction& function = compiled_module->module()->functions[func_index]; 2361 WasmFunction& function = compiled_module->module()->functions[func_index];
2361 Isolate* isolate = compiled_module->GetIsolate(); 2362 Isolate* isolate = compiled_module->GetIsolate();
2362 MaybeHandle<String> string = ExtractStringFromModuleBytes( 2363 MaybeHandle<String> string = ExtractStringFromModuleBytes(
2363 isolate, compiled_module, function.name_offset, function.name_length); 2364 isolate, compiled_module, function.name_offset, function.name_length);
2364 if (!string.is_null()) return string.ToHandleChecked(); 2365 if (!string.is_null()) return string.ToHandleChecked();
2365 return {}; 2366 return {};
2366 } 2367 }
OLDNEW
« no previous file with comments | « src/wasm/wasm-module.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698