OLD | NEW |
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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/runtime_entry.h" | 5 #include "vm/runtime_entry.h" |
6 | 6 |
7 #include "vm/assembler.h" | 7 #include "vm/assembler.h" |
8 #include "vm/ast.h" | 8 #include "vm/ast.h" |
9 #include "vm/code_patcher.h" | 9 #include "vm/code_patcher.h" |
10 #include "vm/compiler.h" | 10 #include "vm/compiler.h" |
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
213 args.SetAt(0, length); | 213 args.SetAt(0, length); |
214 args.SetAt(1, Integer::Handle(Integer::New(0))); | 214 args.SetAt(1, Integer::Handle(Integer::New(0))); |
215 args.SetAt(2, Integer::Handle(Integer::New(Array::kMaxElements))); | 215 args.SetAt(2, Integer::Handle(Integer::New(Array::kMaxElements))); |
216 args.SetAt(3, Symbols::Length()); | 216 args.SetAt(3, Symbols::Length()); |
217 Exceptions::ThrowByType(Exceptions::kRange, args); | 217 Exceptions::ThrowByType(Exceptions::kRange, args); |
218 } | 218 } |
219 | 219 |
220 | 220 |
221 // Helper returning the token position of the Dart caller. | 221 // Helper returning the token position of the Dart caller. |
222 static TokenPosition GetCallerLocation() { | 222 static TokenPosition GetCallerLocation() { |
223 DartFrameIterator iterator; | 223 DartFrameIterator iterator(Thread::Current(), |
| 224 StackFrameIterator::kNoCrossThreadIteration); |
224 StackFrame* caller_frame = iterator.NextFrame(); | 225 StackFrame* caller_frame = iterator.NextFrame(); |
225 ASSERT(caller_frame != NULL); | 226 ASSERT(caller_frame != NULL); |
226 return caller_frame->GetTokenPos(); | 227 return caller_frame->GetTokenPos(); |
227 } | 228 } |
228 | 229 |
229 | 230 |
230 // Allocate a new object. | 231 // Allocate a new object. |
231 // Arg0: class of the object that needs to be allocated. | 232 // Arg0: class of the object that needs to be allocated. |
232 // Arg1: type arguments of the object that needs to be allocated. | 233 // Arg1: type arguments of the object that needs to be allocated. |
233 // Return value: newly allocated object. | 234 // Return value: newly allocated object. |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
375 } | 376 } |
376 | 377 |
377 | 378 |
378 // Helper routine for tracing a type check. | 379 // Helper routine for tracing a type check. |
379 static void PrintTypeCheck(const char* message, | 380 static void PrintTypeCheck(const char* message, |
380 const Instance& instance, | 381 const Instance& instance, |
381 const AbstractType& type, | 382 const AbstractType& type, |
382 const TypeArguments& instantiator_type_arguments, | 383 const TypeArguments& instantiator_type_arguments, |
383 const TypeArguments& function_type_arguments, | 384 const TypeArguments& function_type_arguments, |
384 const Bool& result) { | 385 const Bool& result) { |
385 DartFrameIterator iterator; | 386 DartFrameIterator iterator(Thread::Current(), |
| 387 StackFrameIterator::kNoCrossThreadIteration); |
386 StackFrame* caller_frame = iterator.NextFrame(); | 388 StackFrame* caller_frame = iterator.NextFrame(); |
387 ASSERT(caller_frame != NULL); | 389 ASSERT(caller_frame != NULL); |
388 | 390 |
389 const AbstractType& instance_type = | 391 const AbstractType& instance_type = |
390 AbstractType::Handle(instance.GetType(Heap::kNew)); | 392 AbstractType::Handle(instance.GetType(Heap::kNew)); |
391 ASSERT(instance_type.IsInstantiated()); | 393 ASSERT(instance_type.IsInstantiated()); |
392 if (type.IsInstantiated()) { | 394 if (type.IsInstantiated()) { |
393 OS::PrintErr("%s: '%s' %" Pd " %s '%s' %" Pd " (pc: %#" Px ").\n", message, | 395 OS::PrintErr("%s: '%s' %" Pd " %s '%s' %" Pd " (pc: %#" Px ").\n", message, |
394 String::Handle(instance_type.Name()).ToCString(), | 396 String::Handle(instance_type.Name()).ToCString(), |
395 Class::Handle(instance_type.type_class()).id(), | 397 Class::Handle(instance_type.type_class()).id(), |
(...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
749 const Instance& exception = Instance::CheckedHandle(zone, arguments.ArgAt(0)); | 751 const Instance& exception = Instance::CheckedHandle(zone, arguments.ArgAt(0)); |
750 const Instance& stacktrace = | 752 const Instance& stacktrace = |
751 Instance::CheckedHandle(zone, arguments.ArgAt(1)); | 753 Instance::CheckedHandle(zone, arguments.ArgAt(1)); |
752 Exceptions::ReThrow(thread, exception, stacktrace); | 754 Exceptions::ReThrow(thread, exception, stacktrace); |
753 } | 755 } |
754 | 756 |
755 | 757 |
756 // Patches static call in optimized code with the target's entry point. | 758 // Patches static call in optimized code with the target's entry point. |
757 // Compiles target if necessary. | 759 // Compiles target if necessary. |
758 DEFINE_RUNTIME_ENTRY(PatchStaticCall, 0) { | 760 DEFINE_RUNTIME_ENTRY(PatchStaticCall, 0) { |
759 DartFrameIterator iterator; | 761 DartFrameIterator iterator(thread, |
| 762 StackFrameIterator::kNoCrossThreadIteration); |
760 StackFrame* caller_frame = iterator.NextFrame(); | 763 StackFrame* caller_frame = iterator.NextFrame(); |
761 ASSERT(caller_frame != NULL); | 764 ASSERT(caller_frame != NULL); |
762 const Code& caller_code = Code::Handle(zone, caller_frame->LookupDartCode()); | 765 const Code& caller_code = Code::Handle(zone, caller_frame->LookupDartCode()); |
763 ASSERT(!caller_code.IsNull()); | 766 ASSERT(!caller_code.IsNull()); |
764 ASSERT(caller_code.is_optimized()); | 767 ASSERT(caller_code.is_optimized()); |
765 const Function& target_function = Function::Handle( | 768 const Function& target_function = Function::Handle( |
766 zone, caller_code.GetStaticCallTargetFunctionAt(caller_frame->pc())); | 769 zone, caller_code.GetStaticCallTargetFunctionAt(caller_frame->pc())); |
767 const Code& target_code = Code::Handle(zone, target_function.EnsureHasCode()); | 770 const Code& target_code = Code::Handle(zone, target_function.EnsureHasCode()); |
768 // Before patching verify that we are not repeatedly patching to the same | 771 // Before patching verify that we are not repeatedly patching to the same |
769 // target. | 772 // target. |
(...skipping 23 matching lines...) Expand all Loading... |
793 | 796 |
794 | 797 |
795 #if !defined(TARGET_ARCH_DBC) | 798 #if !defined(TARGET_ARCH_DBC) |
796 // Gets called from debug stub when code reaches a breakpoint | 799 // Gets called from debug stub when code reaches a breakpoint |
797 // set on a runtime stub call. | 800 // set on a runtime stub call. |
798 DEFINE_RUNTIME_ENTRY(BreakpointRuntimeHandler, 0) { | 801 DEFINE_RUNTIME_ENTRY(BreakpointRuntimeHandler, 0) { |
799 if (!FLAG_support_debugger) { | 802 if (!FLAG_support_debugger) { |
800 UNREACHABLE(); | 803 UNREACHABLE(); |
801 return; | 804 return; |
802 } | 805 } |
803 DartFrameIterator iterator; | 806 DartFrameIterator iterator(thread, |
| 807 StackFrameIterator::kNoCrossThreadIteration); |
804 StackFrame* caller_frame = iterator.NextFrame(); | 808 StackFrame* caller_frame = iterator.NextFrame(); |
805 ASSERT(caller_frame != NULL); | 809 ASSERT(caller_frame != NULL); |
806 const Code& orig_stub = Code::Handle( | 810 const Code& orig_stub = Code::Handle( |
807 zone, isolate->debugger()->GetPatchedStubAddress(caller_frame->pc())); | 811 zone, isolate->debugger()->GetPatchedStubAddress(caller_frame->pc())); |
808 const Error& error = | 812 const Error& error = |
809 Error::Handle(zone, isolate->debugger()->PauseBreakpoint()); | 813 Error::Handle(zone, isolate->debugger()->PauseBreakpoint()); |
810 if (!error.IsNull()) { | 814 if (!error.IsNull()) { |
811 Exceptions::PropagateError(error); | 815 Exceptions::PropagateError(error); |
812 UNREACHABLE(); | 816 UNREACHABLE(); |
813 } | 817 } |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
964 ic_data.AddReceiverCheck(args[0]->GetClassId(), target_function); | 968 ic_data.AddReceiverCheck(args[0]->GetClassId(), target_function); |
965 } else { | 969 } else { |
966 GrowableArray<intptr_t> class_ids(args.length()); | 970 GrowableArray<intptr_t> class_ids(args.length()); |
967 ASSERT(ic_data.NumArgsTested() == args.length()); | 971 ASSERT(ic_data.NumArgsTested() == args.length()); |
968 for (intptr_t i = 0; i < args.length(); i++) { | 972 for (intptr_t i = 0; i < args.length(); i++) { |
969 class_ids.Add(args[i]->GetClassId()); | 973 class_ids.Add(args[i]->GetClassId()); |
970 } | 974 } |
971 ic_data.AddCheck(class_ids, target_function); | 975 ic_data.AddCheck(class_ids, target_function); |
972 } | 976 } |
973 if (FLAG_trace_ic_miss_in_optimized || FLAG_trace_ic) { | 977 if (FLAG_trace_ic_miss_in_optimized || FLAG_trace_ic) { |
974 DartFrameIterator iterator; | 978 DartFrameIterator iterator(Thread::Current(), |
| 979 StackFrameIterator::kNoCrossThreadIteration); |
975 StackFrame* caller_frame = iterator.NextFrame(); | 980 StackFrame* caller_frame = iterator.NextFrame(); |
976 ASSERT(caller_frame != NULL); | 981 ASSERT(caller_frame != NULL); |
977 if (FLAG_trace_ic_miss_in_optimized) { | 982 if (FLAG_trace_ic_miss_in_optimized) { |
978 const Code& caller = Code::Handle(Code::LookupCode(caller_frame->pc())); | 983 const Code& caller = Code::Handle(Code::LookupCode(caller_frame->pc())); |
979 if (caller.is_optimized()) { | 984 if (caller.is_optimized()) { |
980 OS::PrintErr("IC miss in optimized code; call %s -> %s\n", | 985 OS::PrintErr("IC miss in optimized code; call %s -> %s\n", |
981 Function::Handle(caller.function()).ToCString(), | 986 Function::Handle(caller.function()).ToCString(), |
982 target_function.ToCString()); | 987 target_function.ToCString()); |
983 } | 988 } |
984 } | 989 } |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1037 DEFINE_RUNTIME_ENTRY(StaticCallMissHandlerOneArg, 2) { | 1042 DEFINE_RUNTIME_ENTRY(StaticCallMissHandlerOneArg, 2) { |
1038 const Instance& arg = Instance::CheckedHandle(arguments.ArgAt(0)); | 1043 const Instance& arg = Instance::CheckedHandle(arguments.ArgAt(0)); |
1039 const ICData& ic_data = ICData::CheckedHandle(arguments.ArgAt(1)); | 1044 const ICData& ic_data = ICData::CheckedHandle(arguments.ArgAt(1)); |
1040 // IC data for static call is prepopulated with the statically known target. | 1045 // IC data for static call is prepopulated with the statically known target. |
1041 ASSERT(ic_data.NumberOfChecksIs(1)); | 1046 ASSERT(ic_data.NumberOfChecksIs(1)); |
1042 const Function& target = Function::Handle(ic_data.GetTargetAt(0)); | 1047 const Function& target = Function::Handle(ic_data.GetTargetAt(0)); |
1043 target.EnsureHasCode(); | 1048 target.EnsureHasCode(); |
1044 ASSERT(!target.IsNull() && target.HasCode()); | 1049 ASSERT(!target.IsNull() && target.HasCode()); |
1045 ic_data.AddReceiverCheck(arg.GetClassId(), target, 1); | 1050 ic_data.AddReceiverCheck(arg.GetClassId(), target, 1); |
1046 if (FLAG_trace_ic) { | 1051 if (FLAG_trace_ic) { |
1047 DartFrameIterator iterator; | 1052 DartFrameIterator iterator(thread, |
| 1053 StackFrameIterator::kNoCrossThreadIteration); |
1048 StackFrame* caller_frame = iterator.NextFrame(); | 1054 StackFrame* caller_frame = iterator.NextFrame(); |
1049 ASSERT(caller_frame != NULL); | 1055 ASSERT(caller_frame != NULL); |
1050 OS::PrintErr("StaticCallMissHandler at %#" Px " target %s (%" Pd ")\n", | 1056 OS::PrintErr("StaticCallMissHandler at %#" Px " target %s (%" Pd ")\n", |
1051 caller_frame->pc(), target.ToCString(), arg.GetClassId()); | 1057 caller_frame->pc(), target.ToCString(), arg.GetClassId()); |
1052 } | 1058 } |
1053 arguments.SetReturn(target); | 1059 arguments.SetReturn(target); |
1054 } | 1060 } |
1055 | 1061 |
1056 | 1062 |
1057 // Handles a static call in unoptimized code that has two argument types not | 1063 // Handles a static call in unoptimized code that has two argument types not |
1058 // seen before. Compile the target if necessary and update the ICData. | 1064 // seen before. Compile the target if necessary and update the ICData. |
1059 // Arg0: argument 0. | 1065 // Arg0: argument 0. |
1060 // Arg1: argument 1. | 1066 // Arg1: argument 1. |
1061 // Arg2: IC data object. | 1067 // Arg2: IC data object. |
1062 DEFINE_RUNTIME_ENTRY(StaticCallMissHandlerTwoArgs, 3) { | 1068 DEFINE_RUNTIME_ENTRY(StaticCallMissHandlerTwoArgs, 3) { |
1063 const Instance& arg0 = Instance::CheckedHandle(arguments.ArgAt(0)); | 1069 const Instance& arg0 = Instance::CheckedHandle(arguments.ArgAt(0)); |
1064 const Instance& arg1 = Instance::CheckedHandle(arguments.ArgAt(1)); | 1070 const Instance& arg1 = Instance::CheckedHandle(arguments.ArgAt(1)); |
1065 const ICData& ic_data = ICData::CheckedHandle(arguments.ArgAt(2)); | 1071 const ICData& ic_data = ICData::CheckedHandle(arguments.ArgAt(2)); |
1066 // IC data for static call is prepopulated with the statically known target. | 1072 // IC data for static call is prepopulated with the statically known target. |
1067 ASSERT(!ic_data.NumberOfChecksIs(0)); | 1073 ASSERT(!ic_data.NumberOfChecksIs(0)); |
1068 const Function& target = Function::Handle(ic_data.GetTargetAt(0)); | 1074 const Function& target = Function::Handle(ic_data.GetTargetAt(0)); |
1069 target.EnsureHasCode(); | 1075 target.EnsureHasCode(); |
1070 GrowableArray<intptr_t> cids(2); | 1076 GrowableArray<intptr_t> cids(2); |
1071 cids.Add(arg0.GetClassId()); | 1077 cids.Add(arg0.GetClassId()); |
1072 cids.Add(arg1.GetClassId()); | 1078 cids.Add(arg1.GetClassId()); |
1073 ic_data.AddCheck(cids, target); | 1079 ic_data.AddCheck(cids, target); |
1074 if (FLAG_trace_ic) { | 1080 if (FLAG_trace_ic) { |
1075 DartFrameIterator iterator; | 1081 DartFrameIterator iterator(thread, |
| 1082 StackFrameIterator::kNoCrossThreadIteration); |
1076 StackFrame* caller_frame = iterator.NextFrame(); | 1083 StackFrame* caller_frame = iterator.NextFrame(); |
1077 ASSERT(caller_frame != NULL); | 1084 ASSERT(caller_frame != NULL); |
1078 OS::PrintErr("StaticCallMissHandler at %#" Px " target %s (%" Pd ", %" Pd | 1085 OS::PrintErr("StaticCallMissHandler at %#" Px " target %s (%" Pd ", %" Pd |
1079 ")\n", | 1086 ")\n", |
1080 caller_frame->pc(), target.ToCString(), cids[0], cids[1]); | 1087 caller_frame->pc(), target.ToCString(), cids[0], cids[1]); |
1081 } | 1088 } |
1082 arguments.SetReturn(target); | 1089 arguments.SetReturn(target); |
1083 } | 1090 } |
1084 | 1091 |
1085 | 1092 |
(...skipping 26 matching lines...) Expand all Loading... |
1112 // Handle a miss of a single target cache. | 1119 // Handle a miss of a single target cache. |
1113 // Arg0: Receiver. | 1120 // Arg0: Receiver. |
1114 // Returns: the ICData used to continue with a polymorphic call. | 1121 // Returns: the ICData used to continue with a polymorphic call. |
1115 DEFINE_RUNTIME_ENTRY(SingleTargetMiss, 1) { | 1122 DEFINE_RUNTIME_ENTRY(SingleTargetMiss, 1) { |
1116 #if defined(TARGET_ARCH_DBC) | 1123 #if defined(TARGET_ARCH_DBC) |
1117 // DBC does not use switchable calls. | 1124 // DBC does not use switchable calls. |
1118 UNREACHABLE(); | 1125 UNREACHABLE(); |
1119 #else | 1126 #else |
1120 const Instance& receiver = Instance::CheckedHandle(zone, arguments.ArgAt(0)); | 1127 const Instance& receiver = Instance::CheckedHandle(zone, arguments.ArgAt(0)); |
1121 | 1128 |
1122 DartFrameIterator iterator; | 1129 DartFrameIterator iterator(thread, |
| 1130 StackFrameIterator::kNoCrossThreadIteration); |
1123 StackFrame* caller_frame = iterator.NextFrame(); | 1131 StackFrame* caller_frame = iterator.NextFrame(); |
1124 ASSERT(caller_frame->IsDartFrame()); | 1132 ASSERT(caller_frame->IsDartFrame()); |
1125 const Code& caller_code = Code::Handle(zone, caller_frame->LookupDartCode()); | 1133 const Code& caller_code = Code::Handle(zone, caller_frame->LookupDartCode()); |
1126 const Function& caller_function = | 1134 const Function& caller_function = |
1127 Function::Handle(zone, caller_frame->LookupDartFunction()); | 1135 Function::Handle(zone, caller_frame->LookupDartFunction()); |
1128 | 1136 |
1129 SingleTargetCache& cache = SingleTargetCache::Handle(zone); | 1137 SingleTargetCache& cache = SingleTargetCache::Handle(zone); |
1130 cache ^= | 1138 cache ^= |
1131 CodePatcher::GetSwitchableCallDataAt(caller_frame->pc(), caller_code); | 1139 CodePatcher::GetSwitchableCallDataAt(caller_frame->pc(), caller_code); |
1132 Code& old_target_code = Code::Handle(zone, cache.target()); | 1140 Code& old_target_code = Code::Handle(zone, cache.target()); |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1198 | 1206 |
1199 DEFINE_RUNTIME_ENTRY(UnlinkedCall, 2) { | 1207 DEFINE_RUNTIME_ENTRY(UnlinkedCall, 2) { |
1200 #if defined(TARGET_ARCH_DBC) | 1208 #if defined(TARGET_ARCH_DBC) |
1201 // DBC does not use switchable calls. | 1209 // DBC does not use switchable calls. |
1202 UNREACHABLE(); | 1210 UNREACHABLE(); |
1203 #else | 1211 #else |
1204 const Instance& receiver = Instance::CheckedHandle(zone, arguments.ArgAt(0)); | 1212 const Instance& receiver = Instance::CheckedHandle(zone, arguments.ArgAt(0)); |
1205 const UnlinkedCall& unlinked = | 1213 const UnlinkedCall& unlinked = |
1206 UnlinkedCall::CheckedHandle(zone, arguments.ArgAt(1)); | 1214 UnlinkedCall::CheckedHandle(zone, arguments.ArgAt(1)); |
1207 | 1215 |
1208 DartFrameIterator iterator; | 1216 DartFrameIterator iterator(thread, |
| 1217 StackFrameIterator::kNoCrossThreadIteration); |
1209 StackFrame* caller_frame = iterator.NextFrame(); | 1218 StackFrame* caller_frame = iterator.NextFrame(); |
1210 ASSERT(caller_frame->IsDartFrame()); | 1219 ASSERT(caller_frame->IsDartFrame()); |
1211 const Code& caller_code = Code::Handle(zone, caller_frame->LookupDartCode()); | 1220 const Code& caller_code = Code::Handle(zone, caller_frame->LookupDartCode()); |
1212 const Function& caller_function = | 1221 const Function& caller_function = |
1213 Function::Handle(zone, caller_frame->LookupDartFunction()); | 1222 Function::Handle(zone, caller_frame->LookupDartFunction()); |
1214 | 1223 |
1215 const String& name = String::Handle(zone, unlinked.target_name()); | 1224 const String& name = String::Handle(zone, unlinked.target_name()); |
1216 const Array& descriptor = Array::Handle(zone, unlinked.args_descriptor()); | 1225 const Array& descriptor = Array::Handle(zone, unlinked.args_descriptor()); |
1217 const ICData& ic_data = | 1226 const ICData& ic_data = |
1218 ICData::Handle(zone, ICData::New(caller_function, name, descriptor, | 1227 ICData::Handle(zone, ICData::New(caller_function, name, descriptor, |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1264 // Handle a miss of a megamorphic cache. | 1273 // Handle a miss of a megamorphic cache. |
1265 // Arg0: Receiver. | 1274 // Arg0: Receiver. |
1266 // Returns: the ICData used to continue with a polymorphic call. | 1275 // Returns: the ICData used to continue with a polymorphic call. |
1267 DEFINE_RUNTIME_ENTRY(MonomorphicMiss, 1) { | 1276 DEFINE_RUNTIME_ENTRY(MonomorphicMiss, 1) { |
1268 #if defined(TARGET_ARCH_DBC) | 1277 #if defined(TARGET_ARCH_DBC) |
1269 // DBC does not use switchable calls. | 1278 // DBC does not use switchable calls. |
1270 UNREACHABLE(); | 1279 UNREACHABLE(); |
1271 #else | 1280 #else |
1272 const Instance& receiver = Instance::CheckedHandle(zone, arguments.ArgAt(0)); | 1281 const Instance& receiver = Instance::CheckedHandle(zone, arguments.ArgAt(0)); |
1273 | 1282 |
1274 DartFrameIterator iterator; | 1283 DartFrameIterator iterator(thread, |
| 1284 StackFrameIterator::kNoCrossThreadIteration); |
1275 StackFrame* caller_frame = iterator.NextFrame(); | 1285 StackFrame* caller_frame = iterator.NextFrame(); |
1276 ASSERT(caller_frame->IsDartFrame()); | 1286 ASSERT(caller_frame->IsDartFrame()); |
1277 const Code& caller_code = Code::Handle(zone, caller_frame->LookupDartCode()); | 1287 const Code& caller_code = Code::Handle(zone, caller_frame->LookupDartCode()); |
1278 const Function& caller_function = | 1288 const Function& caller_function = |
1279 Function::Handle(zone, caller_frame->LookupDartFunction()); | 1289 Function::Handle(zone, caller_frame->LookupDartFunction()); |
1280 | 1290 |
1281 Smi& old_expected_cid = Smi::Handle(zone); | 1291 Smi& old_expected_cid = Smi::Handle(zone); |
1282 old_expected_cid ^= | 1292 old_expected_cid ^= |
1283 CodePatcher::GetSwitchableCallDataAt(caller_frame->pc(), caller_code); | 1293 CodePatcher::GetSwitchableCallDataAt(caller_frame->pc(), caller_code); |
1284 const Code& old_target_code = Code::Handle( | 1294 const Code& old_target_code = Code::Handle( |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1404 // This call site is unlinked: transition to a monomorphic direct call. | 1414 // This call site is unlinked: transition to a monomorphic direct call. |
1405 // Note we cannot do this if the target has optional parameters because | 1415 // Note we cannot do this if the target has optional parameters because |
1406 // the monomorphic direct call does not load the arguments descriptor. | 1416 // the monomorphic direct call does not load the arguments descriptor. |
1407 // We cannot do this if we are still in the middle of precompiling because | 1417 // We cannot do this if we are still in the middle of precompiling because |
1408 // the monomorphic case hides an live instance selector from the | 1418 // the monomorphic case hides an live instance selector from the |
1409 // treeshaker. | 1419 // treeshaker. |
1410 | 1420 |
1411 const Code& target_code = | 1421 const Code& target_code = |
1412 Code::Handle(zone, target_function.EnsureHasCode()); | 1422 Code::Handle(zone, target_function.EnsureHasCode()); |
1413 | 1423 |
1414 DartFrameIterator iterator; | 1424 DartFrameIterator iterator(thread, |
| 1425 StackFrameIterator::kNoCrossThreadIteration); |
1415 StackFrame* miss_function_frame = iterator.NextFrame(); | 1426 StackFrame* miss_function_frame = iterator.NextFrame(); |
1416 ASSERT(miss_function_frame->IsDartFrame()); | 1427 ASSERT(miss_function_frame->IsDartFrame()); |
1417 StackFrame* caller_frame = iterator.NextFrame(); | 1428 StackFrame* caller_frame = iterator.NextFrame(); |
1418 ASSERT(caller_frame->IsDartFrame()); | 1429 ASSERT(caller_frame->IsDartFrame()); |
1419 const Code& caller_code = | 1430 const Code& caller_code = |
1420 Code::Handle(zone, caller_frame->LookupDartCode()); | 1431 Code::Handle(zone, caller_frame->LookupDartCode()); |
1421 const Smi& expected_cid = | 1432 const Smi& expected_cid = |
1422 Smi::Handle(zone, Smi::New(receiver.GetClassId())); | 1433 Smi::Handle(zone, Smi::New(receiver.GetClassId())); |
1423 | 1434 |
1424 CodePatcher::PatchSwitchableCallAt(caller_frame->pc(), caller_code, | 1435 CodePatcher::PatchSwitchableCallAt(caller_frame->pc(), caller_code, |
1425 expected_cid, target_code); | 1436 expected_cid, target_code); |
1426 } else { | 1437 } else { |
1427 ic_data.AddReceiverCheck(receiver.GetClassId(), target_function); | 1438 ic_data.AddReceiverCheck(receiver.GetClassId(), target_function); |
1428 if (number_of_checks > FLAG_max_polymorphic_checks) { | 1439 if (number_of_checks > FLAG_max_polymorphic_checks) { |
1429 // Switch to megamorphic call. | 1440 // Switch to megamorphic call. |
1430 const MegamorphicCache& cache = MegamorphicCache::Handle( | 1441 const MegamorphicCache& cache = MegamorphicCache::Handle( |
1431 zone, MegamorphicCacheTable::Lookup(isolate, name, descriptor)); | 1442 zone, MegamorphicCacheTable::Lookup(isolate, name, descriptor)); |
1432 DartFrameIterator iterator; | 1443 DartFrameIterator iterator(thread, |
| 1444 StackFrameIterator::kNoCrossThreadIteration); |
1433 StackFrame* miss_function_frame = iterator.NextFrame(); | 1445 StackFrame* miss_function_frame = iterator.NextFrame(); |
1434 ASSERT(miss_function_frame->IsDartFrame()); | 1446 ASSERT(miss_function_frame->IsDartFrame()); |
1435 StackFrame* caller_frame = iterator.NextFrame(); | 1447 StackFrame* caller_frame = iterator.NextFrame(); |
1436 ASSERT(caller_frame->IsDartFrame()); | 1448 ASSERT(caller_frame->IsDartFrame()); |
1437 const Code& caller_code = | 1449 const Code& caller_code = |
1438 Code::Handle(zone, caller_frame->LookupDartCode()); | 1450 Code::Handle(zone, caller_frame->LookupDartCode()); |
1439 const Code& stub = | 1451 const Code& stub = |
1440 Code::Handle(zone, StubCode::MegamorphicCall_entry()->code()); | 1452 Code::Handle(zone, StubCode::MegamorphicCall_entry()->code()); |
1441 | 1453 |
1442 CodePatcher::PatchSwitchableCallAt(caller_frame->pc(), caller_code, | 1454 CodePatcher::PatchSwitchableCallAt(caller_frame->pc(), caller_code, |
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1662 } | 1674 } |
1663 if (FLAG_stacktrace_every > 0 && (count % FLAG_stacktrace_every) == 0) { | 1675 if (FLAG_stacktrace_every > 0 && (count % FLAG_stacktrace_every) == 0) { |
1664 do_stacktrace = true; | 1676 do_stacktrace = true; |
1665 } | 1677 } |
1666 if ((isolate_reload_every > 0) && (count % isolate_reload_every) == 0) { | 1678 if ((isolate_reload_every > 0) && (count % isolate_reload_every) == 0) { |
1667 do_reload = isolate->CanReload(); | 1679 do_reload = isolate->CanReload(); |
1668 } | 1680 } |
1669 } | 1681 } |
1670 if ((FLAG_deoptimize_filter != NULL) || (FLAG_stacktrace_filter != NULL) || | 1682 if ((FLAG_deoptimize_filter != NULL) || (FLAG_stacktrace_filter != NULL) || |
1671 FLAG_reload_every_optimized) { | 1683 FLAG_reload_every_optimized) { |
1672 DartFrameIterator iterator; | 1684 DartFrameIterator iterator(thread, |
| 1685 StackFrameIterator::kNoCrossThreadIteration); |
1673 StackFrame* frame = iterator.NextFrame(); | 1686 StackFrame* frame = iterator.NextFrame(); |
1674 ASSERT(frame != NULL); | 1687 ASSERT(frame != NULL); |
1675 const Code& code = Code::Handle(frame->LookupDartCode()); | 1688 const Code& code = Code::Handle(frame->LookupDartCode()); |
1676 ASSERT(!code.IsNull()); | 1689 ASSERT(!code.IsNull()); |
1677 const Function& function = Function::Handle(code.function()); | 1690 const Function& function = Function::Handle(code.function()); |
1678 ASSERT(!function.IsNull()); | 1691 ASSERT(!function.IsNull()); |
1679 const char* function_name = function.ToFullyQualifiedCString(); | 1692 const char* function_name = function.ToFullyQualifiedCString(); |
1680 ASSERT(function_name != NULL); | 1693 ASSERT(function_name != NULL); |
1681 if (!code.is_optimized() && FLAG_reload_every_optimized) { | 1694 if (!code.is_optimized() && FLAG_reload_every_optimized) { |
1682 // Don't do the reload if we aren't inside optimized code. | 1695 // Don't do the reload if we aren't inside optimized code. |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1745 } | 1758 } |
1746 | 1759 |
1747 const Error& error = Error::Handle(thread->HandleInterrupts()); | 1760 const Error& error = Error::Handle(thread->HandleInterrupts()); |
1748 if (!error.IsNull()) { | 1761 if (!error.IsNull()) { |
1749 Exceptions::PropagateError(error); | 1762 Exceptions::PropagateError(error); |
1750 UNREACHABLE(); | 1763 UNREACHABLE(); |
1751 } | 1764 } |
1752 | 1765 |
1753 if ((stack_overflow_flags & Thread::kOsrRequest) != 0) { | 1766 if ((stack_overflow_flags & Thread::kOsrRequest) != 0) { |
1754 ASSERT(isolate->use_osr()); | 1767 ASSERT(isolate->use_osr()); |
1755 DartFrameIterator iterator; | 1768 DartFrameIterator iterator(thread, |
| 1769 StackFrameIterator::kNoCrossThreadIteration); |
1756 StackFrame* frame = iterator.NextFrame(); | 1770 StackFrame* frame = iterator.NextFrame(); |
1757 ASSERT(frame != NULL); | 1771 ASSERT(frame != NULL); |
1758 const Code& code = Code::ZoneHandle(frame->LookupDartCode()); | 1772 const Code& code = Code::ZoneHandle(frame->LookupDartCode()); |
1759 ASSERT(!code.IsNull()); | 1773 ASSERT(!code.IsNull()); |
1760 ASSERT(!code.is_optimized()); | 1774 ASSERT(!code.is_optimized()); |
1761 const Function& function = Function::Handle(code.function()); | 1775 const Function& function = Function::Handle(code.function()); |
1762 ASSERT(!function.IsNull()); | 1776 ASSERT(!function.IsNull()); |
1763 | 1777 |
1764 // If the code of the frame does not match the function's unoptimized code, | 1778 // If the code of the frame does not match the function's unoptimized code, |
1765 // we bail out since the code was reset by an isolate reload. | 1779 // we bail out since the code was reset by an isolate reload. |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1804 frame->set_pc(optimized_entry); | 1818 frame->set_pc(optimized_entry); |
1805 frame->set_pc_marker(code.raw()); | 1819 frame->set_pc_marker(code.raw()); |
1806 } | 1820 } |
1807 } | 1821 } |
1808 } | 1822 } |
1809 | 1823 |
1810 | 1824 |
1811 DEFINE_RUNTIME_ENTRY(TraceICCall, 2) { | 1825 DEFINE_RUNTIME_ENTRY(TraceICCall, 2) { |
1812 const ICData& ic_data = ICData::CheckedHandle(arguments.ArgAt(0)); | 1826 const ICData& ic_data = ICData::CheckedHandle(arguments.ArgAt(0)); |
1813 const Function& function = Function::CheckedHandle(arguments.ArgAt(1)); | 1827 const Function& function = Function::CheckedHandle(arguments.ArgAt(1)); |
1814 DartFrameIterator iterator; | 1828 DartFrameIterator iterator(thread, |
| 1829 StackFrameIterator::kNoCrossThreadIteration); |
1815 StackFrame* frame = iterator.NextFrame(); | 1830 StackFrame* frame = iterator.NextFrame(); |
1816 ASSERT(frame != NULL); | 1831 ASSERT(frame != NULL); |
1817 OS::PrintErr("IC call @%#" Px ": ICData: %p cnt:%" Pd " nchecks: %" Pd | 1832 OS::PrintErr("IC call @%#" Px ": ICData: %p cnt:%" Pd " nchecks: %" Pd |
1818 " %s\n", | 1833 " %s\n", |
1819 frame->pc(), ic_data.raw(), function.usage_counter(), | 1834 frame->pc(), ic_data.raw(), function.usage_counter(), |
1820 ic_data.NumberOfChecks(), function.ToFullyQualifiedCString()); | 1835 ic_data.NumberOfChecks(), function.ToFullyQualifiedCString()); |
1821 } | 1836 } |
1822 | 1837 |
1823 | 1838 |
1824 // This is called from function that needs to be optimized. | 1839 // This is called from function that needs to be optimized. |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1884 arguments.SetReturn(function); | 1899 arguments.SetReturn(function); |
1885 #else | 1900 #else |
1886 UNREACHABLE(); | 1901 UNREACHABLE(); |
1887 #endif // !DART_PRECOMPILED_RUNTIME | 1902 #endif // !DART_PRECOMPILED_RUNTIME |
1888 } | 1903 } |
1889 | 1904 |
1890 | 1905 |
1891 // The caller must be a static call in a Dart frame, or an entry frame. | 1906 // The caller must be a static call in a Dart frame, or an entry frame. |
1892 // Patch static call to point to valid code's entry point. | 1907 // Patch static call to point to valid code's entry point. |
1893 DEFINE_RUNTIME_ENTRY(FixCallersTarget, 0) { | 1908 DEFINE_RUNTIME_ENTRY(FixCallersTarget, 0) { |
1894 StackFrameIterator iterator(StackFrameIterator::kDontValidateFrames); | 1909 StackFrameIterator iterator(StackFrameIterator::kDontValidateFrames, thread, |
| 1910 StackFrameIterator::kNoCrossThreadIteration); |
1895 StackFrame* frame = iterator.NextFrame(); | 1911 StackFrame* frame = iterator.NextFrame(); |
1896 ASSERT(frame != NULL); | 1912 ASSERT(frame != NULL); |
1897 while (frame->IsStubFrame() || frame->IsExitFrame()) { | 1913 while (frame->IsStubFrame() || frame->IsExitFrame()) { |
1898 frame = iterator.NextFrame(); | 1914 frame = iterator.NextFrame(); |
1899 ASSERT(frame != NULL); | 1915 ASSERT(frame != NULL); |
1900 } | 1916 } |
1901 if (frame->IsEntryFrame()) { | 1917 if (frame->IsEntryFrame()) { |
1902 // Since function's current code is always unpatched, the entry frame always | 1918 // Since function's current code is always unpatched, the entry frame always |
1903 // calls to unpatched code. | 1919 // calls to unpatched code. |
1904 UNREACHABLE(); | 1920 UNREACHABLE(); |
(...skipping 17 matching lines...) Expand all Loading... |
1922 } | 1938 } |
1923 ASSERT(!current_target_code.IsDisabled()); | 1939 ASSERT(!current_target_code.IsDisabled()); |
1924 arguments.SetReturn(current_target_code); | 1940 arguments.SetReturn(current_target_code); |
1925 } | 1941 } |
1926 | 1942 |
1927 | 1943 |
1928 // The caller tried to allocate an instance via an invalidated allocation | 1944 // The caller tried to allocate an instance via an invalidated allocation |
1929 // stub. | 1945 // stub. |
1930 DEFINE_RUNTIME_ENTRY(FixAllocationStubTarget, 0) { | 1946 DEFINE_RUNTIME_ENTRY(FixAllocationStubTarget, 0) { |
1931 #if !defined(DART_PRECOMPILED_RUNTIME) | 1947 #if !defined(DART_PRECOMPILED_RUNTIME) |
1932 StackFrameIterator iterator(StackFrameIterator::kDontValidateFrames); | 1948 StackFrameIterator iterator(StackFrameIterator::kDontValidateFrames, thread, |
| 1949 StackFrameIterator::kNoCrossThreadIteration); |
1933 StackFrame* frame = iterator.NextFrame(); | 1950 StackFrame* frame = iterator.NextFrame(); |
1934 ASSERT(frame != NULL); | 1951 ASSERT(frame != NULL); |
1935 while (frame->IsStubFrame() || frame->IsExitFrame()) { | 1952 while (frame->IsStubFrame() || frame->IsExitFrame()) { |
1936 frame = iterator.NextFrame(); | 1953 frame = iterator.NextFrame(); |
1937 ASSERT(frame != NULL); | 1954 ASSERT(frame != NULL); |
1938 } | 1955 } |
1939 if (frame->IsEntryFrame()) { | 1956 if (frame->IsEntryFrame()) { |
1940 // There must be a valid Dart frame. | 1957 // There must be a valid Dart frame. |
1941 UNREACHABLE(); | 1958 UNREACHABLE(); |
1942 } | 1959 } |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2050 #endif // !DBC | 2067 #endif // !DBC |
2051 | 2068 |
2052 // Mark code as dead (do not GC its embedded objects). | 2069 // Mark code as dead (do not GC its embedded objects). |
2053 optimized_code.set_is_alive(false); | 2070 optimized_code.set_is_alive(false); |
2054 } | 2071 } |
2055 | 2072 |
2056 | 2073 |
2057 // Currently checks only that all optimized frames have kDeoptIndex | 2074 // Currently checks only that all optimized frames have kDeoptIndex |
2058 // and unoptimized code has the kDeoptAfter. | 2075 // and unoptimized code has the kDeoptAfter. |
2059 void DeoptimizeFunctionsOnStack() { | 2076 void DeoptimizeFunctionsOnStack() { |
2060 DartFrameIterator iterator; | 2077 DartFrameIterator iterator(Thread::Current(), |
| 2078 StackFrameIterator::kNoCrossThreadIteration); |
2061 StackFrame* frame = iterator.NextFrame(); | 2079 StackFrame* frame = iterator.NextFrame(); |
2062 Code& optimized_code = Code::Handle(); | 2080 Code& optimized_code = Code::Handle(); |
2063 while (frame != NULL) { | 2081 while (frame != NULL) { |
2064 optimized_code = frame->LookupDartCode(); | 2082 optimized_code = frame->LookupDartCode(); |
2065 if (optimized_code.is_optimized()) { | 2083 if (optimized_code.is_optimized()) { |
2066 DeoptimizeAt(optimized_code, frame); | 2084 DeoptimizeAt(optimized_code, frame); |
2067 } | 2085 } |
2068 frame = iterator.NextFrame(); | 2086 frame = iterator.NextFrame(); |
2069 } | 2087 } |
2070 } | 2088 } |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2121 StackZone zone(thread); | 2139 StackZone zone(thread); |
2122 HANDLESCOPE(thread); | 2140 HANDLESCOPE(thread); |
2123 | 2141 |
2124 // All registers have been saved below last-fp as if they were locals. | 2142 // All registers have been saved below last-fp as if they were locals. |
2125 const uword last_fp = saved_registers_address + | 2143 const uword last_fp = saved_registers_address + |
2126 (kNumberOfSavedCpuRegisters * kWordSize) + | 2144 (kNumberOfSavedCpuRegisters * kWordSize) + |
2127 (kNumberOfSavedFpuRegisters * kFpuRegisterSize) - | 2145 (kNumberOfSavedFpuRegisters * kFpuRegisterSize) - |
2128 ((kFirstLocalSlotFromFp + 1) * kWordSize); | 2146 ((kFirstLocalSlotFromFp + 1) * kWordSize); |
2129 | 2147 |
2130 // Get optimized code and frame that need to be deoptimized. | 2148 // Get optimized code and frame that need to be deoptimized. |
2131 DartFrameIterator iterator(last_fp); | 2149 DartFrameIterator iterator(last_fp, thread, |
| 2150 StackFrameIterator::kNoCrossThreadIteration); |
2132 | 2151 |
2133 StackFrame* caller_frame = iterator.NextFrame(); | 2152 StackFrame* caller_frame = iterator.NextFrame(); |
2134 ASSERT(caller_frame != NULL); | 2153 ASSERT(caller_frame != NULL); |
2135 const Code& optimized_code = Code::Handle(caller_frame->LookupDartCode()); | 2154 const Code& optimized_code = Code::Handle(caller_frame->LookupDartCode()); |
2136 ASSERT(optimized_code.is_optimized()); | 2155 ASSERT(optimized_code.is_optimized()); |
2137 const Function& top_function = | 2156 const Function& top_function = |
2138 Function::Handle(thread->zone(), optimized_code.function()); | 2157 Function::Handle(thread->zone(), optimized_code.function()); |
2139 const bool deoptimizing_code = top_function.HasOptimizedCode(); | 2158 const bool deoptimizing_code = top_function.HasOptimizedCode(); |
2140 if (FLAG_trace_deoptimization) { | 2159 if (FLAG_trace_deoptimization) { |
2141 const Function& function = Function::Handle(optimized_code.function()); | 2160 const Function& function = Function::Handle(optimized_code.function()); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2191 // The stack has been adjusted to fit all values for unoptimized frame. | 2210 // The stack has been adjusted to fit all values for unoptimized frame. |
2192 // Fill the unoptimized frame. | 2211 // Fill the unoptimized frame. |
2193 DEFINE_LEAF_RUNTIME_ENTRY(void, DeoptimizeFillFrame, 1, uword last_fp) { | 2212 DEFINE_LEAF_RUNTIME_ENTRY(void, DeoptimizeFillFrame, 1, uword last_fp) { |
2194 #if !defined(DART_PRECOMPILED_RUNTIME) | 2213 #if !defined(DART_PRECOMPILED_RUNTIME) |
2195 Thread* thread = Thread::Current(); | 2214 Thread* thread = Thread::Current(); |
2196 Isolate* isolate = thread->isolate(); | 2215 Isolate* isolate = thread->isolate(); |
2197 StackZone zone(thread); | 2216 StackZone zone(thread); |
2198 HANDLESCOPE(thread); | 2217 HANDLESCOPE(thread); |
2199 | 2218 |
2200 DeoptContext* deopt_context = isolate->deopt_context(); | 2219 DeoptContext* deopt_context = isolate->deopt_context(); |
2201 DartFrameIterator iterator(last_fp); | 2220 DartFrameIterator iterator(last_fp, thread, |
| 2221 StackFrameIterator::kNoCrossThreadIteration); |
2202 StackFrame* caller_frame = iterator.NextFrame(); | 2222 StackFrame* caller_frame = iterator.NextFrame(); |
2203 ASSERT(caller_frame != NULL); | 2223 ASSERT(caller_frame != NULL); |
2204 | 2224 |
2205 #if defined(DEBUG) | 2225 #if defined(DEBUG) |
2206 { | 2226 { |
2207 // The code from the deopt_context. | 2227 // The code from the deopt_context. |
2208 const Code& code = Code::Handle(deopt_context->code()); | 2228 const Code& code = Code::Handle(deopt_context->code()); |
2209 | 2229 |
2210 // The code from our frame. | 2230 // The code from our frame. |
2211 const Code& optimized_code = Code::Handle(caller_frame->LookupDartCode()); | 2231 const Code& optimized_code = Code::Handle(caller_frame->LookupDartCode()); |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2325 const intptr_t new_size = 2 * old_size; | 2345 const intptr_t new_size = 2 * old_size; |
2326 const intptr_t elm_size = old_data.ElementSizeInBytes(); | 2346 const intptr_t elm_size = old_data.ElementSizeInBytes(); |
2327 const TypedData& new_data = | 2347 const TypedData& new_data = |
2328 TypedData::Handle(TypedData::New(cid, new_size, Heap::kOld)); | 2348 TypedData::Handle(TypedData::New(cid, new_size, Heap::kOld)); |
2329 TypedData::Copy(new_data, 0, old_data, 0, old_size * elm_size); | 2349 TypedData::Copy(new_data, 0, old_data, 0, old_size * elm_size); |
2330 typed_data_cell.SetAt(0, new_data); | 2350 typed_data_cell.SetAt(0, new_data); |
2331 arguments.SetReturn(new_data); | 2351 arguments.SetReturn(new_data); |
2332 } | 2352 } |
2333 | 2353 |
2334 } // namespace dart | 2354 } // namespace dart |
OLD | NEW |