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

Side by Side Diff: src/heap.cc

Issue 10808011: Let DescriptorArray::Append insert at proper position, avoiding need for resorting. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Addressed comments Created 8 years, 5 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 | « src/factory.cc ('k') | src/objects.h » ('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 3806 matching lines...) Expand 10 before | Expand all | Expand 10 after
3817 } 3817 }
3818 3818
3819 3819
3820 MaybeObject* Heap::AllocateInitialMap(JSFunction* fun) { 3820 MaybeObject* Heap::AllocateInitialMap(JSFunction* fun) {
3821 ASSERT(!fun->has_initial_map()); 3821 ASSERT(!fun->has_initial_map());
3822 3822
3823 // First create a new map with the size and number of in-object properties 3823 // First create a new map with the size and number of in-object properties
3824 // suggested by the function. 3824 // suggested by the function.
3825 int instance_size = fun->shared()->CalculateInstanceSize(); 3825 int instance_size = fun->shared()->CalculateInstanceSize();
3826 int in_object_properties = fun->shared()->CalculateInObjectProperties(); 3826 int in_object_properties = fun->shared()->CalculateInObjectProperties();
3827 Object* map_obj; 3827 Map* map;
3828 { MaybeObject* maybe_map_obj = AllocateMap(JS_OBJECT_TYPE, instance_size); 3828 MaybeObject* maybe_map = AllocateMap(JS_OBJECT_TYPE, instance_size);
3829 if (!maybe_map_obj->ToObject(&map_obj)) return maybe_map_obj; 3829 if (!maybe_map->To(&map)) return maybe_map;
3830 }
3831 3830
3832 // Fetch or allocate prototype. 3831 // Fetch or allocate prototype.
3833 Object* prototype; 3832 Object* prototype;
3834 if (fun->has_instance_prototype()) { 3833 if (fun->has_instance_prototype()) {
3835 prototype = fun->instance_prototype(); 3834 prototype = fun->instance_prototype();
3836 } else { 3835 } else {
3837 { MaybeObject* maybe_prototype = AllocateFunctionPrototype(fun); 3836 MaybeObject* maybe_prototype = AllocateFunctionPrototype(fun);
3838 if (!maybe_prototype->ToObject(&prototype)) return maybe_prototype; 3837 if (!maybe_prototype->To(&prototype)) return maybe_prototype;
3839 }
3840 } 3838 }
3841 Map* map = Map::cast(map_obj);
3842 map->set_inobject_properties(in_object_properties); 3839 map->set_inobject_properties(in_object_properties);
3843 map->set_unused_property_fields(in_object_properties); 3840 map->set_unused_property_fields(in_object_properties);
3844 map->set_prototype(prototype); 3841 map->set_prototype(prototype);
3845 ASSERT(map->has_fast_object_elements()); 3842 ASSERT(map->has_fast_object_elements());
3846 3843
3847 // If the function has only simple this property assignments add 3844 // If the function has only simple this property assignments add
3848 // field descriptors for these to the initial map as the object 3845 // field descriptors for these to the initial map as the object
3849 // cannot be constructed without having these properties. Guard by 3846 // cannot be constructed without having these properties. Guard by
3850 // the inline_new flag so we only change the map if we generate a 3847 // the inline_new flag so we only change the map if we generate a
3851 // specialized construct stub. 3848 // specialized construct stub.
3852 ASSERT(in_object_properties <= Map::kMaxPreAllocatedPropertyFields); 3849 ASSERT(in_object_properties <= Map::kMaxPreAllocatedPropertyFields);
3853 if (fun->shared()->CanGenerateInlineConstructor(prototype)) { 3850 if (fun->shared()->CanGenerateInlineConstructor(prototype)) {
3854 int count = fun->shared()->this_property_assignments_count(); 3851 int count = fun->shared()->this_property_assignments_count();
3855 if (count > in_object_properties) { 3852 if (count > in_object_properties) {
3856 // Inline constructor can only handle inobject properties. 3853 // Inline constructor can only handle inobject properties.
3857 fun->shared()->ForbidInlineConstructor(); 3854 fun->shared()->ForbidInlineConstructor();
3858 } else { 3855 } else {
3859 DescriptorArray* descriptors; 3856 DescriptorArray* descriptors;
3860 { MaybeObject* maybe_descriptors_obj = 3857 MaybeObject* maybe_descriptors =
3861 DescriptorArray::Allocate(count, DescriptorArray::MAY_BE_SHARED); 3858 DescriptorArray::Allocate(count, DescriptorArray::MAY_BE_SHARED);
3862 if (!maybe_descriptors_obj->To<DescriptorArray>(&descriptors)) { 3859 if (!maybe_descriptors->To(&descriptors)) return maybe_descriptors;
3863 return maybe_descriptors_obj; 3860
3864 }
3865 }
3866 DescriptorArray::WhitenessWitness witness(descriptors); 3861 DescriptorArray::WhitenessWitness witness(descriptors);
3867 for (int i = 0; i < count; i++) { 3862 for (int i = 0; i < count; i++) {
3868 String* name = fun->shared()->GetThisPropertyAssignmentName(i); 3863 String* name = fun->shared()->GetThisPropertyAssignmentName(i);
3869 ASSERT(name->IsSymbol()); 3864 ASSERT(name->IsSymbol());
3870 FieldDescriptor field(name, i, NONE, i + 1); 3865 FieldDescriptor field(name, i, NONE, i + 1);
3871 descriptors->Set(i, &field, witness); 3866 descriptors->Set(i, &field, witness);
3872 } 3867 }
3873 descriptors->SortUnchecked(witness); 3868 descriptors->Sort(witness);
3874 3869
3875 // The descriptors may contain duplicates because the compiler does not 3870 // The descriptors may contain duplicates because the compiler does not
3876 // guarantee the uniqueness of property names (it would have required 3871 // guarantee the uniqueness of property names (it would have required
3877 // quadratic time). Once the descriptors are sorted we can check for 3872 // quadratic time). Once the descriptors are sorted we can check for
3878 // duplicates in linear time. 3873 // duplicates in linear time.
3879 if (HasDuplicates(descriptors)) { 3874 if (HasDuplicates(descriptors)) {
3880 fun->shared()->ForbidInlineConstructor(); 3875 fun->shared()->ForbidInlineConstructor();
3881 } else { 3876 } else {
3882 map->set_instance_descriptors(descriptors); 3877 map->InitializeDescriptors(descriptors);
3883 map->set_pre_allocated_property_fields(count); 3878 map->set_pre_allocated_property_fields(count);
3884 map->set_unused_property_fields(in_object_properties - count); 3879 map->set_unused_property_fields(in_object_properties - count);
3885 } 3880 }
3886 } 3881 }
3887 } 3882 }
3888 3883
3889 fun->shared()->StartInobjectSlackTracking(map); 3884 fun->shared()->StartInobjectSlackTracking(map);
3890 3885
3891 return map; 3886 return map;
3892 } 3887 }
(...skipping 3329 matching lines...) Expand 10 before | Expand all | Expand 10 after
7222 static_cast<int>(object_sizes_last_time_[index])); 7217 static_cast<int>(object_sizes_last_time_[index]));
7223 CODE_KIND_LIST(ADJUST_LAST_TIME_OBJECT_COUNT) 7218 CODE_KIND_LIST(ADJUST_LAST_TIME_OBJECT_COUNT)
7224 #undef ADJUST_LAST_TIME_OBJECT_COUNT 7219 #undef ADJUST_LAST_TIME_OBJECT_COUNT
7225 7220
7226 memcpy(object_counts_last_time_, object_counts_, sizeof(object_counts_)); 7221 memcpy(object_counts_last_time_, object_counts_, sizeof(object_counts_));
7227 memcpy(object_sizes_last_time_, object_sizes_, sizeof(object_sizes_)); 7222 memcpy(object_sizes_last_time_, object_sizes_, sizeof(object_sizes_));
7228 ClearObjectStats(); 7223 ClearObjectStats();
7229 } 7224 }
7230 7225
7231 } } // namespace v8::internal 7226 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/factory.cc ('k') | src/objects.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698