| OLD | NEW |
| 1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 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/runtime/runtime-utils.h" | 5 #include "src/runtime/runtime-utils.h" |
| 6 | 6 |
| 7 #include "src/arguments.h" | 7 #include "src/arguments.h" |
| 8 #include "src/assembler.h" | 8 #include "src/assembler.h" |
| 9 #include "src/compiler/wasm-compiler.h" | 9 #include "src/compiler/wasm-compiler.h" |
| 10 #include "src/conversions.h" | 10 #include "src/conversions.h" |
| 11 #include "src/debug/debug.h" | 11 #include "src/debug/debug.h" |
| 12 #include "src/factory.h" | 12 #include "src/factory.h" |
| 13 #include "src/frames-inl.h" | 13 #include "src/frames-inl.h" |
| 14 #include "src/objects-inl.h" | 14 #include "src/objects-inl.h" |
| 15 #include "src/v8memory.h" | 15 #include "src/v8memory.h" |
| 16 #include "src/wasm/wasm-module.h" | 16 #include "src/wasm/wasm-module.h" |
| 17 #include "src/wasm/wasm-objects.h" |
| 17 | 18 |
| 18 namespace v8 { | 19 namespace v8 { |
| 19 namespace internal { | 20 namespace internal { |
| 20 | 21 |
| 21 RUNTIME_FUNCTION(Runtime_WasmMemorySize) { | 22 RUNTIME_FUNCTION(Runtime_WasmMemorySize) { |
| 22 HandleScope scope(isolate); | 23 HandleScope scope(isolate); |
| 23 DCHECK_EQ(0, args.length()); | 24 DCHECK_EQ(0, args.length()); |
| 24 | 25 |
| 25 Handle<JSObject> module_instance; | 26 Handle<WasmInstanceObject> instance; |
| 26 { | 27 { |
| 27 // Get the module JSObject | 28 // Get the module JSObject |
| 28 DisallowHeapAllocation no_allocation; | 29 DisallowHeapAllocation no_allocation; |
| 29 const Address entry = Isolate::c_entry_fp(isolate->thread_local_top()); | 30 const Address entry = Isolate::c_entry_fp(isolate->thread_local_top()); |
| 30 Address pc = | 31 Address pc = |
| 31 Memory::Address_at(entry + StandardFrameConstants::kCallerPCOffset); | 32 Memory::Address_at(entry + StandardFrameConstants::kCallerPCOffset); |
| 32 Code* code = | 33 Code* code = |
| 33 isolate->inner_pointer_to_code_cache()->GetCacheEntry(pc)->code; | 34 isolate->inner_pointer_to_code_cache()->GetCacheEntry(pc)->code; |
| 34 Object* owning_instance = wasm::GetOwningWasmInstance(code); | 35 WasmInstanceObject* owning_instance = wasm::GetOwningWasmInstance(code); |
| 35 CHECK_NOT_NULL(owning_instance); | 36 CHECK_NOT_NULL(owning_instance); |
| 36 module_instance = handle(JSObject::cast(owning_instance), isolate); | 37 instance = handle(owning_instance, isolate); |
| 37 } | 38 } |
| 38 return *isolate->factory()->NewNumberFromInt( | 39 return *isolate->factory()->NewNumberFromInt( |
| 39 wasm::GetInstanceMemorySize(isolate, module_instance)); | 40 wasm::GetInstanceMemorySize(isolate, instance)); |
| 40 } | 41 } |
| 41 | 42 |
| 42 RUNTIME_FUNCTION(Runtime_WasmGrowMemory) { | 43 RUNTIME_FUNCTION(Runtime_WasmGrowMemory) { |
| 43 HandleScope scope(isolate); | 44 HandleScope scope(isolate); |
| 44 DCHECK_EQ(1, args.length()); | 45 DCHECK_EQ(1, args.length()); |
| 45 CONVERT_UINT32_ARG_CHECKED(delta_pages, 0); | 46 CONVERT_UINT32_ARG_CHECKED(delta_pages, 0); |
| 46 Handle<JSObject> module_instance; | 47 Handle<WasmInstanceObject> instance; |
| 47 { | 48 { |
| 48 // Get the module JSObject | 49 // Get the module JSObject |
| 49 DisallowHeapAllocation no_allocation; | 50 DisallowHeapAllocation no_allocation; |
| 50 const Address entry = Isolate::c_entry_fp(isolate->thread_local_top()); | 51 const Address entry = Isolate::c_entry_fp(isolate->thread_local_top()); |
| 51 Address pc = | 52 Address pc = |
| 52 Memory::Address_at(entry + StandardFrameConstants::kCallerPCOffset); | 53 Memory::Address_at(entry + StandardFrameConstants::kCallerPCOffset); |
| 53 Code* code = | 54 Code* code = |
| 54 isolate->inner_pointer_to_code_cache()->GetCacheEntry(pc)->code; | 55 isolate->inner_pointer_to_code_cache()->GetCacheEntry(pc)->code; |
| 55 Object* owning_instance = wasm::GetOwningWasmInstance(code); | 56 WasmInstanceObject* owning_instance = wasm::GetOwningWasmInstance(code); |
| 56 CHECK_NOT_NULL(owning_instance); | 57 CHECK_NOT_NULL(owning_instance); |
| 57 module_instance = handle(JSObject::cast(owning_instance), isolate); | 58 instance = handle(owning_instance, isolate); |
| 58 } | 59 } |
| 59 return *isolate->factory()->NewNumberFromInt( | 60 return *isolate->factory()->NewNumberFromInt( |
| 60 wasm::GrowInstanceMemory(isolate, module_instance, delta_pages)); | 61 wasm::GrowInstanceMemory(isolate, instance, delta_pages)); |
| 61 } | 62 } |
| 62 | 63 |
| 63 RUNTIME_FUNCTION(Runtime_WasmThrowTypeError) { | 64 RUNTIME_FUNCTION(Runtime_WasmThrowTypeError) { |
| 64 HandleScope scope(isolate); | 65 HandleScope scope(isolate); |
| 65 DCHECK_EQ(0, args.length()); | 66 DCHECK_EQ(0, args.length()); |
| 66 THROW_NEW_ERROR_RETURN_FAILURE( | 67 THROW_NEW_ERROR_RETURN_FAILURE( |
| 67 isolate, NewTypeError(MessageTemplate::kWasmTrapTypeError)); | 68 isolate, NewTypeError(MessageTemplate::kWasmTrapTypeError)); |
| 68 } | 69 } |
| 69 | 70 |
| 70 RUNTIME_FUNCTION(Runtime_WasmThrow) { | 71 RUNTIME_FUNCTION(Runtime_WasmThrow) { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 84 Object* exception = args[0]; | 85 Object* exception = args[0]; |
| 85 // The unwinder will only deliver exceptions to wasm if the exception is a | 86 // The unwinder will only deliver exceptions to wasm if the exception is a |
| 86 // Number or a Smi (which we have just converted to a Number.) This logic | 87 // Number or a Smi (which we have just converted to a Number.) This logic |
| 87 // lives in Isolate::is_catchable_by_wasm(Object*). | 88 // lives in Isolate::is_catchable_by_wasm(Object*). |
| 88 CHECK(exception->IsNumber()); | 89 CHECK(exception->IsNumber()); |
| 89 return exception; | 90 return exception; |
| 90 } | 91 } |
| 91 | 92 |
| 92 } // namespace internal | 93 } // namespace internal |
| 93 } // namespace v8 | 94 } // namespace v8 |
| OLD | NEW |