diff options
Diffstat (limited to 'deps/v8/src/runtime/runtime-wasm.cc')
-rw-r--r-- | deps/v8/src/runtime/runtime-wasm.cc | 124 |
1 files changed, 54 insertions, 70 deletions
diff --git a/deps/v8/src/runtime/runtime-wasm.cc b/deps/v8/src/runtime/runtime-wasm.cc index 8ed4e7c57d..e8aef3fa97 100644 --- a/deps/v8/src/runtime/runtime-wasm.cc +++ b/deps/v8/src/runtime/runtime-wasm.cc @@ -16,6 +16,7 @@ #include "src/trap-handler/trap-handler.h" #include "src/v8memory.h" #include "src/wasm/module-compiler.h" +#include "src/wasm/wasm-heap.h" #include "src/wasm/wasm-objects.h" #include "src/wasm/wasm-opcodes.h" @@ -29,18 +30,41 @@ WasmInstanceObject* GetWasmInstanceOnStackTop(Isolate* isolate) { 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; - DCHECK_EQ(Code::WASM_FUNCTION, code->kind()); - WasmInstanceObject* owning_instance = - WasmInstanceObject::GetOwningInstance(code); + WasmInstanceObject* owning_instance = nullptr; + if (FLAG_wasm_jit_to_native) { + owning_instance = WasmInstanceObject::GetOwningInstance( + isolate->wasm_code_manager()->LookupCode(pc)); + } else { + owning_instance = WasmInstanceObject::GetOwningInstanceGC( + isolate->inner_pointer_to_code_cache()->GetCacheEntry(pc)->code); + } CHECK_NOT_NULL(owning_instance); return owning_instance; } + Context* GetWasmContextOnStackTop(Isolate* isolate) { return GetWasmInstanceOnStackTop(isolate) ->compiled_module() ->ptr_to_native_context(); } + +class ClearThreadInWasmScope { + public: + explicit ClearThreadInWasmScope(bool coming_from_wasm) + : coming_from_wasm_(coming_from_wasm) { + DCHECK_EQ(trap_handler::UseTrapHandler() && coming_from_wasm, + trap_handler::IsThreadInWasm()); + if (coming_from_wasm) trap_handler::ClearThreadInWasm(); + } + ~ClearThreadInWasmScope() { + DCHECK(!trap_handler::IsThreadInWasm()); + if (coming_from_wasm_) trap_handler::SetThreadInWasm(); + } + + private: + const bool coming_from_wasm_; +}; + } // namespace RUNTIME_FUNCTION(Runtime_WasmGrowMemory) { @@ -50,6 +74,9 @@ RUNTIME_FUNCTION(Runtime_WasmGrowMemory) { Handle<WasmInstanceObject> instance(GetWasmInstanceOnStackTop(isolate), isolate); + // This runtime function is always being called from wasm code. + ClearThreadInWasmScope flag_scope(true); + // Set the current isolate's context. DCHECK_NULL(isolate->context()); isolate->set_context(instance->compiled_module()->ptr_to_native_context()); @@ -58,68 +85,19 @@ RUNTIME_FUNCTION(Runtime_WasmGrowMemory) { WasmInstanceObject::GrowMemory(isolate, instance, delta_pages)); } -Object* ThrowRuntimeError(Isolate* isolate, int message_id, int byte_offset, - bool patch_source_position) { +RUNTIME_FUNCTION(Runtime_ThrowWasmError) { + DCHECK_EQ(1, args.length()); + CONVERT_SMI_ARG_CHECKED(message_id, 0); + ClearThreadInWasmScope clear_wasm_flag(isolate->context() == nullptr); + HandleScope scope(isolate); DCHECK_NULL(isolate->context()); isolate->set_context(GetWasmContextOnStackTop(isolate)); Handle<Object> error_obj = isolate->factory()->NewWasmRuntimeError( static_cast<MessageTemplate::Template>(message_id)); - - if (!patch_source_position) { - return isolate->Throw(*error_obj); - } - - // For wasm traps, the byte offset (a.k.a source position) can not be - // determined from relocation info, since the explicit checks for traps - // converge in one singe block which calls this runtime function. - // We hence pass the byte offset explicitely, and patch it into the top-most - // frame (a wasm frame) on the collected stack trace. - // TODO(wasm): This implementation is temporary, see bug #5007: - // https://bugs.chromium.org/p/v8/issues/detail?id=5007 - Handle<JSObject> error = Handle<JSObject>::cast(error_obj); - Handle<Object> stack_trace_obj = JSReceiver::GetDataProperty( - error, isolate->factory()->stack_trace_symbol()); - // Patch the stack trace (array of <receiver, function, code, position>). - if (stack_trace_obj->IsJSArray()) { - Handle<FrameArray> stack_elements( - FrameArray::cast(JSArray::cast(*stack_trace_obj)->elements())); - DCHECK(stack_elements->Code(0)->kind() == AbstractCode::WASM_FUNCTION); - DCHECK_LE(0, stack_elements->Offset(0)->value()); - stack_elements->SetOffset(0, Smi::FromInt(-1 - byte_offset)); - } - - // Patch the detailed stack trace (array of JSObjects with various - // properties). - Handle<Object> detailed_stack_trace_obj = JSReceiver::GetDataProperty( - error, isolate->factory()->detailed_stack_trace_symbol()); - if (detailed_stack_trace_obj->IsFixedArray()) { - Handle<FixedArray> stack_elements( - FixedArray::cast(*detailed_stack_trace_obj)); - DCHECK_GE(stack_elements->length(), 1); - Handle<StackFrameInfo> top_frame( - StackFrameInfo::cast(stack_elements->get(0))); - if (top_frame->column_number()) { - top_frame->set_column_number(byte_offset + 1); - } - } - return isolate->Throw(*error_obj); } -RUNTIME_FUNCTION(Runtime_ThrowWasmErrorFromTrapIf) { - DCHECK_EQ(1, args.length()); - CONVERT_SMI_ARG_CHECKED(message_id, 0); - return ThrowRuntimeError(isolate, message_id, 0, false); -} - -RUNTIME_FUNCTION(Runtime_ThrowWasmError) { - DCHECK_EQ(2, args.length()); - CONVERT_SMI_ARG_CHECKED(message_id, 0); - CONVERT_SMI_ARG_CHECKED(byte_offset, 1); - return ThrowRuntimeError(isolate, message_id, byte_offset, true); -} - RUNTIME_FUNCTION(Runtime_ThrowWasmStackOverflow) { SealHandleScope shs(isolate); DCHECK_LE(0, args.length()); @@ -149,7 +127,7 @@ RUNTIME_FUNCTION(Runtime_WasmThrowCreate) { CHECK(!JSReceiver::SetProperty(exception, isolate->factory()->InternalizeUtf8String( wasm::WasmException::kRuntimeIdStr), - id, STRICT) + id, LanguageMode::kStrict) .is_null()); CONVERT_SMI_ARG_CHECKED(size, 1); Handle<JSTypedArray> values = @@ -157,7 +135,7 @@ RUNTIME_FUNCTION(Runtime_WasmThrowCreate) { CHECK(!JSReceiver::SetProperty(exception, isolate->factory()->InternalizeUtf8String( wasm::WasmException::kRuntimeValuesStr), - values, STRICT) + values, LanguageMode::kStrict) .is_null()); return isolate->heap()->undefined_value(); } @@ -253,11 +231,11 @@ RUNTIME_FUNCTION(Runtime_WasmExceptionSetElement) { } RUNTIME_FUNCTION(Runtime_WasmRunInterpreter) { - DCHECK_EQ(3, args.length()); + DCHECK_EQ(2, args.length()); HandleScope scope(isolate); - CONVERT_ARG_HANDLE_CHECKED(WasmInstanceObject, instance, 0); - CONVERT_NUMBER_CHECKED(int32_t, func_index, Int32, args[1]); - CONVERT_ARG_HANDLE_CHECKED(Object, arg_buffer_obj, 2); + CONVERT_NUMBER_CHECKED(int32_t, func_index, Int32, args[0]); + CONVERT_ARG_HANDLE_CHECKED(Object, arg_buffer_obj, 1); + Handle<WasmInstanceObject> instance(GetWasmInstanceOnStackTop(isolate)); // The arg buffer is the raw pointer to the caller's stack. It looks like a // Smi (lowest bit not set, as checked by IsSmi), but is no valid Smi. We just @@ -266,6 +244,8 @@ RUNTIME_FUNCTION(Runtime_WasmRunInterpreter) { CHECK(arg_buffer_obj->IsSmi()); uint8_t* arg_buffer = reinterpret_cast<uint8_t*>(*arg_buffer_obj); + ClearThreadInWasmScope wasm_flag(true); + // Set the current isolate's context. DCHECK_NULL(isolate->context()); isolate->set_context(instance->compiled_module()->ptr_to_native_context()); @@ -297,11 +277,7 @@ RUNTIME_FUNCTION(Runtime_WasmStackGuard) { DCHECK_EQ(0, args.length()); DCHECK(!trap_handler::UseTrapHandler() || trap_handler::IsThreadInWasm()); - struct ClearAndRestoreThreadInWasm { - ClearAndRestoreThreadInWasm() { trap_handler::ClearThreadInWasm(); } - - ~ClearAndRestoreThreadInWasm() { trap_handler::SetThreadInWasm(); } - } restore_thread_in_wasm; + ClearThreadInWasmScope wasm_flag(true); // Set the current isolate's context. DCHECK_NULL(isolate->context()); @@ -318,7 +294,15 @@ RUNTIME_FUNCTION(Runtime_WasmCompileLazy) { DCHECK_EQ(0, args.length()); HandleScope scope(isolate); - return *wasm::CompileLazy(isolate); + if (FLAG_wasm_jit_to_native) { + Address new_func = wasm::CompileLazy(isolate); + // The alternative to this is having 2 lazy compile builtins. The builtins + // are part of the snapshot, so the flag has no impact on the codegen there. + return reinterpret_cast<Object*>(new_func - Code::kHeaderSize + + kHeapObjectTag); + } else { + return *wasm::CompileLazyOnGCHeap(isolate); + } } } // namespace internal |