| 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 2582 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2593 SKIP_WRITE_BARRIER); | 2593 SKIP_WRITE_BARRIER); |
| 2594 | 2594 |
| 2595 // Check the state of the object | 2595 // Check the state of the object |
| 2596 ASSERT(JSObject::cast(result)->HasFastProperties()); | 2596 ASSERT(JSObject::cast(result)->HasFastProperties()); |
| 2597 ASSERT(JSObject::cast(result)->HasFastElements()); | 2597 ASSERT(JSObject::cast(result)->HasFastElements()); |
| 2598 | 2598 |
| 2599 return result; | 2599 return result; |
| 2600 } | 2600 } |
| 2601 | 2601 |
| 2602 | 2602 |
| 2603 static bool HasDuplicates(DescriptorArray* descriptors) { |
| 2604 int count = descriptors->number_of_descriptors(); |
| 2605 if (count > 1) { |
| 2606 String* prev_key = descriptors->GetKey(0); |
| 2607 for (int i = 1; i != count; i++) { |
| 2608 String* current_key = descriptors->GetKey(i); |
| 2609 if (prev_key == current_key) return true; |
| 2610 prev_key = current_key; |
| 2611 } |
| 2612 } |
| 2613 return false; |
| 2614 } |
| 2615 |
| 2616 |
| 2603 Object* Heap::AllocateInitialMap(JSFunction* fun) { | 2617 Object* Heap::AllocateInitialMap(JSFunction* fun) { |
| 2604 ASSERT(!fun->has_initial_map()); | 2618 ASSERT(!fun->has_initial_map()); |
| 2605 | 2619 |
| 2606 // First create a new map with the size and number of in-object properties | 2620 // First create a new map with the size and number of in-object properties |
| 2607 // suggested by the function. | 2621 // suggested by the function. |
| 2608 int instance_size = fun->shared()->CalculateInstanceSize(); | 2622 int instance_size = fun->shared()->CalculateInstanceSize(); |
| 2609 int in_object_properties = fun->shared()->CalculateInObjectProperties(); | 2623 int in_object_properties = fun->shared()->CalculateInObjectProperties(); |
| 2610 Object* map_obj = Heap::AllocateMap(JS_OBJECT_TYPE, instance_size); | 2624 Object* map_obj = Heap::AllocateMap(JS_OBJECT_TYPE, instance_size); |
| 2611 if (map_obj->IsFailure()) return map_obj; | 2625 if (map_obj->IsFailure()) return map_obj; |
| 2612 | 2626 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 2626 | 2640 |
| 2627 // If the function has only simple this property assignments add | 2641 // If the function has only simple this property assignments add |
| 2628 // field descriptors for these to the initial map as the object | 2642 // field descriptors for these to the initial map as the object |
| 2629 // cannot be constructed without having these properties. Guard by | 2643 // cannot be constructed without having these properties. Guard by |
| 2630 // the inline_new flag so we only change the map if we generate a | 2644 // the inline_new flag so we only change the map if we generate a |
| 2631 // specialized construct stub. | 2645 // specialized construct stub. |
| 2632 ASSERT(in_object_properties <= Map::kMaxPreAllocatedPropertyFields); | 2646 ASSERT(in_object_properties <= Map::kMaxPreAllocatedPropertyFields); |
| 2633 if (fun->shared()->CanGenerateInlineConstructor(prototype)) { | 2647 if (fun->shared()->CanGenerateInlineConstructor(prototype)) { |
| 2634 int count = fun->shared()->this_property_assignments_count(); | 2648 int count = fun->shared()->this_property_assignments_count(); |
| 2635 if (count > in_object_properties) { | 2649 if (count > in_object_properties) { |
| 2636 count = in_object_properties; | 2650 // Inline constructor can only handle inobject properties. |
| 2651 fun->shared()->ForbidInlineConstructor(); |
| 2652 } else { |
| 2653 Object* descriptors_obj = DescriptorArray::Allocate(count); |
| 2654 if (descriptors_obj->IsFailure()) return descriptors_obj; |
| 2655 DescriptorArray* descriptors = DescriptorArray::cast(descriptors_obj); |
| 2656 for (int i = 0; i < count; i++) { |
| 2657 String* name = fun->shared()->GetThisPropertyAssignmentName(i); |
| 2658 ASSERT(name->IsSymbol()); |
| 2659 FieldDescriptor field(name, i, NONE); |
| 2660 field.SetEnumerationIndex(i); |
| 2661 descriptors->Set(i, &field); |
| 2662 } |
| 2663 descriptors->SetNextEnumerationIndex(count); |
| 2664 descriptors->SortUnchecked(); |
| 2665 |
| 2666 // The descriptors may contain duplicates because the compiler does not |
| 2667 // guarantee the uniqueness of property names (it would have required |
| 2668 // quadratic time). Once the descriptors are sorted we can check for |
| 2669 // duplicates in linear time. |
| 2670 if (HasDuplicates(descriptors)) { |
| 2671 fun->shared()->ForbidInlineConstructor(); |
| 2672 } else { |
| 2673 map->set_instance_descriptors(descriptors); |
| 2674 map->set_pre_allocated_property_fields(count); |
| 2675 map->set_unused_property_fields(in_object_properties - count); |
| 2676 } |
| 2637 } | 2677 } |
| 2638 Object* descriptors_obj = DescriptorArray::Allocate(count); | |
| 2639 if (descriptors_obj->IsFailure()) return descriptors_obj; | |
| 2640 DescriptorArray* descriptors = DescriptorArray::cast(descriptors_obj); | |
| 2641 for (int i = 0; i < count; i++) { | |
| 2642 String* name = fun->shared()->GetThisPropertyAssignmentName(i); | |
| 2643 ASSERT(name->IsSymbol()); | |
| 2644 FieldDescriptor field(name, i, NONE); | |
| 2645 field.SetEnumerationIndex(i); | |
| 2646 descriptors->Set(i, &field); | |
| 2647 } | |
| 2648 descriptors->SetNextEnumerationIndex(count); | |
| 2649 descriptors->Sort(); | |
| 2650 map->set_instance_descriptors(descriptors); | |
| 2651 map->set_pre_allocated_property_fields(count); | |
| 2652 map->set_unused_property_fields(in_object_properties - count); | |
| 2653 } | 2678 } |
| 2654 return map; | 2679 return map; |
| 2655 } | 2680 } |
| 2656 | 2681 |
| 2657 | 2682 |
| 2658 void Heap::InitializeJSObjectFromMap(JSObject* obj, | 2683 void Heap::InitializeJSObjectFromMap(JSObject* obj, |
| 2659 FixedArray* properties, | 2684 FixedArray* properties, |
| 2660 Map* map) { | 2685 Map* map) { |
| 2661 obj->set_properties(properties); | 2686 obj->set_properties(properties); |
| 2662 obj->initialize_elements(); | 2687 obj->initialize_elements(); |
| (...skipping 2214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4877 void ExternalStringTable::TearDown() { | 4902 void ExternalStringTable::TearDown() { |
| 4878 new_space_strings_.Free(); | 4903 new_space_strings_.Free(); |
| 4879 old_space_strings_.Free(); | 4904 old_space_strings_.Free(); |
| 4880 } | 4905 } |
| 4881 | 4906 |
| 4882 | 4907 |
| 4883 List<Object*> ExternalStringTable::new_space_strings_; | 4908 List<Object*> ExternalStringTable::new_space_strings_; |
| 4884 List<Object*> ExternalStringTable::old_space_strings_; | 4909 List<Object*> ExternalStringTable::old_space_strings_; |
| 4885 | 4910 |
| 4886 } } // namespace v8::internal | 4911 } } // namespace v8::internal |
| OLD | NEW |