Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(351)

Side by Side Diff: src/runtime/runtime-wasm.cc

Issue 2541633003: [wasm] Move wasm runtime functions to runtime-wasm.cc (Closed)
Patch Set: Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/runtime/runtime-internal.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 Code* code = 54 Code* code =
55 isolate->inner_pointer_to_code_cache()->GetCacheEntry(pc)->code; 55 isolate->inner_pointer_to_code_cache()->GetCacheEntry(pc)->code;
56 WasmInstanceObject* owning_instance = wasm::GetOwningWasmInstance(code); 56 WasmInstanceObject* owning_instance = wasm::GetOwningWasmInstance(code);
57 CHECK_NOT_NULL(owning_instance); 57 CHECK_NOT_NULL(owning_instance);
58 instance = handle(owning_instance, isolate); 58 instance = handle(owning_instance, isolate);
59 } 59 }
60 return *isolate->factory()->NewNumberFromInt( 60 return *isolate->factory()->NewNumberFromInt(
61 wasm::GrowMemory(isolate, instance, delta_pages)); 61 wasm::GrowMemory(isolate, instance, delta_pages));
62 } 62 }
63 63
64 RUNTIME_FUNCTION(Runtime_ThrowWasmError) {
65 HandleScope scope(isolate);
66 DCHECK_EQ(2, args.length());
67 CONVERT_SMI_ARG_CHECKED(message_id, 0);
68 CONVERT_SMI_ARG_CHECKED(byte_offset, 1);
69 Handle<Object> error_obj = isolate->factory()->NewWasmRuntimeError(
70 static_cast<MessageTemplate::Template>(message_id));
71
72 // For wasm traps, the byte offset (a.k.a source position) can not be
73 // determined from relocation info, since the explicit checks for traps
74 // converge in one singe block which calls this runtime function.
75 // We hence pass the byte offset explicitely, and patch it into the top-most
76 // frame (a wasm frame) on the collected stack trace.
77 // TODO(wasm): This implementation is temporary, see bug #5007:
78 // https://bugs.chromium.org/p/v8/issues/detail?id=5007
79 Handle<JSObject> error = Handle<JSObject>::cast(error_obj);
80 Handle<Object> stack_trace_obj = JSReceiver::GetDataProperty(
81 error, isolate->factory()->stack_trace_symbol());
82 // Patch the stack trace (array of <receiver, function, code, position>).
83 if (stack_trace_obj->IsJSArray()) {
84 Handle<FrameArray> stack_elements(
85 FrameArray::cast(JSArray::cast(*stack_trace_obj)->elements()));
86 DCHECK(stack_elements->Code(0)->kind() == AbstractCode::WASM_FUNCTION);
87 DCHECK(stack_elements->Offset(0)->value() >= 0);
88 stack_elements->SetOffset(0, Smi::FromInt(-1 - byte_offset));
89 }
90
91 // Patch the detailed stack trace (array of JSObjects with various
92 // properties).
93 Handle<Object> detailed_stack_trace_obj = JSReceiver::GetDataProperty(
94 error, isolate->factory()->detailed_stack_trace_symbol());
95 if (detailed_stack_trace_obj->IsJSArray()) {
96 Handle<FixedArray> stack_elements(
97 FixedArray::cast(JSArray::cast(*detailed_stack_trace_obj)->elements()));
98 DCHECK_GE(stack_elements->length(), 1);
99 Handle<JSObject> top_frame(JSObject::cast(stack_elements->get(0)));
100 Handle<String> wasm_offset_key =
101 isolate->factory()->InternalizeOneByteString(
102 STATIC_CHAR_VECTOR("column"));
103 LookupIterator it(top_frame, wasm_offset_key, top_frame,
104 LookupIterator::PROTOTYPE_CHAIN_SKIP_INTERCEPTOR);
105 if (it.IsFound()) {
106 DCHECK(JSReceiver::GetDataProperty(&it)->IsSmi());
107 // Make column number 1-based here.
108 Maybe<bool> data_set = JSReceiver::SetDataProperty(
109 &it, handle(Smi::FromInt(byte_offset + 1), isolate));
110 DCHECK(data_set.IsJust() && data_set.FromJust() == true);
111 USE(data_set);
112 }
113 }
114
115 return isolate->Throw(*error_obj);
116 }
117
64 RUNTIME_FUNCTION(Runtime_WasmThrowTypeError) { 118 RUNTIME_FUNCTION(Runtime_WasmThrowTypeError) {
65 HandleScope scope(isolate); 119 HandleScope scope(isolate);
66 DCHECK_EQ(0, args.length()); 120 DCHECK_EQ(0, args.length());
67 THROW_NEW_ERROR_RETURN_FAILURE( 121 THROW_NEW_ERROR_RETURN_FAILURE(
68 isolate, NewTypeError(MessageTemplate::kWasmTrapTypeError)); 122 isolate, NewTypeError(MessageTemplate::kWasmTrapTypeError));
69 } 123 }
70 124
71 RUNTIME_FUNCTION(Runtime_WasmThrow) { 125 RUNTIME_FUNCTION(Runtime_WasmThrow) {
72 HandleScope scope(isolate); 126 HandleScope scope(isolate);
73 DCHECK_EQ(2, args.length()); 127 DCHECK_EQ(2, args.length());
(...skipping 11 matching lines...) Expand all
85 Object* exception = args[0]; 139 Object* exception = args[0];
86 // The unwinder will only deliver exceptions to wasm if the exception is a 140 // The unwinder will only deliver exceptions to wasm if the exception is a
87 // Number or a Smi (which we have just converted to a Number.) This logic 141 // Number or a Smi (which we have just converted to a Number.) This logic
88 // lives in Isolate::is_catchable_by_wasm(Object*). 142 // lives in Isolate::is_catchable_by_wasm(Object*).
89 CHECK(exception->IsNumber()); 143 CHECK(exception->IsNumber());
90 return exception; 144 return exception;
91 } 145 }
92 146
93 } // namespace internal 147 } // namespace internal
94 } // namespace v8 148 } // namespace v8
OLDNEW
« no previous file with comments | « src/runtime/runtime-internal.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698