OLD | NEW |
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/assembler-inl.h" | 7 #include "src/assembler-inl.h" |
8 #include "src/base/adapters.h" | 8 #include "src/base/adapters.h" |
9 #include "src/base/atomic-utils.h" | 9 #include "src/base/atomic-utils.h" |
10 #include "src/code-stubs.h" | 10 #include "src/code-stubs.h" |
(...skipping 737 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
748 Vector<const uint8_t>(reinterpret_cast<uint8_t*>(buffer), name_chars), | 748 Vector<const uint8_t>(reinterpret_cast<uint8_t*>(buffer), name_chars), |
749 TENURED); | 749 TENURED); |
750 script->set_name(*name_str.ToHandleChecked()); | 750 script->set_name(*name_str.ToHandleChecked()); |
751 | 751 |
752 return script; | 752 return script; |
753 } | 753 } |
754 } // namespace | 754 } // namespace |
755 | 755 |
756 Handle<JSArrayBuffer> wasm::NewArrayBuffer(Isolate* isolate, size_t size, | 756 Handle<JSArrayBuffer> wasm::NewArrayBuffer(Isolate* isolate, size_t size, |
757 bool enable_guard_regions) { | 757 bool enable_guard_regions) { |
758 if (size > (kV8MaxWasmMemoryPages * WasmModule::kPageSize)) { | 758 if (size > (FLAG_wasm_max_mem_pages * WasmModule::kPageSize)) { |
759 // TODO(titzer): lift restriction on maximum memory allocated here. | 759 // TODO(titzer): lift restriction on maximum memory allocated here. |
760 return Handle<JSArrayBuffer>::null(); | 760 return Handle<JSArrayBuffer>::null(); |
761 } | 761 } |
762 | 762 |
763 enable_guard_regions = enable_guard_regions && kGuardRegionsSupported; | 763 enable_guard_regions = enable_guard_regions && kGuardRegionsSupported; |
764 | 764 |
765 bool is_external; // Set by TryAllocateBackingStore | 765 bool is_external; // Set by TryAllocateBackingStore |
766 void* memory = | 766 void* memory = |
767 TryAllocateBackingStore(isolate, size, enable_guard_regions, is_external); | 767 TryAllocateBackingStore(isolate, size, enable_guard_regions, is_external); |
768 | 768 |
(...skipping 1058 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1827 break; | 1827 break; |
1828 default: | 1828 default: |
1829 UNREACHABLE(); | 1829 UNREACHABLE(); |
1830 break; | 1830 break; |
1831 } | 1831 } |
1832 } | 1832 } |
1833 } | 1833 } |
1834 | 1834 |
1835 // Allocate memory for a module instance as a new JSArrayBuffer. | 1835 // Allocate memory for a module instance as a new JSArrayBuffer. |
1836 Handle<JSArrayBuffer> AllocateMemory(uint32_t min_mem_pages) { | 1836 Handle<JSArrayBuffer> AllocateMemory(uint32_t min_mem_pages) { |
1837 if (min_mem_pages > kV8MaxWasmMemoryPages) { | 1837 if (min_mem_pages > FLAG_wasm_max_mem_pages) { |
1838 thrower_->RangeError("Out of memory: wasm memory too large"); | 1838 thrower_->RangeError("Out of memory: wasm memory too large"); |
1839 return Handle<JSArrayBuffer>::null(); | 1839 return Handle<JSArrayBuffer>::null(); |
1840 } | 1840 } |
1841 const bool enable_guard_regions = EnableGuardRegions(); | 1841 const bool enable_guard_regions = EnableGuardRegions(); |
1842 Handle<JSArrayBuffer> mem_buffer = NewArrayBuffer( | 1842 Handle<JSArrayBuffer> mem_buffer = NewArrayBuffer( |
1843 isolate_, min_mem_pages * WasmModule::kPageSize, enable_guard_regions); | 1843 isolate_, min_mem_pages * WasmModule::kPageSize, enable_guard_regions); |
1844 | 1844 |
1845 if (mem_buffer.is_null()) { | 1845 if (mem_buffer.is_null()) { |
1846 thrower_->RangeError("Out of memory: wasm memory"); | 1846 thrower_->RangeError("Out of memory: wasm memory"); |
1847 } | 1847 } |
(...skipping 421 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2269 return buffer->byte_length()->Number() / WasmModule::kPageSize; | 2269 return buffer->byte_length()->Number() / WasmModule::kPageSize; |
2270 } | 2270 } |
2271 } | 2271 } |
2272 | 2272 |
2273 uint32_t GetMaxInstanceMemoryPages(Isolate* isolate, | 2273 uint32_t GetMaxInstanceMemoryPages(Isolate* isolate, |
2274 Handle<WasmInstanceObject> instance) { | 2274 Handle<WasmInstanceObject> instance) { |
2275 if (instance->has_memory_object()) { | 2275 if (instance->has_memory_object()) { |
2276 Handle<WasmMemoryObject> memory_object(instance->memory_object(), isolate); | 2276 Handle<WasmMemoryObject> memory_object(instance->memory_object(), isolate); |
2277 if (memory_object->has_maximum_pages()) { | 2277 if (memory_object->has_maximum_pages()) { |
2278 uint32_t maximum = static_cast<uint32_t>(memory_object->maximum_pages()); | 2278 uint32_t maximum = static_cast<uint32_t>(memory_object->maximum_pages()); |
2279 if (maximum < kV8MaxWasmMemoryPages) return maximum; | 2279 if (maximum < FLAG_wasm_max_mem_pages) return maximum; |
2280 } | 2280 } |
2281 } | 2281 } |
2282 uint32_t compiled_max_pages = instance->compiled_module()->max_mem_pages(); | 2282 uint32_t compiled_max_pages = instance->compiled_module()->max_mem_pages(); |
2283 isolate->counters()->wasm_max_mem_pages_count()->AddSample( | 2283 isolate->counters()->wasm_max_mem_pages_count()->AddSample( |
2284 compiled_max_pages); | 2284 compiled_max_pages); |
2285 if (compiled_max_pages != 0) return compiled_max_pages; | 2285 if (compiled_max_pages != 0) return compiled_max_pages; |
2286 return kV8MaxWasmMemoryPages; | 2286 return FLAG_wasm_max_mem_pages; |
2287 } | 2287 } |
2288 | 2288 |
2289 Handle<JSArrayBuffer> GrowMemoryBuffer(Isolate* isolate, | 2289 Handle<JSArrayBuffer> GrowMemoryBuffer(Isolate* isolate, |
2290 MaybeHandle<JSArrayBuffer> buffer, | 2290 MaybeHandle<JSArrayBuffer> buffer, |
2291 uint32_t pages, uint32_t max_pages) { | 2291 uint32_t pages, uint32_t max_pages) { |
2292 Handle<JSArrayBuffer> old_buffer; | 2292 Handle<JSArrayBuffer> old_buffer; |
2293 Address old_mem_start = nullptr; | 2293 Address old_mem_start = nullptr; |
2294 uint32_t old_size = 0; | 2294 uint32_t old_size = 0; |
2295 if (buffer.ToHandle(&old_buffer) && old_buffer->backing_store() != nullptr) { | 2295 if (buffer.ToHandle(&old_buffer) && old_buffer->backing_store() != nullptr) { |
2296 old_mem_start = static_cast<Address>(old_buffer->backing_store()); | 2296 old_mem_start = static_cast<Address>(old_buffer->backing_store()); |
2297 DCHECK_NOT_NULL(old_mem_start); | 2297 DCHECK_NOT_NULL(old_mem_start); |
2298 old_size = old_buffer->byte_length()->Number(); | 2298 old_size = old_buffer->byte_length()->Number(); |
2299 } | 2299 } |
2300 DCHECK(old_size + pages * WasmModule::kPageSize <= | 2300 DCHECK(old_size + pages * WasmModule::kPageSize <= |
2301 std::numeric_limits<uint32_t>::max()); | 2301 std::numeric_limits<uint32_t>::max()); |
2302 uint32_t new_size = old_size + pages * WasmModule::kPageSize; | 2302 uint32_t new_size = old_size + pages * WasmModule::kPageSize; |
2303 if (new_size <= old_size || max_pages * WasmModule::kPageSize < new_size || | 2303 if (new_size <= old_size || max_pages * WasmModule::kPageSize < new_size || |
2304 kV8MaxWasmMemoryPages * WasmModule::kPageSize < new_size) { | 2304 FLAG_wasm_max_mem_pages * WasmModule::kPageSize < new_size) { |
2305 return Handle<JSArrayBuffer>::null(); | 2305 return Handle<JSArrayBuffer>::null(); |
2306 } | 2306 } |
2307 | 2307 |
2308 Handle<JSArrayBuffer> new_buffer; | 2308 Handle<JSArrayBuffer> new_buffer; |
2309 if (!old_buffer.is_null() && old_buffer->has_guard_region()) { | 2309 if (!old_buffer.is_null() && old_buffer->has_guard_region()) { |
2310 // We don't move the backing store, we simply change the protection to make | 2310 // We don't move the backing store, we simply change the protection to make |
2311 // more of it accessible. | 2311 // more of it accessible. |
2312 base::OS::Unprotect(old_buffer->backing_store(), new_size); | 2312 base::OS::Unprotect(old_buffer->backing_store(), new_size); |
2313 reinterpret_cast<v8::Isolate*>(isolate) | 2313 reinterpret_cast<v8::Isolate*>(isolate) |
2314 ->AdjustAmountOfExternalAllocatedMemory(pages * WasmModule::kPageSize); | 2314 ->AdjustAmountOfExternalAllocatedMemory(pages * WasmModule::kPageSize); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2361 if (pages == 0) { | 2361 if (pages == 0) { |
2362 DCHECK(old_size % WasmModule::kPageSize == 0); | 2362 DCHECK(old_size % WasmModule::kPageSize == 0); |
2363 return (old_size / WasmModule::kPageSize); | 2363 return (old_size / WasmModule::kPageSize); |
2364 } | 2364 } |
2365 Handle<JSArrayBuffer> new_buffer; | 2365 Handle<JSArrayBuffer> new_buffer; |
2366 if (!memory_object->has_instances_link()) { | 2366 if (!memory_object->has_instances_link()) { |
2367 // Memory object does not have an instance associated with it, just grow | 2367 // Memory object does not have an instance associated with it, just grow |
2368 uint32_t max_pages; | 2368 uint32_t max_pages; |
2369 if (memory_object->has_maximum_pages()) { | 2369 if (memory_object->has_maximum_pages()) { |
2370 max_pages = static_cast<uint32_t>(memory_object->maximum_pages()); | 2370 max_pages = static_cast<uint32_t>(memory_object->maximum_pages()); |
2371 if (kV8MaxWasmMemoryPages < max_pages) return -1; | 2371 if (FLAG_wasm_max_mem_pages < max_pages) return -1; |
2372 } else { | 2372 } else { |
2373 max_pages = kV8MaxWasmMemoryPages; | 2373 max_pages = FLAG_wasm_max_mem_pages; |
2374 } | 2374 } |
2375 new_buffer = GrowMemoryBuffer(isolate, memory_buffer, pages, max_pages); | 2375 new_buffer = GrowMemoryBuffer(isolate, memory_buffer, pages, max_pages); |
2376 if (new_buffer.is_null()) return -1; | 2376 if (new_buffer.is_null()) return -1; |
2377 } else { | 2377 } else { |
2378 Handle<WasmInstanceWrapper> instance_wrapper( | 2378 Handle<WasmInstanceWrapper> instance_wrapper( |
2379 memory_object->instances_link()); | 2379 memory_object->instances_link()); |
2380 DCHECK(WasmInstanceWrapper::IsWasmInstanceWrapper(*instance_wrapper)); | 2380 DCHECK(WasmInstanceWrapper::IsWasmInstanceWrapper(*instance_wrapper)); |
2381 DCHECK(instance_wrapper->has_instance()); | 2381 DCHECK(instance_wrapper->has_instance()); |
2382 Handle<WasmInstanceObject> instance = instance_wrapper->instance_object(); | 2382 Handle<WasmInstanceObject> instance = instance_wrapper->instance_object(); |
2383 DCHECK(IsWasmInstance(*instance)); | 2383 DCHECK(IsWasmInstance(*instance)); |
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2642 | 2642 |
2643 JSObject::AddProperty(entry, name_string, export_name.ToHandleChecked(), | 2643 JSObject::AddProperty(entry, name_string, export_name.ToHandleChecked(), |
2644 NONE); | 2644 NONE); |
2645 JSObject::AddProperty(entry, kind_string, export_kind, NONE); | 2645 JSObject::AddProperty(entry, kind_string, export_kind, NONE); |
2646 | 2646 |
2647 storage->set(index, *entry); | 2647 storage->set(index, *entry); |
2648 } | 2648 } |
2649 | 2649 |
2650 return array_object; | 2650 return array_object; |
2651 } | 2651 } |
OLD | NEW |