| OLD | NEW |
| 1 // Copyright 2009 the V8 project authors. All rights reserved. | 1 // Copyright 2009 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 2719 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2730 SKIP_WRITE_BARRIER); | 2730 SKIP_WRITE_BARRIER); |
| 2731 | 2731 |
| 2732 // Check the state of the object | 2732 // Check the state of the object |
| 2733 ASSERT(JSObject::cast(result)->HasFastProperties()); | 2733 ASSERT(JSObject::cast(result)->HasFastProperties()); |
| 2734 ASSERT(JSObject::cast(result)->HasFastElements()); | 2734 ASSERT(JSObject::cast(result)->HasFastElements()); |
| 2735 | 2735 |
| 2736 return result; | 2736 return result; |
| 2737 } | 2737 } |
| 2738 | 2738 |
| 2739 | 2739 |
| 2740 static bool HasDuplicates(DescriptorArray* descriptors) { |
| 2741 int count = descriptors->number_of_descriptors(); |
| 2742 if (count > 1) { |
| 2743 String* prev_key = descriptors->GetKey(0); |
| 2744 for (int i = 1; i != count; i++) { |
| 2745 String* current_key = descriptors->GetKey(i); |
| 2746 if (prev_key == current_key) return true; |
| 2747 prev_key = current_key; |
| 2748 } |
| 2749 } |
| 2750 return false; |
| 2751 } |
| 2752 |
| 2753 |
| 2740 Object* Heap::AllocateInitialMap(JSFunction* fun) { | 2754 Object* Heap::AllocateInitialMap(JSFunction* fun) { |
| 2741 ASSERT(!fun->has_initial_map()); | 2755 ASSERT(!fun->has_initial_map()); |
| 2742 | 2756 |
| 2743 // First create a new map with the size and number of in-object properties | 2757 // First create a new map with the size and number of in-object properties |
| 2744 // suggested by the function. | 2758 // suggested by the function. |
| 2745 int instance_size = fun->shared()->CalculateInstanceSize(); | 2759 int instance_size = fun->shared()->CalculateInstanceSize(); |
| 2746 int in_object_properties = fun->shared()->CalculateInObjectProperties(); | 2760 int in_object_properties = fun->shared()->CalculateInObjectProperties(); |
| 2747 Object* map_obj = Heap::AllocateMap(JS_OBJECT_TYPE, instance_size); | 2761 Object* map_obj = Heap::AllocateMap(JS_OBJECT_TYPE, instance_size); |
| 2748 if (map_obj->IsFailure()) return map_obj; | 2762 if (map_obj->IsFailure()) return map_obj; |
| 2749 | 2763 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 2763 | 2777 |
| 2764 // If the function has only simple this property assignments add | 2778 // If the function has only simple this property assignments add |
| 2765 // field descriptors for these to the initial map as the object | 2779 // field descriptors for these to the initial map as the object |
| 2766 // cannot be constructed without having these properties. Guard by | 2780 // cannot be constructed without having these properties. Guard by |
| 2767 // the inline_new flag so we only change the map if we generate a | 2781 // the inline_new flag so we only change the map if we generate a |
| 2768 // specialized construct stub. | 2782 // specialized construct stub. |
| 2769 ASSERT(in_object_properties <= Map::kMaxPreAllocatedPropertyFields); | 2783 ASSERT(in_object_properties <= Map::kMaxPreAllocatedPropertyFields); |
| 2770 if (fun->shared()->CanGenerateInlineConstructor(prototype)) { | 2784 if (fun->shared()->CanGenerateInlineConstructor(prototype)) { |
| 2771 int count = fun->shared()->this_property_assignments_count(); | 2785 int count = fun->shared()->this_property_assignments_count(); |
| 2772 if (count > in_object_properties) { | 2786 if (count > in_object_properties) { |
| 2773 count = in_object_properties; | 2787 // Inline constructor can only handle inobject properties. |
| 2788 fun->shared()->ForbidInlineConstructor(); |
| 2789 } else { |
| 2790 Object* descriptors_obj = DescriptorArray::Allocate(count); |
| 2791 if (descriptors_obj->IsFailure()) return descriptors_obj; |
| 2792 DescriptorArray* descriptors = DescriptorArray::cast(descriptors_obj); |
| 2793 for (int i = 0; i < count; i++) { |
| 2794 String* name = fun->shared()->GetThisPropertyAssignmentName(i); |
| 2795 ASSERT(name->IsSymbol()); |
| 2796 FieldDescriptor field(name, i, NONE); |
| 2797 field.SetEnumerationIndex(i); |
| 2798 descriptors->Set(i, &field); |
| 2799 } |
| 2800 descriptors->SetNextEnumerationIndex(count); |
| 2801 descriptors->SortUnchecked(); |
| 2802 |
| 2803 // The descriptors may contain duplicates because the compiler does not |
| 2804 // guarantee the uniqueness of property names (it would have required |
| 2805 // quadratic time). Once the descriptors are sorted we can check for |
| 2806 // duplicates in linear time. |
| 2807 if (HasDuplicates(descriptors)) { |
| 2808 fun->shared()->ForbidInlineConstructor(); |
| 2809 } else { |
| 2810 map->set_instance_descriptors(descriptors); |
| 2811 map->set_pre_allocated_property_fields(count); |
| 2812 map->set_unused_property_fields(in_object_properties - count); |
| 2813 } |
| 2774 } | 2814 } |
| 2775 Object* descriptors_obj = DescriptorArray::Allocate(count); | |
| 2776 if (descriptors_obj->IsFailure()) return descriptors_obj; | |
| 2777 DescriptorArray* descriptors = DescriptorArray::cast(descriptors_obj); | |
| 2778 for (int i = 0; i < count; i++) { | |
| 2779 String* name = fun->shared()->GetThisPropertyAssignmentName(i); | |
| 2780 ASSERT(name->IsSymbol()); | |
| 2781 FieldDescriptor field(name, i, NONE); | |
| 2782 field.SetEnumerationIndex(i); | |
| 2783 descriptors->Set(i, &field); | |
| 2784 } | |
| 2785 descriptors->SetNextEnumerationIndex(count); | |
| 2786 descriptors->Sort(); | |
| 2787 map->set_instance_descriptors(descriptors); | |
| 2788 map->set_pre_allocated_property_fields(count); | |
| 2789 map->set_unused_property_fields(in_object_properties - count); | |
| 2790 } | 2815 } |
| 2791 return map; | 2816 return map; |
| 2792 } | 2817 } |
| 2793 | 2818 |
| 2794 | 2819 |
| 2795 void Heap::InitializeJSObjectFromMap(JSObject* obj, | 2820 void Heap::InitializeJSObjectFromMap(JSObject* obj, |
| 2796 FixedArray* properties, | 2821 FixedArray* properties, |
| 2797 Map* map) { | 2822 Map* map) { |
| 2798 obj->set_properties(properties); | 2823 obj->set_properties(properties); |
| 2799 obj->initialize_elements(); | 2824 obj->initialize_elements(); |
| (...skipping 2207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5007 void ExternalStringTable::TearDown() { | 5032 void ExternalStringTable::TearDown() { |
| 5008 new_space_strings_.Free(); | 5033 new_space_strings_.Free(); |
| 5009 old_space_strings_.Free(); | 5034 old_space_strings_.Free(); |
| 5010 } | 5035 } |
| 5011 | 5036 |
| 5012 | 5037 |
| 5013 List<Object*> ExternalStringTable::new_space_strings_; | 5038 List<Object*> ExternalStringTable::new_space_strings_; |
| 5014 List<Object*> ExternalStringTable::old_space_strings_; | 5039 List<Object*> ExternalStringTable::old_space_strings_; |
| 5015 | 5040 |
| 5016 } } // namespace v8::internal | 5041 } } // namespace v8::internal |
| OLD | NEW |