Move runtime array constructor functions from builtins.cc to runtime.cc.

Not only is runtime.cc a better location, but situations arise soon where we'll
want to make runtime calls to these functions.

BUG=
R=mstarzinger@chromium.org

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

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@14977 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 6f5d8992
...@@ -30,7 +30,6 @@ ...@@ -30,7 +30,6 @@
#if defined(V8_TARGET_ARCH_ARM) #if defined(V8_TARGET_ARCH_ARM)
#include "bootstrapper.h" #include "bootstrapper.h"
#include "builtins-decls.h"
#include "code-stubs.h" #include "code-stubs.h"
#include "regexp-macro-assembler.h" #include "regexp-macro-assembler.h"
#include "stub-cache.h" #include "stub-cache.h"
...@@ -146,7 +145,7 @@ static void InitializeArrayConstructorDescriptor( ...@@ -146,7 +145,7 @@ static void InitializeArrayConstructorDescriptor(
descriptor->register_params_ = registers; descriptor->register_params_ = registers;
descriptor->function_mode_ = JS_FUNCTION_STUB_MODE; descriptor->function_mode_ = JS_FUNCTION_STUB_MODE;
descriptor->deoptimization_handler_ = descriptor->deoptimization_handler_ =
FUNCTION_ADDR(ArrayConstructor_StubFailure); Runtime::FunctionForId(Runtime::kArrayConstructor)->entry;
} }
...@@ -168,7 +167,7 @@ static void InitializeInternalArrayConstructorDescriptor( ...@@ -168,7 +167,7 @@ static void InitializeInternalArrayConstructorDescriptor(
descriptor->register_params_ = registers; descriptor->register_params_ = registers;
descriptor->function_mode_ = JS_FUNCTION_STUB_MODE; descriptor->function_mode_ = JS_FUNCTION_STUB_MODE;
descriptor->deoptimization_handler_ = descriptor->deoptimization_handler_ =
FUNCTION_ADDR(InternalArrayConstructor_StubFailure); Runtime::FunctionForId(Runtime::kInternalArrayConstructor)->entry;
} }
......
// Copyright 2013 the V8 project authors. All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef V8_BUILTINS_DECLS_H_
#define V8_BUILTINS_DECLS_H_
#include "arguments.h"
namespace v8 {
namespace internal {
// TODO(mvstanton): move these to runtime.h/.cc
DECLARE_RUNTIME_FUNCTION(MaybeObject*, ArrayConstructor_StubFailure);
DECLARE_RUNTIME_FUNCTION(MaybeObject*, InternalArrayConstructor_StubFailure);
} } // namespace v8::internal
#endif // V8_BUILTINS_DECLS_H_
...@@ -194,106 +194,6 @@ BUILTIN(EmptyFunction) { ...@@ -194,106 +194,6 @@ BUILTIN(EmptyFunction) {
} }
static MaybeObject* ArrayConstructorStubFailureCommon(
Isolate* isolate,
Handle<JSFunction> constructor,
Handle<Object> type_info,
Arguments* caller_args) {
bool holey = false;
bool can_use_type_feedback = true;
if (caller_args->length() == 1) {
Object* argument_one = (*caller_args)[0];
if (argument_one->IsSmi()) {
int value = Smi::cast(argument_one)->value();
if (value < 0 || value >= JSObject::kInitialMaxFastElementArray) {
// the array is a dictionary in this case.
can_use_type_feedback = false;
} else if (value != 0) {
holey = true;
}
} else {
// Non-smi length argument produces a dictionary
can_use_type_feedback = false;
}
}
JSArray* array;
MaybeObject* maybe_array;
if (!type_info.is_null() &&
*type_info != isolate->heap()->undefined_value() &&
JSGlobalPropertyCell::cast(*type_info)->value()->IsSmi() &&
can_use_type_feedback) {
JSGlobalPropertyCell* cell = JSGlobalPropertyCell::cast(*type_info);
Smi* smi = Smi::cast(cell->value());
ElementsKind to_kind = static_cast<ElementsKind>(smi->value());
if (holey && !IsFastHoleyElementsKind(to_kind)) {
to_kind = GetHoleyElementsKind(to_kind);
// Update the allocation site info to reflect the advice alteration.
cell->set_value(Smi::FromInt(to_kind));
}
maybe_array = isolate->heap()->AllocateJSObjectWithAllocationSite(
*constructor, type_info);
if (!maybe_array->To(&array)) return maybe_array;
} else {
maybe_array = isolate->heap()->AllocateJSObject(*constructor);
if (!maybe_array->To(&array)) return maybe_array;
// We might need to transition to holey
ElementsKind kind = constructor->initial_map()->elements_kind();
if (holey && !IsFastHoleyElementsKind(kind)) {
kind = GetHoleyElementsKind(kind);
maybe_array = array->TransitionElementsKind(kind);
if (maybe_array->IsFailure()) return maybe_array;
}
}
maybe_array = isolate->heap()->AllocateJSArrayStorage(array, 0, 0,
DONT_INITIALIZE_ARRAY_ELEMENTS);
if (maybe_array->IsFailure()) return maybe_array;
maybe_array = ArrayConstructInitializeElements(array, caller_args);
if (maybe_array->IsFailure()) return maybe_array;
return array;
}
RUNTIME_FUNCTION(MaybeObject*, ArrayConstructor_StubFailure) {
// If we get 2 arguments then they are the stub parameters (constructor, type
// info). If we get 3, then the first one is a pointer to the arguments
// passed by the caller.
Arguments empty_args(0, NULL);
bool no_caller_args = args.length() == 2;
ASSERT(no_caller_args || args.length() == 3);
int parameters_start = no_caller_args ? 0 : 1;
Arguments* caller_args = no_caller_args
? &empty_args
: reinterpret_cast<Arguments*>(args[0]);
Handle<JSFunction> constructor = args.at<JSFunction>(parameters_start);
Handle<Object> type_info = args.at<Object>(parameters_start + 1);
return ArrayConstructorStubFailureCommon(isolate,
constructor,
type_info,
caller_args);
}
RUNTIME_FUNCTION(MaybeObject*, InternalArrayConstructor_StubFailure) {
Arguments empty_args(0, NULL);
bool no_caller_args = args.length() == 1;
ASSERT(no_caller_args || args.length() == 2);
int parameters_start = no_caller_args ? 0 : 1;
Arguments* caller_args = no_caller_args
? &empty_args
: reinterpret_cast<Arguments*>(args[0]);
Handle<JSFunction> constructor = args.at<JSFunction>(parameters_start);
return ArrayConstructorStubFailureCommon(isolate,
constructor,
Handle<Object>::null(),
caller_args);
}
static MaybeObject* ArrayCodeGenericCommon(Arguments* args, static MaybeObject* ArrayCodeGenericCommon(Arguments* args,
Isolate* isolate, Isolate* isolate,
JSFunction* constructor) { JSFunction* constructor) {
......
...@@ -30,7 +30,6 @@ ...@@ -30,7 +30,6 @@
#if defined(V8_TARGET_ARCH_IA32) #if defined(V8_TARGET_ARCH_IA32)
#include "bootstrapper.h" #include "bootstrapper.h"
#include "builtins-decls.h"
#include "code-stubs.h" #include "code-stubs.h"
#include "isolate.h" #include "isolate.h"
#include "jsregexp.h" #include "jsregexp.h"
...@@ -138,7 +137,7 @@ static void InitializeArrayConstructorDescriptor( ...@@ -138,7 +137,7 @@ static void InitializeArrayConstructorDescriptor(
descriptor->register_params_ = registers; descriptor->register_params_ = registers;
descriptor->function_mode_ = JS_FUNCTION_STUB_MODE; descriptor->function_mode_ = JS_FUNCTION_STUB_MODE;
descriptor->deoptimization_handler_ = descriptor->deoptimization_handler_ =
FUNCTION_ADDR(ArrayConstructor_StubFailure); Runtime::FunctionForId(Runtime::kArrayConstructor)->entry;
} }
...@@ -160,7 +159,7 @@ static void InitializeInternalArrayConstructorDescriptor( ...@@ -160,7 +159,7 @@ static void InitializeInternalArrayConstructorDescriptor(
descriptor->register_params_ = registers; descriptor->register_params_ = registers;
descriptor->function_mode_ = JS_FUNCTION_STUB_MODE; descriptor->function_mode_ = JS_FUNCTION_STUB_MODE;
descriptor->deoptimization_handler_ = descriptor->deoptimization_handler_ =
FUNCTION_ADDR(InternalArrayConstructor_StubFailure); Runtime::FunctionForId(Runtime::kInternalArrayConstructor)->entry;
} }
......
...@@ -30,7 +30,6 @@ ...@@ -30,7 +30,6 @@
#if defined(V8_TARGET_ARCH_MIPS) #if defined(V8_TARGET_ARCH_MIPS)
#include "bootstrapper.h" #include "bootstrapper.h"
#include "builtins-decls.h"
#include "code-stubs.h" #include "code-stubs.h"
#include "codegen.h" #include "codegen.h"
#include "regexp-macro-assembler.h" #include "regexp-macro-assembler.h"
...@@ -147,7 +146,7 @@ static void InitializeArrayConstructorDescriptor( ...@@ -147,7 +146,7 @@ static void InitializeArrayConstructorDescriptor(
descriptor->register_params_ = registers; descriptor->register_params_ = registers;
descriptor->function_mode_ = JS_FUNCTION_STUB_MODE; descriptor->function_mode_ = JS_FUNCTION_STUB_MODE;
descriptor->deoptimization_handler_ = descriptor->deoptimization_handler_ =
FUNCTION_ADDR(ArrayConstructor_StubFailure); Runtime::FunctionForId(Runtime::kArrayConstructor)->entry;
} }
...@@ -169,7 +168,7 @@ static void InitializeInternalArrayConstructorDescriptor( ...@@ -169,7 +168,7 @@ static void InitializeInternalArrayConstructorDescriptor(
descriptor->register_params_ = registers; descriptor->register_params_ = registers;
descriptor->function_mode_ = JS_FUNCTION_STUB_MODE; descriptor->function_mode_ = JS_FUNCTION_STUB_MODE;
descriptor->deoptimization_handler_ = descriptor->deoptimization_handler_ =
FUNCTION_ADDR(InternalArrayConstructor_StubFailure); Runtime::FunctionForId(Runtime::kInternalArrayConstructor)->entry;
} }
......
...@@ -13441,6 +13441,107 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_UnwrapGlobalProxy) { ...@@ -13441,6 +13441,107 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_UnwrapGlobalProxy) {
} }
static MaybeObject* ArrayConstructorCommon(Isolate* isolate,
Handle<JSFunction> constructor,
Handle<Object> type_info,
Arguments* caller_args) {
bool holey = false;
bool can_use_type_feedback = true;
if (caller_args->length() == 1) {
Object* argument_one = (*caller_args)[0];
if (argument_one->IsSmi()) {
int value = Smi::cast(argument_one)->value();
if (value < 0 || value >= JSObject::kInitialMaxFastElementArray) {
// the array is a dictionary in this case.
can_use_type_feedback = false;
} else if (value != 0) {
holey = true;
}
} else {
// Non-smi length argument produces a dictionary
can_use_type_feedback = false;
}
}
JSArray* array;
MaybeObject* maybe_array;
if (!type_info.is_null() &&
*type_info != isolate->heap()->undefined_value() &&
JSGlobalPropertyCell::cast(*type_info)->value()->IsSmi() &&
can_use_type_feedback) {
JSGlobalPropertyCell* cell = JSGlobalPropertyCell::cast(*type_info);
Smi* smi = Smi::cast(cell->value());
ElementsKind to_kind = static_cast<ElementsKind>(smi->value());
if (holey && !IsFastHoleyElementsKind(to_kind)) {
to_kind = GetHoleyElementsKind(to_kind);
// Update the allocation site info to reflect the advice alteration.
cell->set_value(Smi::FromInt(to_kind));
}
maybe_array = isolate->heap()->AllocateJSObjectWithAllocationSite(
*constructor, type_info);
if (!maybe_array->To(&array)) return maybe_array;
} else {
maybe_array = isolate->heap()->AllocateJSObject(*constructor);
if (!maybe_array->To(&array)) return maybe_array;
// We might need to transition to holey
ElementsKind kind = constructor->initial_map()->elements_kind();
if (holey && !IsFastHoleyElementsKind(kind)) {
kind = GetHoleyElementsKind(kind);
maybe_array = array->TransitionElementsKind(kind);
if (maybe_array->IsFailure()) return maybe_array;
}
}
maybe_array = isolate->heap()->AllocateJSArrayStorage(array, 0, 0,
DONT_INITIALIZE_ARRAY_ELEMENTS);
if (maybe_array->IsFailure()) return maybe_array;
maybe_array = ArrayConstructInitializeElements(array, caller_args);
if (maybe_array->IsFailure()) return maybe_array;
return array;
}
RUNTIME_FUNCTION(MaybeObject*, Runtime_ArrayConstructor) {
HandleScope scope(isolate);
// If we get 2 arguments then they are the stub parameters (constructor, type
// info). If we get 3, then the first one is a pointer to the arguments
// passed by the caller.
Arguments empty_args(0, NULL);
bool no_caller_args = args.length() == 2;
ASSERT(no_caller_args || args.length() == 3);
int parameters_start = no_caller_args ? 0 : 1;
Arguments* caller_args = no_caller_args
? &empty_args
: reinterpret_cast<Arguments*>(args[0]);
CONVERT_ARG_HANDLE_CHECKED(JSFunction, constructor, parameters_start);
CONVERT_ARG_HANDLE_CHECKED(Object, type_info, parameters_start + 1);
return ArrayConstructorCommon(isolate,
constructor,
type_info,
caller_args);
}
RUNTIME_FUNCTION(MaybeObject*, Runtime_InternalArrayConstructor) {
HandleScope scope(isolate);
Arguments empty_args(0, NULL);
bool no_caller_args = args.length() == 1;
ASSERT(no_caller_args || args.length() == 2);
int parameters_start = no_caller_args ? 0 : 1;
Arguments* caller_args = no_caller_args
? &empty_args
: reinterpret_cast<Arguments*>(args[0]);
CONVERT_ARG_HANDLE_CHECKED(JSFunction, constructor, parameters_start);
return ArrayConstructorCommon(isolate,
constructor,
Handle<Object>::null(),
caller_args);
}
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// Implementation of Runtime // Implementation of Runtime
......
...@@ -287,6 +287,8 @@ namespace internal { ...@@ -287,6 +287,8 @@ namespace internal {
F(GetArrayKeys, 2, 1) \ F(GetArrayKeys, 2, 1) \
F(MoveArrayContents, 2, 1) \ F(MoveArrayContents, 2, 1) \
F(EstimateNumberOfElements, 1, 1) \ F(EstimateNumberOfElements, 1, 1) \
F(ArrayConstructor, -1, 1) \
F(InternalArrayConstructor, -1, 1) \
\ \
/* Getters and Setters */ \ /* Getters and Setters */ \
F(LookupAccessor, 3, 1) \ F(LookupAccessor, 3, 1) \
......
...@@ -30,7 +30,6 @@ ...@@ -30,7 +30,6 @@
#if defined(V8_TARGET_ARCH_X64) #if defined(V8_TARGET_ARCH_X64)
#include "bootstrapper.h" #include "bootstrapper.h"
#include "builtins-decls.h"
#include "code-stubs.h" #include "code-stubs.h"
#include "regexp-macro-assembler.h" #include "regexp-macro-assembler.h"
#include "stub-cache.h" #include "stub-cache.h"
...@@ -133,7 +132,7 @@ static void InitializeArrayConstructorDescriptor( ...@@ -133,7 +132,7 @@ static void InitializeArrayConstructorDescriptor(
descriptor->register_params_ = registers; descriptor->register_params_ = registers;
descriptor->function_mode_ = JS_FUNCTION_STUB_MODE; descriptor->function_mode_ = JS_FUNCTION_STUB_MODE;
descriptor->deoptimization_handler_ = descriptor->deoptimization_handler_ =
FUNCTION_ADDR(ArrayConstructor_StubFailure); Runtime::FunctionForId(Runtime::kArrayConstructor)->entry;
} }
...@@ -155,7 +154,7 @@ static void InitializeInternalArrayConstructorDescriptor( ...@@ -155,7 +154,7 @@ static void InitializeInternalArrayConstructorDescriptor(
descriptor->register_params_ = registers; descriptor->register_params_ = registers;
descriptor->function_mode_ = JS_FUNCTION_STUB_MODE; descriptor->function_mode_ = JS_FUNCTION_STUB_MODE;
descriptor->deoptimization_handler_ = descriptor->deoptimization_handler_ =
FUNCTION_ADDR(InternalArrayConstructor_StubFailure); Runtime::FunctionForId(Runtime::kInternalArrayConstructor)->entry;
} }
......
...@@ -162,6 +162,8 @@ var knownProblems = { ...@@ -162,6 +162,8 @@ var knownProblems = {
"ResolvePossiblyDirectEval": true, "ResolvePossiblyDirectEval": true,
"Log": true, "Log": true,
"DeclareGlobals": true, "DeclareGlobals": true,
"ArrayConstructor": true,
"InternalArrayConstructor": true,
"PromoteScheduledException": true, "PromoteScheduledException": true,
"DeleteHandleScopeExtensions": true, "DeleteHandleScopeExtensions": true,
......
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