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/assembler_macros.h" | 7 #include "vm/assembler_macros.h" |
8 #include "vm/ast.h" | 8 #include "vm/ast.h" |
9 #include "vm/bigint_operations.h" | 9 #include "vm/bigint_operations.h" |
10 #include "vm/code_patcher.h" | 10 #include "vm/code_patcher.h" |
(...skipping 748 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
759 StackFrame* caller_frame = iterator.NextFrame(); | 759 StackFrame* caller_frame = iterator.NextFrame(); |
760 ASSERT(caller_frame != NULL); | 760 ASSERT(caller_frame != NULL); |
761 const Code& caller_code = Code::Handle(caller_frame->LookupDartCode()); | 761 const Code& caller_code = Code::Handle(caller_frame->LookupDartCode()); |
762 ASSERT(!caller_code.IsNull()); | 762 ASSERT(!caller_code.IsNull()); |
763 const Function& target_function = Function::Handle( | 763 const Function& target_function = Function::Handle( |
764 caller_code.GetStaticCallTargetFunctionAt(caller_frame->pc())); | 764 caller_code.GetStaticCallTargetFunctionAt(caller_frame->pc())); |
765 if (!target_function.HasCode()) { | 765 if (!target_function.HasCode()) { |
766 const Error& error = | 766 const Error& error = |
767 Error::Handle(Compiler::CompileFunction(target_function)); | 767 Error::Handle(Compiler::CompileFunction(target_function)); |
768 if (!error.IsNull()) { | 768 if (!error.IsNull()) { |
769 Exceptions::PropagateError(error); | 769 Exceptions::PropagateError(error); |
siva
2012/12/14 18:30:25
PropagateError already has an UNREACHABLE().
regis
2012/12/14 18:49:49
Done.
| |
770 UNREACHABLE(); | |
770 } | 771 } |
771 } | 772 } |
772 const Code& target_code = Code::Handle(target_function.CurrentCode()); | 773 const Code& target_code = Code::Handle(target_function.CurrentCode()); |
773 // Before patching verify that we are not repeatedly patching to the same | 774 // Before patching verify that we are not repeatedly patching to the same |
774 // target. | 775 // target. |
775 ASSERT(target_code.EntryPoint() != | 776 ASSERT(target_code.EntryPoint() != |
776 CodePatcher::GetStaticCallTargetAt(caller_frame->pc())); | 777 CodePatcher::GetStaticCallTargetAt(caller_frame->pc())); |
777 CodePatcher::PatchStaticCallAt(caller_frame->pc(), target_code.EntryPoint()); | 778 CodePatcher::PatchStaticCallAt(caller_frame->pc(), target_code.EntryPoint()); |
778 caller_code.SetStaticCallTargetCodeAt(caller_frame->pc(), target_code); | 779 caller_code.SetStaticCallTargetCodeAt(caller_frame->pc(), target_code); |
779 if (FLAG_trace_patching) { | 780 if (FLAG_trace_patching) { |
(...skipping 24 matching lines...) Expand all Loading... | |
804 function_name, | 805 function_name, |
805 num_arguments, | 806 num_arguments, |
806 num_named_arguments); | 807 num_named_arguments); |
807 if (function.IsNull()) { | 808 if (function.IsNull()) { |
808 return Code::null(); | 809 return Code::null(); |
809 } else { | 810 } else { |
810 if (!function.HasCode()) { | 811 if (!function.HasCode()) { |
811 const Error& error = Error::Handle(Compiler::CompileFunction(function)); | 812 const Error& error = Error::Handle(Compiler::CompileFunction(function)); |
812 if (!error.IsNull()) { | 813 if (!error.IsNull()) { |
813 Exceptions::PropagateError(error); | 814 Exceptions::PropagateError(error); |
815 UNREACHABLE(); | |
814 } | 816 } |
815 } | 817 } |
816 return function.CurrentCode(); | 818 return function.CurrentCode(); |
817 } | 819 } |
818 } | 820 } |
819 | 821 |
820 | 822 |
821 // Result of an invoke may be an unhandled exception, in which case we | 823 // Result of an invoke may be an unhandled exception, in which case we |
822 // rethrow it. | 824 // rethrow it. |
823 static void CheckResultError(const Object& result) { | 825 static void CheckResultError(const Object& result) { |
824 if (result.IsError()) { | 826 if (result.IsError()) { |
825 Exceptions::PropagateError(Error::Cast(result)); | 827 Exceptions::PropagateError(Error::Cast(result)); |
828 UNREACHABLE(); | |
826 } | 829 } |
827 } | 830 } |
828 | 831 |
829 | 832 |
830 // Gets called from debug stub when code reaches a breakpoint. | 833 // Gets called from debug stub when code reaches a breakpoint. |
831 DEFINE_RUNTIME_ENTRY(BreakpointStaticHandler, 0) { | 834 DEFINE_RUNTIME_ENTRY(BreakpointStaticHandler, 0) { |
832 ASSERT(arguments.ArgCount() == | 835 ASSERT(arguments.ArgCount() == |
833 kBreakpointStaticHandlerRuntimeEntry.argument_count()); | 836 kBreakpointStaticHandlerRuntimeEntry.argument_count()); |
834 ASSERT(isolate->debugger() != NULL); | 837 ASSERT(isolate->debugger() != NULL); |
835 isolate->debugger()->SignalBpReached(); | 838 isolate->debugger()->SignalBpReached(); |
836 // Make sure the static function that is about to be called is | 839 // Make sure the static function that is about to be called is |
837 // compiled. The stub will jump to the entry point without any | 840 // compiled. The stub will jump to the entry point without any |
838 // further tests. | 841 // further tests. |
839 DartFrameIterator iterator; | 842 DartFrameIterator iterator; |
840 StackFrame* caller_frame = iterator.NextFrame(); | 843 StackFrame* caller_frame = iterator.NextFrame(); |
841 ASSERT(caller_frame != NULL); | 844 ASSERT(caller_frame != NULL); |
842 const Code& code = Code::Handle(caller_frame->LookupDartCode()); | 845 const Code& code = Code::Handle(caller_frame->LookupDartCode()); |
843 const Function& function = | 846 const Function& function = |
844 Function::Handle(code.GetStaticCallTargetFunctionAt(caller_frame->pc())); | 847 Function::Handle(code.GetStaticCallTargetFunctionAt(caller_frame->pc())); |
845 | 848 |
846 if (!function.HasCode()) { | 849 if (!function.HasCode()) { |
847 const Error& error = Error::Handle(Compiler::CompileFunction(function)); | 850 const Error& error = Error::Handle(Compiler::CompileFunction(function)); |
848 if (!error.IsNull()) { | 851 if (!error.IsNull()) { |
849 Exceptions::PropagateError(error); | 852 Exceptions::PropagateError(error); |
853 UNREACHABLE(); | |
850 } | 854 } |
851 } | 855 } |
852 arguments.SetReturn(Code::ZoneHandle(function.CurrentCode())); | 856 arguments.SetReturn(Code::ZoneHandle(function.CurrentCode())); |
853 } | 857 } |
854 | 858 |
855 | 859 |
856 // Gets called from debug stub when code reaches a breakpoint at a return | 860 // Gets called from debug stub when code reaches a breakpoint at a return |
857 // in Dart code. | 861 // in Dart code. |
858 DEFINE_RUNTIME_ENTRY(BreakpointReturnHandler, 0) { | 862 DEFINE_RUNTIME_ENTRY(BreakpointReturnHandler, 0) { |
859 ASSERT(arguments.ArgCount() == | 863 ASSERT(arguments.ArgCount() == |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1034 arg_count - Smi::Cast(Object::Handle(descriptor.At(1))).Value(); | 1038 arg_count - Smi::Cast(Object::Handle(descriptor.At(1))).Value(); |
1035 const Function& target = Function::Handle( | 1039 const Function& target = Function::Handle( |
1036 Resolver::ResolveDynamicForReceiverClass(cls, | 1040 Resolver::ResolveDynamicForReceiverClass(cls, |
1037 name, | 1041 name, |
1038 arg_count, | 1042 arg_count, |
1039 named_arg_count)); | 1043 named_arg_count)); |
1040 | 1044 |
1041 Instructions& instructions = Instructions::Handle(); | 1045 Instructions& instructions = Instructions::Handle(); |
1042 if (!target.IsNull()) { | 1046 if (!target.IsNull()) { |
1043 if (!target.HasCode()) { | 1047 if (!target.HasCode()) { |
1044 const Error& error = | 1048 const Error& error = Error::Handle(Compiler::CompileFunction(target)); |
1045 Error::Handle(Compiler::CompileFunction(target)); | 1049 if (!error.IsNull()) { |
1046 if (!error.IsNull()) Exceptions::PropagateError(error); | 1050 Exceptions::PropagateError(error); |
1051 UNREACHABLE(); | |
1052 } | |
1047 } | 1053 } |
1048 ASSERT(target.HasCode()); | 1054 ASSERT(target.HasCode()); |
1049 instructions = Code::Handle(target.CurrentCode()).instructions(); | 1055 instructions = Code::Handle(target.CurrentCode()).instructions(); |
1050 } | 1056 } |
1051 arguments.SetReturn(instructions); | 1057 arguments.SetReturn(instructions); |
1052 if (instructions.IsNull()) return; | 1058 if (instructions.IsNull()) return; |
1053 | 1059 |
1054 cache.EnsureCapacity(); | 1060 cache.EnsureCapacity(); |
1055 const Smi& class_id = Smi::Handle(Smi::New(cls.id())); | 1061 const Smi& class_id = Smi::Handle(Smi::New(cls.id())); |
1056 cache.Insert(class_id, target); | 1062 cache.Insert(class_id, target); |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1209 } | 1215 } |
1210 | 1216 |
1211 current_class = current_class.SuperClass(); | 1217 current_class = current_class.SuperClass(); |
1212 } while (!current_class.IsNull()); | 1218 } while (!current_class.IsNull()); |
1213 | 1219 |
1214 const Object& null_object = Object::Handle(); | 1220 const Object& null_object = Object::Handle(); |
1215 GrowableArray<const Object*> dart_arguments(5); | 1221 GrowableArray<const Object*> dart_arguments(5); |
1216 dart_arguments.Add(&receiver); | 1222 dart_arguments.Add(&receiver); |
1217 dart_arguments.Add(&call_symbol); | 1223 dart_arguments.Add(&call_symbol); |
1218 dart_arguments.Add(&arguments); | 1224 dart_arguments.Add(&arguments); |
1219 dart_arguments.Add(&null_object); | 1225 dart_arguments.Add(&null_object); // TODO(regis): Provide names. |
1220 // If a function "call" with different arguments exists, it will have been | 1226 // If a function "call" with different arguments exists, it will have been |
1221 // invoked above, so no need to handle this case here. | 1227 // invoked above, so no need to handle this case here. |
1222 Exceptions::ThrowByType(Exceptions::kNoSuchMethod, dart_arguments); | 1228 Exceptions::ThrowByType(Exceptions::kNoSuchMethod, dart_arguments); |
1223 UNREACHABLE(); | 1229 UNREACHABLE(); |
1224 return Object::null(); | 1230 return Object::null(); |
1225 } | 1231 } |
1226 | 1232 |
1227 | 1233 |
1228 // An instance call of the form o.f(...) could not be resolved. Check if | 1234 // An instance call of the form o.f(...) could not be resolved. Check if |
1229 // there is a getter with the same name. If so, invoke it. If the value is | 1235 // there is a getter with the same name. If so, invoke it. If the value is |
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1531 (strstr(function.ToFullyQualifiedCString(), | 1537 (strstr(function.ToFullyQualifiedCString(), |
1532 FLAG_optimization_filter) == NULL)) { | 1538 FLAG_optimization_filter) == NULL)) { |
1533 function.set_usage_counter(kLowInvocationCount); | 1539 function.set_usage_counter(kLowInvocationCount); |
1534 return; | 1540 return; |
1535 } | 1541 } |
1536 if (function.is_optimizable()) { | 1542 if (function.is_optimizable()) { |
1537 const Error& error = | 1543 const Error& error = |
1538 Error::Handle(Compiler::CompileOptimizedFunction(function)); | 1544 Error::Handle(Compiler::CompileOptimizedFunction(function)); |
1539 if (!error.IsNull()) { | 1545 if (!error.IsNull()) { |
1540 Exceptions::PropagateError(error); | 1546 Exceptions::PropagateError(error); |
1547 UNREACHABLE(); | |
1541 } | 1548 } |
1542 const Code& optimized_code = Code::Handle(function.CurrentCode()); | 1549 const Code& optimized_code = Code::Handle(function.CurrentCode()); |
1543 ASSERT(!optimized_code.IsNull()); | 1550 ASSERT(!optimized_code.IsNull()); |
1544 // Set usage counter for reoptimization. | 1551 // Set usage counter for reoptimization. |
1545 function.set_usage_counter( | 1552 function.set_usage_counter( |
1546 function.usage_counter() - FLAG_reoptimization_counter_threshold); | 1553 function.usage_counter() - FLAG_reoptimization_counter_threshold); |
1547 } else { | 1554 } else { |
1548 if (FLAG_trace_failed_optimization_attempts) { | 1555 if (FLAG_trace_failed_optimization_attempts) { |
1549 PrintCaller("Not Optimizable"); | 1556 PrintCaller("Not Optimizable"); |
1550 } | 1557 } |
(...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1940 Isolate* isolate = Isolate::Current(); | 1947 Isolate* isolate = Isolate::Current(); |
1941 StackZone zone(isolate); | 1948 StackZone zone(isolate); |
1942 HANDLESCOPE(isolate); | 1949 HANDLESCOPE(isolate); |
1943 const Bigint& big_left = Bigint::Handle(left); | 1950 const Bigint& big_left = Bigint::Handle(left); |
1944 const Bigint& big_right = Bigint::Handle(right); | 1951 const Bigint& big_right = Bigint::Handle(right); |
1945 return BigintOperations::Compare(big_left, big_right); | 1952 return BigintOperations::Compare(big_left, big_right); |
1946 } | 1953 } |
1947 END_LEAF_RUNTIME_ENTRY | 1954 END_LEAF_RUNTIME_ENTRY |
1948 | 1955 |
1949 } // namespace dart | 1956 } // namespace dart |
OLD | NEW |