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(), false); |
224 StackFrame* caller_frame = iterator.NextFrame(); | 224 StackFrame* caller_frame = iterator.NextFrame(); |
225 ASSERT(caller_frame != NULL); | 225 ASSERT(caller_frame != NULL); |
226 return caller_frame->GetTokenPos(); | 226 return caller_frame->GetTokenPos(); |
227 } | 227 } |
228 | 228 |
229 | 229 |
230 // Allocate a new object. | 230 // Allocate a new object. |
231 // Arg0: class of the object that needs to be allocated. | 231 // Arg0: class of the object that needs to be allocated. |
232 // Arg1: type arguments of the object that needs to be allocated. | 232 // Arg1: type arguments of the object that needs to be allocated. |
233 // Return value: newly allocated object. | 233 // Return value: newly allocated object. |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
375 } | 375 } |
376 | 376 |
377 | 377 |
378 // Helper routine for tracing a type check. | 378 // Helper routine for tracing a type check. |
379 static void PrintTypeCheck(const char* message, | 379 static void PrintTypeCheck(const char* message, |
380 const Instance& instance, | 380 const Instance& instance, |
381 const AbstractType& type, | 381 const AbstractType& type, |
382 const TypeArguments& instantiator_type_arguments, | 382 const TypeArguments& instantiator_type_arguments, |
383 const TypeArguments& function_type_arguments, | 383 const TypeArguments& function_type_arguments, |
384 const Bool& result) { | 384 const Bool& result) { |
385 DartFrameIterator iterator; | 385 DartFrameIterator iterator(Thread::Current(), false); |
386 StackFrame* caller_frame = iterator.NextFrame(); | 386 StackFrame* caller_frame = iterator.NextFrame(); |
387 ASSERT(caller_frame != NULL); | 387 ASSERT(caller_frame != NULL); |
388 | 388 |
389 const AbstractType& instance_type = | 389 const AbstractType& instance_type = |
390 AbstractType::Handle(instance.GetType(Heap::kNew)); | 390 AbstractType::Handle(instance.GetType(Heap::kNew)); |
391 ASSERT(instance_type.IsInstantiated()); | 391 ASSERT(instance_type.IsInstantiated()); |
392 if (type.IsInstantiated()) { | 392 if (type.IsInstantiated()) { |
393 OS::PrintErr("%s: '%s' %" Pd " %s '%s' %" Pd " (pc: %#" Px ").\n", message, | 393 OS::PrintErr("%s: '%s' %" Pd " %s '%s' %" Pd " (pc: %#" Px ").\n", message, |
394 String::Handle(instance_type.Name()).ToCString(), | 394 String::Handle(instance_type.Name()).ToCString(), |
395 Class::Handle(instance_type.type_class()).id(), | 395 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)); | 749 const Instance& exception = Instance::CheckedHandle(zone, arguments.ArgAt(0)); |
750 const Instance& stacktrace = | 750 const Instance& stacktrace = |
751 Instance::CheckedHandle(zone, arguments.ArgAt(1)); | 751 Instance::CheckedHandle(zone, arguments.ArgAt(1)); |
752 Exceptions::ReThrow(thread, exception, stacktrace); | 752 Exceptions::ReThrow(thread, exception, stacktrace); |
753 } | 753 } |
754 | 754 |
755 | 755 |
756 // Patches static call in optimized code with the target's entry point. | 756 // Patches static call in optimized code with the target's entry point. |
757 // Compiles target if necessary. | 757 // Compiles target if necessary. |
758 DEFINE_RUNTIME_ENTRY(PatchStaticCall, 0) { | 758 DEFINE_RUNTIME_ENTRY(PatchStaticCall, 0) { |
759 DartFrameIterator iterator; | 759 DartFrameIterator iterator(thread, false); |
760 StackFrame* caller_frame = iterator.NextFrame(); | 760 StackFrame* caller_frame = iterator.NextFrame(); |
761 ASSERT(caller_frame != NULL); | 761 ASSERT(caller_frame != NULL); |
762 const Code& caller_code = Code::Handle(zone, caller_frame->LookupDartCode()); | 762 const Code& caller_code = Code::Handle(zone, caller_frame->LookupDartCode()); |
763 ASSERT(!caller_code.IsNull()); | 763 ASSERT(!caller_code.IsNull()); |
764 ASSERT(caller_code.is_optimized()); | 764 ASSERT(caller_code.is_optimized()); |
765 const Function& target_function = Function::Handle( | 765 const Function& target_function = Function::Handle( |
766 zone, caller_code.GetStaticCallTargetFunctionAt(caller_frame->pc())); | 766 zone, caller_code.GetStaticCallTargetFunctionAt(caller_frame->pc())); |
767 const Code& target_code = Code::Handle(zone, target_function.EnsureHasCode()); | 767 const Code& target_code = Code::Handle(zone, target_function.EnsureHasCode()); |
768 // Before patching verify that we are not repeatedly patching to the same | 768 // Before patching verify that we are not repeatedly patching to the same |
769 // target. | 769 // target. |
(...skipping 23 matching lines...) Expand all Loading... |
793 | 793 |
794 | 794 |
795 #if !defined(TARGET_ARCH_DBC) | 795 #if !defined(TARGET_ARCH_DBC) |
796 // Gets called from debug stub when code reaches a breakpoint | 796 // Gets called from debug stub when code reaches a breakpoint |
797 // set on a runtime stub call. | 797 // set on a runtime stub call. |
798 DEFINE_RUNTIME_ENTRY(BreakpointRuntimeHandler, 0) { | 798 DEFINE_RUNTIME_ENTRY(BreakpointRuntimeHandler, 0) { |
799 if (!FLAG_support_debugger) { | 799 if (!FLAG_support_debugger) { |
800 UNREACHABLE(); | 800 UNREACHABLE(); |
801 return; | 801 return; |
802 } | 802 } |
803 DartFrameIterator iterator; | 803 DartFrameIterator iterator(thread, false); |
804 StackFrame* caller_frame = iterator.NextFrame(); | 804 StackFrame* caller_frame = iterator.NextFrame(); |
805 ASSERT(caller_frame != NULL); | 805 ASSERT(caller_frame != NULL); |
806 const Code& orig_stub = Code::Handle( | 806 const Code& orig_stub = Code::Handle( |
807 zone, isolate->debugger()->GetPatchedStubAddress(caller_frame->pc())); | 807 zone, isolate->debugger()->GetPatchedStubAddress(caller_frame->pc())); |
808 const Error& error = | 808 const Error& error = |
809 Error::Handle(zone, isolate->debugger()->PauseBreakpoint()); | 809 Error::Handle(zone, isolate->debugger()->PauseBreakpoint()); |
810 if (!error.IsNull()) { | 810 if (!error.IsNull()) { |
811 Exceptions::PropagateError(error); | 811 Exceptions::PropagateError(error); |
812 UNREACHABLE(); | 812 UNREACHABLE(); |
813 } | 813 } |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
964 ic_data.AddReceiverCheck(args[0]->GetClassId(), target_function); | 964 ic_data.AddReceiverCheck(args[0]->GetClassId(), target_function); |
965 } else { | 965 } else { |
966 GrowableArray<intptr_t> class_ids(args.length()); | 966 GrowableArray<intptr_t> class_ids(args.length()); |
967 ASSERT(ic_data.NumArgsTested() == args.length()); | 967 ASSERT(ic_data.NumArgsTested() == args.length()); |
968 for (intptr_t i = 0; i < args.length(); i++) { | 968 for (intptr_t i = 0; i < args.length(); i++) { |
969 class_ids.Add(args[i]->GetClassId()); | 969 class_ids.Add(args[i]->GetClassId()); |
970 } | 970 } |
971 ic_data.AddCheck(class_ids, target_function); | 971 ic_data.AddCheck(class_ids, target_function); |
972 } | 972 } |
973 if (FLAG_trace_ic_miss_in_optimized || FLAG_trace_ic) { | 973 if (FLAG_trace_ic_miss_in_optimized || FLAG_trace_ic) { |
974 DartFrameIterator iterator; | 974 DartFrameIterator iterator(Thread::Current(), false); |
975 StackFrame* caller_frame = iterator.NextFrame(); | 975 StackFrame* caller_frame = iterator.NextFrame(); |
976 ASSERT(caller_frame != NULL); | 976 ASSERT(caller_frame != NULL); |
977 if (FLAG_trace_ic_miss_in_optimized) { | 977 if (FLAG_trace_ic_miss_in_optimized) { |
978 const Code& caller = Code::Handle(Code::LookupCode(caller_frame->pc())); | 978 const Code& caller = Code::Handle(Code::LookupCode(caller_frame->pc())); |
979 if (caller.is_optimized()) { | 979 if (caller.is_optimized()) { |
980 OS::PrintErr("IC miss in optimized code; call %s -> %s\n", | 980 OS::PrintErr("IC miss in optimized code; call %s -> %s\n", |
981 Function::Handle(caller.function()).ToCString(), | 981 Function::Handle(caller.function()).ToCString(), |
982 target_function.ToCString()); | 982 target_function.ToCString()); |
983 } | 983 } |
984 } | 984 } |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1037 DEFINE_RUNTIME_ENTRY(StaticCallMissHandlerOneArg, 2) { | 1037 DEFINE_RUNTIME_ENTRY(StaticCallMissHandlerOneArg, 2) { |
1038 const Instance& arg = Instance::CheckedHandle(arguments.ArgAt(0)); | 1038 const Instance& arg = Instance::CheckedHandle(arguments.ArgAt(0)); |
1039 const ICData& ic_data = ICData::CheckedHandle(arguments.ArgAt(1)); | 1039 const ICData& ic_data = ICData::CheckedHandle(arguments.ArgAt(1)); |
1040 // IC data for static call is prepopulated with the statically known target. | 1040 // IC data for static call is prepopulated with the statically known target. |
1041 ASSERT(ic_data.NumberOfChecksIs(1)); | 1041 ASSERT(ic_data.NumberOfChecksIs(1)); |
1042 const Function& target = Function::Handle(ic_data.GetTargetAt(0)); | 1042 const Function& target = Function::Handle(ic_data.GetTargetAt(0)); |
1043 target.EnsureHasCode(); | 1043 target.EnsureHasCode(); |
1044 ASSERT(!target.IsNull() && target.HasCode()); | 1044 ASSERT(!target.IsNull() && target.HasCode()); |
1045 ic_data.AddReceiverCheck(arg.GetClassId(), target, 1); | 1045 ic_data.AddReceiverCheck(arg.GetClassId(), target, 1); |
1046 if (FLAG_trace_ic) { | 1046 if (FLAG_trace_ic) { |
1047 DartFrameIterator iterator; | 1047 DartFrameIterator iterator(thread, false); |
1048 StackFrame* caller_frame = iterator.NextFrame(); | 1048 StackFrame* caller_frame = iterator.NextFrame(); |
1049 ASSERT(caller_frame != NULL); | 1049 ASSERT(caller_frame != NULL); |
1050 OS::PrintErr("StaticCallMissHandler at %#" Px " target %s (%" Pd ")\n", | 1050 OS::PrintErr("StaticCallMissHandler at %#" Px " target %s (%" Pd ")\n", |
1051 caller_frame->pc(), target.ToCString(), arg.GetClassId()); | 1051 caller_frame->pc(), target.ToCString(), arg.GetClassId()); |
1052 } | 1052 } |
1053 arguments.SetReturn(target); | 1053 arguments.SetReturn(target); |
1054 } | 1054 } |
1055 | 1055 |
1056 | 1056 |
1057 // Handles a static call in unoptimized code that has two argument types not | 1057 // 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. | 1058 // seen before. Compile the target if necessary and update the ICData. |
1059 // Arg0: argument 0. | 1059 // Arg0: argument 0. |
1060 // Arg1: argument 1. | 1060 // Arg1: argument 1. |
1061 // Arg2: IC data object. | 1061 // Arg2: IC data object. |
1062 DEFINE_RUNTIME_ENTRY(StaticCallMissHandlerTwoArgs, 3) { | 1062 DEFINE_RUNTIME_ENTRY(StaticCallMissHandlerTwoArgs, 3) { |
1063 const Instance& arg0 = Instance::CheckedHandle(arguments.ArgAt(0)); | 1063 const Instance& arg0 = Instance::CheckedHandle(arguments.ArgAt(0)); |
1064 const Instance& arg1 = Instance::CheckedHandle(arguments.ArgAt(1)); | 1064 const Instance& arg1 = Instance::CheckedHandle(arguments.ArgAt(1)); |
1065 const ICData& ic_data = ICData::CheckedHandle(arguments.ArgAt(2)); | 1065 const ICData& ic_data = ICData::CheckedHandle(arguments.ArgAt(2)); |
1066 // IC data for static call is prepopulated with the statically known target. | 1066 // IC data for static call is prepopulated with the statically known target. |
1067 ASSERT(!ic_data.NumberOfChecksIs(0)); | 1067 ASSERT(!ic_data.NumberOfChecksIs(0)); |
1068 const Function& target = Function::Handle(ic_data.GetTargetAt(0)); | 1068 const Function& target = Function::Handle(ic_data.GetTargetAt(0)); |
1069 target.EnsureHasCode(); | 1069 target.EnsureHasCode(); |
1070 GrowableArray<intptr_t> cids(2); | 1070 GrowableArray<intptr_t> cids(2); |
1071 cids.Add(arg0.GetClassId()); | 1071 cids.Add(arg0.GetClassId()); |
1072 cids.Add(arg1.GetClassId()); | 1072 cids.Add(arg1.GetClassId()); |
1073 ic_data.AddCheck(cids, target); | 1073 ic_data.AddCheck(cids, target); |
1074 if (FLAG_trace_ic) { | 1074 if (FLAG_trace_ic) { |
1075 DartFrameIterator iterator; | 1075 DartFrameIterator iterator(thread, false); |
1076 StackFrame* caller_frame = iterator.NextFrame(); | 1076 StackFrame* caller_frame = iterator.NextFrame(); |
1077 ASSERT(caller_frame != NULL); | 1077 ASSERT(caller_frame != NULL); |
1078 OS::PrintErr("StaticCallMissHandler at %#" Px " target %s (%" Pd ", %" Pd | 1078 OS::PrintErr("StaticCallMissHandler at %#" Px " target %s (%" Pd ", %" Pd |
1079 ")\n", | 1079 ")\n", |
1080 caller_frame->pc(), target.ToCString(), cids[0], cids[1]); | 1080 caller_frame->pc(), target.ToCString(), cids[0], cids[1]); |
1081 } | 1081 } |
1082 arguments.SetReturn(target); | 1082 arguments.SetReturn(target); |
1083 } | 1083 } |
1084 | 1084 |
1085 | 1085 |
(...skipping 26 matching lines...) Expand all Loading... |
1112 // Handle a miss of a single target cache. | 1112 // Handle a miss of a single target cache. |
1113 // Arg0: Receiver. | 1113 // Arg0: Receiver. |
1114 // Returns: the ICData used to continue with a polymorphic call. | 1114 // Returns: the ICData used to continue with a polymorphic call. |
1115 DEFINE_RUNTIME_ENTRY(SingleTargetMiss, 1) { | 1115 DEFINE_RUNTIME_ENTRY(SingleTargetMiss, 1) { |
1116 #if defined(TARGET_ARCH_DBC) | 1116 #if defined(TARGET_ARCH_DBC) |
1117 // DBC does not use switchable calls. | 1117 // DBC does not use switchable calls. |
1118 UNREACHABLE(); | 1118 UNREACHABLE(); |
1119 #else | 1119 #else |
1120 const Instance& receiver = Instance::CheckedHandle(zone, arguments.ArgAt(0)); | 1120 const Instance& receiver = Instance::CheckedHandle(zone, arguments.ArgAt(0)); |
1121 | 1121 |
1122 DartFrameIterator iterator; | 1122 DartFrameIterator iterator(thread, false); |
1123 StackFrame* caller_frame = iterator.NextFrame(); | 1123 StackFrame* caller_frame = iterator.NextFrame(); |
1124 ASSERT(caller_frame->IsDartFrame()); | 1124 ASSERT(caller_frame->IsDartFrame()); |
1125 const Code& caller_code = Code::Handle(zone, caller_frame->LookupDartCode()); | 1125 const Code& caller_code = Code::Handle(zone, caller_frame->LookupDartCode()); |
1126 const Function& caller_function = | 1126 const Function& caller_function = |
1127 Function::Handle(zone, caller_frame->LookupDartFunction()); | 1127 Function::Handle(zone, caller_frame->LookupDartFunction()); |
1128 | 1128 |
1129 SingleTargetCache& cache = SingleTargetCache::Handle(zone); | 1129 SingleTargetCache& cache = SingleTargetCache::Handle(zone); |
1130 cache ^= | 1130 cache ^= |
1131 CodePatcher::GetSwitchableCallDataAt(caller_frame->pc(), caller_code); | 1131 CodePatcher::GetSwitchableCallDataAt(caller_frame->pc(), caller_code); |
1132 Code& old_target_code = Code::Handle(zone, cache.target()); | 1132 Code& old_target_code = Code::Handle(zone, cache.target()); |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1198 | 1198 |
1199 DEFINE_RUNTIME_ENTRY(UnlinkedCall, 2) { | 1199 DEFINE_RUNTIME_ENTRY(UnlinkedCall, 2) { |
1200 #if defined(TARGET_ARCH_DBC) | 1200 #if defined(TARGET_ARCH_DBC) |
1201 // DBC does not use switchable calls. | 1201 // DBC does not use switchable calls. |
1202 UNREACHABLE(); | 1202 UNREACHABLE(); |
1203 #else | 1203 #else |
1204 const Instance& receiver = Instance::CheckedHandle(zone, arguments.ArgAt(0)); | 1204 const Instance& receiver = Instance::CheckedHandle(zone, arguments.ArgAt(0)); |
1205 const UnlinkedCall& unlinked = | 1205 const UnlinkedCall& unlinked = |
1206 UnlinkedCall::CheckedHandle(zone, arguments.ArgAt(1)); | 1206 UnlinkedCall::CheckedHandle(zone, arguments.ArgAt(1)); |
1207 | 1207 |
1208 DartFrameIterator iterator; | 1208 DartFrameIterator iterator(thread, false); |
1209 StackFrame* caller_frame = iterator.NextFrame(); | 1209 StackFrame* caller_frame = iterator.NextFrame(); |
1210 ASSERT(caller_frame->IsDartFrame()); | 1210 ASSERT(caller_frame->IsDartFrame()); |
1211 const Code& caller_code = Code::Handle(zone, caller_frame->LookupDartCode()); | 1211 const Code& caller_code = Code::Handle(zone, caller_frame->LookupDartCode()); |
1212 const Function& caller_function = | 1212 const Function& caller_function = |
1213 Function::Handle(zone, caller_frame->LookupDartFunction()); | 1213 Function::Handle(zone, caller_frame->LookupDartFunction()); |
1214 | 1214 |
1215 const String& name = String::Handle(zone, unlinked.target_name()); | 1215 const String& name = String::Handle(zone, unlinked.target_name()); |
1216 const Array& descriptor = Array::Handle(zone, unlinked.args_descriptor()); | 1216 const Array& descriptor = Array::Handle(zone, unlinked.args_descriptor()); |
1217 const ICData& ic_data = | 1217 const ICData& ic_data = |
1218 ICData::Handle(zone, ICData::New(caller_function, name, descriptor, | 1218 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. | 1264 // Handle a miss of a megamorphic cache. |
1265 // Arg0: Receiver. | 1265 // Arg0: Receiver. |
1266 // Returns: the ICData used to continue with a polymorphic call. | 1266 // Returns: the ICData used to continue with a polymorphic call. |
1267 DEFINE_RUNTIME_ENTRY(MonomorphicMiss, 1) { | 1267 DEFINE_RUNTIME_ENTRY(MonomorphicMiss, 1) { |
1268 #if defined(TARGET_ARCH_DBC) | 1268 #if defined(TARGET_ARCH_DBC) |
1269 // DBC does not use switchable calls. | 1269 // DBC does not use switchable calls. |
1270 UNREACHABLE(); | 1270 UNREACHABLE(); |
1271 #else | 1271 #else |
1272 const Instance& receiver = Instance::CheckedHandle(zone, arguments.ArgAt(0)); | 1272 const Instance& receiver = Instance::CheckedHandle(zone, arguments.ArgAt(0)); |
1273 | 1273 |
1274 DartFrameIterator iterator; | 1274 DartFrameIterator iterator(thread, false); |
1275 StackFrame* caller_frame = iterator.NextFrame(); | 1275 StackFrame* caller_frame = iterator.NextFrame(); |
1276 ASSERT(caller_frame->IsDartFrame()); | 1276 ASSERT(caller_frame->IsDartFrame()); |
1277 const Code& caller_code = Code::Handle(zone, caller_frame->LookupDartCode()); | 1277 const Code& caller_code = Code::Handle(zone, caller_frame->LookupDartCode()); |
1278 const Function& caller_function = | 1278 const Function& caller_function = |
1279 Function::Handle(zone, caller_frame->LookupDartFunction()); | 1279 Function::Handle(zone, caller_frame->LookupDartFunction()); |
1280 | 1280 |
1281 Smi& old_expected_cid = Smi::Handle(zone); | 1281 Smi& old_expected_cid = Smi::Handle(zone); |
1282 old_expected_cid ^= | 1282 old_expected_cid ^= |
1283 CodePatcher::GetSwitchableCallDataAt(caller_frame->pc(), caller_code); | 1283 CodePatcher::GetSwitchableCallDataAt(caller_frame->pc(), caller_code); |
1284 const Code& old_target_code = Code::Handle( | 1284 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. | 1404 // This call site is unlinked: transition to a monomorphic direct call. |
1405 // Note we cannot do this if the target has optional parameters because | 1405 // Note we cannot do this if the target has optional parameters because |
1406 // the monomorphic direct call does not load the arguments descriptor. | 1406 // 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 | 1407 // 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 | 1408 // the monomorphic case hides an live instance selector from the |
1409 // treeshaker. | 1409 // treeshaker. |
1410 | 1410 |
1411 const Code& target_code = | 1411 const Code& target_code = |
1412 Code::Handle(zone, target_function.EnsureHasCode()); | 1412 Code::Handle(zone, target_function.EnsureHasCode()); |
1413 | 1413 |
1414 DartFrameIterator iterator; | 1414 DartFrameIterator iterator(thread, false); |
1415 StackFrame* miss_function_frame = iterator.NextFrame(); | 1415 StackFrame* miss_function_frame = iterator.NextFrame(); |
1416 ASSERT(miss_function_frame->IsDartFrame()); | 1416 ASSERT(miss_function_frame->IsDartFrame()); |
1417 StackFrame* caller_frame = iterator.NextFrame(); | 1417 StackFrame* caller_frame = iterator.NextFrame(); |
1418 ASSERT(caller_frame->IsDartFrame()); | 1418 ASSERT(caller_frame->IsDartFrame()); |
1419 const Code& caller_code = | 1419 const Code& caller_code = |
1420 Code::Handle(zone, caller_frame->LookupDartCode()); | 1420 Code::Handle(zone, caller_frame->LookupDartCode()); |
1421 const Smi& expected_cid = | 1421 const Smi& expected_cid = |
1422 Smi::Handle(zone, Smi::New(receiver.GetClassId())); | 1422 Smi::Handle(zone, Smi::New(receiver.GetClassId())); |
1423 | 1423 |
1424 CodePatcher::PatchSwitchableCallAt(caller_frame->pc(), caller_code, | 1424 CodePatcher::PatchSwitchableCallAt(caller_frame->pc(), caller_code, |
1425 expected_cid, target_code); | 1425 expected_cid, target_code); |
1426 } else { | 1426 } else { |
1427 ic_data.AddReceiverCheck(receiver.GetClassId(), target_function); | 1427 ic_data.AddReceiverCheck(receiver.GetClassId(), target_function); |
1428 if (number_of_checks > FLAG_max_polymorphic_checks) { | 1428 if (number_of_checks > FLAG_max_polymorphic_checks) { |
1429 // Switch to megamorphic call. | 1429 // Switch to megamorphic call. |
1430 const MegamorphicCache& cache = MegamorphicCache::Handle( | 1430 const MegamorphicCache& cache = MegamorphicCache::Handle( |
1431 zone, MegamorphicCacheTable::Lookup(isolate, name, descriptor)); | 1431 zone, MegamorphicCacheTable::Lookup(isolate, name, descriptor)); |
1432 DartFrameIterator iterator; | 1432 DartFrameIterator iterator(thread, false); |
1433 StackFrame* miss_function_frame = iterator.NextFrame(); | 1433 StackFrame* miss_function_frame = iterator.NextFrame(); |
1434 ASSERT(miss_function_frame->IsDartFrame()); | 1434 ASSERT(miss_function_frame->IsDartFrame()); |
1435 StackFrame* caller_frame = iterator.NextFrame(); | 1435 StackFrame* caller_frame = iterator.NextFrame(); |
1436 ASSERT(caller_frame->IsDartFrame()); | 1436 ASSERT(caller_frame->IsDartFrame()); |
1437 const Code& caller_code = | 1437 const Code& caller_code = |
1438 Code::Handle(zone, caller_frame->LookupDartCode()); | 1438 Code::Handle(zone, caller_frame->LookupDartCode()); |
1439 const Code& stub = | 1439 const Code& stub = |
1440 Code::Handle(zone, StubCode::MegamorphicCall_entry()->code()); | 1440 Code::Handle(zone, StubCode::MegamorphicCall_entry()->code()); |
1441 | 1441 |
1442 CodePatcher::PatchSwitchableCallAt(caller_frame->pc(), caller_code, | 1442 CodePatcher::PatchSwitchableCallAt(caller_frame->pc(), caller_code, |
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1662 } | 1662 } |
1663 if (FLAG_stacktrace_every > 0 && (count % FLAG_stacktrace_every) == 0) { | 1663 if (FLAG_stacktrace_every > 0 && (count % FLAG_stacktrace_every) == 0) { |
1664 do_stacktrace = true; | 1664 do_stacktrace = true; |
1665 } | 1665 } |
1666 if ((isolate_reload_every > 0) && (count % isolate_reload_every) == 0) { | 1666 if ((isolate_reload_every > 0) && (count % isolate_reload_every) == 0) { |
1667 do_reload = isolate->CanReload(); | 1667 do_reload = isolate->CanReload(); |
1668 } | 1668 } |
1669 } | 1669 } |
1670 if ((FLAG_deoptimize_filter != NULL) || (FLAG_stacktrace_filter != NULL) || | 1670 if ((FLAG_deoptimize_filter != NULL) || (FLAG_stacktrace_filter != NULL) || |
1671 FLAG_reload_every_optimized) { | 1671 FLAG_reload_every_optimized) { |
1672 DartFrameIterator iterator; | 1672 DartFrameIterator iterator(thread, false); |
1673 StackFrame* frame = iterator.NextFrame(); | 1673 StackFrame* frame = iterator.NextFrame(); |
1674 ASSERT(frame != NULL); | 1674 ASSERT(frame != NULL); |
1675 const Code& code = Code::Handle(frame->LookupDartCode()); | 1675 const Code& code = Code::Handle(frame->LookupDartCode()); |
1676 ASSERT(!code.IsNull()); | 1676 ASSERT(!code.IsNull()); |
1677 const Function& function = Function::Handle(code.function()); | 1677 const Function& function = Function::Handle(code.function()); |
1678 ASSERT(!function.IsNull()); | 1678 ASSERT(!function.IsNull()); |
1679 const char* function_name = function.ToFullyQualifiedCString(); | 1679 const char* function_name = function.ToFullyQualifiedCString(); |
1680 ASSERT(function_name != NULL); | 1680 ASSERT(function_name != NULL); |
1681 if (!code.is_optimized() && FLAG_reload_every_optimized) { | 1681 if (!code.is_optimized() && FLAG_reload_every_optimized) { |
1682 // Don't do the reload if we aren't inside optimized code. | 1682 // 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 } | 1745 } |
1746 | 1746 |
1747 const Error& error = Error::Handle(thread->HandleInterrupts()); | 1747 const Error& error = Error::Handle(thread->HandleInterrupts()); |
1748 if (!error.IsNull()) { | 1748 if (!error.IsNull()) { |
1749 Exceptions::PropagateError(error); | 1749 Exceptions::PropagateError(error); |
1750 UNREACHABLE(); | 1750 UNREACHABLE(); |
1751 } | 1751 } |
1752 | 1752 |
1753 if ((stack_overflow_flags & Thread::kOsrRequest) != 0) { | 1753 if ((stack_overflow_flags & Thread::kOsrRequest) != 0) { |
1754 ASSERT(isolate->use_osr()); | 1754 ASSERT(isolate->use_osr()); |
1755 DartFrameIterator iterator; | 1755 DartFrameIterator iterator(thread, false); |
1756 StackFrame* frame = iterator.NextFrame(); | 1756 StackFrame* frame = iterator.NextFrame(); |
1757 ASSERT(frame != NULL); | 1757 ASSERT(frame != NULL); |
1758 const Code& code = Code::ZoneHandle(frame->LookupDartCode()); | 1758 const Code& code = Code::ZoneHandle(frame->LookupDartCode()); |
1759 ASSERT(!code.IsNull()); | 1759 ASSERT(!code.IsNull()); |
1760 ASSERT(!code.is_optimized()); | 1760 ASSERT(!code.is_optimized()); |
1761 const Function& function = Function::Handle(code.function()); | 1761 const Function& function = Function::Handle(code.function()); |
1762 ASSERT(!function.IsNull()); | 1762 ASSERT(!function.IsNull()); |
1763 | 1763 |
1764 // If the code of the frame does not match the function's unoptimized code, | 1764 // 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. | 1765 // 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); | 1804 frame->set_pc(optimized_entry); |
1805 frame->set_pc_marker(code.raw()); | 1805 frame->set_pc_marker(code.raw()); |
1806 } | 1806 } |
1807 } | 1807 } |
1808 } | 1808 } |
1809 | 1809 |
1810 | 1810 |
1811 DEFINE_RUNTIME_ENTRY(TraceICCall, 2) { | 1811 DEFINE_RUNTIME_ENTRY(TraceICCall, 2) { |
1812 const ICData& ic_data = ICData::CheckedHandle(arguments.ArgAt(0)); | 1812 const ICData& ic_data = ICData::CheckedHandle(arguments.ArgAt(0)); |
1813 const Function& function = Function::CheckedHandle(arguments.ArgAt(1)); | 1813 const Function& function = Function::CheckedHandle(arguments.ArgAt(1)); |
1814 DartFrameIterator iterator; | 1814 DartFrameIterator iterator(thread, false); |
1815 StackFrame* frame = iterator.NextFrame(); | 1815 StackFrame* frame = iterator.NextFrame(); |
1816 ASSERT(frame != NULL); | 1816 ASSERT(frame != NULL); |
1817 OS::PrintErr("IC call @%#" Px ": ICData: %p cnt:%" Pd " nchecks: %" Pd | 1817 OS::PrintErr("IC call @%#" Px ": ICData: %p cnt:%" Pd " nchecks: %" Pd |
1818 " %s\n", | 1818 " %s\n", |
1819 frame->pc(), ic_data.raw(), function.usage_counter(), | 1819 frame->pc(), ic_data.raw(), function.usage_counter(), |
1820 ic_data.NumberOfChecks(), function.ToFullyQualifiedCString()); | 1820 ic_data.NumberOfChecks(), function.ToFullyQualifiedCString()); |
1821 } | 1821 } |
1822 | 1822 |
1823 | 1823 |
1824 // This is called from function that needs to be optimized. | 1824 // 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); | 1884 arguments.SetReturn(function); |
1885 #else | 1885 #else |
1886 UNREACHABLE(); | 1886 UNREACHABLE(); |
1887 #endif // !DART_PRECOMPILED_RUNTIME | 1887 #endif // !DART_PRECOMPILED_RUNTIME |
1888 } | 1888 } |
1889 | 1889 |
1890 | 1890 |
1891 // The caller must be a static call in a Dart frame, or an entry frame. | 1891 // 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. | 1892 // Patch static call to point to valid code's entry point. |
1893 DEFINE_RUNTIME_ENTRY(FixCallersTarget, 0) { | 1893 DEFINE_RUNTIME_ENTRY(FixCallersTarget, 0) { |
1894 StackFrameIterator iterator(StackFrameIterator::kDontValidateFrames); | 1894 StackFrameIterator iterator(StackFrameIterator::kDontValidateFrames, thread, |
| 1895 false); |
1895 StackFrame* frame = iterator.NextFrame(); | 1896 StackFrame* frame = iterator.NextFrame(); |
1896 ASSERT(frame != NULL); | 1897 ASSERT(frame != NULL); |
1897 while (frame->IsStubFrame() || frame->IsExitFrame()) { | 1898 while (frame->IsStubFrame() || frame->IsExitFrame()) { |
1898 frame = iterator.NextFrame(); | 1899 frame = iterator.NextFrame(); |
1899 ASSERT(frame != NULL); | 1900 ASSERT(frame != NULL); |
1900 } | 1901 } |
1901 if (frame->IsEntryFrame()) { | 1902 if (frame->IsEntryFrame()) { |
1902 // Since function's current code is always unpatched, the entry frame always | 1903 // Since function's current code is always unpatched, the entry frame always |
1903 // calls to unpatched code. | 1904 // calls to unpatched code. |
1904 UNREACHABLE(); | 1905 UNREACHABLE(); |
(...skipping 17 matching lines...) Expand all Loading... |
1922 } | 1923 } |
1923 ASSERT(!current_target_code.IsDisabled()); | 1924 ASSERT(!current_target_code.IsDisabled()); |
1924 arguments.SetReturn(current_target_code); | 1925 arguments.SetReturn(current_target_code); |
1925 } | 1926 } |
1926 | 1927 |
1927 | 1928 |
1928 // The caller tried to allocate an instance via an invalidated allocation | 1929 // The caller tried to allocate an instance via an invalidated allocation |
1929 // stub. | 1930 // stub. |
1930 DEFINE_RUNTIME_ENTRY(FixAllocationStubTarget, 0) { | 1931 DEFINE_RUNTIME_ENTRY(FixAllocationStubTarget, 0) { |
1931 #if !defined(DART_PRECOMPILED_RUNTIME) | 1932 #if !defined(DART_PRECOMPILED_RUNTIME) |
1932 StackFrameIterator iterator(StackFrameIterator::kDontValidateFrames); | 1933 StackFrameIterator iterator(StackFrameIterator::kDontValidateFrames, thread, |
| 1934 false); |
1933 StackFrame* frame = iterator.NextFrame(); | 1935 StackFrame* frame = iterator.NextFrame(); |
1934 ASSERT(frame != NULL); | 1936 ASSERT(frame != NULL); |
1935 while (frame->IsStubFrame() || frame->IsExitFrame()) { | 1937 while (frame->IsStubFrame() || frame->IsExitFrame()) { |
1936 frame = iterator.NextFrame(); | 1938 frame = iterator.NextFrame(); |
1937 ASSERT(frame != NULL); | 1939 ASSERT(frame != NULL); |
1938 } | 1940 } |
1939 if (frame->IsEntryFrame()) { | 1941 if (frame->IsEntryFrame()) { |
1940 // There must be a valid Dart frame. | 1942 // There must be a valid Dart frame. |
1941 UNREACHABLE(); | 1943 UNREACHABLE(); |
1942 } | 1944 } |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2050 #endif // !DBC | 2052 #endif // !DBC |
2051 | 2053 |
2052 // Mark code as dead (do not GC its embedded objects). | 2054 // Mark code as dead (do not GC its embedded objects). |
2053 optimized_code.set_is_alive(false); | 2055 optimized_code.set_is_alive(false); |
2054 } | 2056 } |
2055 | 2057 |
2056 | 2058 |
2057 // Currently checks only that all optimized frames have kDeoptIndex | 2059 // Currently checks only that all optimized frames have kDeoptIndex |
2058 // and unoptimized code has the kDeoptAfter. | 2060 // and unoptimized code has the kDeoptAfter. |
2059 void DeoptimizeFunctionsOnStack() { | 2061 void DeoptimizeFunctionsOnStack() { |
2060 DartFrameIterator iterator; | 2062 DartFrameIterator iterator(Thread::Current(), false); |
2061 StackFrame* frame = iterator.NextFrame(); | 2063 StackFrame* frame = iterator.NextFrame(); |
2062 Code& optimized_code = Code::Handle(); | 2064 Code& optimized_code = Code::Handle(); |
2063 while (frame != NULL) { | 2065 while (frame != NULL) { |
2064 optimized_code = frame->LookupDartCode(); | 2066 optimized_code = frame->LookupDartCode(); |
2065 if (optimized_code.is_optimized()) { | 2067 if (optimized_code.is_optimized()) { |
2066 DeoptimizeAt(optimized_code, frame); | 2068 DeoptimizeAt(optimized_code, frame); |
2067 } | 2069 } |
2068 frame = iterator.NextFrame(); | 2070 frame = iterator.NextFrame(); |
2069 } | 2071 } |
2070 } | 2072 } |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2121 StackZone zone(thread); | 2123 StackZone zone(thread); |
2122 HANDLESCOPE(thread); | 2124 HANDLESCOPE(thread); |
2123 | 2125 |
2124 // All registers have been saved below last-fp as if they were locals. | 2126 // All registers have been saved below last-fp as if they were locals. |
2125 const uword last_fp = saved_registers_address + | 2127 const uword last_fp = saved_registers_address + |
2126 (kNumberOfSavedCpuRegisters * kWordSize) + | 2128 (kNumberOfSavedCpuRegisters * kWordSize) + |
2127 (kNumberOfSavedFpuRegisters * kFpuRegisterSize) - | 2129 (kNumberOfSavedFpuRegisters * kFpuRegisterSize) - |
2128 ((kFirstLocalSlotFromFp + 1) * kWordSize); | 2130 ((kFirstLocalSlotFromFp + 1) * kWordSize); |
2129 | 2131 |
2130 // Get optimized code and frame that need to be deoptimized. | 2132 // Get optimized code and frame that need to be deoptimized. |
2131 DartFrameIterator iterator(last_fp); | 2133 DartFrameIterator iterator(last_fp, thread, false); |
2132 | 2134 |
2133 StackFrame* caller_frame = iterator.NextFrame(); | 2135 StackFrame* caller_frame = iterator.NextFrame(); |
2134 ASSERT(caller_frame != NULL); | 2136 ASSERT(caller_frame != NULL); |
2135 const Code& optimized_code = Code::Handle(caller_frame->LookupDartCode()); | 2137 const Code& optimized_code = Code::Handle(caller_frame->LookupDartCode()); |
2136 ASSERT(optimized_code.is_optimized()); | 2138 ASSERT(optimized_code.is_optimized()); |
2137 const Function& top_function = | 2139 const Function& top_function = |
2138 Function::Handle(thread->zone(), optimized_code.function()); | 2140 Function::Handle(thread->zone(), optimized_code.function()); |
2139 const bool deoptimizing_code = top_function.HasOptimizedCode(); | 2141 const bool deoptimizing_code = top_function.HasOptimizedCode(); |
2140 if (FLAG_trace_deoptimization) { | 2142 if (FLAG_trace_deoptimization) { |
2141 const Function& function = Function::Handle(optimized_code.function()); | 2143 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. | 2193 // The stack has been adjusted to fit all values for unoptimized frame. |
2192 // Fill the unoptimized frame. | 2194 // Fill the unoptimized frame. |
2193 DEFINE_LEAF_RUNTIME_ENTRY(void, DeoptimizeFillFrame, 1, uword last_fp) { | 2195 DEFINE_LEAF_RUNTIME_ENTRY(void, DeoptimizeFillFrame, 1, uword last_fp) { |
2194 #if !defined(DART_PRECOMPILED_RUNTIME) | 2196 #if !defined(DART_PRECOMPILED_RUNTIME) |
2195 Thread* thread = Thread::Current(); | 2197 Thread* thread = Thread::Current(); |
2196 Isolate* isolate = thread->isolate(); | 2198 Isolate* isolate = thread->isolate(); |
2197 StackZone zone(thread); | 2199 StackZone zone(thread); |
2198 HANDLESCOPE(thread); | 2200 HANDLESCOPE(thread); |
2199 | 2201 |
2200 DeoptContext* deopt_context = isolate->deopt_context(); | 2202 DeoptContext* deopt_context = isolate->deopt_context(); |
2201 DartFrameIterator iterator(last_fp); | 2203 DartFrameIterator iterator(last_fp, thread, false); |
2202 StackFrame* caller_frame = iterator.NextFrame(); | 2204 StackFrame* caller_frame = iterator.NextFrame(); |
2203 ASSERT(caller_frame != NULL); | 2205 ASSERT(caller_frame != NULL); |
2204 | 2206 |
2205 #if defined(DEBUG) | 2207 #if defined(DEBUG) |
2206 { | 2208 { |
2207 // The code from the deopt_context. | 2209 // The code from the deopt_context. |
2208 const Code& code = Code::Handle(deopt_context->code()); | 2210 const Code& code = Code::Handle(deopt_context->code()); |
2209 | 2211 |
2210 // The code from our frame. | 2212 // The code from our frame. |
2211 const Code& optimized_code = Code::Handle(caller_frame->LookupDartCode()); | 2213 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; | 2327 const intptr_t new_size = 2 * old_size; |
2326 const intptr_t elm_size = old_data.ElementSizeInBytes(); | 2328 const intptr_t elm_size = old_data.ElementSizeInBytes(); |
2327 const TypedData& new_data = | 2329 const TypedData& new_data = |
2328 TypedData::Handle(TypedData::New(cid, new_size, Heap::kOld)); | 2330 TypedData::Handle(TypedData::New(cid, new_size, Heap::kOld)); |
2329 TypedData::Copy(new_data, 0, old_data, 0, old_size * elm_size); | 2331 TypedData::Copy(new_data, 0, old_data, 0, old_size * elm_size); |
2330 typed_data_cell.SetAt(0, new_data); | 2332 typed_data_cell.SetAt(0, new_data); |
2331 arguments.SetReturn(new_data); | 2333 arguments.SetReturn(new_data); |
2332 } | 2334 } |
2333 | 2335 |
2334 } // namespace dart | 2336 } // namespace dart |
OLD | NEW |