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/asmjs/asm-js.h" | 7 #include "src/asmjs/asm-js.h" |
8 #include "src/assembler-inl.h" | 8 #include "src/assembler-inl.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 837 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
848 void* backing_store, size_t size, | 848 void* backing_store, size_t size, |
849 bool is_external, | 849 bool is_external, |
850 bool enable_guard_regions) { | 850 bool enable_guard_regions) { |
851 Handle<JSArrayBuffer> buffer = isolate->factory()->NewJSArrayBuffer(); | 851 Handle<JSArrayBuffer> buffer = isolate->factory()->NewJSArrayBuffer(); |
852 JSArrayBuffer::Setup(buffer, isolate, is_external, backing_store, | 852 JSArrayBuffer::Setup(buffer, isolate, is_external, backing_store, |
853 static_cast<int>(size)); | 853 static_cast<int>(size)); |
854 buffer->set_is_neuterable(false); | 854 buffer->set_is_neuterable(false); |
855 buffer->set_is_wasm_buffer(true); | 855 buffer->set_is_wasm_buffer(true); |
856 buffer->set_has_guard_region(enable_guard_regions); | 856 buffer->set_has_guard_region(enable_guard_regions); |
857 | 857 |
858 if (is_external) { | 858 if (enable_guard_regions) { |
859 // We mark the buffer as external if we allocated it here with guard | 859 // We mark the buffer as external if we allocated it here with guard |
860 // pages. That means we need to arrange for it to be freed. | 860 // pages. That means we need to arrange for it to be freed. |
861 | 861 |
862 // TODO(eholk): Finalizers may not run when the main thread is shutting | 862 // TODO(eholk): Finalizers may not run when the main thread is shutting |
863 // down, which means we may leak memory here. | 863 // down, which means we may leak memory here. |
864 Handle<Object> global_handle = isolate->global_handles()->Create(*buffer); | 864 Handle<Object> global_handle = isolate->global_handles()->Create(*buffer); |
865 GlobalHandles::MakeWeak(global_handle.location(), global_handle.location(), | 865 GlobalHandles::MakeWeak(global_handle.location(), global_handle.location(), |
866 &MemoryFinalizer, v8::WeakCallbackType::kFinalizer); | 866 &MemoryFinalizer, v8::WeakCallbackType::kFinalizer); |
867 } | 867 } |
868 return buffer; | 868 return buffer; |
(...skipping 1355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2224 WasmInstanceObject::cast(*instance)->compiled_module(); | 2224 WasmInstanceObject::cast(*instance)->compiled_module(); |
2225 return handle(compiled_module->script()); | 2225 return handle(compiled_module->script()); |
2226 } | 2226 } |
2227 | 2227 |
2228 bool wasm::IsWasmCodegenAllowed(Isolate* isolate, Handle<Context> context) { | 2228 bool wasm::IsWasmCodegenAllowed(Isolate* isolate, Handle<Context> context) { |
2229 return isolate->allow_code_gen_callback() == nullptr || | 2229 return isolate->allow_code_gen_callback() == nullptr || |
2230 isolate->allow_code_gen_callback()(v8::Utils::ToLocal(context)); | 2230 isolate->allow_code_gen_callback()(v8::Utils::ToLocal(context)); |
2231 } | 2231 } |
2232 | 2232 |
2233 void wasm::DetachWebAssemblyMemoryBuffer(Isolate* isolate, | 2233 void wasm::DetachWebAssemblyMemoryBuffer(Isolate* isolate, |
2234 Handle<JSArrayBuffer> buffer) { | 2234 Handle<JSArrayBuffer> buffer, |
| 2235 bool free_memory) { |
2235 int64_t byte_length = | 2236 int64_t byte_length = |
2236 buffer->byte_length()->IsNumber() | 2237 buffer->byte_length()->IsNumber() |
2237 ? static_cast<uint32_t>(buffer->byte_length()->Number()) | 2238 ? static_cast<uint32_t>(buffer->byte_length()->Number()) |
2238 : 0; | 2239 : 0; |
2239 if (buffer.is_null() || byte_length == 0) return; | 2240 if (buffer.is_null() || byte_length == 0) return; |
2240 const bool has_guard_regions = buffer->has_guard_region(); | 2241 const bool has_guard_regions = buffer->has_guard_region(); |
2241 const bool is_external = buffer->is_external(); | 2242 const bool is_external = buffer->is_external(); |
2242 void* backing_store = buffer->backing_store(); | 2243 void* backing_store = buffer->backing_store(); |
2243 DCHECK(!buffer->is_neuterable()); | 2244 DCHECK(!buffer->is_neuterable()); |
2244 if (!has_guard_regions && !is_external) { | 2245 if (!has_guard_regions && !is_external) { |
2245 buffer->set_is_external(true); | 2246 buffer->set_is_external(true); |
2246 isolate->heap()->UnregisterArrayBuffer(*buffer); | 2247 isolate->heap()->UnregisterArrayBuffer(*buffer); |
2247 } | 2248 } |
2248 buffer->set_is_neuterable(true); | 2249 buffer->set_is_neuterable(true); |
2249 buffer->Neuter(); | 2250 buffer->Neuter(); |
| 2251 // Neuter but do not free, as when pages == 0, the backing store is being used |
| 2252 // by the new buffer. |
| 2253 if (!free_memory) return; |
2250 if (has_guard_regions) { | 2254 if (has_guard_regions) { |
2251 base::OS::Free(backing_store, RoundUp(i::wasm::kWasmMaxHeapOffset, | 2255 base::OS::Free(backing_store, RoundUp(i::wasm::kWasmMaxHeapOffset, |
2252 base::OS::CommitPageSize())); | 2256 base::OS::CommitPageSize())); |
2253 reinterpret_cast<v8::Isolate*>(isolate) | 2257 reinterpret_cast<v8::Isolate*>(isolate) |
2254 ->AdjustAmountOfExternalAllocatedMemory(-byte_length); | 2258 ->AdjustAmountOfExternalAllocatedMemory(-byte_length); |
2255 } else if (!has_guard_regions && !is_external) { | 2259 } else if (!has_guard_regions && !is_external) { |
2256 isolate->array_buffer_allocator()->Free(backing_store, byte_length); | 2260 isolate->array_buffer_allocator()->Free(backing_store, byte_length); |
2257 } | 2261 } |
2258 } | 2262 } |
2259 | 2263 |
(...skipping 1094 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3354 callee_compiled->instruction_start()); | 3358 callee_compiled->instruction_start()); |
3355 } | 3359 } |
3356 DCHECK_EQ(non_compiled_functions.size(), idx); | 3360 DCHECK_EQ(non_compiled_functions.size(), idx); |
3357 } | 3361 } |
3358 | 3362 |
3359 Code* ret = | 3363 Code* ret = |
3360 Code::cast(compiled_module->code_table()->get(func_to_return_idx)); | 3364 Code::cast(compiled_module->code_table()->get(func_to_return_idx)); |
3361 DCHECK_EQ(Code::WASM_FUNCTION, ret->kind()); | 3365 DCHECK_EQ(Code::WASM_FUNCTION, ret->kind()); |
3362 return handle(ret, isolate); | 3366 return handle(ret, isolate); |
3363 } | 3367 } |
OLD | NEW |