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

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

Issue 1873143003: - Use a hash table to canonicalize instances/arrays to avoid having to iterate over a linear list a… (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: address-code-review Created 4 years, 8 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
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/class_finalizer.h" 7 #include "vm/class_finalizer.h"
8 #include "vm/code_generator.h" 8 #include "vm/code_generator.h"
9 #include "vm/compiler.h" 9 #include "vm/compiler.h"
10 #include "vm/debugger.h" 10 #include "vm/debugger.h"
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 optional_arguments_names.IsNull() ? 0 : optional_arguments_names.Length(); 315 optional_arguments_names.IsNull() ? 0 : optional_arguments_names.Length();
316 if (num_named_args == 0) { 316 if (num_named_args == 0) {
317 return ArgumentsDescriptor::New(num_arguments); 317 return ArgumentsDescriptor::New(num_arguments);
318 } 318 }
319 const intptr_t num_pos_args = num_arguments - num_named_args; 319 const intptr_t num_pos_args = num_arguments - num_named_args;
320 320
321 // Build the arguments descriptor array, which consists of the total 321 // Build the arguments descriptor array, which consists of the total
322 // argument count; the positional argument count; a sequence of (name, 322 // argument count; the positional argument count; a sequence of (name,
323 // position) pairs, sorted by name, for each named optional argument; and 323 // position) pairs, sorted by name, for each named optional argument; and
324 // a terminating null to simplify iterating in generated code. 324 // a terminating null to simplify iterating in generated code.
325 Thread* thread = Thread::Current();
326 Zone* zone = thread->zone();
325 const intptr_t descriptor_len = LengthFor(num_named_args); 327 const intptr_t descriptor_len = LengthFor(num_named_args);
326 Array& descriptor = Array::Handle(Array::New(descriptor_len, Heap::kOld)); 328 Array& descriptor = Array::Handle(
329 zone, Array::New(descriptor_len, Heap::kOld));
327 330
328 // Set total number of passed arguments. 331 // Set total number of passed arguments.
329 descriptor.SetAt(kCountIndex, Smi::Handle(Smi::New(num_arguments))); 332 descriptor.SetAt(kCountIndex, Smi::Handle(Smi::New(num_arguments)));
330 // Set number of positional arguments. 333 // Set number of positional arguments.
331 descriptor.SetAt(kPositionalCountIndex, Smi::Handle(Smi::New(num_pos_args))); 334 descriptor.SetAt(kPositionalCountIndex, Smi::Handle(Smi::New(num_pos_args)));
332 // Set alphabetically sorted entries for named arguments. 335 // Set alphabetically sorted entries for named arguments.
333 String& name = String::Handle(); 336 String& name = String::Handle(zone);
334 Smi& pos = Smi::Handle(); 337 Smi& pos = Smi::Handle(zone);
338 String& previous_name = String::Handle(zone);
339 Smi& previous_pos = Smi::Handle(zone);
335 for (intptr_t i = 0; i < num_named_args; i++) { 340 for (intptr_t i = 0; i < num_named_args; i++) {
336 name ^= optional_arguments_names.At(i); 341 name ^= optional_arguments_names.At(i);
337 pos = Smi::New(num_pos_args + i); 342 pos = Smi::New(num_pos_args + i);
338 intptr_t insert_index = kFirstNamedEntryIndex + (kNamedEntrySize * i); 343 intptr_t insert_index = kFirstNamedEntryIndex + (kNamedEntrySize * i);
339 // Shift already inserted pairs with "larger" names. 344 // Shift already inserted pairs with "larger" names.
340 String& previous_name = String::Handle();
341 Smi& previous_pos = Smi::Handle();
342 while (insert_index > kFirstNamedEntryIndex) { 345 while (insert_index > kFirstNamedEntryIndex) {
343 intptr_t previous_index = insert_index - kNamedEntrySize; 346 intptr_t previous_index = insert_index - kNamedEntrySize;
344 previous_name ^= descriptor.At(previous_index + kNameOffset); 347 previous_name ^= descriptor.At(previous_index + kNameOffset);
345 intptr_t result = name.CompareTo(previous_name); 348 intptr_t result = name.CompareTo(previous_name);
346 ASSERT(result != 0); // Duplicate argument names checked in parser. 349 ASSERT(result != 0); // Duplicate argument names checked in parser.
347 if (result > 0) break; 350 if (result > 0) break;
348 previous_pos ^= descriptor.At(previous_index + kPositionOffset); 351 previous_pos ^= descriptor.At(previous_index + kPositionOffset);
349 descriptor.SetAt(insert_index + kNameOffset, previous_name); 352 descriptor.SetAt(insert_index + kNameOffset, previous_name);
350 descriptor.SetAt(insert_index + kPositionOffset, previous_pos); 353 descriptor.SetAt(insert_index + kPositionOffset, previous_pos);
351 insert_index = previous_index; 354 insert_index = previous_index;
352 } 355 }
353 // Insert pair in descriptor array. 356 // Insert pair in descriptor array.
354 descriptor.SetAt(insert_index + kNameOffset, name); 357 descriptor.SetAt(insert_index + kNameOffset, name);
355 descriptor.SetAt(insert_index + kPositionOffset, pos); 358 descriptor.SetAt(insert_index + kPositionOffset, pos);
356 } 359 }
357 // Set terminating null. 360 // Set terminating null.
358 descriptor.SetAt(descriptor_len - 1, Object::null_object()); 361 descriptor.SetAt(descriptor_len - 1, Object::null_object());
359 362
360 // Share the immutable descriptor when possible by canonicalizing it. 363 // Share the immutable descriptor when possible by canonicalizing it.
361 descriptor.MakeImmutable(); 364 descriptor.MakeImmutable();
362 descriptor ^= descriptor.CheckAndCanonicalize(NULL); 365 descriptor ^= descriptor.CheckAndCanonicalize(thread, NULL);
363 ASSERT(!descriptor.IsNull()); 366 ASSERT(!descriptor.IsNull());
364 return descriptor.raw(); 367 return descriptor.raw();
365 } 368 }
366 369
367 370
368 RawArray* ArgumentsDescriptor::New(intptr_t num_arguments) { 371 RawArray* ArgumentsDescriptor::New(intptr_t num_arguments) {
369 ASSERT(num_arguments >= 0); 372 ASSERT(num_arguments >= 0);
370 if (num_arguments < kCachedDescriptorCount) { 373 if (num_arguments < kCachedDescriptorCount) {
371 return cached_args_descriptors_[num_arguments]; 374 return cached_args_descriptors_[num_arguments];
372 } 375 }
373 return NewNonCached(num_arguments); 376 return NewNonCached(num_arguments);
374 } 377 }
375 378
376 379
377 RawArray* ArgumentsDescriptor::NewNonCached(intptr_t num_arguments, 380 RawArray* ArgumentsDescriptor::NewNonCached(intptr_t num_arguments,
378 bool canonicalize) { 381 bool canonicalize) {
379 // Build the arguments descriptor array, which consists of the total 382 // Build the arguments descriptor array, which consists of the total
380 // argument count; the positional argument count; and 383 // argument count; the positional argument count; and
381 // a terminating null to simplify iterating in generated code. 384 // a terminating null to simplify iterating in generated code.
385 Thread* thread = Thread::Current();
386 Zone* zone = thread->zone();
382 const intptr_t descriptor_len = LengthFor(0); 387 const intptr_t descriptor_len = LengthFor(0);
383 Array& descriptor = Array::Handle(Array::New(descriptor_len, Heap::kOld)); 388 Array& descriptor = Array::Handle(
384 const Smi& arg_count = Smi::Handle(Smi::New(num_arguments)); 389 zone, Array::New(descriptor_len, Heap::kOld));
390 const Smi& arg_count = Smi::Handle(zone, Smi::New(num_arguments));
385 391
386 // Set total number of passed arguments. 392 // Set total number of passed arguments.
387 descriptor.SetAt(kCountIndex, arg_count); 393 descriptor.SetAt(kCountIndex, arg_count);
388 394
389 // Set number of positional arguments. 395 // Set number of positional arguments.
390 descriptor.SetAt(kPositionalCountIndex, arg_count); 396 descriptor.SetAt(kPositionalCountIndex, arg_count);
391 397
392 // Set terminating null. 398 // Set terminating null.
393 descriptor.SetAt((descriptor_len - 1), Object::null_object()); 399 descriptor.SetAt((descriptor_len - 1), Object::null_object());
394 400
395 // Share the immutable descriptor when possible by canonicalizing it. 401 // Share the immutable descriptor when possible by canonicalizing it.
396 descriptor.MakeImmutable(); 402 descriptor.MakeImmutable();
397 if (canonicalize) { 403 if (canonicalize) {
398 descriptor ^= descriptor.CheckAndCanonicalize(NULL); 404 descriptor ^= descriptor.CheckAndCanonicalize(thread, NULL);
399 } 405 }
400 ASSERT(!descriptor.IsNull()); 406 ASSERT(!descriptor.IsNull());
401 return descriptor.raw(); 407 return descriptor.raw();
402 } 408 }
403 409
404 410
405 void ArgumentsDescriptor::InitOnce() { 411 void ArgumentsDescriptor::InitOnce() {
406 for (int i = 0; i < kCachedDescriptorCount; i++) { 412 for (int i = 0; i < kCachedDescriptorCount; i++) {
407 cached_args_descriptors_[i] = ArgumentsDescriptor::NewNonCached(i, false); 413 cached_args_descriptors_[i] = ArgumentsDescriptor::NewNonCached(i, false);
408 } 414 }
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
595 const Array& args = Array::Handle(Array::New(kNumArguments)); 601 const Array& args = Array::Handle(Array::New(kNumArguments));
596 args.SetAt(0, map); 602 args.SetAt(0, map);
597 args.SetAt(1, key); 603 args.SetAt(1, key);
598 args.SetAt(2, value); 604 args.SetAt(2, value);
599 const Object& result = Object::Handle(DartEntry::InvokeFunction(function, 605 const Object& result = Object::Handle(DartEntry::InvokeFunction(function,
600 args)); 606 args));
601 return result.raw(); 607 return result.raw();
602 } 608 }
603 609
604 } // namespace dart 610 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698