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

Side by Side Diff: src/handles.cc

Issue 214893002: Revert "Fix property enum cache creation to include only own properties" (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | test/mjsunit/regress/regress-enum-prop-keys-cache-size.js » ('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 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 609 matching lines...) Expand 10 before | Expand all | Expand 10 after
620 array->GetIsolate()->factory()->NewFixedArray(length); 620 array->GetIsolate()->factory()->NewFixedArray(length);
621 for (int i = 0; i < length; ++i) new_array->set(i, array->get(i)); 621 for (int i = 0; i < length; ++i) new_array->set(i, array->get(i));
622 return new_array; 622 return new_array;
623 } 623 }
624 624
625 625
626 Handle<FixedArray> GetEnumPropertyKeys(Handle<JSObject> object, 626 Handle<FixedArray> GetEnumPropertyKeys(Handle<JSObject> object,
627 bool cache_result) { 627 bool cache_result) {
628 Isolate* isolate = object->GetIsolate(); 628 Isolate* isolate = object->GetIsolate();
629 if (object->HasFastProperties()) { 629 if (object->HasFastProperties()) {
630 int own_property_count = object->map()->EnumLength(); 630 if (object->map()->instance_descriptors()->HasEnumCache()) {
631 // If the enum length of the given map is set to kInvalidEnumCache, this 631 int own_property_count = object->map()->EnumLength();
632 // means that the map itself has never used the present enum cache. The 632 // If we have an enum cache, but the enum length of the given map is set
633 // first step to using the cache is to set the enum length of the map by 633 // to kInvalidEnumCache, this means that the map itself has never used the
634 // counting the number of own descriptors that are not DONT_ENUM or 634 // present enum cache. The first step to using the cache is to set the
635 // SYMBOLIC. 635 // enum length of the map by counting the number of own descriptors that
636 if (own_property_count == kInvalidEnumCacheSentinel) { 636 // are not DONT_ENUM or SYMBOLIC.
637 own_property_count = object->map()->NumberOfDescribedProperties( 637 if (own_property_count == kInvalidEnumCacheSentinel) {
638 OWN_DESCRIPTORS, DONT_SHOW); 638 own_property_count = object->map()->NumberOfDescribedProperties(
639 } else { 639 OWN_DESCRIPTORS, DONT_SHOW);
640 ASSERT(own_property_count == object->map()->NumberOfDescribedProperties(
641 OWN_DESCRIPTORS, DONT_SHOW));
642 }
643 640
644 if (object->map()->instance_descriptors()->HasEnumCache()) { 641 if (cache_result) object->map()->SetEnumLength(own_property_count);
642 }
643
645 DescriptorArray* desc = object->map()->instance_descriptors(); 644 DescriptorArray* desc = object->map()->instance_descriptors();
646 Handle<FixedArray> keys(desc->GetEnumCache(), isolate); 645 Handle<FixedArray> keys(desc->GetEnumCache(), isolate);
647 646
648 // In case the number of properties required in the enum are actually 647 // In case the number of properties required in the enum are actually
649 // present, we can reuse the enum cache. Otherwise, this means that the 648 // present, we can reuse the enum cache. Otherwise, this means that the
650 // enum cache was generated for a previous (smaller) version of the 649 // enum cache was generated for a previous (smaller) version of the
651 // Descriptor Array. In that case we regenerate the enum cache. 650 // Descriptor Array. In that case we regenerate the enum cache.
652 if (own_property_count <= keys->length()) { 651 if (own_property_count <= keys->length()) {
653 if (cache_result) object->map()->SetEnumLength(own_property_count);
654 isolate->counters()->enum_cache_hits()->Increment(); 652 isolate->counters()->enum_cache_hits()->Increment();
655 return ReduceFixedArrayTo(keys, own_property_count); 653 return ReduceFixedArrayTo(keys, own_property_count);
656 } 654 }
657 } 655 }
658 656
659 Handle<Map> map(object->map()); 657 Handle<Map> map(object->map());
660 658
661 if (map->instance_descriptors()->IsEmpty()) { 659 if (map->instance_descriptors()->IsEmpty()) {
662 isolate->counters()->enum_cache_hits()->Increment(); 660 isolate->counters()->enum_cache_hits()->Increment();
663 if (cache_result) map->SetEnumLength(0); 661 if (cache_result) map->SetEnumLength(0);
664 return isolate->factory()->empty_fixed_array(); 662 return isolate->factory()->empty_fixed_array();
665 } 663 }
666 664
667 isolate->counters()->enum_cache_misses()->Increment(); 665 isolate->counters()->enum_cache_misses()->Increment();
666 int num_enum = map->NumberOfDescribedProperties(ALL_DESCRIPTORS, DONT_SHOW);
668 667
669 Handle<FixedArray> storage = isolate->factory()->NewFixedArray( 668 Handle<FixedArray> storage = isolate->factory()->NewFixedArray(num_enum);
670 own_property_count); 669 Handle<FixedArray> indices = isolate->factory()->NewFixedArray(num_enum);
671 Handle<FixedArray> indices = isolate->factory()->NewFixedArray(
672 own_property_count);
673 670
674 Handle<DescriptorArray> descs = 671 Handle<DescriptorArray> descs =
675 Handle<DescriptorArray>(object->map()->instance_descriptors(), isolate); 672 Handle<DescriptorArray>(object->map()->instance_descriptors(), isolate);
676 673
677 int size = map->NumberOfOwnDescriptors(); 674 int real_size = map->NumberOfOwnDescriptors();
675 int enum_size = 0;
678 int index = 0; 676 int index = 0;
679 677
680 for (int i = 0; i < size; i++) { 678 for (int i = 0; i < descs->number_of_descriptors(); i++) {
681 PropertyDetails details = descs->GetDetails(i); 679 PropertyDetails details = descs->GetDetails(i);
682 Object* key = descs->GetKey(i); 680 Object* key = descs->GetKey(i);
683 if (!(details.IsDontEnum() || key->IsSymbol())) { 681 if (!(details.IsDontEnum() || key->IsSymbol())) {
682 if (i < real_size) ++enum_size;
684 storage->set(index, key); 683 storage->set(index, key);
685 if (!indices.is_null()) { 684 if (!indices.is_null()) {
686 if (details.type() != FIELD) { 685 if (details.type() != FIELD) {
687 indices = Handle<FixedArray>(); 686 indices = Handle<FixedArray>();
688 } else { 687 } else {
689 int field_index = descs->GetFieldIndex(i); 688 int field_index = descs->GetFieldIndex(i);
690 if (field_index >= map->inobject_properties()) { 689 if (field_index >= map->inobject_properties()) {
691 field_index = -(field_index - map->inobject_properties() + 1); 690 field_index = -(field_index - map->inobject_properties() + 1);
692 } 691 }
693 indices->set(index, Smi::FromInt(field_index)); 692 indices->set(index, Smi::FromInt(field_index));
694 } 693 }
695 } 694 }
696 index++; 695 index++;
697 } 696 }
698 } 697 }
699 ASSERT(index == storage->length()); 698 ASSERT(index == storage->length());
700 699
701 Handle<FixedArray> bridge_storage = 700 Handle<FixedArray> bridge_storage =
702 isolate->factory()->NewFixedArray( 701 isolate->factory()->NewFixedArray(
703 DescriptorArray::kEnumCacheBridgeLength); 702 DescriptorArray::kEnumCacheBridgeLength);
704 DescriptorArray* desc = object->map()->instance_descriptors(); 703 DescriptorArray* desc = object->map()->instance_descriptors();
705 desc->SetEnumCache(*bridge_storage, 704 desc->SetEnumCache(*bridge_storage,
706 *storage, 705 *storage,
707 indices.is_null() ? Object::cast(Smi::FromInt(0)) 706 indices.is_null() ? Object::cast(Smi::FromInt(0))
708 : Object::cast(*indices)); 707 : Object::cast(*indices));
709 if (cache_result) { 708 if (cache_result) {
710 object->map()->SetEnumLength(own_property_count); 709 object->map()->SetEnumLength(enum_size);
711 } 710 }
712 return storage; 711
712 return ReduceFixedArrayTo(storage, enum_size);
713 } else { 713 } else {
714 Handle<NameDictionary> dictionary(object->property_dictionary()); 714 Handle<NameDictionary> dictionary(object->property_dictionary());
715 int length = dictionary->NumberOfEnumElements(); 715 int length = dictionary->NumberOfEnumElements();
716 if (length == 0) { 716 if (length == 0) {
717 return Handle<FixedArray>(isolate->heap()->empty_fixed_array()); 717 return Handle<FixedArray>(isolate->heap()->empty_fixed_array());
718 } 718 }
719 Handle<FixedArray> storage = isolate->factory()->NewFixedArray(length); 719 Handle<FixedArray> storage = isolate->factory()->NewFixedArray(length);
720 dictionary->CopyEnumKeysTo(*storage); 720 dictionary->CopyEnumKeysTo(*storage);
721 return storage; 721 return storage;
722 } 722 }
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
767 Handle<Code> code) { 767 Handle<Code> code) {
768 heap->EnsureWeakObjectToCodeTable(); 768 heap->EnsureWeakObjectToCodeTable();
769 Handle<DependentCode> dep(heap->LookupWeakObjectToCodeDependency(*object)); 769 Handle<DependentCode> dep(heap->LookupWeakObjectToCodeDependency(*object));
770 dep = DependentCode::Insert(dep, DependentCode::kWeaklyEmbeddedGroup, code); 770 dep = DependentCode::Insert(dep, DependentCode::kWeaklyEmbeddedGroup, code);
771 CALL_HEAP_FUNCTION_VOID(heap->isolate(), 771 CALL_HEAP_FUNCTION_VOID(heap->isolate(),
772 heap->AddWeakObjectToCodeDependency(*object, *dep)); 772 heap->AddWeakObjectToCodeDependency(*object, *dep));
773 } 773 }
774 774
775 775
776 } } // namespace v8::internal 776 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « no previous file | test/mjsunit/regress/regress-enum-prop-keys-cache-size.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698