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 | 17 |
18 namespace v8 { | 18 namespace v8 { |
19 namespace internal { | 19 namespace internal { |
20 | 20 |
21 RUNTIME_FUNCTION(Runtime_WasmMemorySize) { | |
22 HandleScope scope(isolate); | |
23 DCHECK_EQ(0, args.length()); | |
24 | |
25 Handle<JSObject> module_instance; | |
26 { | |
27 // Get the module JSObject | |
28 DisallowHeapAllocation no_allocation; | |
29 const Address entry = Isolate::c_entry_fp(isolate->thread_local_top()); | |
30 Address pc = | |
31 Memory::Address_at(entry + StandardFrameConstants::kCallerPCOffset); | |
32 Code* code = | |
33 isolate->inner_pointer_to_code_cache()->GetCacheEntry(pc)->code; | |
34 Object* owning_instance = wasm::GetOwningWasmInstance(code); | |
35 CHECK_NOT_NULL(owning_instance); | |
36 module_instance = handle(JSObject::cast(owning_instance), isolate); | |
37 } | |
38 | |
39 // Get mem buffer associated with module object | |
40 MaybeHandle<JSArrayBuffer> maybe_mem_buffer = | |
41 wasm::GetInstanceMemory(isolate, module_instance); | |
42 Handle<JSArrayBuffer> old_buffer; | |
43 if (!maybe_mem_buffer.ToHandle(&old_buffer)) { | |
44 return *isolate->factory()->NewNumberFromInt(0); | |
45 } else { | |
46 uint32_t old_size = old_buffer->byte_length()->Number(); | |
47 return *isolate->factory()->NewNumberFromInt(old_size / | |
48 wasm::WasmModule::kPageSize); | |
49 } | |
50 } | |
51 | |
52 RUNTIME_FUNCTION(Runtime_WasmGrowMemory) { | 21 RUNTIME_FUNCTION(Runtime_WasmGrowMemory) { |
53 HandleScope scope(isolate); | 22 HandleScope scope(isolate); |
54 DCHECK_EQ(1, args.length()); | 23 DCHECK_EQ(1, args.length()); |
55 CONVERT_UINT32_ARG_CHECKED(delta_pages, 0); | 24 CONVERT_UINT32_ARG_CHECKED(delta_pages, 0); |
56 Handle<JSObject> module_instance; | 25 Handle<JSObject> module_instance; |
57 | 26 |
58 { | 27 { |
59 // Get the module JSObject | 28 // Get the module JSObject |
60 DisallowHeapAllocation no_allocation; | 29 DisallowHeapAllocation no_allocation; |
61 const Address entry = Isolate::c_entry_fp(isolate->thread_local_top()); | 30 const Address entry = Isolate::c_entry_fp(isolate->thread_local_top()); |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 Object* exception = args[0]; | 133 Object* exception = args[0]; |
165 // The unwinder will only deliver exceptions to wasm if the exception is a | 134 // The unwinder will only deliver exceptions to wasm if the exception is a |
166 // Number or a Smi (which we have just converted to a Number.) This logic | 135 // Number or a Smi (which we have just converted to a Number.) This logic |
167 // lives in Isolate::is_catchable_by_wasm(Object*). | 136 // lives in Isolate::is_catchable_by_wasm(Object*). |
168 CHECK(exception->IsNumber()); | 137 CHECK(exception->IsNumber()); |
169 return exception; | 138 return exception; |
170 } | 139 } |
171 | 140 |
172 } // namespace internal | 141 } // namespace internal |
173 } // namespace v8 | 142 } // namespace v8 |
OLD | NEW |