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

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

Issue 11773008: - Preallocate non-named ArgumentsDescriptors with a small amount of parameters. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 11 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
« runtime/vm/dart_entry.h ('K') | « runtime/vm/dart_entry.h ('k') | no next file » | 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) 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/dart_entry.h" 5 #include "vm/dart_entry.h"
6 6
7 #include "vm/code_generator.h" 7 #include "vm/code_generator.h"
8 #include "vm/compiler.h" 8 #include "vm/compiler.h"
9 #include "vm/object_store.h" 9 #include "vm/object_store.h"
10 #include "vm/resolver.h" 10 #include "vm/resolver.h"
11 #include "vm/stub_code.h" 11 #include "vm/stub_code.h"
12 #include "vm/symbols.h" 12 #include "vm/symbols.h"
13 13
14 namespace dart { 14 namespace dart {
15 15
16 // A cache of VM heap allocated arguments descriptors.
17 RawArray* ArgumentsDescriptor::cached_args_descriptors_[kCachedDescriptors];
18
19
16 RawObject* DartEntry::InvokeDynamic(const Function& function, 20 RawObject* DartEntry::InvokeDynamic(const Function& function,
17 const Array& arguments) { 21 const Array& arguments) {
18 const Array& arg_desc = 22 const Array& arg_desc =
19 Array::Handle(ArgumentsDescriptor::New(arguments.Length())); 23 Array::Handle(ArgumentsDescriptor::New(arguments.Length()));
20 return InvokeDynamic(function, arguments, arg_desc); 24 return InvokeDynamic(function, arguments, arg_desc);
21 } 25 }
22 26
23 27
24 RawObject* DartEntry::InvokeDynamic(const Function& function, 28 RawObject* DartEntry::InvokeDynamic(const Function& function,
25 const Array& arguments, 29 const Array& arguments,
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 216
213 intptr_t ArgumentsDescriptor::first_named_entry_offset() { 217 intptr_t ArgumentsDescriptor::first_named_entry_offset() {
214 return Array::data_offset() + (kFirstNamedEntryIndex * kWordSize); 218 return Array::data_offset() + (kFirstNamedEntryIndex * kWordSize);
215 } 219 }
216 220
217 221
218 RawArray* ArgumentsDescriptor::New(intptr_t num_arguments, 222 RawArray* ArgumentsDescriptor::New(intptr_t num_arguments,
219 const Array& optional_arguments_names) { 223 const Array& optional_arguments_names) {
220 const intptr_t num_named_args = 224 const intptr_t num_named_args =
221 optional_arguments_names.IsNull() ? 0 : optional_arguments_names.Length(); 225 optional_arguments_names.IsNull() ? 0 : optional_arguments_names.Length();
226 if (num_named_args == 0) {
227 return ArgumentsDescriptor::New(num_arguments);
228 }
222 const intptr_t num_pos_args = num_arguments - num_named_args; 229 const intptr_t num_pos_args = num_arguments - num_named_args;
223 230
224 // Build the arguments descriptor array, which consists of the total 231 // Build the arguments descriptor array, which consists of the total
225 // argument count; the positional argument count; a sequence of (name, 232 // argument count; the positional argument count; a sequence of (name,
226 // position) pairs, sorted by name, for each named optional argument; and 233 // position) pairs, sorted by name, for each named optional argument; and
227 // a terminating null to simplify iterating in generated code. 234 // a terminating null to simplify iterating in generated code.
228 const intptr_t descriptor_len = LengthFor(num_named_args); 235 const intptr_t descriptor_len = LengthFor(num_named_args);
229 Array& descriptor = Array::Handle(Array::New(descriptor_len, Heap::kOld)); 236 Array& descriptor = Array::Handle(Array::New(descriptor_len, Heap::kOld));
230 237
231 // Set total number of passed arguments. 238 // Set total number of passed arguments.
(...skipping 29 matching lines...) Expand all
261 descriptor.SetAt(descriptor_len - 1, Object::Handle()); 268 descriptor.SetAt(descriptor_len - 1, Object::Handle());
262 269
263 // Share the immutable descriptor when possible by canonicalizing it. 270 // Share the immutable descriptor when possible by canonicalizing it.
264 descriptor.MakeImmutable(); 271 descriptor.MakeImmutable();
265 descriptor ^= descriptor.Canonicalize(); 272 descriptor ^= descriptor.Canonicalize();
266 return descriptor.raw(); 273 return descriptor.raw();
267 } 274 }
268 275
269 276
270 RawArray* ArgumentsDescriptor::New(intptr_t num_arguments) { 277 RawArray* ArgumentsDescriptor::New(intptr_t num_arguments) {
278 ASSERT(num_arguments >= 0);
279 if (num_arguments < kCachedDescriptors) {
280 return cached_args_descriptors_[num_arguments];
281 }
282 return NewNonCached(num_arguments);
283 }
284
285
286 RawArray* ArgumentsDescriptor::NewNonCached(intptr_t num_arguments,
287 bool canonicalize) {
271 // Build the arguments descriptor array, which consists of the total 288 // Build the arguments descriptor array, which consists of the total
272 // argument count; the positional argument count; and 289 // argument count; the positional argument count; and
273 // a terminating null to simplify iterating in generated code. 290 // a terminating null to simplify iterating in generated code.
274 const intptr_t descriptor_len = LengthFor(0); 291 const intptr_t descriptor_len = LengthFor(0);
275 Array& descriptor = Array::Handle(Array::New(descriptor_len, Heap::kOld)); 292 Array& descriptor = Array::Handle(Array::New(descriptor_len, Heap::kOld));
276 const Smi& arg_count = Smi::Handle(Smi::New(num_arguments)); 293 const Smi& arg_count = Smi::Handle(Smi::New(num_arguments));
277 294
278 // Set total number of passed arguments. 295 // Set total number of passed arguments.
279 descriptor.SetAt(kCountIndex, arg_count); 296 descriptor.SetAt(kCountIndex, arg_count);
280 297
281 // Set number of positional arguments. 298 // Set number of positional arguments.
282 descriptor.SetAt(kPositionalCountIndex, arg_count); 299 descriptor.SetAt(kPositionalCountIndex, arg_count);
283 300
284 // Set terminating null. 301 // Set terminating null.
285 descriptor.SetAt((descriptor_len - 1), Object::Handle()); 302 descriptor.SetAt((descriptor_len - 1), Object::Handle());
286 303
287 // Share the immutable descriptor when possible by canonicalizing it. 304 // Share the immutable descriptor when possible by canonicalizing it.
288 descriptor.MakeImmutable(); 305 if (canonicalize) {
regis 2013/01/05 01:05:29 I suppose you do not canonicalize the cached descr
Ivan Posva 2013/01/07 18:27:12 Making them immutable now. For this we need to mak
289 descriptor ^= descriptor.Canonicalize(); 306 descriptor.MakeImmutable();
307 descriptor ^= descriptor.Canonicalize();
308 }
290 return descriptor.raw(); 309 return descriptor.raw();
291 } 310 }
292 311
293 312
313 void ArgumentsDescriptor::InitOnce() {
314 for (int i = 0; i < kCachedDescriptors; i++) {
315 cached_args_descriptors_[i] = ArgumentsDescriptor::NewNonCached(i, false);
316 }
317 }
318
319
294 RawObject* DartLibraryCalls::ExceptionCreate(const Library& lib, 320 RawObject* DartLibraryCalls::ExceptionCreate(const Library& lib,
295 const String& class_name, 321 const String& class_name,
296 const Array& arguments) { 322 const Array& arguments) {
297 const Class& cls = Class::Handle(lib.LookupClassAllowPrivate(class_name)); 323 const Class& cls = Class::Handle(lib.LookupClassAllowPrivate(class_name));
298 ASSERT(!cls.IsNull()); 324 ASSERT(!cls.IsNull());
299 // For now, we only support a non-parameterized or raw type. 325 // For now, we only support a non-parameterized or raw type.
300 const int kNumExtraArgs = 2; // implicit rcvr and construction phase args. 326 const int kNumExtraArgs = 2; // implicit rcvr and construction phase args.
301 const Instance& exception_object = Instance::Handle(Instance::New(cls)); 327 const Instance& exception_object = Instance::Handle(Instance::New(cls));
302 const Array& constructor_arguments = 328 const Array& constructor_arguments =
303 Array::Handle(Array::New(arguments.Length() + kNumExtraArgs)); 329 Array::Handle(Array::New(arguments.Length() + kNumExtraArgs));
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
467 const String& func_name = String::Handle(Field::GetterName(Symbols::_id())); 493 const String& func_name = String::Handle(Field::GetterName(Symbols::_id()));
468 const Function& func = Function::Handle(cls.LookupDynamicFunction(func_name)); 494 const Function& func = Function::Handle(cls.LookupDynamicFunction(func_name));
469 ASSERT(!func.IsNull()); 495 ASSERT(!func.IsNull());
470 const Array& args = Array::Handle(Array::New(1)); 496 const Array& args = Array::Handle(Array::New(1));
471 args.SetAt(0, port); 497 args.SetAt(0, port);
472 return DartEntry::InvokeDynamic(func, args); 498 return DartEntry::InvokeDynamic(func, args);
473 } 499 }
474 500
475 501
476 } // namespace dart 502 } // namespace dart
OLDNEW
« runtime/vm/dart_entry.h ('K') | « runtime/vm/dart_entry.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698