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

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

Issue 2562393002: [wasm] Introduce the TrapIf and TrapUnless operators to generate trap code. (Closed)
Patch Set: Rename UseSourcePosition to IsSourcePositionUsed 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.h ('k') | src/wasm/wasm-external-refs.h » ('j') | 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"
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 #include "src/wasm/wasm-objects.h"
18 #include "src/wasm/wasm-opcodes.h"
18 19
19 namespace v8 { 20 namespace v8 {
20 namespace internal { 21 namespace internal {
21 22
22 RUNTIME_FUNCTION(Runtime_WasmMemorySize) { 23 RUNTIME_FUNCTION(Runtime_WasmMemorySize) {
23 HandleScope scope(isolate); 24 HandleScope scope(isolate);
24 DCHECK_EQ(0, args.length()); 25 DCHECK_EQ(0, args.length());
25 26
26 Handle<WasmInstanceObject> instance; 27 Handle<WasmInstanceObject> instance;
27 { 28 {
(...skipping 26 matching lines...) Expand all
54 Code* code = 55 Code* code =
55 isolate->inner_pointer_to_code_cache()->GetCacheEntry(pc)->code; 56 isolate->inner_pointer_to_code_cache()->GetCacheEntry(pc)->code;
56 WasmInstanceObject* owning_instance = wasm::GetOwningWasmInstance(code); 57 WasmInstanceObject* owning_instance = wasm::GetOwningWasmInstance(code);
57 CHECK_NOT_NULL(owning_instance); 58 CHECK_NOT_NULL(owning_instance);
58 instance = handle(owning_instance, isolate); 59 instance = handle(owning_instance, isolate);
59 } 60 }
60 return *isolate->factory()->NewNumberFromInt( 61 return *isolate->factory()->NewNumberFromInt(
61 wasm::GrowMemory(isolate, instance, delta_pages)); 62 wasm::GrowMemory(isolate, instance, delta_pages));
62 } 63 }
63 64
64 RUNTIME_FUNCTION(Runtime_ThrowWasmError) { 65 Object* ThrowRuntimeError(Isolate* isolate, int message_id, int byte_offset,
66 bool patch_source_position) {
65 HandleScope scope(isolate); 67 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( 68 Handle<Object> error_obj = isolate->factory()->NewWasmRuntimeError(
70 static_cast<MessageTemplate::Template>(message_id)); 69 static_cast<MessageTemplate::Template>(message_id));
71 70
71 if (!patch_source_position) {
72 return isolate->Throw(*error_obj);
73 }
74
72 // For wasm traps, the byte offset (a.k.a source position) can not be 75 // 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 76 // determined from relocation info, since the explicit checks for traps
74 // converge in one singe block which calls this runtime function. 77 // 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 78 // We hence pass the byte offset explicitely, and patch it into the top-most
76 // frame (a wasm frame) on the collected stack trace. 79 // frame (a wasm frame) on the collected stack trace.
77 // TODO(wasm): This implementation is temporary, see bug #5007: 80 // TODO(wasm): This implementation is temporary, see bug #5007:
78 // https://bugs.chromium.org/p/v8/issues/detail?id=5007 81 // https://bugs.chromium.org/p/v8/issues/detail?id=5007
79 Handle<JSObject> error = Handle<JSObject>::cast(error_obj); 82 Handle<JSObject> error = Handle<JSObject>::cast(error_obj);
80 Handle<Object> stack_trace_obj = JSReceiver::GetDataProperty( 83 Handle<Object> stack_trace_obj = JSReceiver::GetDataProperty(
81 error, isolate->factory()->stack_trace_symbol()); 84 error, isolate->factory()->stack_trace_symbol());
(...skipping 26 matching lines...) Expand all
108 Maybe<bool> data_set = JSReceiver::SetDataProperty( 111 Maybe<bool> data_set = JSReceiver::SetDataProperty(
109 &it, handle(Smi::FromInt(byte_offset + 1), isolate)); 112 &it, handle(Smi::FromInt(byte_offset + 1), isolate));
110 DCHECK(data_set.IsJust() && data_set.FromJust() == true); 113 DCHECK(data_set.IsJust() && data_set.FromJust() == true);
111 USE(data_set); 114 USE(data_set);
112 } 115 }
113 } 116 }
114 117
115 return isolate->Throw(*error_obj); 118 return isolate->Throw(*error_obj);
116 } 119 }
117 120
121 RUNTIME_FUNCTION(Runtime_ThrowWasmError) {
122 DCHECK_EQ(2, args.length());
123 CONVERT_SMI_ARG_CHECKED(message_id, 0);
124 CONVERT_SMI_ARG_CHECKED(byte_offset, 1);
125 return ThrowRuntimeError(isolate, message_id, byte_offset, true);
126 }
127
128 #define DECLARE_ENUM(name) \
129 RUNTIME_FUNCTION(Runtime_ThrowWasm##name) { \
130 int message_id = wasm::WasmOpcodes::TrapReasonToMessageId(wasm::k##name); \
131 return ThrowRuntimeError(isolate, message_id, 0, false); \
132 }
133 FOREACH_WASM_TRAPREASON(DECLARE_ENUM)
134 #undef DECLARE_ENUM
135
118 RUNTIME_FUNCTION(Runtime_WasmThrowTypeError) { 136 RUNTIME_FUNCTION(Runtime_WasmThrowTypeError) {
119 HandleScope scope(isolate); 137 HandleScope scope(isolate);
120 DCHECK_EQ(0, args.length()); 138 DCHECK_EQ(0, args.length());
121 THROW_NEW_ERROR_RETURN_FAILURE( 139 THROW_NEW_ERROR_RETURN_FAILURE(
122 isolate, NewTypeError(MessageTemplate::kWasmTrapTypeError)); 140 isolate, NewTypeError(MessageTemplate::kWasmTrapTypeError));
123 } 141 }
124 142
125 RUNTIME_FUNCTION(Runtime_WasmThrow) { 143 RUNTIME_FUNCTION(Runtime_WasmThrow) {
126 HandleScope scope(isolate); 144 HandleScope scope(isolate);
127 DCHECK_EQ(2, args.length()); 145 DCHECK_EQ(2, args.length());
(...skipping 11 matching lines...) Expand all
139 Object* exception = args[0]; 157 Object* exception = args[0];
140 // The unwinder will only deliver exceptions to wasm if the exception is a 158 // The unwinder will only deliver exceptions to wasm if the exception is a
141 // Number or a Smi (which we have just converted to a Number.) This logic 159 // Number or a Smi (which we have just converted to a Number.) This logic
142 // lives in Isolate::is_catchable_by_wasm(Object*). 160 // lives in Isolate::is_catchable_by_wasm(Object*).
143 CHECK(exception->IsNumber()); 161 CHECK(exception->IsNumber());
144 return exception; 162 return exception;
145 } 163 }
146 164
147 } // namespace internal 165 } // namespace internal
148 } // namespace v8 166 } // namespace v8
OLDNEW
« no previous file with comments | « src/runtime/runtime.h ('k') | src/wasm/wasm-external-refs.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698