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

Side by Side Diff: src/heap.cc

Issue 151146: Treat the builtins object like other global objects (with... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 11 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/heap.h ('k') | src/ia32/stub-cache-ia32.cc » ('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 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 1540 matching lines...) Expand 10 before | Expand all | Expand 10 after
1551 (pretenure == TENURED) ? OLD_DATA_SPACE : NEW_SPACE; 1551 (pretenure == TENURED) ? OLD_DATA_SPACE : NEW_SPACE;
1552 Object* result = Allocate(proxy_map(), space); 1552 Object* result = Allocate(proxy_map(), space);
1553 if (result->IsFailure()) return result; 1553 if (result->IsFailure()) return result;
1554 1554
1555 Proxy::cast(result)->set_proxy(proxy); 1555 Proxy::cast(result)->set_proxy(proxy);
1556 return result; 1556 return result;
1557 } 1557 }
1558 1558
1559 1559
1560 Object* Heap::AllocateSharedFunctionInfo(Object* name) { 1560 Object* Heap::AllocateSharedFunctionInfo(Object* name) {
1561 Object* result = Allocate(shared_function_info_map(), NEW_SPACE); 1561 Object* result = Allocate(shared_function_info_map(), OLD_POINTER_SPACE);
1562 if (result->IsFailure()) return result; 1562 if (result->IsFailure()) return result;
1563 1563
1564 SharedFunctionInfo* share = SharedFunctionInfo::cast(result); 1564 SharedFunctionInfo* share = SharedFunctionInfo::cast(result);
1565 share->set_name(name); 1565 share->set_name(name);
1566 Code* illegal = Builtins::builtin(Builtins::Illegal); 1566 Code* illegal = Builtins::builtin(Builtins::Illegal);
1567 share->set_code(illegal); 1567 share->set_code(illegal);
1568 Code* construct_stub = Builtins::builtin(Builtins::JSConstructStubGeneric); 1568 Code* construct_stub = Builtins::builtin(Builtins::JSConstructStubGeneric);
1569 share->set_construct_stub(construct_stub); 1569 share->set_construct_stub(construct_stub);
1570 share->set_expected_nof_properties(0); 1570 share->set_expected_nof_properties(0);
1571 share->set_length(0); 1571 share->set_length(0);
(...skipping 471 matching lines...) Expand 10 before | Expand all | Expand 10 after
2043 } 2043 }
2044 2044
2045 2045
2046 Object* Heap::AllocateJSObjectFromMap(Map* map, PretenureFlag pretenure) { 2046 Object* Heap::AllocateJSObjectFromMap(Map* map, PretenureFlag pretenure) {
2047 // JSFunctions should be allocated using AllocateFunction to be 2047 // JSFunctions should be allocated using AllocateFunction to be
2048 // properly initialized. 2048 // properly initialized.
2049 ASSERT(map->instance_type() != JS_FUNCTION_TYPE); 2049 ASSERT(map->instance_type() != JS_FUNCTION_TYPE);
2050 2050
2051 // Allocate the backing storage for the properties. 2051 // Allocate the backing storage for the properties.
2052 int prop_size = map->unused_property_fields() - map->inobject_properties(); 2052 int prop_size = map->unused_property_fields() - map->inobject_properties();
2053 Object* properties = AllocateFixedArray(prop_size); 2053 Object* properties = AllocateFixedArray(prop_size, pretenure);
2054 if (properties->IsFailure()) return properties; 2054 if (properties->IsFailure()) return properties;
2055 2055
2056 // Allocate the JSObject. 2056 // Allocate the JSObject.
2057 AllocationSpace space = 2057 AllocationSpace space =
2058 (pretenure == TENURED) ? OLD_POINTER_SPACE : NEW_SPACE; 2058 (pretenure == TENURED) ? OLD_POINTER_SPACE : NEW_SPACE;
2059 if (map->instance_size() > MaxObjectSizeInPagedSpace()) space = LO_SPACE; 2059 if (map->instance_size() > MaxObjectSizeInPagedSpace()) space = LO_SPACE;
2060 Object* obj = Allocate(map, space); 2060 Object* obj = Allocate(map, space);
2061 if (obj->IsFailure()) return obj; 2061 if (obj->IsFailure()) return obj;
2062 2062
2063 // Initialize the JSObject. 2063 // Initialize the JSObject.
2064 InitializeJSObjectFromMap(JSObject::cast(obj), 2064 InitializeJSObjectFromMap(JSObject::cast(obj),
2065 FixedArray::cast(properties), 2065 FixedArray::cast(properties),
2066 map); 2066 map);
2067 return obj; 2067 return obj;
2068 } 2068 }
2069 2069
2070 2070
2071 Object* Heap::AllocateJSObject(JSFunction* constructor, 2071 Object* Heap::AllocateJSObject(JSFunction* constructor,
2072 PretenureFlag pretenure) { 2072 PretenureFlag pretenure) {
2073 // Allocate the initial map if absent. 2073 // Allocate the initial map if absent.
2074 if (!constructor->has_initial_map()) { 2074 if (!constructor->has_initial_map()) {
2075 Object* initial_map = AllocateInitialMap(constructor); 2075 Object* initial_map = AllocateInitialMap(constructor);
2076 if (initial_map->IsFailure()) return initial_map; 2076 if (initial_map->IsFailure()) return initial_map;
2077 constructor->set_initial_map(Map::cast(initial_map)); 2077 constructor->set_initial_map(Map::cast(initial_map));
2078 Map::cast(initial_map)->set_constructor(constructor); 2078 Map::cast(initial_map)->set_constructor(constructor);
2079 } 2079 }
2080 // Allocate the object based on the constructors initial map. 2080 // Allocate the object based on the constructors initial map.
2081 Object* result = 2081 Object* result =
2082 AllocateJSObjectFromMap(constructor->initial_map(), pretenure); 2082 AllocateJSObjectFromMap(constructor->initial_map(), pretenure);
2083 // Make sure result is NOT a JS global object if valid. 2083 // Make sure result is NOT a global object if valid.
2084 ASSERT(result->IsFailure() || !result->IsJSGlobalObject()); 2084 ASSERT(result->IsFailure() || !result->IsGlobalObject());
2085 return result; 2085 return result;
2086 } 2086 }
2087 2087
2088 2088
2089 Object* Heap::AllocateJSGlobalObject(JSFunction* constructor) { 2089 Object* Heap::AllocateGlobalObject(JSFunction* constructor) {
2090 ASSERT(constructor->has_initial_map()); 2090 ASSERT(constructor->has_initial_map());
2091 // Make sure no field properties are described in the initial map. 2091 // Make sure no field properties are described in the initial map.
2092 // This guarantees us that normalizing the properties does not 2092 // This guarantees us that normalizing the properties does not
2093 // require us to change property values to JSGlobalPropertyCells. 2093 // require us to change property values to JSGlobalPropertyCells.
2094 ASSERT(constructor->initial_map()->NextFreePropertyIndex() == 0); 2094 ASSERT(constructor->initial_map()->NextFreePropertyIndex() == 0);
2095 2095
2096 // Make sure we don't have a ton of pre-allocated slots in the
2097 // global objects. They will be unused once we normalize the object.
2098 ASSERT(constructor->initial_map()->unused_property_fields() == 0);
2099 ASSERT(constructor->initial_map()->inobject_properties() == 0);
2100
2096 // Allocate the object based on the constructors initial map. 2101 // Allocate the object based on the constructors initial map.
2097 Object* result = AllocateJSObjectFromMap(constructor->initial_map(), TENURED); 2102 Object* result = AllocateJSObjectFromMap(constructor->initial_map(), TENURED);
2098 if (result->IsFailure()) return result; 2103 if (result->IsFailure()) return result;
2099 2104
2100 // Normalize the result. 2105 // Normalize the result.
2101 JSObject* global = JSObject::cast(result); 2106 JSObject* global = JSObject::cast(result);
2102 result = global->NormalizeProperties(CLEAR_INOBJECT_PROPERTIES); 2107 result = global->NormalizeProperties(CLEAR_INOBJECT_PROPERTIES);
2103 if (result->IsFailure()) return result; 2108 if (result->IsFailure()) return result;
2104 2109
2105 // Make sure result is a JS global object with properties in dictionary. 2110 // Make sure result is a global object with properties in dictionary.
2106 ASSERT(global->IsJSGlobalObject()); 2111 ASSERT(global->IsGlobalObject());
2107 ASSERT(!global->HasFastProperties()); 2112 ASSERT(!global->HasFastProperties());
2108 return global; 2113 return global;
2109 } 2114 }
2110 2115
2111 2116
2112 Object* Heap::CopyJSObject(JSObject* source) { 2117 Object* Heap::CopyJSObject(JSObject* source) {
2113 // Never used to copy functions. If functions need to be copied we 2118 // Never used to copy functions. If functions need to be copied we
2114 // have to be careful to clear the literals array. 2119 // have to be careful to clear the literals array.
2115 ASSERT(!source->IsJSFunction()); 2120 ASSERT(!source->IsJSFunction());
2116 2121
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
2175 } 2180 }
2176 2181
2177 Map* map = constructor->initial_map(); 2182 Map* map = constructor->initial_map();
2178 2183
2179 // Check that the already allocated object has the same size as 2184 // Check that the already allocated object has the same size as
2180 // objects allocated using the constructor. 2185 // objects allocated using the constructor.
2181 ASSERT(map->instance_size() == object->map()->instance_size()); 2186 ASSERT(map->instance_size() == object->map()->instance_size());
2182 2187
2183 // Allocate the backing storage for the properties. 2188 // Allocate the backing storage for the properties.
2184 int prop_size = map->unused_property_fields() - map->inobject_properties(); 2189 int prop_size = map->unused_property_fields() - map->inobject_properties();
2185 Object* properties = AllocateFixedArray(prop_size); 2190 Object* properties = AllocateFixedArray(prop_size, TENURED);
2186 if (properties->IsFailure()) return properties; 2191 if (properties->IsFailure()) return properties;
2187 2192
2188 // Reset the map for the object. 2193 // Reset the map for the object.
2189 object->set_map(constructor->initial_map()); 2194 object->set_map(constructor->initial_map());
2190 2195
2191 // Reinitialize the object from the constructor map. 2196 // Reinitialize the object from the constructor map.
2192 InitializeJSObjectFromMap(object, FixedArray::cast(properties), map); 2197 InitializeJSObjectFromMap(object, FixedArray::cast(properties), map);
2193 return object; 2198 return object;
2194 } 2199 }
2195 2200
(...skipping 1469 matching lines...) Expand 10 before | Expand all | Expand 10 after
3665 #ifdef DEBUG 3670 #ifdef DEBUG
3666 bool Heap::GarbageCollectionGreedyCheck() { 3671 bool Heap::GarbageCollectionGreedyCheck() {
3667 ASSERT(FLAG_gc_greedy); 3672 ASSERT(FLAG_gc_greedy);
3668 if (Bootstrapper::IsActive()) return true; 3673 if (Bootstrapper::IsActive()) return true;
3669 if (disallow_allocation_failure()) return true; 3674 if (disallow_allocation_failure()) return true;
3670 return CollectGarbage(0, NEW_SPACE); 3675 return CollectGarbage(0, NEW_SPACE);
3671 } 3676 }
3672 #endif 3677 #endif
3673 3678
3674 } } // namespace v8::internal 3679 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/heap.h ('k') | src/ia32/stub-cache-ia32.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698