OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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/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 636 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
647 | 647 |
648 // Result of an invoke may be an unhandled exception, in which case we | 648 // Result of an invoke may be an unhandled exception, in which case we |
649 // rethrow it. | 649 // rethrow it. |
650 static void CheckResultError(const Object& result) { | 650 static void CheckResultError(const Object& result) { |
651 if (result.IsError()) { | 651 if (result.IsError()) { |
652 Exceptions::PropagateError(Error::Cast(result)); | 652 Exceptions::PropagateError(Error::Cast(result)); |
653 } | 653 } |
654 } | 654 } |
655 | 655 |
656 | 656 |
| 657 #if !defined(TARGET_ARCH_DBC) |
657 // Gets called from debug stub when code reaches a breakpoint | 658 // Gets called from debug stub when code reaches a breakpoint |
658 // set on a runtime stub call. | 659 // set on a runtime stub call. |
659 DEFINE_RUNTIME_ENTRY(BreakpointRuntimeHandler, 0) { | 660 DEFINE_RUNTIME_ENTRY(BreakpointRuntimeHandler, 0) { |
660 if (!FLAG_support_debugger) { | 661 if (!FLAG_support_debugger) { |
661 UNREACHABLE(); | 662 UNREACHABLE(); |
662 return; | 663 return; |
663 } | 664 } |
664 DartFrameIterator iterator; | 665 DartFrameIterator iterator; |
665 StackFrame* caller_frame = iterator.NextFrame(); | 666 StackFrame* caller_frame = iterator.NextFrame(); |
666 ASSERT(caller_frame != NULL); | 667 ASSERT(caller_frame != NULL); |
667 const Code& orig_stub = Code::Handle( | 668 const Code& orig_stub = Code::Handle( |
668 zone, isolate->debugger()->GetPatchedStubAddress(caller_frame->pc())); | 669 zone, isolate->debugger()->GetPatchedStubAddress(caller_frame->pc())); |
669 const Error& error = | 670 const Error& error = |
670 Error::Handle(zone, isolate->debugger()->SignalBpReached()); | 671 Error::Handle(zone, isolate->debugger()->SignalBpReached()); |
671 if (!error.IsNull()) { | 672 if (!error.IsNull()) { |
672 Exceptions::PropagateError(error); | 673 Exceptions::PropagateError(error); |
673 UNREACHABLE(); | 674 UNREACHABLE(); |
674 } | 675 } |
675 arguments.SetReturn(orig_stub); | 676 arguments.SetReturn(orig_stub); |
676 } | 677 } |
| 678 #else |
| 679 // Gets called from the simulator when the breakpoint is reached. |
| 680 DEFINE_RUNTIME_ENTRY(BreakpointRuntimeHandler, 0) { |
| 681 if (!FLAG_support_debugger) { |
| 682 UNREACHABLE(); |
| 683 return; |
| 684 } |
| 685 const Error& error = Error::Handle(isolate->debugger()->SignalBpReached()); |
| 686 if (!error.IsNull()) { |
| 687 Exceptions::PropagateError(error); |
| 688 UNREACHABLE(); |
| 689 } |
| 690 } |
| 691 #endif // !defined(TARGET_ARCH_DBC) |
677 | 692 |
678 | 693 |
679 DEFINE_RUNTIME_ENTRY(SingleStepHandler, 0) { | 694 DEFINE_RUNTIME_ENTRY(SingleStepHandler, 0) { |
680 if (!FLAG_support_debugger) { | 695 if (!FLAG_support_debugger) { |
681 UNREACHABLE(); | 696 UNREACHABLE(); |
682 return; | 697 return; |
683 } | 698 } |
684 const Error& error = | 699 const Error& error = |
685 Error::Handle(zone, isolate->debugger()->DebuggerStepCallback()); | 700 Error::Handle(zone, isolate->debugger()->DebuggerStepCallback()); |
686 if (!error.IsNull()) { | 701 if (!error.IsNull()) { |
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
949 arguments.SetReturn(target); | 964 arguments.SetReturn(target); |
950 } | 965 } |
951 | 966 |
952 | 967 |
953 // Handle a miss of a megamorphic cache. | 968 // Handle a miss of a megamorphic cache. |
954 // Arg0: Receiver. | 969 // Arg0: Receiver. |
955 // Arg1: ICData or MegamorphicCache. | 970 // Arg1: ICData or MegamorphicCache. |
956 // Arg2: Arguments descriptor array. | 971 // Arg2: Arguments descriptor array. |
957 // Returns: target function to call. | 972 // Returns: target function to call. |
958 DEFINE_RUNTIME_ENTRY(MegamorphicCacheMissHandler, 3) { | 973 DEFINE_RUNTIME_ENTRY(MegamorphicCacheMissHandler, 3) { |
| 974 // DBC does not use megamorphic calls right now. |
| 975 #if !defined(TARGET_ARCH_DBC) |
959 const Instance& receiver = Instance::CheckedHandle(zone, arguments.ArgAt(0)); | 976 const Instance& receiver = Instance::CheckedHandle(zone, arguments.ArgAt(0)); |
960 const Object& ic_data_or_cache = Object::Handle(zone, arguments.ArgAt(1)); | 977 const Object& ic_data_or_cache = Object::Handle(zone, arguments.ArgAt(1)); |
961 const Array& descriptor = Array::CheckedHandle(zone, arguments.ArgAt(2)); | 978 const Array& descriptor = Array::CheckedHandle(zone, arguments.ArgAt(2)); |
962 String& name = String::Handle(zone); | 979 String& name = String::Handle(zone); |
963 if (ic_data_or_cache.IsICData()) { | 980 if (ic_data_or_cache.IsICData()) { |
964 name = ICData::Cast(ic_data_or_cache).target_name(); | 981 name = ICData::Cast(ic_data_or_cache).target_name(); |
965 } else { | 982 } else { |
966 ASSERT(ic_data_or_cache.IsMegamorphicCache()); | 983 ASSERT(ic_data_or_cache.IsMegamorphicCache()); |
967 name = MegamorphicCache::Cast(ic_data_or_cache).target_name(); | 984 name = MegamorphicCache::Cast(ic_data_or_cache).target_name(); |
968 } | 985 } |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1006 code, ic_data, cache, stub); | 1023 code, ic_data, cache, stub); |
1007 } | 1024 } |
1008 } else { | 1025 } else { |
1009 const MegamorphicCache& cache = MegamorphicCache::Cast(ic_data_or_cache); | 1026 const MegamorphicCache& cache = MegamorphicCache::Cast(ic_data_or_cache); |
1010 // Insert function found into cache and return it. | 1027 // Insert function found into cache and return it. |
1011 cache.EnsureCapacity(); | 1028 cache.EnsureCapacity(); |
1012 const Smi& class_id = Smi::Handle(zone, Smi::New(cls.id())); | 1029 const Smi& class_id = Smi::Handle(zone, Smi::New(cls.id())); |
1013 cache.Insert(class_id, target_function); | 1030 cache.Insert(class_id, target_function); |
1014 } | 1031 } |
1015 arguments.SetReturn(target_function); | 1032 arguments.SetReturn(target_function); |
| 1033 #else |
| 1034 UNREACHABLE(); |
| 1035 #endif // !defined(TARGET_ARCH_DBC) |
1016 } | 1036 } |
1017 | 1037 |
1018 | 1038 |
1019 // Invoke appropriate noSuchMethod or closure from getter. | 1039 // Invoke appropriate noSuchMethod or closure from getter. |
1020 // Arg0: receiver | 1040 // Arg0: receiver |
1021 // Arg1: ICData or MegamorphicCache | 1041 // Arg1: ICData or MegamorphicCache |
1022 // Arg2: arguments descriptor array | 1042 // Arg2: arguments descriptor array |
1023 // Arg3: arguments array | 1043 // Arg3: arguments array |
1024 DEFINE_RUNTIME_ENTRY(InvokeNoSuchMethodDispatcher, 4) { | 1044 DEFINE_RUNTIME_ENTRY(InvokeNoSuchMethodDispatcher, 4) { |
1025 ASSERT(!FLAG_lazy_dispatchers); | 1045 ASSERT(!FLAG_lazy_dispatchers); |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1185 original_function_name, | 1205 original_function_name, |
1186 orig_arguments, | 1206 orig_arguments, |
1187 orig_arguments_desc)); | 1207 orig_arguments_desc)); |
1188 CheckResultError(result); | 1208 CheckResultError(result); |
1189 arguments.SetReturn(result); | 1209 arguments.SetReturn(result); |
1190 } | 1210 } |
1191 | 1211 |
1192 | 1212 |
1193 DEFINE_RUNTIME_ENTRY(StackOverflow, 0) { | 1213 DEFINE_RUNTIME_ENTRY(StackOverflow, 0) { |
1194 #if defined(USING_SIMULATOR) | 1214 #if defined(USING_SIMULATOR) |
1195 uword stack_pos = Simulator::Current()->get_register(SPREG); | 1215 uword stack_pos = Simulator::Current()->get_sp(); |
1196 #else | 1216 #else |
1197 uword stack_pos = Thread::GetCurrentStackPointer(); | 1217 uword stack_pos = Thread::GetCurrentStackPointer(); |
1198 #endif | 1218 #endif |
1199 // Always clear the stack overflow flags. They are meant for this | 1219 // Always clear the stack overflow flags. They are meant for this |
1200 // particular stack overflow runtime call and are not meant to | 1220 // particular stack overflow runtime call and are not meant to |
1201 // persist. | 1221 // persist. |
1202 uword stack_overflow_flags = thread->GetAndClearStackOverflowFlags(); | 1222 uword stack_overflow_flags = thread->GetAndClearStackOverflowFlags(); |
1203 | 1223 |
1204 // If an interrupt happens at the same time as a stack overflow, we | 1224 // If an interrupt happens at the same time as a stack overflow, we |
1205 // process the stack overflow now and leave the interrupt for next | 1225 // process the stack overflow now and leave the interrupt for next |
1206 // time. | 1226 // time. |
1207 if (stack_pos < thread->saved_stack_limit()) { | 1227 if (IsCalleeFrameOf(thread->saved_stack_limit(), stack_pos)) { |
1208 // Use the preallocated stack overflow exception to avoid calling | 1228 // Use the preallocated stack overflow exception to avoid calling |
1209 // into dart code. | 1229 // into dart code. |
1210 const Instance& exception = | 1230 const Instance& exception = |
1211 Instance::Handle(isolate->object_store()->stack_overflow()); | 1231 Instance::Handle(isolate->object_store()->stack_overflow()); |
1212 Exceptions::Throw(thread, exception); | 1232 Exceptions::Throw(thread, exception); |
1213 UNREACHABLE(); | 1233 UNREACHABLE(); |
1214 } | 1234 } |
1215 | 1235 |
1216 // The following code is used to stress test deoptimization and | 1236 // The following code is used to stress test deoptimization and |
1217 // debugger stack tracing. | 1237 // debugger stack tracing. |
(...skipping 600 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1818 const intptr_t elm_size = old_data.ElementSizeInBytes(); | 1838 const intptr_t elm_size = old_data.ElementSizeInBytes(); |
1819 const TypedData& new_data = | 1839 const TypedData& new_data = |
1820 TypedData::Handle(TypedData::New(cid, new_size, Heap::kOld)); | 1840 TypedData::Handle(TypedData::New(cid, new_size, Heap::kOld)); |
1821 TypedData::Copy(new_data, 0, old_data, 0, old_size * elm_size); | 1841 TypedData::Copy(new_data, 0, old_data, 0, old_size * elm_size); |
1822 typed_data_cell.SetAt(0, new_data); | 1842 typed_data_cell.SetAt(0, new_data); |
1823 arguments.SetReturn(new_data); | 1843 arguments.SetReturn(new_data); |
1824 } | 1844 } |
1825 | 1845 |
1826 | 1846 |
1827 } // namespace dart | 1847 } // namespace dart |
OLD | NEW |