Commit 9a340d1f authored by ishell@chromium.org's avatar ishell@chromium.org

Handlification of ArrayConstructorCommon().

R=yangguo@chromium.org

Review URL: https://codereview.chromium.org/200213003

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@20001 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent e4a18df7
...@@ -1910,6 +1910,15 @@ MUST_USE_RESULT MaybeObject* ElementsAccessorBase<ElementsAccessorSubclass, ...@@ -1910,6 +1910,15 @@ MUST_USE_RESULT MaybeObject* ElementsAccessorBase<ElementsAccessorSubclass,
} }
// TODO(ishell): Temporary wrapper until handlified.
Handle<Object> ArrayConstructInitializeElements(Handle<JSArray> array,
Arguments* args) {
CALL_HEAP_FUNCTION(array->GetIsolate(),
ArrayConstructInitializeElements(*array, args),
Object);
}
MUST_USE_RESULT MaybeObject* ArrayConstructInitializeElements( MUST_USE_RESULT MaybeObject* ArrayConstructInitializeElements(
JSArray* array, Arguments* args) { JSArray* array, Arguments* args) {
Heap* heap = array->GetIsolate()->heap(); Heap* heap = array->GetIsolate()->heap();
......
...@@ -200,6 +200,9 @@ class ElementsAccessor { ...@@ -200,6 +200,9 @@ class ElementsAccessor {
void CheckArrayAbuse(JSObject* obj, const char* op, uint32_t key, void CheckArrayAbuse(JSObject* obj, const char* op, uint32_t key,
bool allow_appending = false); bool allow_appending = false);
Handle<Object> ArrayConstructInitializeElements(Handle<JSArray> array,
Arguments* args);
MUST_USE_RESULT MaybeObject* ArrayConstructInitializeElements( MUST_USE_RESULT MaybeObject* ArrayConstructInitializeElements(
JSArray* array, Arguments* args); JSArray* array, Arguments* args);
......
...@@ -1408,12 +1408,18 @@ Handle<GlobalObject> Factory::NewGlobalObject(Handle<JSFunction> constructor) { ...@@ -1408,12 +1408,18 @@ Handle<GlobalObject> Factory::NewGlobalObject(Handle<JSFunction> constructor) {
} }
Handle<JSObject> Factory::NewJSObjectFromMap(Handle<Map> map, Handle<JSObject> Factory::NewJSObjectFromMap(
PretenureFlag pretenure, Handle<Map> map,
bool alloc_props) { PretenureFlag pretenure,
bool alloc_props,
Handle<AllocationSite> allocation_site) {
CALL_HEAP_FUNCTION( CALL_HEAP_FUNCTION(
isolate(), isolate(),
isolate()->heap()->AllocateJSObjectFromMap(*map, pretenure, alloc_props), isolate()->heap()->AllocateJSObjectFromMap(
*map,
pretenure,
alloc_props,
allocation_site.is_null() ? NULL : *allocation_site),
JSObject); JSObject);
} }
...@@ -1448,6 +1454,18 @@ Handle<JSArray> Factory::NewJSArrayWithElements(Handle<FixedArrayBase> elements, ...@@ -1448,6 +1454,18 @@ Handle<JSArray> Factory::NewJSArrayWithElements(Handle<FixedArrayBase> elements,
} }
void Factory::NewJSArrayStorage(Handle<JSArray> array,
int length,
int capacity,
ArrayStorageAllocationMode mode) {
CALL_HEAP_FUNCTION_VOID(isolate(),
isolate()->heap()->AllocateJSArrayStorage(*array,
length,
capacity,
mode));
}
void Factory::SetElementsCapacityAndLength(Handle<JSArray> array, void Factory::SetElementsCapacityAndLength(Handle<JSArray> array,
int capacity, int capacity,
int length) { int length) {
......
...@@ -334,9 +334,11 @@ class Factory { ...@@ -334,9 +334,11 @@ class Factory {
// JS objects are pretenured when allocated by the bootstrapper and // JS objects are pretenured when allocated by the bootstrapper and
// runtime. // runtime.
Handle<JSObject> NewJSObjectFromMap(Handle<Map> map, Handle<JSObject> NewJSObjectFromMap(
PretenureFlag pretenure = NOT_TENURED, Handle<Map> map,
bool allocate_properties = true); PretenureFlag pretenure = NOT_TENURED,
bool allocate_properties = true,
Handle<AllocationSite> allocation_site = Handle<AllocationSite>::null());
Handle<JSObject> NewJSObjectFromMapForDeoptimizer( Handle<JSObject> NewJSObjectFromMapForDeoptimizer(
Handle<Map> map, PretenureFlag pretenure = NOT_TENURED); Handle<Map> map, PretenureFlag pretenure = NOT_TENURED);
...@@ -356,6 +358,12 @@ class Factory { ...@@ -356,6 +358,12 @@ class Factory {
ElementsKind elements_kind = TERMINAL_FAST_ELEMENTS_KIND, ElementsKind elements_kind = TERMINAL_FAST_ELEMENTS_KIND,
PretenureFlag pretenure = NOT_TENURED); PretenureFlag pretenure = NOT_TENURED);
void NewJSArrayStorage(
Handle<JSArray> array,
int length,
int capacity,
ArrayStorageAllocationMode mode = DONT_INITIALIZE_ARRAY_ELEMENTS);
void SetElementsCapacityAndLength(Handle<JSArray> array, void SetElementsCapacityAndLength(Handle<JSArray> array,
int capacity, int capacity,
int length); int length);
......
...@@ -3362,6 +3362,15 @@ MaybeObject* JSObject::GetElementsTransitionMapSlow(ElementsKind to_kind) { ...@@ -3362,6 +3362,15 @@ MaybeObject* JSObject::GetElementsTransitionMapSlow(ElementsKind to_kind) {
} }
// TODO(ishell): Temporary wrapper until handlified.
// static
Handle<Map> Map::AsElementsKind(Handle<Map> map, ElementsKind kind) {
CALL_HEAP_FUNCTION(map->GetIsolate(),
map->AsElementsKind(kind),
Map);
}
MaybeObject* Map::AsElementsKind(ElementsKind kind) { MaybeObject* Map::AsElementsKind(ElementsKind kind) {
Map* closest_map = FindClosestElementsTransition(this, kind); Map* closest_map = FindClosestElementsTransition(this, kind);
......
...@@ -6222,6 +6222,7 @@ class Map: public HeapObject { ...@@ -6222,6 +6222,7 @@ class Map: public HeapObject {
Descriptor* descriptor, Descriptor* descriptor,
int index, int index,
TransitionFlag flag); TransitionFlag flag);
static Handle<Map> AsElementsKind(Handle<Map> map, ElementsKind kind);
MUST_USE_RESULT MaybeObject* AsElementsKind(ElementsKind kind); MUST_USE_RESULT MaybeObject* AsElementsKind(ElementsKind kind);
MUST_USE_RESULT MaybeObject* CopyAsElementsKind(ElementsKind kind, MUST_USE_RESULT MaybeObject* CopyAsElementsKind(ElementsKind kind,
......
...@@ -14749,12 +14749,14 @@ static MaybeObject* ArrayConstructorCommon(Isolate* isolate, ...@@ -14749,12 +14749,14 @@ static MaybeObject* ArrayConstructorCommon(Isolate* isolate,
Handle<JSFunction> constructor, Handle<JSFunction> constructor,
Handle<AllocationSite> site, Handle<AllocationSite> site,
Arguments* caller_args) { Arguments* caller_args) {
Factory* factory = isolate->factory();
bool holey = false; bool holey = false;
bool can_use_type_feedback = true; bool can_use_type_feedback = true;
if (caller_args->length() == 1) { if (caller_args->length() == 1) {
Object* argument_one = (*caller_args)[0]; Handle<Object> argument_one = caller_args->at<Object>(0);
if (argument_one->IsSmi()) { if (argument_one->IsSmi()) {
int value = Smi::cast(argument_one)->value(); int value = Handle<Smi>::cast(argument_one)->value();
if (value < 0 || value >= JSObject::kInitialMaxFastElementArray) { if (value < 0 || value >= JSObject::kInitialMaxFastElementArray) {
// the array is a dictionary in this case. // the array is a dictionary in this case.
can_use_type_feedback = false; can_use_type_feedback = false;
...@@ -14767,8 +14769,7 @@ static MaybeObject* ArrayConstructorCommon(Isolate* isolate, ...@@ -14767,8 +14769,7 @@ static MaybeObject* ArrayConstructorCommon(Isolate* isolate,
} }
} }
JSArray* array; Handle<JSArray> array;
MaybeObject* maybe_array;
if (!site.is_null() && can_use_type_feedback) { if (!site.is_null() && can_use_type_feedback) {
ElementsKind to_kind = site->GetElementsKind(); ElementsKind to_kind = site->GetElementsKind();
if (holey && !IsFastHoleyElementsKind(to_kind)) { if (holey && !IsFastHoleyElementsKind(to_kind)) {
...@@ -14780,42 +14781,37 @@ static MaybeObject* ArrayConstructorCommon(Isolate* isolate, ...@@ -14780,42 +14781,37 @@ static MaybeObject* ArrayConstructorCommon(Isolate* isolate,
// We should allocate with an initial map that reflects the allocation site // We should allocate with an initial map that reflects the allocation site
// advice. Therefore we use AllocateJSObjectFromMap instead of passing // advice. Therefore we use AllocateJSObjectFromMap instead of passing
// the constructor. // the constructor.
Map* initial_map = constructor->initial_map(); Handle<Map> initial_map(constructor->initial_map(), isolate);
if (to_kind != initial_map->elements_kind()) { if (to_kind != initial_map->elements_kind()) {
MaybeObject* maybe_new_map = initial_map->AsElementsKind(to_kind); initial_map = Map::AsElementsKind(initial_map, to_kind);
if (!maybe_new_map->To(&initial_map)) return maybe_new_map; RETURN_IF_EMPTY_HANDLE(isolate, initial_map);
} }
// If we don't care to track arrays of to_kind ElementsKind, then // If we don't care to track arrays of to_kind ElementsKind, then
// don't emit a memento for them. // don't emit a memento for them.
AllocationSite* allocation_site = Handle<AllocationSite> allocation_site;
(AllocationSite::GetMode(to_kind) == TRACK_ALLOCATION_SITE) if (AllocationSite::GetMode(to_kind) == TRACK_ALLOCATION_SITE) {
? *site allocation_site = site;
: NULL; }
maybe_array = isolate->heap()->AllocateJSObjectFromMap(initial_map, array = Handle<JSArray>::cast(factory->NewJSObjectFromMap(
NOT_TENURED, initial_map, NOT_TENURED, true, allocation_site));
true,
allocation_site);
if (!maybe_array->To(&array)) return maybe_array;
} else { } else {
maybe_array = isolate->heap()->AllocateJSObject(*constructor); array = Handle<JSArray>::cast(factory->NewJSObject(constructor));
if (!maybe_array->To(&array)) return maybe_array;
// We might need to transition to holey // We might need to transition to holey
ElementsKind kind = constructor->initial_map()->elements_kind(); ElementsKind kind = constructor->initial_map()->elements_kind();
if (holey && !IsFastHoleyElementsKind(kind)) { if (holey && !IsFastHoleyElementsKind(kind)) {
kind = GetHoleyElementsKind(kind); kind = GetHoleyElementsKind(kind);
maybe_array = array->TransitionElementsKind(kind); JSObject::TransitionElementsKind(array, kind);
if (maybe_array->IsFailure()) return maybe_array;
} }
} }
maybe_array = isolate->heap()->AllocateJSArrayStorage(array, 0, 0, factory->NewJSArrayStorage(array, 0, 0, DONT_INITIALIZE_ARRAY_ELEMENTS);
DONT_INITIALIZE_ARRAY_ELEMENTS);
if (maybe_array->IsFailure()) return maybe_array;
ElementsKind old_kind = array->GetElementsKind(); ElementsKind old_kind = array->GetElementsKind();
maybe_array = ArrayConstructInitializeElements(array, caller_args); RETURN_IF_EMPTY_HANDLE(isolate,
if (maybe_array->IsFailure()) return maybe_array; ArrayConstructInitializeElements(array, caller_args));
if (!site.is_null() && if (!site.is_null() &&
(old_kind != array->GetElementsKind() || (old_kind != array->GetElementsKind() ||
!can_use_type_feedback)) { !can_use_type_feedback)) {
...@@ -14824,7 +14820,7 @@ static MaybeObject* ArrayConstructorCommon(Isolate* isolate, ...@@ -14824,7 +14820,7 @@ static MaybeObject* ArrayConstructorCommon(Isolate* isolate,
// We must mark the allocationsite as un-inlinable. // We must mark the allocationsite as un-inlinable.
site->SetDoNotInlineCall(); site->SetDoNotInlineCall();
} }
return array; return *array;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment