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

Unified Diff: src/heap.cc

Issue 170703002: Refactoring to clean up duplicate code in Heap::Allocate methods. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Comment response. Created 6 years, 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/heap.h ('k') | src/runtime.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/heap.cc
diff --git a/src/heap.cc b/src/heap.cc
index c7f363821fcb25ea226bbaa8f6456078ed8551a5..6482baa1f4a3d459c70c7acada713bd1d6c44d81 100644
--- a/src/heap.cc
+++ b/src/heap.cc
@@ -4192,28 +4192,8 @@ void Heap::InitializeAllocationMemento(AllocationMemento* memento,
}
-MaybeObject* Heap::AllocateWithAllocationSite(Map* map, AllocationSpace space,
- Handle<AllocationSite> allocation_site) {
- ASSERT(gc_state_ == NOT_IN_GC);
- ASSERT(map->instance_type() != MAP_TYPE);
- // If allocation failures are disallowed, we may allocate in a different
- // space when new space is full and the object is not a large object.
- AllocationSpace retry_space =
- (space != NEW_SPACE) ? space : TargetSpaceId(map->instance_type());
- int size = map->instance_size() + AllocationMemento::kSize;
- Object* result;
- MaybeObject* maybe_result = AllocateRaw(size, space, retry_space);
- if (!maybe_result->ToObject(&result)) return maybe_result;
- // No need for write barrier since object is white and map is in old space.
- HeapObject::cast(result)->set_map_no_write_barrier(map);
- AllocationMemento* alloc_memento = reinterpret_cast<AllocationMemento*>(
- reinterpret_cast<Address>(result) + map->instance_size());
- InitializeAllocationMemento(alloc_memento, *allocation_site);
- return result;
-}
-
-
-MaybeObject* Heap::Allocate(Map* map, AllocationSpace space) {
+MaybeObject* Heap::Allocate(Map* map, AllocationSpace space,
+ AllocationSite* allocation_site) {
ASSERT(gc_state_ == NOT_IN_GC);
ASSERT(map->instance_type() != MAP_TYPE);
// If allocation failures are disallowed, we may allocate in a different
@@ -4221,11 +4201,19 @@ MaybeObject* Heap::Allocate(Map* map, AllocationSpace space) {
AllocationSpace retry_space =
(space != NEW_SPACE) ? space : TargetSpaceId(map->instance_type());
int size = map->instance_size();
+ if (allocation_site != NULL) {
+ size += AllocationMemento::kSize;
+ }
Object* result;
MaybeObject* maybe_result = AllocateRaw(size, space, retry_space);
if (!maybe_result->ToObject(&result)) return maybe_result;
// No need for write barrier since object is white and map is in old space.
HeapObject::cast(result)->set_map_no_write_barrier(map);
+ if (allocation_site != NULL) {
+ AllocationMemento* alloc_memento = reinterpret_cast<AllocationMemento*>(
+ reinterpret_cast<Address>(result) + map->instance_size());
+ InitializeAllocationMemento(alloc_memento, allocation_site);
+ }
return result;
}
@@ -4349,7 +4337,10 @@ void Heap::InitializeJSObjectFromMap(JSObject* obj,
MaybeObject* Heap::AllocateJSObjectFromMap(
- Map* map, PretenureFlag pretenure, bool allocate_properties) {
+ Map* map,
+ PretenureFlag pretenure,
+ bool allocate_properties,
+ AllocationSite* allocation_site) {
// JSFunctions should be allocated using AllocateFunction to be
// properly initialized.
ASSERT(map->instance_type() != JS_FUNCTION_TYPE);
@@ -4375,7 +4366,7 @@ MaybeObject* Heap::AllocateJSObjectFromMap(
int size = map->instance_size();
AllocationSpace space = SelectSpace(size, OLD_POINTER_SPACE, pretenure);
Object* obj;
- MaybeObject* maybe_obj = Allocate(map, space);
+ MaybeObject* maybe_obj = Allocate(map, space, allocation_site);
if (!maybe_obj->To(&obj)) return maybe_obj;
// Initialize the JSObject.
@@ -4386,79 +4377,16 @@ MaybeObject* Heap::AllocateJSObjectFromMap(
}
-MaybeObject* Heap::AllocateJSObjectFromMapWithAllocationSite(
- Map* map, Handle<AllocationSite> allocation_site) {
- // JSFunctions should be allocated using AllocateFunction to be
- // properly initialized.
- ASSERT(map->instance_type() != JS_FUNCTION_TYPE);
-
- // Both types of global objects should be allocated using
- // AllocateGlobalObject to be properly initialized.
- ASSERT(map->instance_type() != JS_GLOBAL_OBJECT_TYPE);
- ASSERT(map->instance_type() != JS_BUILTINS_OBJECT_TYPE);
-
- // Allocate the backing storage for the properties.
- int prop_size = map->InitialPropertiesLength();
- ASSERT(prop_size >= 0);
- FixedArray* properties;
- { MaybeObject* maybe_properties = AllocateFixedArray(prop_size);
- if (!maybe_properties->To(&properties)) return maybe_properties;
- }
-
- // Allocate the JSObject.
- int size = map->instance_size();
- AllocationSpace space = SelectSpace(size, OLD_POINTER_SPACE, NOT_TENURED);
- Object* obj;
- MaybeObject* maybe_obj =
- AllocateWithAllocationSite(map, space, allocation_site);
- if (!maybe_obj->To(&obj)) return maybe_obj;
-
- // Initialize the JSObject.
- InitializeJSObjectFromMap(JSObject::cast(obj), properties, map);
- ASSERT(JSObject::cast(obj)->HasFastElements());
- return obj;
-}
-
-
MaybeObject* Heap::AllocateJSObject(JSFunction* constructor,
- PretenureFlag pretenure) {
+ PretenureFlag pretenure,
+ AllocationSite* allocation_site) {
ASSERT(constructor->has_initial_map());
- // Allocate the object based on the constructors initial map.
- MaybeObject* result = AllocateJSObjectFromMap(
- constructor->initial_map(), pretenure);
-#ifdef DEBUG
- // Make sure result is NOT a global object if valid.
- Object* non_failure;
- ASSERT(!result->ToObject(&non_failure) || !non_failure->IsGlobalObject());
-#endif
- return result;
-}
-
-MaybeObject* Heap::AllocateJSObjectWithAllocationSite(JSFunction* constructor,
- Handle<AllocationSite> allocation_site) {
- ASSERT(constructor->has_initial_map());
- // Allocate the object based on the constructors initial map, or the payload
- // advice
- Map* initial_map = constructor->initial_map();
-
- ElementsKind to_kind = allocation_site->GetElementsKind();
- AllocationSiteMode mode = TRACK_ALLOCATION_SITE;
- if (to_kind != initial_map->elements_kind()) {
- MaybeObject* maybe_new_map = initial_map->AsElementsKind(to_kind);
- if (!maybe_new_map->To(&initial_map)) return maybe_new_map;
- // Possibly alter the mode, since we found an updated elements kind
- // in the type info cell.
- mode = AllocationSite::GetMode(to_kind);
- }
-
- MaybeObject* result;
- if (mode == TRACK_ALLOCATION_SITE) {
- result = AllocateJSObjectFromMapWithAllocationSite(initial_map,
- allocation_site);
- } else {
- result = AllocateJSObjectFromMap(initial_map, NOT_TENURED);
- }
+ // Allocate the object based on the constructors initial map.
+ MaybeObject* result = AllocateJSObjectFromMap(constructor->initial_map(),
+ pretenure,
+ true,
+ allocation_site);
#ifdef DEBUG
// Make sure result is NOT a global object if valid.
Object* non_failure;
« no previous file with comments | « src/heap.h ('k') | src/runtime.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698