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

Unified Diff: src/runtime.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.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/runtime.cc
diff --git a/src/runtime.cc b/src/runtime.cc
index 05392caefcc3cadcb11f026eb854a62d0ff1ef77..51dab07be7fdec435e234ffe6bab61517eb0cbb5 100644
--- a/src/runtime.cc
+++ b/src/runtime.cc
@@ -14716,8 +14716,26 @@ static MaybeObject* ArrayConstructorCommon(Isolate* isolate,
site->SetElementsKind(to_kind);
}
- maybe_array = isolate->heap()->AllocateJSObjectWithAllocationSite(
- *constructor, site);
+ // We should allocate with an initial map that reflects the allocation site
+ // advice. Therefore we use AllocateJSObjectFromMap instead of passing
+ // the constructor.
+ Map* initial_map = constructor->initial_map();
+ 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;
+ }
+
+ // If we don't care to track arrays of to_kind ElementsKind, then
+ // don't emit a memento for them.
+ AllocationSite* allocation_site =
+ (AllocationSite::GetMode(to_kind) == TRACK_ALLOCATION_SITE)
+ ? *site
+ : NULL;
+
+ maybe_array = isolate->heap()->AllocateJSObjectFromMap(initial_map,
+ NOT_TENURED,
+ true,
+ allocation_site);
if (!maybe_array->To(&array)) return maybe_array;
} else {
maybe_array = isolate->heap()->AllocateJSObject(*constructor);
« no previous file with comments | « src/heap.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698