Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(170)

Side by Side Diff: runtime/vm/code_generator.cc

Issue 17571010: Reland: Optimizing noSuchMethod invocation with no arguments. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/vm/class_finalizer.cc ('k') | runtime/vm/debugger.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 860 matching lines...) Expand 10 before | Expand all | Expand 10 after
871 const GrowableArray<const Instance*>& args, 871 const GrowableArray<const Instance*>& args,
872 const ICData& ic_data, 872 const ICData& ic_data,
873 const Array& args_descriptor_array) { 873 const Array& args_descriptor_array) {
874 const Instance& receiver = *args[0]; 874 const Instance& receiver = *args[0];
875 const Code& target_code = 875 const Code& target_code =
876 Code::Handle(ResolveCompileInstanceCallTarget(receiver, ic_data)); 876 Code::Handle(ResolveCompileInstanceCallTarget(receiver, ic_data));
877 if (target_code.IsNull()) { 877 if (target_code.IsNull()) {
878 // Let the megamorphic stub handle special cases: NoSuchMethod, 878 // Let the megamorphic stub handle special cases: NoSuchMethod,
879 // closure calls. 879 // closure calls.
880 if (FLAG_trace_ic) { 880 if (FLAG_trace_ic) {
881 OS::PrintErr("InlineCacheMissHandler NULL code for receiver: %s\n", 881 OS::PrintErr("InlineCacheMissHandler NULL code for %s receiver: %s\n",
882 receiver.ToCString()); 882 String::Handle(ic_data.target_name()).ToCString(),
883 receiver.ToCString());
883 } 884 }
884 return Function::null(); 885 return Function::null();
885 } 886 }
886 const Function& target_function = 887 const Function& target_function =
887 Function::Handle(target_code.function()); 888 Function::Handle(target_code.function());
888 ASSERT(!target_function.IsNull()); 889 ASSERT(!target_function.IsNull());
889 if (args.length() == 1) { 890 if (args.length() == 1) {
890 ic_data.AddReceiverCheck(args[0]->GetClassId(), target_function); 891 ic_data.AddReceiverCheck(args[0]->GetClassId(), target_function);
891 } else { 892 } else {
892 GrowableArray<intptr_t> class_ids(args.length()); 893 GrowableArray<intptr_t> class_ids(args.length());
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after
1147 Object* result) { 1148 Object* result) {
1148 // 1. Check if there is a getter with the same name. 1149 // 1. Check if there is a getter with the same name.
1149 const String& getter_name = String::Handle(Field::GetterName(target_name)); 1150 const String& getter_name = String::Handle(Field::GetterName(target_name));
1150 const int kNumArguments = 1; 1151 const int kNumArguments = 1;
1151 const int kNumNamedArguments = 0; 1152 const int kNumNamedArguments = 0;
1152 const Function& getter = Function::Handle( 1153 const Function& getter = Function::Handle(
1153 Resolver::ResolveDynamicForReceiverClass(receiver_class, 1154 Resolver::ResolveDynamicForReceiverClass(receiver_class,
1154 getter_name, 1155 getter_name,
1155 kNumArguments, 1156 kNumArguments,
1156 kNumNamedArguments)); 1157 kNumNamedArguments));
1157 if (getter.IsNull() || getter.IsMethodExtractor()) { 1158 if (getter.IsNull() ||
1159 getter.IsMethodExtractor() ||
1160 getter.IsNoSuchMethodDispatcher()) {
1158 return false; 1161 return false;
1159 } 1162 }
1160 1163
1161 // 2. Invoke the getter. 1164 // 2. Invoke the getter.
1162 const Array& args = Array::Handle(Array::New(kNumArguments)); 1165 const Array& args = Array::Handle(Array::New(kNumArguments));
1163 args.SetAt(0, receiver); 1166 args.SetAt(0, receiver);
1164 const Object& value = Object::Handle(DartEntry::InvokeFunction(getter, args)); 1167 const Object& value = Object::Handle(DartEntry::InvokeFunction(getter, args));
1165 1168
1166 // 3. If the getter threw an exception, treat it as no such method. 1169 // 3. If the getter threw an exception, treat it as no such method.
1167 if (value.IsUnhandledException()) return false; 1170 if (value.IsUnhandledException()) return false;
1168 1171
1169 // 4. If there was some other error, propagate it. 1172 // 4. If there was some other error, propagate it.
1170 CheckResultError(value); 1173 CheckResultError(value);
1171 1174
1172 // 5. Invoke the value as a closure. 1175 // 5. Invoke the value as a closure.
1173 Instance& instance = Instance::Handle(); 1176 Instance& instance = Instance::Handle();
1174 instance ^= value.raw(); 1177 instance ^= value.raw();
1175 arguments.SetAt(0, instance); 1178 arguments.SetAt(0, instance);
1176 *result = DartEntry::InvokeClosure(arguments, arguments_descriptor); 1179 *result = DartEntry::InvokeClosure(arguments, arguments_descriptor);
1177 CheckResultError(*result); 1180 CheckResultError(*result);
1178 return true; 1181 return true;
1179 } 1182 }
1180 1183
1181 1184
1185 // Create a method for noSuchMethod invocation and attach it to the receiver
1186 // class.
1187 static RawFunction* CreateNoSuchMethodDispatcher(
1188 const String& target_name,
1189 const Class& receiver_class,
1190 const Array& arguments_descriptor) {
1191 Function& invocation = Function::Handle(
1192 Function::New(String::Handle(Symbols::New(target_name)),
1193 RawFunction::kNoSuchMethodDispatcher,
1194 false, // Not static.
1195 false, // Not const.
1196 false, // Not abstract.
1197 false, // Not external.
1198 receiver_class,
1199 0)); // No token position.
1200
1201 // Initialize signature: receiver is a single fixed parameter.
1202 const intptr_t kNumParameters = 1;
1203 invocation.set_num_fixed_parameters(kNumParameters);
1204 invocation.SetNumOptionalParameters(0, 0);
1205 invocation.set_parameter_types(Array::Handle(Array::New(kNumParameters,
1206 Heap::kOld)));
1207 invocation.set_parameter_names(Array::Handle(Array::New(kNumParameters,
1208 Heap::kOld)));
1209 invocation.SetParameterTypeAt(0, Type::Handle(Type::DynamicType()));
1210 invocation.SetParameterNameAt(0, Symbols::This());
1211 invocation.set_result_type(Type::Handle(Type::DynamicType()));
1212 invocation.set_is_visible(false); // Not visible in stack trace.
1213
1214 receiver_class.AddFunction(invocation);
1215
1216 return invocation.raw();
1217 }
1218
1219
1182 // The IC miss handler has failed to find a (cacheable) instance function to 1220 // The IC miss handler has failed to find a (cacheable) instance function to
1183 // invoke. Handle three possibilities: 1221 // invoke. Handle three possibilities:
1184 // 1222 //
1185 // 1. If the call was a getter o.f, there may be an instance function with 1223 // 1. If the call was a getter o.f, there may be an instance function with
1186 // the same name. If so, create an implicit closure and return it. 1224 // the same name. If so, create an implicit closure and return it.
1187 // 1225 //
1188 // 2. If the call was an instance call o.f(...), there may be a getter with 1226 // 2. If the call was an instance call o.f(...), there may be a getter with
1189 // the same name. If so, invoke it. If the value is a closure, invoke 1227 // the same name. If so, invoke it. If the value is a closure, invoke
1190 // it with the given arguments. If the value is a non-closure, attempt 1228 // it with the given arguments. If the value is a non-closure, attempt
1191 // to invoke "call" on it. 1229 // to invoke "call" on it.
(...skipping 14 matching lines...) Expand all
1206 } 1244 }
1207 const String& target_name = String::Handle(ic_data.target_name()); 1245 const String& target_name = String::Handle(ic_data.target_name());
1208 1246
1209 Object& result = Object::Handle(); 1247 Object& result = Object::Handle();
1210 if (!ResolveCallThroughGetter(receiver, 1248 if (!ResolveCallThroughGetter(receiver,
1211 receiver_class, 1249 receiver_class,
1212 target_name, 1250 target_name,
1213 args_descriptor, 1251 args_descriptor,
1214 args, 1252 args,
1215 &result)) { 1253 &result)) {
1216 result = DartEntry::InvokeNoSuchMethod(receiver, 1254 ArgumentsDescriptor desc(args_descriptor);
1217 target_name, 1255 Function& target_function = Function::Handle(
1218 args, 1256 Resolver::ResolveDynamicAnyArgs(receiver_class, target_name));
1219 args_descriptor); 1257 // Check number of arguments and check that there is not already a method
1258 // with the same name present.
1259 // TODO(fschneider): Handle multiple arguments.
1260 if (target_function.IsNull() &&
1261 (desc.Count() == 1) && (desc.PositionalCount() == 1)) {
1262 // Create Function for noSuchMethodInvocation and add it to the class.
1263 target_function ^= CreateNoSuchMethodDispatcher(target_name,
1264 receiver_class,
1265 args_descriptor);
1266
1267 // Update IC data.
1268 ASSERT(!target_function.IsNull());
1269 ic_data.AddReceiverCheck(receiver.GetClassId(), target_function);
1270 if (FLAG_trace_ic) {
1271 OS::PrintErr("NoSuchMethod IC miss: adding <%s> id:%"Pd" -> <%s>\n",
1272 Class::Handle(receiver.clazz()).ToCString(),
1273 receiver.GetClassId(),
1274 target_function.ToCString());
1275 }
1276 result =
1277 DartEntry::InvokeFunction(target_function, args, args_descriptor);
1278 } else {
1279 result = DartEntry::InvokeNoSuchMethod(receiver,
1280 target_name,
1281 args,
1282 args_descriptor);
1283 }
1220 } 1284 }
1221 CheckResultError(result); 1285 CheckResultError(result);
1222 arguments.SetReturn(result); 1286 arguments.SetReturn(result);
1223 } 1287 }
1224 1288
1225 1289
1226 static bool CanOptimizeFunction(const Function& function, Isolate* isolate) { 1290 static bool CanOptimizeFunction(const Function& function, Isolate* isolate) {
1227 const intptr_t kLowInvocationCount = -100000000; 1291 const intptr_t kLowInvocationCount = -100000000;
1228 if (isolate->debugger()->HasBreakpoint(function)) { 1292 if (isolate->debugger()->HasBreakpoint(function)) {
1229 // We cannot set breakpoints in optimized code, so do not optimize 1293 // We cannot set breakpoints in optimized code, so do not optimize
(...skipping 573 matching lines...) Expand 10 before | Expand all | Expand 10 after
1803 // Arg1: Value that is being stored. 1867 // Arg1: Value that is being stored.
1804 DEFINE_RUNTIME_ENTRY(UpdateFieldCid, 2) { 1868 DEFINE_RUNTIME_ENTRY(UpdateFieldCid, 2) {
1805 ASSERT(arguments.ArgCount() == kUpdateFieldCidRuntimeEntry.argument_count()); 1869 ASSERT(arguments.ArgCount() == kUpdateFieldCidRuntimeEntry.argument_count());
1806 const Field& field = Field::CheckedHandle(arguments.ArgAt(0)); 1870 const Field& field = Field::CheckedHandle(arguments.ArgAt(0));
1807 const Object& value = Object::Handle(arguments.ArgAt(1)); 1871 const Object& value = Object::Handle(arguments.ArgAt(1));
1808 1872
1809 field.UpdateCid(value.GetClassId()); 1873 field.UpdateCid(value.GetClassId());
1810 } 1874 }
1811 1875
1812 } // namespace dart 1876 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/class_finalizer.cc ('k') | runtime/vm/debugger.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698