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/bigint_operations.h" | 9 #include "vm/bigint_operations.h" |
10 #include "vm/code_patcher.h" | 10 #include "vm/code_patcher.h" |
(...skipping 783 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
794 } | 794 } |
795 | 795 |
796 | 796 |
797 // Resolves and compiles the target function of an instance call, updates | 797 // Resolves and compiles the target function of an instance call, updates |
798 // function cache of the receiver's class and returns the compiled code or null. | 798 // function cache of the receiver's class and returns the compiled code or null. |
799 // Only the number of named arguments is checked, but not the actual names. | 799 // Only the number of named arguments is checked, but not the actual names. |
800 RawCode* ResolveCompileInstanceCallTarget(const Instance& receiver, | 800 RawCode* ResolveCompileInstanceCallTarget(const Instance& receiver, |
801 const ICData& ic_data) { | 801 const ICData& ic_data) { |
802 ArgumentsDescriptor | 802 ArgumentsDescriptor |
803 arguments_descriptor(Array::Handle(ic_data.arguments_descriptor())); | 803 arguments_descriptor(Array::Handle(ic_data.arguments_descriptor())); |
804 intptr_t num_arguments = arguments_descriptor.Count(); | |
805 int num_named_arguments = arguments_descriptor.NamedCount(); | |
806 String& function_name = String::Handle(ic_data.target_name()); | 804 String& function_name = String::Handle(ic_data.target_name()); |
807 ASSERT(function_name.IsSymbol()); | 805 ASSERT(function_name.IsSymbol()); |
808 | 806 |
809 Function& function = Function::Handle(); | 807 Function& function = Function::Handle(); |
810 function = Resolver::ResolveDynamic(receiver, | 808 function = Resolver::ResolveDynamic(receiver, |
811 function_name, | 809 function_name, |
812 num_arguments, | 810 arguments_descriptor); |
813 num_named_arguments); | |
814 if (function.IsNull()) { | 811 if (function.IsNull()) { |
815 return Code::null(); | 812 return Code::null(); |
816 } else { | 813 } else { |
817 if (!function.HasCode()) { | 814 if (!function.HasCode()) { |
818 const Error& error = Error::Handle(Compiler::CompileFunction(function)); | 815 const Error& error = Error::Handle(Compiler::CompileFunction(function)); |
819 if (!error.IsNull()) { | 816 if (!error.IsNull()) { |
820 Exceptions::PropagateError(error); | 817 Exceptions::PropagateError(error); |
821 } | 818 } |
822 } | 819 } |
823 return function.CurrentCode(); | 820 return function.CurrentCode(); |
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1056 // For lookups treat null as an instance of class Object. | 1053 // For lookups treat null as an instance of class Object. |
1057 if (is_null) { | 1054 if (is_null) { |
1058 cls = isolate->object_store()->object_class(); | 1055 cls = isolate->object_store()->object_class(); |
1059 } | 1056 } |
1060 ASSERT(!cls.IsNull()); | 1057 ASSERT(!cls.IsNull()); |
1061 if (FLAG_trace_ic || FLAG_trace_ic_miss_in_optimized) { | 1058 if (FLAG_trace_ic || FLAG_trace_ic_miss_in_optimized) { |
1062 OS::PrintErr("Megamorphic IC miss, class=%s, function=%s\n", | 1059 OS::PrintErr("Megamorphic IC miss, class=%s, function=%s\n", |
1063 cls.ToCString(), name.ToCString()); | 1060 cls.ToCString(), name.ToCString()); |
1064 } | 1061 } |
1065 | 1062 |
1066 intptr_t arg_count = | 1063 ArgumentsDescriptor args_desc(descriptor); |
1067 Smi::Cast(Object::Handle(descriptor.At(0))).Value(); | |
1068 intptr_t named_arg_count = | |
1069 arg_count - Smi::Cast(Object::Handle(descriptor.At(1))).Value(); | |
1070 const Function& target = Function::Handle( | 1064 const Function& target = Function::Handle( |
1071 Resolver::ResolveDynamicForReceiverClass(cls, | 1065 Resolver::ResolveDynamicForReceiverClass(cls, |
1072 name, | 1066 name, |
1073 arg_count, | 1067 args_desc)); |
1074 named_arg_count)); | |
1075 | 1068 |
1076 Instructions& instructions = Instructions::Handle(); | 1069 Instructions& instructions = Instructions::Handle(); |
1077 if (!target.IsNull()) { | 1070 if (!target.IsNull()) { |
1078 if (!target.HasCode()) { | 1071 if (!target.HasCode()) { |
1079 const Error& error = Error::Handle(Compiler::CompileFunction(target)); | 1072 const Error& error = Error::Handle(Compiler::CompileFunction(target)); |
1080 if (!error.IsNull()) { | 1073 if (!error.IsNull()) { |
1081 Exceptions::PropagateError(error); | 1074 Exceptions::PropagateError(error); |
1082 } | 1075 } |
1083 } | 1076 } |
1084 ASSERT(target.HasCode()); | 1077 ASSERT(target.HasCode()); |
(...skipping 20 matching lines...) Expand all Loading... |
1105 ASSERT(arguments.ArgCount() == | 1098 ASSERT(arguments.ArgCount() == |
1106 kUpdateICDataTwoArgsRuntimeEntry.argument_count()); | 1099 kUpdateICDataTwoArgsRuntimeEntry.argument_count()); |
1107 const Instance& receiver = Instance::CheckedHandle(arguments.ArgAt(0)); | 1100 const Instance& receiver = Instance::CheckedHandle(arguments.ArgAt(0)); |
1108 const Instance& arg1 = Instance::CheckedHandle(arguments.ArgAt(1)); | 1101 const Instance& arg1 = Instance::CheckedHandle(arguments.ArgAt(1)); |
1109 const String& target_name = String::CheckedHandle(arguments.ArgAt(2)); | 1102 const String& target_name = String::CheckedHandle(arguments.ArgAt(2)); |
1110 const ICData& ic_data = ICData::CheckedHandle(arguments.ArgAt(3)); | 1103 const ICData& ic_data = ICData::CheckedHandle(arguments.ArgAt(3)); |
1111 GrowableArray<const Instance*> args(2); | 1104 GrowableArray<const Instance*> args(2); |
1112 args.Add(&receiver); | 1105 args.Add(&receiver); |
1113 args.Add(&arg1); | 1106 args.Add(&arg1); |
1114 const intptr_t kNumArguments = 2; | 1107 const intptr_t kNumArguments = 2; |
1115 const intptr_t kNumNamedArguments = 0; | 1108 ArgumentsDescriptor args_desc( |
1116 Function& target_function = Function::Handle(); | 1109 Array::Handle(ArgumentsDescriptor::New(kNumArguments))); |
1117 target_function = Resolver::ResolveDynamic(receiver, | 1110 const Function& target_function = Function::Handle( |
1118 target_name, | 1111 Resolver::ResolveDynamic(receiver, |
1119 kNumArguments, | 1112 target_name, |
1120 kNumNamedArguments); | 1113 args_desc)); |
1121 ASSERT(!target_function.IsNull()); | 1114 ASSERT(!target_function.IsNull()); |
1122 GrowableArray<intptr_t> class_ids(kNumArguments); | 1115 GrowableArray<intptr_t> class_ids(kNumArguments); |
1123 ASSERT(ic_data.num_args_tested() == kNumArguments); | 1116 ASSERT(ic_data.num_args_tested() == kNumArguments); |
1124 class_ids.Add(receiver.GetClassId()); | 1117 class_ids.Add(receiver.GetClassId()); |
1125 class_ids.Add(arg1.GetClassId()); | 1118 class_ids.Add(arg1.GetClassId()); |
1126 ic_data.AddCheck(class_ids, target_function); | 1119 ic_data.AddCheck(class_ids, target_function); |
1127 } | 1120 } |
1128 | 1121 |
1129 | 1122 |
1130 // Invoke appropriate noSuchMethod function. | 1123 // Invoke appropriate noSuchMethod function. |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1182 static bool ResolveCallThroughGetter(const Instance& receiver, | 1175 static bool ResolveCallThroughGetter(const Instance& receiver, |
1183 const Class& receiver_class, | 1176 const Class& receiver_class, |
1184 const String& target_name, | 1177 const String& target_name, |
1185 const Array& arguments_descriptor, | 1178 const Array& arguments_descriptor, |
1186 const Array& arguments, | 1179 const Array& arguments, |
1187 const ICData& ic_data, | 1180 const ICData& ic_data, |
1188 Object* result) { | 1181 Object* result) { |
1189 // 1. Check if there is a getter with the same name. | 1182 // 1. Check if there is a getter with the same name. |
1190 const String& getter_name = String::Handle(Field::GetterName(target_name)); | 1183 const String& getter_name = String::Handle(Field::GetterName(target_name)); |
1191 const int kNumArguments = 1; | 1184 const int kNumArguments = 1; |
1192 const int kNumNamedArguments = 0; | 1185 ArgumentsDescriptor args_desc( |
| 1186 Array::Handle(ArgumentsDescriptor::New(kNumArguments))); |
1193 const Function& getter = Function::Handle( | 1187 const Function& getter = Function::Handle( |
1194 Resolver::ResolveDynamicForReceiverClass(receiver_class, | 1188 Resolver::ResolveDynamicForReceiverClass(receiver_class, |
1195 getter_name, | 1189 getter_name, |
1196 kNumArguments, | 1190 args_desc)); |
1197 kNumNamedArguments)); | |
1198 if (getter.IsNull() || getter.IsMethodExtractor()) { | 1191 if (getter.IsNull() || getter.IsMethodExtractor()) { |
1199 return false; | 1192 return false; |
1200 } | 1193 } |
1201 | 1194 |
1202 const Function& target_function = | 1195 const Function& target_function = |
1203 Function::Handle(receiver_class.GetInvocationDispatcher( | 1196 Function::Handle(receiver_class.GetInvocationDispatcher( |
1204 target_name, | 1197 target_name, |
1205 arguments_descriptor, | 1198 arguments_descriptor, |
1206 RawFunction::kInvokeFieldDispatcher)); | 1199 RawFunction::kInvokeFieldDispatcher)); |
1207 // Update IC data. | 1200 // Update IC data. |
(...skipping 683 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1891 // Arg1: Value that is being stored. | 1884 // Arg1: Value that is being stored. |
1892 DEFINE_RUNTIME_ENTRY(UpdateFieldCid, 2) { | 1885 DEFINE_RUNTIME_ENTRY(UpdateFieldCid, 2) { |
1893 ASSERT(arguments.ArgCount() == kUpdateFieldCidRuntimeEntry.argument_count()); | 1886 ASSERT(arguments.ArgCount() == kUpdateFieldCidRuntimeEntry.argument_count()); |
1894 const Field& field = Field::CheckedHandle(arguments.ArgAt(0)); | 1887 const Field& field = Field::CheckedHandle(arguments.ArgAt(0)); |
1895 const Object& value = Object::Handle(arguments.ArgAt(1)); | 1888 const Object& value = Object::Handle(arguments.ArgAt(1)); |
1896 | 1889 |
1897 field.UpdateCid(value.GetClassId()); | 1890 field.UpdateCid(value.GetClassId()); |
1898 } | 1891 } |
1899 | 1892 |
1900 } // namespace dart | 1893 } // namespace dart |
OLD | NEW |