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

Side by Side Diff: src/heap.cc

Issue 7341: Allocate room for expected number of properties based on the... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 12 years, 2 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/builtins-ia32.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 2006-2008 the V8 project authors. All rights reserved. 1 // Copyright 2006-2008 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 825 matching lines...) Expand 10 before | Expand all | Expand 10 after
836 836
837 Object* Heap::AllocatePartialMap(InstanceType instance_type, 837 Object* Heap::AllocatePartialMap(InstanceType instance_type,
838 int instance_size) { 838 int instance_size) {
839 Object* result = AllocateRawMap(Map::kSize); 839 Object* result = AllocateRawMap(Map::kSize);
840 if (result->IsFailure()) return result; 840 if (result->IsFailure()) return result;
841 841
842 // Map::cast cannot be used due to uninitialized map field. 842 // Map::cast cannot be used due to uninitialized map field.
843 reinterpret_cast<Map*>(result)->set_map(meta_map()); 843 reinterpret_cast<Map*>(result)->set_map(meta_map());
844 reinterpret_cast<Map*>(result)->set_instance_type(instance_type); 844 reinterpret_cast<Map*>(result)->set_instance_type(instance_type);
845 reinterpret_cast<Map*>(result)->set_instance_size(instance_size); 845 reinterpret_cast<Map*>(result)->set_instance_size(instance_size);
846 reinterpret_cast<Map*>(result)->set_inobject_properties(0);
846 reinterpret_cast<Map*>(result)->set_unused_property_fields(0); 847 reinterpret_cast<Map*>(result)->set_unused_property_fields(0);
847 return result; 848 return result;
848 } 849 }
849 850
850 851
851 Object* Heap::AllocateMap(InstanceType instance_type, int instance_size) { 852 Object* Heap::AllocateMap(InstanceType instance_type, int instance_size) {
852 Object* result = AllocateRawMap(Map::kSize); 853 Object* result = AllocateRawMap(Map::kSize);
853 if (result->IsFailure()) return result; 854 if (result->IsFailure()) return result;
854 855
855 Map* map = reinterpret_cast<Map*>(result); 856 Map* map = reinterpret_cast<Map*>(result);
856 map->set_map(meta_map()); 857 map->set_map(meta_map());
857 map->set_instance_type(instance_type); 858 map->set_instance_type(instance_type);
858 map->set_prototype(null_value()); 859 map->set_prototype(null_value());
859 map->set_constructor(null_value()); 860 map->set_constructor(null_value());
860 map->set_instance_size(instance_size); 861 map->set_instance_size(instance_size);
862 map->set_inobject_properties(0);
861 map->set_instance_descriptors(empty_descriptor_array()); 863 map->set_instance_descriptors(empty_descriptor_array());
862 map->set_code_cache(empty_fixed_array()); 864 map->set_code_cache(empty_fixed_array());
863 map->set_unused_property_fields(0); 865 map->set_unused_property_fields(0);
864 map->set_bit_field(0); 866 map->set_bit_field(0);
865 return map; 867 return map;
866 } 868 }
867 869
868 870
869 bool Heap::CreateInitialMaps() { 871 bool Heap::CreateInitialMaps() {
870 Object* obj = AllocatePartialMap(MAP_TYPE, Map::kSize); 872 Object* obj = AllocatePartialMap(MAP_TYPE, Map::kSize);
(...skipping 783 matching lines...) Expand 10 before | Expand all | Expand 10 after
1654 ASSERT(JSObject::cast(result)->HasFastProperties()); 1656 ASSERT(JSObject::cast(result)->HasFastProperties());
1655 ASSERT(JSObject::cast(result)->HasFastElements()); 1657 ASSERT(JSObject::cast(result)->HasFastElements());
1656 1658
1657 return result; 1659 return result;
1658 } 1660 }
1659 1661
1660 1662
1661 Object* Heap::AllocateInitialMap(JSFunction* fun) { 1663 Object* Heap::AllocateInitialMap(JSFunction* fun) {
1662 ASSERT(!fun->has_initial_map()); 1664 ASSERT(!fun->has_initial_map());
1663 1665
1664 // First create a new map. 1666 // First create a new map with the expected number of properties being
1665 Object* map_obj = Heap::AllocateMap(JS_OBJECT_TYPE, JSObject::kHeaderSize); 1667 // allocated in-object.
1668 int expected_nof_properties = fun->shared()->expected_nof_properties();
1669 Object* map_obj = Heap::AllocateMap(JS_OBJECT_TYPE,
1670 JSObject::kHeaderSize + expected_nof_properties * kPointerSize);
1666 if (map_obj->IsFailure()) return map_obj; 1671 if (map_obj->IsFailure()) return map_obj;
1667 1672
1668 // Fetch or allocate prototype. 1673 // Fetch or allocate prototype.
1669 Object* prototype; 1674 Object* prototype;
1670 if (fun->has_instance_prototype()) { 1675 if (fun->has_instance_prototype()) {
1671 prototype = fun->instance_prototype(); 1676 prototype = fun->instance_prototype();
1672 } else { 1677 } else {
1673 prototype = AllocateFunctionPrototype(fun); 1678 prototype = AllocateFunctionPrototype(fun);
1674 if (prototype->IsFailure()) return prototype; 1679 if (prototype->IsFailure()) return prototype;
1675 } 1680 }
1676 Map* map = Map::cast(map_obj); 1681 Map* map = Map::cast(map_obj);
1677 map->set_unused_property_fields(fun->shared()->expected_nof_properties()); 1682 map->set_inobject_properties(expected_nof_properties);
1683 map->set_unused_property_fields(expected_nof_properties);
1678 map->set_prototype(prototype); 1684 map->set_prototype(prototype);
1679 return map; 1685 return map;
1680 } 1686 }
1681 1687
1682 1688
1683 void Heap::InitializeJSObjectFromMap(JSObject* obj, 1689 void Heap::InitializeJSObjectFromMap(JSObject* obj,
1684 FixedArray* properties, 1690 FixedArray* properties,
1685 Map* map) { 1691 Map* map) {
1686 obj->set_properties(properties); 1692 obj->set_properties(properties);
1687 obj->initialize_elements(); 1693 obj->initialize_elements();
1688 // TODO(1240798): Initialize the object's body using valid initial values 1694 // TODO(1240798): Initialize the object's body using valid initial values
1689 // according to the object's initial map. For example, if the map's 1695 // according to the object's initial map. For example, if the map's
1690 // instance type is JS_ARRAY_TYPE, the length field should be initialized 1696 // instance type is JS_ARRAY_TYPE, the length field should be initialized
1691 // to a number (eg, Smi::FromInt(0)) and the elements initialized to a 1697 // to a number (eg, Smi::FromInt(0)) and the elements initialized to a
1692 // fixed array (eg, Heap::empty_fixed_array()). Currently, the object 1698 // fixed array (eg, Heap::empty_fixed_array()). Currently, the object
1693 // verification code has to cope with (temporarily) invalid objects. See 1699 // verification code has to cope with (temporarily) invalid objects. See
1694 // for example, JSArray::JSArrayVerify). 1700 // for example, JSArray::JSArrayVerify).
1695 obj->InitializeBody(map->instance_size()); 1701 obj->InitializeBody(map->instance_size());
1696 } 1702 }
1697 1703
1698 1704
1699 Object* Heap::AllocateJSObjectFromMap(Map* map, PretenureFlag pretenure) { 1705 Object* Heap::AllocateJSObjectFromMap(Map* map, PretenureFlag pretenure) {
1700 // JSFunctions should be allocated using AllocateFunction to be 1706 // JSFunctions should be allocated using AllocateFunction to be
1701 // properly initialized. 1707 // properly initialized.
1702 ASSERT(map->instance_type() != JS_FUNCTION_TYPE); 1708 ASSERT(map->instance_type() != JS_FUNCTION_TYPE);
1703 1709
1704 // Allocate the backing storage for the properties. 1710 // Allocate the backing storage for the properties.
1705 Object* properties = AllocateFixedArray(map->unused_property_fields()); 1711 int prop_size = map->unused_property_fields() - map->inobject_properties();
1712 Object* properties = AllocateFixedArray(prop_size);
1706 if (properties->IsFailure()) return properties; 1713 if (properties->IsFailure()) return properties;
1707 1714
1708 // Allocate the JSObject. 1715 // Allocate the JSObject.
1709 AllocationSpace space = 1716 AllocationSpace space =
1710 (pretenure == TENURED) ? OLD_POINTER_SPACE : NEW_SPACE; 1717 (pretenure == TENURED) ? OLD_POINTER_SPACE : NEW_SPACE;
1711 if (map->instance_size() > MaxHeapObjectSize()) space = LO_SPACE; 1718 if (map->instance_size() > MaxHeapObjectSize()) space = LO_SPACE;
1712 Object* obj = Allocate(map, space); 1719 Object* obj = Allocate(map, space);
1713 if (obj->IsFailure()) return obj; 1720 if (obj->IsFailure()) return obj;
1714 1721
1715 // Initialize the JSObject. 1722 // Initialize the JSObject.
(...skipping 28 matching lines...) Expand all
1744 Map::cast(initial_map)->set_constructor(constructor); 1751 Map::cast(initial_map)->set_constructor(constructor);
1745 } 1752 }
1746 1753
1747 Map* map = constructor->initial_map(); 1754 Map* map = constructor->initial_map();
1748 1755
1749 // Check that the already allocated object has the same size as 1756 // Check that the already allocated object has the same size as
1750 // objects allocated using the constructor. 1757 // objects allocated using the constructor.
1751 ASSERT(map->instance_size() == object->map()->instance_size()); 1758 ASSERT(map->instance_size() == object->map()->instance_size());
1752 1759
1753 // Allocate the backing storage for the properties. 1760 // Allocate the backing storage for the properties.
1754 Object* properties = AllocateFixedArray(map->unused_property_fields()); 1761 int prop_size = map->unused_property_fields() - map->inobject_properties();
1762 Object* properties = AllocateFixedArray(prop_size);
1755 if (properties->IsFailure()) return properties; 1763 if (properties->IsFailure()) return properties;
1756 1764
1757 // Reset the map for the object. 1765 // Reset the map for the object.
1758 object->set_map(constructor->initial_map()); 1766 object->set_map(constructor->initial_map());
1759 1767
1760 // Reinitialize the object from the constructor map. 1768 // Reinitialize the object from the constructor map.
1761 InitializeJSObjectFromMap(object, FixedArray::cast(properties), map); 1769 InitializeJSObjectFromMap(object, FixedArray::cast(properties), map);
1762 return object; 1770 return object;
1763 } 1771 }
1764 1772
(...skipping 1305 matching lines...) Expand 10 before | Expand all | Expand 10 after
3070 return "Scavenge"; 3078 return "Scavenge";
3071 case MARK_COMPACTOR: 3079 case MARK_COMPACTOR:
3072 return MarkCompactCollector::HasCompacted() ? "Mark-compact" 3080 return MarkCompactCollector::HasCompacted() ? "Mark-compact"
3073 : "Mark-sweep"; 3081 : "Mark-sweep";
3074 } 3082 }
3075 return "Unknown GC"; 3083 return "Unknown GC";
3076 } 3084 }
3077 3085
3078 3086
3079 } } // namespace v8::internal 3087 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/builtins-ia32.cc ('k') | src/objects.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698