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

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: 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
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) {
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( 66 Handle<Object> error_obj = isolate->factory()->NewWasmRuntimeError(
70 static_cast<MessageTemplate::Template>(message_id)); 67 static_cast<MessageTemplate::Template>(message_id));
71 68
69 if (FLAG_wasm_trap_if) {
70 return isolate->Throw(*error_obj);
71 }
72
72 // For wasm traps, the byte offset (a.k.a source position) can not be 73 // 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 // determined from relocation info, since the explicit checks for traps
74 // converge in one singe block which calls this runtime function. 75 // 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 // 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 // frame (a wasm frame) on the collected stack trace.
77 // TODO(wasm): This implementation is temporary, see bug #5007: 78 // TODO(wasm): This implementation is temporary, see bug #5007:
78 // https://bugs.chromium.org/p/v8/issues/detail?id=5007 79 // https://bugs.chromium.org/p/v8/issues/detail?id=5007
79 Handle<JSObject> error = Handle<JSObject>::cast(error_obj); 80 Handle<JSObject> error = Handle<JSObject>::cast(error_obj);
80 Handle<Object> stack_trace_obj = JSReceiver::GetDataProperty( 81 Handle<Object> stack_trace_obj = JSReceiver::GetDataProperty(
81 error, isolate->factory()->stack_trace_symbol()); 82 error, isolate->factory()->stack_trace_symbol());
(...skipping 26 matching lines...) Expand all
108 Maybe<bool> data_set = JSReceiver::SetDataProperty( 109 Maybe<bool> data_set = JSReceiver::SetDataProperty(
109 &it, handle(Smi::FromInt(byte_offset + 1), isolate)); 110 &it, handle(Smi::FromInt(byte_offset + 1), isolate));
110 DCHECK(data_set.IsJust() && data_set.FromJust() == true); 111 DCHECK(data_set.IsJust() && data_set.FromJust() == true);
111 USE(data_set); 112 USE(data_set);
112 } 113 }
113 } 114 }
114 115
115 return isolate->Throw(*error_obj); 116 return isolate->Throw(*error_obj);
116 } 117 }
117 118
119 RUNTIME_FUNCTION(Runtime_ThrowWasmError) {
120 HandleScope scope(isolate);
121 DCHECK_EQ(2, args.length());
122 CONVERT_SMI_ARG_CHECKED(message_id, 0);
123 CONVERT_SMI_ARG_CHECKED(byte_offset, 1);
124 return ThrowRuntimeError(isolate, message_id, byte_offset);
125 }
126
127 #define DECLARE_ENUM(name) \
128 RUNTIME_FUNCTION(Runtime_ThrowWasm##name) { \
titzer 2016/12/12 14:21:34 Can you factor the common code out of this macro i
ahaas 2016/12/13 12:38:59 Done.
129 HandleScope scope(isolate); \
130 int message_id = wasm::WasmOpcodes::TrapReasonToMessageId(wasm::k##name); \
131 printf("Throw trap %s\n", \
132 wasm::WasmOpcodes::TrapReasonMessage(wasm::k##name)); \
133 int byte_offset = 1; \
134 return ThrowRuntimeError(isolate, message_id, byte_offset); \
135 }
136 FOREACH_WASM_TRAPREASON(DECLARE_ENUM)
137 #undef DECLARE_ENUM
138
118 RUNTIME_FUNCTION(Runtime_WasmThrowTypeError) { 139 RUNTIME_FUNCTION(Runtime_WasmThrowTypeError) {
119 HandleScope scope(isolate); 140 HandleScope scope(isolate);
120 DCHECK_EQ(0, args.length()); 141 DCHECK_EQ(0, args.length());
121 THROW_NEW_ERROR_RETURN_FAILURE( 142 THROW_NEW_ERROR_RETURN_FAILURE(
122 isolate, NewTypeError(MessageTemplate::kWasmTrapTypeError)); 143 isolate, NewTypeError(MessageTemplate::kWasmTrapTypeError));
123 } 144 }
124 145
125 RUNTIME_FUNCTION(Runtime_WasmThrow) { 146 RUNTIME_FUNCTION(Runtime_WasmThrow) {
126 HandleScope scope(isolate); 147 HandleScope scope(isolate);
127 DCHECK_EQ(2, args.length()); 148 DCHECK_EQ(2, args.length());
(...skipping 11 matching lines...) Expand all
139 Object* exception = args[0]; 160 Object* exception = args[0];
140 // The unwinder will only deliver exceptions to wasm if the exception is a 161 // 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 162 // Number or a Smi (which we have just converted to a Number.) This logic
142 // lives in Isolate::is_catchable_by_wasm(Object*). 163 // lives in Isolate::is_catchable_by_wasm(Object*).
143 CHECK(exception->IsNumber()); 164 CHECK(exception->IsNumber());
144 return exception; 165 return exception;
145 } 166 }
146 167
147 } // namespace internal 168 } // namespace internal
148 } // namespace v8 169 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698