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/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" |
(...skipping 2182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2193 ModuleResult result = | 2193 ModuleResult result = |
2194 DecodeWasmModule(isolate, &zone, start, end, false, origin); | 2194 DecodeWasmModule(isolate, &zone, start, end, false, origin); |
2195 if (result.ok()) { | 2195 if (result.ok()) { |
2196 DCHECK_NOT_NULL(result.val); | 2196 DCHECK_NOT_NULL(result.val); |
2197 delete result.val; | 2197 delete result.val; |
2198 return true; | 2198 return true; |
2199 } | 2199 } |
2200 return false; | 2200 return false; |
2201 } | 2201 } |
2202 | 2202 |
2203 namespace { | 2203 MaybeHandle<JSArrayBuffer> wasm::GetInstanceMemory(Isolate* isolate, |
2204 | 2204 Handle<JSObject> instance) { |
2205 MaybeHandle<JSArrayBuffer> GetInstanceMemory(Isolate* isolate, | |
2206 Handle<JSObject> instance) { | |
2207 Object* mem = instance->GetInternalField(kWasmMemArrayBuffer); | 2205 Object* mem = instance->GetInternalField(kWasmMemArrayBuffer); |
2208 DCHECK(IsWasmObject(*instance)); | 2206 DCHECK(IsWasmObject(*instance)); |
2209 if (mem->IsUndefined(isolate)) return MaybeHandle<JSArrayBuffer>(); | 2207 if (mem->IsUndefined(isolate)) return MaybeHandle<JSArrayBuffer>(); |
2210 return Handle<JSArrayBuffer>(JSArrayBuffer::cast(mem)); | 2208 return Handle<JSArrayBuffer>(JSArrayBuffer::cast(mem)); |
2211 } | 2209 } |
2212 | 2210 |
2213 void SetInstanceMemory(Handle<JSObject> instance, JSArrayBuffer* buffer) { | 2211 void SetInstanceMemory(Handle<JSObject> instance, JSArrayBuffer* buffer) { |
2214 DisallowHeapAllocation no_gc; | 2212 DisallowHeapAllocation no_gc; |
2215 DCHECK(IsWasmObject(*instance)); | 2213 DCHECK(IsWasmObject(*instance)); |
2216 instance->SetInternalField(kWasmMemArrayBuffer, buffer); | 2214 instance->SetInternalField(kWasmMemArrayBuffer, buffer); |
2217 WasmCompiledModule* compiled_module = GetCompiledModule(*instance); | 2215 WasmCompiledModule* compiled_module = GetCompiledModule(*instance); |
2218 compiled_module->set_ptr_to_heap(buffer); | 2216 compiled_module->set_ptr_to_heap(buffer); |
2219 } | 2217 } |
2220 | 2218 |
2221 } // namespace | |
2222 | |
2223 int32_t wasm::GetInstanceMemorySize(Isolate* isolate, | 2219 int32_t wasm::GetInstanceMemorySize(Isolate* isolate, |
2224 Handle<JSObject> instance) { | 2220 Handle<JSObject> instance) { |
2225 MaybeHandle<JSArrayBuffer> maybe_mem_buffer = | 2221 MaybeHandle<JSArrayBuffer> maybe_mem_buffer = |
2226 GetInstanceMemory(isolate, instance); | 2222 GetInstanceMemory(isolate, instance); |
2227 Handle<JSArrayBuffer> buffer; | 2223 Handle<JSArrayBuffer> buffer; |
2228 if (!maybe_mem_buffer.ToHandle(&buffer)) { | 2224 if (!maybe_mem_buffer.ToHandle(&buffer)) { |
2229 return 0; | 2225 return 0; |
2230 } else { | 2226 } else { |
2231 return buffer->byte_length()->Number() / WasmModule::kPageSize; | 2227 return buffer->byte_length()->Number() / WasmModule::kPageSize; |
2232 } | 2228 } |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2323 } | 2319 } |
2324 | 2320 |
2325 void testing::ValidateOrphanedInstance(Isolate* isolate, | 2321 void testing::ValidateOrphanedInstance(Isolate* isolate, |
2326 Handle<JSObject> instance) { | 2322 Handle<JSObject> instance) { |
2327 DisallowHeapAllocation no_gc; | 2323 DisallowHeapAllocation no_gc; |
2328 CHECK(IsWasmObject(*instance)); | 2324 CHECK(IsWasmObject(*instance)); |
2329 WasmCompiledModule* compiled_module = GetCompiledModule(*instance); | 2325 WasmCompiledModule* compiled_module = GetCompiledModule(*instance); |
2330 CHECK(compiled_module->has_weak_module_object()); | 2326 CHECK(compiled_module->has_weak_module_object()); |
2331 CHECK(compiled_module->ptr_to_weak_module_object()->cleared()); | 2327 CHECK(compiled_module->ptr_to_weak_module_object()->cleared()); |
2332 } | 2328 } |
OLD | NEW |