OLD | NEW |
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 Loading... |
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(); |
| 631 // If the enum length of the given map is set to kInvalidEnumCache, this |
| 632 // means that the map itself has never used the present enum cache. The |
| 633 // first step to using the cache is to set the enum length of the map by |
| 634 // counting the number of own descriptors that are not DONT_ENUM or |
| 635 // SYMBOLIC. |
| 636 if (own_property_count == kInvalidEnumCacheSentinel) { |
| 637 own_property_count = object->map()->NumberOfDescribedProperties( |
| 638 OWN_DESCRIPTORS, DONT_SHOW); |
| 639 } else { |
| 640 ASSERT(own_property_count == object->map()->NumberOfDescribedProperties( |
| 641 OWN_DESCRIPTORS, DONT_SHOW)); |
| 642 } |
| 643 |
630 if (object->map()->instance_descriptors()->HasEnumCache()) { | 644 if (object->map()->instance_descriptors()->HasEnumCache()) { |
631 int own_property_count = object->map()->EnumLength(); | |
632 // If we have an enum cache, but the enum length of the given map is set | |
633 // to kInvalidEnumCache, this means that the map itself has never used the | |
634 // present enum cache. The first step to using the cache is to set the | |
635 // enum length of the map by counting the number of own descriptors that | |
636 // are not DONT_ENUM or SYMBOLIC. | |
637 if (own_property_count == kInvalidEnumCacheSentinel) { | |
638 own_property_count = object->map()->NumberOfDescribedProperties( | |
639 OWN_DESCRIPTORS, DONT_SHOW); | |
640 | |
641 if (cache_result) object->map()->SetEnumLength(own_property_count); | |
642 } | |
643 | |
644 DescriptorArray* desc = object->map()->instance_descriptors(); | 645 DescriptorArray* desc = object->map()->instance_descriptors(); |
645 Handle<FixedArray> keys(desc->GetEnumCache(), isolate); | 646 Handle<FixedArray> keys(desc->GetEnumCache(), isolate); |
646 | 647 |
647 // In case the number of properties required in the enum are actually | 648 // In case the number of properties required in the enum are actually |
648 // present, we can reuse the enum cache. Otherwise, this means that the | 649 // present, we can reuse the enum cache. Otherwise, this means that the |
649 // enum cache was generated for a previous (smaller) version of the | 650 // enum cache was generated for a previous (smaller) version of the |
650 // Descriptor Array. In that case we regenerate the enum cache. | 651 // Descriptor Array. In that case we regenerate the enum cache. |
651 if (own_property_count <= keys->length()) { | 652 if (own_property_count <= keys->length()) { |
| 653 if (cache_result) object->map()->SetEnumLength(own_property_count); |
652 isolate->counters()->enum_cache_hits()->Increment(); | 654 isolate->counters()->enum_cache_hits()->Increment(); |
653 return ReduceFixedArrayTo(keys, own_property_count); | 655 return ReduceFixedArrayTo(keys, own_property_count); |
654 } | 656 } |
655 } | 657 } |
656 | 658 |
657 Handle<Map> map(object->map()); | 659 Handle<Map> map(object->map()); |
658 | 660 |
659 if (map->instance_descriptors()->IsEmpty()) { | 661 if (map->instance_descriptors()->IsEmpty()) { |
660 isolate->counters()->enum_cache_hits()->Increment(); | 662 isolate->counters()->enum_cache_hits()->Increment(); |
661 if (cache_result) map->SetEnumLength(0); | 663 if (cache_result) map->SetEnumLength(0); |
662 return isolate->factory()->empty_fixed_array(); | 664 return isolate->factory()->empty_fixed_array(); |
663 } | 665 } |
664 | 666 |
665 isolate->counters()->enum_cache_misses()->Increment(); | 667 isolate->counters()->enum_cache_misses()->Increment(); |
666 int num_enum = map->NumberOfDescribedProperties(ALL_DESCRIPTORS, DONT_SHOW); | |
667 | 668 |
668 Handle<FixedArray> storage = isolate->factory()->NewFixedArray(num_enum); | 669 Handle<FixedArray> storage = isolate->factory()->NewFixedArray( |
669 Handle<FixedArray> indices = isolate->factory()->NewFixedArray(num_enum); | 670 own_property_count); |
| 671 Handle<FixedArray> indices = isolate->factory()->NewFixedArray( |
| 672 own_property_count); |
670 | 673 |
671 Handle<DescriptorArray> descs = | 674 Handle<DescriptorArray> descs = |
672 Handle<DescriptorArray>(object->map()->instance_descriptors(), isolate); | 675 Handle<DescriptorArray>(object->map()->instance_descriptors(), isolate); |
673 | 676 |
674 int real_size = map->NumberOfOwnDescriptors(); | 677 int size = map->NumberOfOwnDescriptors(); |
675 int enum_size = 0; | |
676 int index = 0; | 678 int index = 0; |
677 | 679 |
678 for (int i = 0; i < descs->number_of_descriptors(); i++) { | 680 for (int i = 0; i < size; i++) { |
679 PropertyDetails details = descs->GetDetails(i); | 681 PropertyDetails details = descs->GetDetails(i); |
680 Object* key = descs->GetKey(i); | 682 Object* key = descs->GetKey(i); |
681 if (!(details.IsDontEnum() || key->IsSymbol())) { | 683 if (!(details.IsDontEnum() || key->IsSymbol())) { |
682 if (i < real_size) ++enum_size; | |
683 storage->set(index, key); | 684 storage->set(index, key); |
684 if (!indices.is_null()) { | 685 if (!indices.is_null()) { |
685 if (details.type() != FIELD) { | 686 if (details.type() != FIELD) { |
686 indices = Handle<FixedArray>(); | 687 indices = Handle<FixedArray>(); |
687 } else { | 688 } else { |
688 int field_index = descs->GetFieldIndex(i); | 689 int field_index = descs->GetFieldIndex(i); |
689 if (field_index >= map->inobject_properties()) { | 690 if (field_index >= map->inobject_properties()) { |
690 field_index = -(field_index - map->inobject_properties() + 1); | 691 field_index = -(field_index - map->inobject_properties() + 1); |
691 } | 692 } |
692 indices->set(index, Smi::FromInt(field_index)); | 693 indices->set(index, Smi::FromInt(field_index)); |
693 } | 694 } |
694 } | 695 } |
695 index++; | 696 index++; |
696 } | 697 } |
697 } | 698 } |
698 ASSERT(index == storage->length()); | 699 ASSERT(index == storage->length()); |
699 | 700 |
700 Handle<FixedArray> bridge_storage = | 701 Handle<FixedArray> bridge_storage = |
701 isolate->factory()->NewFixedArray( | 702 isolate->factory()->NewFixedArray( |
702 DescriptorArray::kEnumCacheBridgeLength); | 703 DescriptorArray::kEnumCacheBridgeLength); |
703 DescriptorArray* desc = object->map()->instance_descriptors(); | 704 DescriptorArray* desc = object->map()->instance_descriptors(); |
704 desc->SetEnumCache(*bridge_storage, | 705 desc->SetEnumCache(*bridge_storage, |
705 *storage, | 706 *storage, |
706 indices.is_null() ? Object::cast(Smi::FromInt(0)) | 707 indices.is_null() ? Object::cast(Smi::FromInt(0)) |
707 : Object::cast(*indices)); | 708 : Object::cast(*indices)); |
708 if (cache_result) { | 709 if (cache_result) { |
709 object->map()->SetEnumLength(enum_size); | 710 object->map()->SetEnumLength(own_property_count); |
710 } | 711 } |
711 | 712 return storage; |
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 Loading... |
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 |
OLD | NEW |