diff options
author | Michaël Zasso <targos@protonmail.com> | 2016-12-23 16:30:57 +0100 |
---|---|---|
committer | Michaël Zasso <targos@protonmail.com> | 2017-01-26 22:46:17 +0100 |
commit | 2739185b790e040c3b044c577327f5d44bffad4a (patch) | |
tree | 29a466999212f4c85958379d9d400eec8a185ba5 /deps/v8/src/runtime/runtime-wasm.cc | |
parent | a67a04d7654faaa04c8da00e42981ebc9fd0911c (diff) | |
download | node-new-2739185b790e040c3b044c577327f5d44bffad4a.tar.gz |
deps: update V8 to 5.5.372.40
PR-URL: https://github.com/nodejs/node/pull/9618
Reviewed-By: Ali Ijaz Sheikh <ofrobots@google.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Diffstat (limited to 'deps/v8/src/runtime/runtime-wasm.cc')
-rw-r--r-- | deps/v8/src/runtime/runtime-wasm.cc | 125 |
1 files changed, 49 insertions, 76 deletions
diff --git a/deps/v8/src/runtime/runtime-wasm.cc b/deps/v8/src/runtime/runtime-wasm.cc index 37608e61cd..ab69046c45 100644 --- a/deps/v8/src/runtime/runtime-wasm.cc +++ b/deps/v8/src/runtime/runtime-wasm.cc @@ -18,17 +18,32 @@ namespace v8 { namespace internal { -namespace { -const int kWasmMemArrayBuffer = 2; +RUNTIME_FUNCTION(Runtime_WasmMemorySize) { + HandleScope scope(isolate); + DCHECK_EQ(0, args.length()); + + Handle<JSObject> module_instance; + { + // Get the module JSObject + DisallowHeapAllocation no_allocation; + const Address entry = Isolate::c_entry_fp(isolate->thread_local_top()); + Address pc = + Memory::Address_at(entry + StandardFrameConstants::kCallerPCOffset); + Code* code = + isolate->inner_pointer_to_code_cache()->GetCacheEntry(pc)->code; + Object* owning_instance = wasm::GetOwningWasmInstance(code); + CHECK_NOT_NULL(owning_instance); + module_instance = handle(JSObject::cast(owning_instance), isolate); + } + return *isolate->factory()->NewNumberFromInt( + wasm::GetInstanceMemorySize(isolate, module_instance)); } RUNTIME_FUNCTION(Runtime_WasmGrowMemory) { HandleScope scope(isolate); DCHECK_EQ(1, args.length()); - uint32_t delta_pages = 0; - CHECK(args[0]->ToUint32(&delta_pages)); - Handle<JSObject> module_object; - + CONVERT_UINT32_ARG_CHECKED(delta_pages, 0); + Handle<JSObject> module_instance; { // Get the module JSObject DisallowHeapAllocation no_allocation; @@ -37,77 +52,12 @@ RUNTIME_FUNCTION(Runtime_WasmGrowMemory) { Memory::Address_at(entry + StandardFrameConstants::kCallerPCOffset); Code* code = isolate->inner_pointer_to_code_cache()->GetCacheEntry(pc)->code; - FixedArray* deopt_data = code->deoptimization_data(); - DCHECK(deopt_data->length() == 2); - module_object = Handle<JSObject>::cast(handle(deopt_data->get(0), isolate)); - CHECK(!module_object->IsNull(isolate)); - } - - Address old_mem_start, new_mem_start; - uint32_t old_size, new_size; - - // Get mem buffer associated with module object - Handle<Object> obj(module_object->GetInternalField(kWasmMemArrayBuffer), - isolate); - - if (obj->IsUndefined(isolate)) { - // If module object does not have linear memory associated with it, - // Allocate new array buffer of given size. - old_mem_start = nullptr; - old_size = 0; - // TODO(gdeepti): Fix bounds check to take into account size of memtype. - new_size = delta_pages * wasm::WasmModule::kPageSize; - if (delta_pages > wasm::WasmModule::kMaxMemPages) { - return *isolate->factory()->NewNumberFromInt(-1); - } - new_mem_start = - static_cast<Address>(isolate->array_buffer_allocator()->Allocate( - static_cast<uint32_t>(new_size))); - if (new_mem_start == NULL) { - return *isolate->factory()->NewNumberFromInt(-1); - } -#if DEBUG - // Double check the API allocator actually zero-initialized the memory. - for (size_t i = old_size; i < new_size; i++) { - DCHECK_EQ(0, new_mem_start[i]); - } -#endif - } else { - Handle<JSArrayBuffer> old_buffer = Handle<JSArrayBuffer>::cast(obj); - old_mem_start = static_cast<Address>(old_buffer->backing_store()); - old_size = old_buffer->byte_length()->Number(); - // If the old memory was zero-sized, we should have been in the - // "undefined" case above. - DCHECK_NOT_NULL(old_mem_start); - DCHECK_NE(0, old_size); - - new_size = old_size + delta_pages * wasm::WasmModule::kPageSize; - if (new_size > - wasm::WasmModule::kMaxMemPages * wasm::WasmModule::kPageSize) { - return *isolate->factory()->NewNumberFromInt(-1); - } - new_mem_start = static_cast<Address>(realloc(old_mem_start, new_size)); - if (new_mem_start == NULL) { - return *isolate->factory()->NewNumberFromInt(-1); - } - old_buffer->set_is_external(true); - isolate->heap()->UnregisterArrayBuffer(*old_buffer); - // Zero initializing uninitialized memory from realloc - memset(new_mem_start + old_size, 0, new_size - old_size); + Object* owning_instance = wasm::GetOwningWasmInstance(code); + CHECK_NOT_NULL(owning_instance); + module_instance = handle(JSObject::cast(owning_instance), isolate); } - - Handle<JSArrayBuffer> buffer = isolate->factory()->NewJSArrayBuffer(); - JSArrayBuffer::Setup(buffer, isolate, false, new_mem_start, new_size); - buffer->set_is_neuterable(false); - - // Set new buffer to be wasm memory - module_object->SetInternalField(kWasmMemArrayBuffer, *buffer); - - CHECK(wasm::UpdateWasmModuleMemory(module_object, old_mem_start, - new_mem_start, old_size, new_size)); - - return *isolate->factory()->NewNumberFromInt(old_size / - wasm::WasmModule::kPageSize); + return *isolate->factory()->NewNumberFromInt( + wasm::GrowInstanceMemory(isolate, module_instance, delta_pages)); } RUNTIME_FUNCTION(Runtime_WasmThrowTypeError) { @@ -116,5 +66,28 @@ RUNTIME_FUNCTION(Runtime_WasmThrowTypeError) { THROW_NEW_ERROR_RETURN_FAILURE( isolate, NewTypeError(MessageTemplate::kWasmTrapTypeError)); } + +RUNTIME_FUNCTION(Runtime_WasmThrow) { + HandleScope scope(isolate); + DCHECK_EQ(2, args.length()); + CONVERT_SMI_ARG_CHECKED(lower, 0); + CONVERT_SMI_ARG_CHECKED(upper, 1); + + const int32_t thrown_value = (upper << 16) | lower; + + return isolate->Throw(*isolate->factory()->NewNumberFromInt(thrown_value)); +} + +RUNTIME_FUNCTION(Runtime_WasmGetCaughtExceptionValue) { + HandleScope scope(isolate); + DCHECK_EQ(1, args.length()); + Object* exception = args[0]; + // The unwinder will only deliver exceptions to wasm if the exception is a + // Number or a Smi (which we have just converted to a Number.) This logic + // lives in Isolate::is_catchable_by_wasm(Object*). + CHECK(exception->IsNumber()); + return exception; +} + } // namespace internal } // namespace v8 |