OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #include "vm/code_generator.h" | 5 #include "vm/code_generator.h" |
6 | 6 |
7 #include "vm/code_patcher.h" | 7 #include "vm/code_patcher.h" |
8 #include "vm/compiler.h" | 8 #include "vm/compiler.h" |
9 #include "vm/dart_api_impl.h" | 9 #include "vm/dart_api_impl.h" |
10 #include "vm/dart_entry.h" | 10 #include "vm/dart_entry.h" |
11 #include "vm/debugger.h" | 11 #include "vm/debugger.h" |
12 #include "vm/exceptions.h" | 12 #include "vm/exceptions.h" |
13 #include "vm/object_store.h" | 13 #include "vm/object_store.h" |
14 #include "vm/message.h" | 14 #include "vm/message.h" |
| 15 #include "vm/message_handler.h" |
15 #include "vm/resolver.h" | 16 #include "vm/resolver.h" |
16 #include "vm/runtime_entry.h" | 17 #include "vm/runtime_entry.h" |
17 #include "vm/stack_frame.h" | 18 #include "vm/stack_frame.h" |
18 #include "vm/verifier.h" | 19 #include "vm/verifier.h" |
19 | 20 |
20 namespace dart { | 21 namespace dart { |
21 | 22 |
22 DEFINE_FLAG(bool, inline_cache, true, "enable inline caches"); | 23 DEFINE_FLAG(bool, inline_cache, true, "enable inline caches"); |
23 DEFINE_FLAG(bool, trace_deopt, false, "Trace deoptimization"); | 24 DEFINE_FLAG(bool, trace_deopt, false, "Trace deoptimization"); |
24 DEFINE_FLAG(bool, trace_ic, false, "trace IC handling"); | 25 DEFINE_FLAG(bool, trace_ic, false, "trace IC handling"); |
(...skipping 1093 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1118 | 1119 |
1119 | 1120 |
1120 DEFINE_RUNTIME_ENTRY(ClosureArgumentMismatch, 0) { | 1121 DEFINE_RUNTIME_ENTRY(ClosureArgumentMismatch, 0) { |
1121 ASSERT(arguments.Count() == | 1122 ASSERT(arguments.Count() == |
1122 kClosureArgumentMismatchRuntimeEntry.argument_count()); | 1123 kClosureArgumentMismatchRuntimeEntry.argument_count()); |
1123 GrowableArray<const Object*> args; | 1124 GrowableArray<const Object*> args; |
1124 Exceptions::ThrowByType(Exceptions::kClosureArgumentMismatch, args); | 1125 Exceptions::ThrowByType(Exceptions::kClosureArgumentMismatch, args); |
1125 } | 1126 } |
1126 | 1127 |
1127 | 1128 |
1128 static RawInstance* DeserializeMessage(void* data) { | |
1129 // Create a snapshot object using the buffer. | |
1130 const Snapshot* snapshot = Snapshot::SetupFromBuffer(data); | |
1131 ASSERT(snapshot->IsMessageSnapshot()); | |
1132 | |
1133 // Read object back from the snapshot. | |
1134 SnapshotReader reader(snapshot, Isolate::Current()); | |
1135 Instance& instance = Instance::Handle(); | |
1136 instance ^= reader.ReadObject(); | |
1137 return instance.raw(); | |
1138 } | |
1139 | |
1140 | |
1141 | |
1142 DEFINE_RUNTIME_ENTRY(StackOverflow, 0) { | 1129 DEFINE_RUNTIME_ENTRY(StackOverflow, 0) { |
1143 ASSERT(arguments.Count() == | 1130 ASSERT(arguments.Count() == |
1144 kStackOverflowRuntimeEntry.argument_count()); | 1131 kStackOverflowRuntimeEntry.argument_count()); |
1145 uword stack_pos = reinterpret_cast<uword>(&arguments); | 1132 uword stack_pos = reinterpret_cast<uword>(&arguments); |
1146 | 1133 |
1147 // If an interrupt happens at the same time as a stack overflow, we | 1134 // If an interrupt happens at the same time as a stack overflow, we |
1148 // process the stack overflow first. | 1135 // process the stack overflow first. |
1149 if (stack_pos < isolate->saved_stack_limit()) { | 1136 if (stack_pos < isolate->saved_stack_limit()) { |
1150 // Use the preallocated stack overflow exception to avoid calling | 1137 // Use the preallocated stack overflow exception to avoid calling |
1151 // into dart code. | 1138 // into dart code. |
1152 const Instance& exception = | 1139 const Instance& exception = |
1153 Instance::Handle(isolate->object_store()->stack_overflow()); | 1140 Instance::Handle(isolate->object_store()->stack_overflow()); |
1154 Exceptions::Throw(exception); | 1141 Exceptions::Throw(exception); |
1155 UNREACHABLE(); | 1142 UNREACHABLE(); |
1156 } | 1143 } |
1157 | 1144 |
1158 uword interrupt_bits = isolate->GetAndClearInterrupts(); | 1145 uword interrupt_bits = isolate->GetAndClearInterrupts(); |
1159 if (interrupt_bits & Isolate::kMessageInterrupt) { | 1146 if (interrupt_bits & Isolate::kMessageInterrupt) { |
1160 while (true) { | 1147 isolate->message_handler()->HandleOOBMessages(); |
1161 // TODO(turnidge): This code is duplicated elsewhere. Consolidate. | |
1162 Message* message = | |
1163 isolate->message_handler()->queue()->DequeueNoWaitWithPriority( | |
1164 Message::kOOBPriority); | |
1165 if (message == NULL) { | |
1166 // No more OOB messages to handle. | |
1167 break; | |
1168 } | |
1169 const Instance& msg = | |
1170 Instance::Handle(DeserializeMessage(message->data())); | |
1171 // For now the only OOB messages are Mirrors messages. | |
1172 const Object& result = Object::Handle( | |
1173 DartLibraryCalls::HandleMirrorsMessage( | |
1174 message->dest_port(), message->reply_port(), msg)); | |
1175 delete message; | |
1176 if (result.IsError()) { | |
1177 // TODO(turnidge): Propagating the error is probably wrong here. | |
1178 Exceptions::PropagateError(result); | |
1179 } | |
1180 ASSERT(result.IsNull()); | |
1181 } | |
1182 } | 1148 } |
1183 if (interrupt_bits & Isolate::kApiInterrupt) { | 1149 if (interrupt_bits & Isolate::kApiInterrupt) { |
1184 Dart_IsolateInterruptCallback callback = isolate->InterruptCallback(); | 1150 Dart_IsolateInterruptCallback callback = isolate->InterruptCallback(); |
1185 if (callback) { | 1151 if (callback) { |
1186 if ((*callback)()) { | 1152 if ((*callback)()) { |
1187 return; | 1153 return; |
1188 } else { | 1154 } else { |
1189 // TODO(turnidge): Unwind the stack. | 1155 // TODO(turnidge): Unwind the stack. |
1190 UNIMPLEMENTED(); | 1156 UNIMPLEMENTED(); |
1191 } | 1157 } |
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1429 } | 1395 } |
1430 } | 1396 } |
1431 } | 1397 } |
1432 // The cache is null terminated, therefore the loop above should never | 1398 // The cache is null terminated, therefore the loop above should never |
1433 // terminate by itself. | 1399 // terminate by itself. |
1434 UNREACHABLE(); | 1400 UNREACHABLE(); |
1435 return Code::null(); | 1401 return Code::null(); |
1436 } | 1402 } |
1437 | 1403 |
1438 } // namespace dart | 1404 } // namespace dart |
OLD | NEW |