Commit 0d7bdc0f authored by ishell@chromium.org's avatar ishell@chromium.org

Callers of ElementsAccessor::SetCapacityAndLength() handlified.

R=verwaest@chromium.org

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

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@20229 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 793d4cb0
...@@ -357,8 +357,7 @@ void ArrayLiteral::BuildConstantElements(Isolate* isolate) { ...@@ -357,8 +357,7 @@ void ArrayLiteral::BuildConstantElements(Isolate* isolate) {
// Allocate a fixed array to hold all the object literals. // Allocate a fixed array to hold all the object literals.
Handle<JSArray> array = Handle<JSArray> array =
isolate->factory()->NewJSArray(0, FAST_HOLEY_SMI_ELEMENTS); isolate->factory()->NewJSArray(0, FAST_HOLEY_SMI_ELEMENTS);
isolate->factory()->SetElementsCapacityAndLength( JSArray::Expand(array, values()->length());
array, values()->length(), values()->length());
// Fill in the literals. // Fill in the literals.
bool is_simple = true; bool is_simple = true;
......
...@@ -766,14 +766,16 @@ class ElementsAccessorBase : public ElementsAccessor { ...@@ -766,14 +766,16 @@ class ElementsAccessorBase : public ElementsAccessor {
Handle<Object> length, Handle<Object> length,
Handle<FixedArrayBase> backing_store); Handle<FixedArrayBase> backing_store);
MUST_USE_RESULT virtual MaybeObject* SetCapacityAndLength( virtual void SetCapacityAndLength(
JSArray* array, Handle<JSArray> array,
int capacity, int capacity,
int length) V8_FINAL V8_OVERRIDE { int length) V8_FINAL V8_OVERRIDE {
return ElementsAccessorSubclass::SetFastElementsCapacityAndLength( CALL_HEAP_FUNCTION_VOID(
array, array->GetIsolate(),
capacity, ElementsAccessorSubclass::SetFastElementsCapacityAndLength(
length); *array,
capacity,
length));
} }
MUST_USE_RESULT static MaybeObject* SetFastElementsCapacityAndLength( MUST_USE_RESULT static MaybeObject* SetFastElementsCapacityAndLength(
......
...@@ -126,9 +126,10 @@ class ElementsAccessor { ...@@ -126,9 +126,10 @@ class ElementsAccessor {
// elements. This method should only be called for array expansion OR by // elements. This method should only be called for array expansion OR by
// runtime JavaScript code that use InternalArrays and don't care about // runtime JavaScript code that use InternalArrays and don't care about
// EcmaScript 5.1 semantics. // EcmaScript 5.1 semantics.
MUST_USE_RESULT virtual MaybeObject* SetCapacityAndLength(JSArray* array, virtual void SetCapacityAndLength(
int capacity, Handle<JSArray> array,
int length) = 0; int capacity,
int length) = 0;
// Deletes an element in an object, returning a new elements backing store. // Deletes an element in an object, returning a new elements backing store.
MUST_USE_RESULT virtual Handle<Object> Delete( MUST_USE_RESULT virtual Handle<Object> Delete(
......
...@@ -1489,16 +1489,6 @@ void Factory::NewJSArrayStorage(Handle<JSArray> array, ...@@ -1489,16 +1489,6 @@ void Factory::NewJSArrayStorage(Handle<JSArray> array,
} }
void Factory::SetElementsCapacityAndLength(Handle<JSArray> array,
int capacity,
int length) {
ElementsAccessor* accessor = array->GetElementsAccessor();
CALL_HEAP_FUNCTION_VOID(
isolate(),
accessor->SetCapacityAndLength(*array, capacity, length));
}
Handle<JSGeneratorObject> Factory::NewJSGeneratorObject( Handle<JSGeneratorObject> Factory::NewJSGeneratorObject(
Handle<JSFunction> function) { Handle<JSFunction> function) {
ASSERT(function->shared()->is_generator()); ASSERT(function->shared()->is_generator());
......
...@@ -387,10 +387,6 @@ class Factory { ...@@ -387,10 +387,6 @@ class Factory {
int capacity, int capacity,
ArrayStorageAllocationMode mode = DONT_INITIALIZE_ARRAY_ELEMENTS); ArrayStorageAllocationMode mode = DONT_INITIALIZE_ARRAY_ELEMENTS);
void SetElementsCapacityAndLength(Handle<JSArray> array,
int capacity,
int length);
Handle<JSGeneratorObject> NewJSGeneratorObject(Handle<JSFunction> function); Handle<JSGeneratorObject> NewJSGeneratorObject(Handle<JSFunction> function);
Handle<JSArrayBuffer> NewJSArrayBuffer(); Handle<JSArrayBuffer> NewJSArrayBuffer();
......
...@@ -393,13 +393,16 @@ BasicJsonStringifier::Result BasicJsonStringifier::StackPush( ...@@ -393,13 +393,16 @@ BasicJsonStringifier::Result BasicJsonStringifier::StackPush(
if (check.HasOverflowed()) return STACK_OVERFLOW; if (check.HasOverflowed()) return STACK_OVERFLOW;
int length = Smi::cast(stack_->length())->value(); int length = Smi::cast(stack_->length())->value();
FixedArray* elements = FixedArray::cast(stack_->elements()); {
for (int i = 0; i < length; i++) { DisallowHeapAllocation no_allocation;
if (elements->get(i) == *object) { FixedArray* elements = FixedArray::cast(stack_->elements());
return CIRCULAR; for (int i = 0; i < length; i++) {
if (elements->get(i) == *object) {
return CIRCULAR;
}
} }
} }
stack_->EnsureSize(length + 1); JSArray::EnsureSize(stack_, length + 1);
FixedArray::cast(stack_->elements())->set(length, *object); FixedArray::cast(stack_->elements())->set(length, *object);
stack_->set_length(Smi::FromInt(length + 1)); stack_->set_length(Smi::FromInt(length + 1));
return SUCCESS; return SUCCESS;
......
...@@ -691,7 +691,8 @@ Handle<JSArray> RegExpImpl::SetLastMatchInfo(Handle<JSArray> last_match_info, ...@@ -691,7 +691,8 @@ Handle<JSArray> RegExpImpl::SetLastMatchInfo(Handle<JSArray> last_match_info,
int32_t* match) { int32_t* match) {
ASSERT(last_match_info->HasFastObjectElements()); ASSERT(last_match_info->HasFastObjectElements());
int capture_register_count = (capture_count + 1) * 2; int capture_register_count = (capture_count + 1) * 2;
last_match_info->EnsureSize(capture_register_count + kLastMatchOverhead); JSArray::EnsureSize(last_match_info,
capture_register_count + kLastMatchOverhead);
DisallowHeapAllocation no_allocation; DisallowHeapAllocation no_allocation;
FixedArray* array = FixedArray::cast(last_match_info->elements()); FixedArray* array = FixedArray::cast(last_match_info->elements());
if (match != NULL) { if (match != NULL) {
......
...@@ -6527,20 +6527,20 @@ void Map::ClearCodeCache(Heap* heap) { ...@@ -6527,20 +6527,20 @@ void Map::ClearCodeCache(Heap* heap) {
} }
void JSArray::EnsureSize(int required_size) { void JSArray::EnsureSize(Handle<JSArray> array, int required_size) {
ASSERT(HasFastSmiOrObjectElements()); ASSERT(array->HasFastSmiOrObjectElements());
FixedArray* elts = FixedArray::cast(elements()); Handle<FixedArray> elts = handle(FixedArray::cast(array->elements()));
const int kArraySizeThatFitsComfortablyInNewSpace = 128; const int kArraySizeThatFitsComfortablyInNewSpace = 128;
if (elts->length() < required_size) { if (elts->length() < required_size) {
// Doubling in size would be overkill, but leave some slack to avoid // Doubling in size would be overkill, but leave some slack to avoid
// constantly growing. // constantly growing.
Expand(required_size + (required_size >> 3)); Expand(array, required_size + (required_size >> 3));
// It's a performance benefit to keep a frequently used array in new-space. // It's a performance benefit to keep a frequently used array in new-space.
} else if (!GetHeap()->new_space()->Contains(elts) && } else if (!array->GetHeap()->new_space()->Contains(*elts) &&
required_size < kArraySizeThatFitsComfortablyInNewSpace) { required_size < kArraySizeThatFitsComfortablyInNewSpace) {
// Expand will allocate a new backing store in new space even if the size // Expand will allocate a new backing store in new space even if the size
// we asked for isn't larger than what we had before. // we asked for isn't larger than what we had before.
Expand(required_size); Expand(array, required_size);
} }
} }
......
...@@ -11279,9 +11279,9 @@ void JSArray::Initialize(Handle<JSArray> array, int capacity, int length) { ...@@ -11279,9 +11279,9 @@ void JSArray::Initialize(Handle<JSArray> array, int capacity, int length) {
} }
void JSArray::Expand(int required_size) { void JSArray::Expand(Handle<JSArray> array, int required_size) {
GetIsolate()->factory()->SetElementsCapacityAndLength( ElementsAccessor* accessor = array->GetElementsAccessor();
Handle<JSArray>(this), required_size, required_size); accessor->SetCapacityAndLength(array, required_size, required_size);
} }
......
...@@ -10028,9 +10028,15 @@ class JSArray: public JSObject { ...@@ -10028,9 +10028,15 @@ class JSArray: public JSObject {
// Casting. // Casting.
static inline JSArray* cast(Object* obj); static inline JSArray* cast(Object* obj);
// Uses handles. Ensures that the fixed array backing the JSArray has at // Ensures that the fixed array backing the JSArray has at
// least the stated size. // least the stated size.
inline void EnsureSize(int minimum_size_of_backing_fixed_array); static inline void EnsureSize(Handle<JSArray> array,
int minimum_size_of_backing_fixed_array);
// Expand the fixed array backing of a fast-case JSArray to at least
// the requested size.
static void Expand(Handle<JSArray> array,
int minimum_size_of_backing_fixed_array);
// Dispatched behavior. // Dispatched behavior.
DECLARE_PRINTER(JSArray) DECLARE_PRINTER(JSArray)
...@@ -10044,10 +10050,6 @@ class JSArray: public JSObject { ...@@ -10044,10 +10050,6 @@ class JSArray: public JSObject {
static const int kSize = kLengthOffset + kPointerSize; static const int kSize = kLengthOffset + kPointerSize;
private: private:
// Expand the fixed array backing of a fast-case JSArray to at least
// the requested size.
void Expand(int minimum_size_of_backing_fixed_array);
DISALLOW_IMPLICIT_CONSTRUCTORS(JSArray); DISALLOW_IMPLICIT_CONSTRUCTORS(JSArray);
}; };
......
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