From 38b82f40d083cfa21e595afddd26211adfe7406c Mon Sep 17 00:00:00 2001 From: "yangguo@chromium.org" Date: Mon, 28 Apr 2014 15:33:16 +0000 Subject: [PATCH] Remove some remnants of MaybeObjects in objects.*. R=hpayer@chromium.org Review URL: https://codereview.chromium.org/256993003 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@21027 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/api.cc | 2 +- src/arm/lithium-codegen-arm.cc | 2 +- src/arm64/lithium-codegen-arm64.cc | 2 +- src/factory.cc | 53 ++++++++----------------- src/factory.h | 14 ++----- src/full-codegen.cc | 4 +- src/ia32/lithium-codegen-ia32.cc | 2 +- src/ic.cc | 3 +- src/mips/lithium-codegen-mips.cc | 2 +- src/objects-inl.h | 36 ----------------- src/objects.cc | 79 +++++++++++++++++++------------------- src/objects.h | 28 ++++---------- src/x64/lithium-codegen-x64.cc | 2 +- 13 files changed, 76 insertions(+), 153 deletions(-) diff --git a/src/api.cc b/src/api.cc index 694a51f..938a2b3 100644 --- a/src/api.cc +++ b/src/api.cc @@ -694,7 +694,7 @@ static i::Handle EmbedderDataFor(Context* context, return i::Handle(); } int new_size = i::Max(index, data->length() << 1) + 1; - data = env->GetIsolate()->factory()->CopySizeFixedArray(data, new_size); + data = i::FixedArray::CopySize(data, new_size); env->set_embedder_data(*data); return data; } diff --git a/src/arm/lithium-codegen-arm.cc b/src/arm/lithium-codegen-arm.cc index fe6469b..8039be1 100644 --- a/src/arm/lithium-codegen-arm.cc +++ b/src/arm/lithium-codegen-arm.cc @@ -917,7 +917,7 @@ void LCodeGen::PopulateDeoptimizationData(Handle code) { int length = deoptimizations_.length(); if (length == 0) return; Handle data = - factory()->NewDeoptimizationInputData(length, TENURED); + DeoptimizationInputData::New(isolate(), length, TENURED); Handle translations = translations_.CreateByteArray(isolate()->factory()); diff --git a/src/arm64/lithium-codegen-arm64.cc b/src/arm64/lithium-codegen-arm64.cc index 78ec9f9..693ae8b 100644 --- a/src/arm64/lithium-codegen-arm64.cc +++ b/src/arm64/lithium-codegen-arm64.cc @@ -927,7 +927,7 @@ void LCodeGen::PopulateDeoptimizationData(Handle code) { if (length == 0) return; Handle data = - factory()->NewDeoptimizationInputData(length, TENURED); + DeoptimizationInputData::New(isolate(), length, TENURED); Handle translations = translations_.CreateByteArray(isolate()->factory()); diff --git a/src/factory.cc b/src/factory.cc index 3c3b187..a085bba 100644 --- a/src/factory.cc +++ b/src/factory.cc @@ -141,30 +141,6 @@ Handle Factory::NewOrderedHashMap() { } -Handle Factory::NewDeoptimizationInputData( - int deopt_entry_count, - PretenureFlag pretenure) { - ASSERT(deopt_entry_count > 0); - CALL_HEAP_FUNCTION(isolate(), - DeoptimizationInputData::Allocate(isolate(), - deopt_entry_count, - pretenure), - DeoptimizationInputData); -} - - -Handle Factory::NewDeoptimizationOutputData( - int deopt_entry_count, - PretenureFlag pretenure) { - ASSERT(deopt_entry_count > 0); - CALL_HEAP_FUNCTION(isolate(), - DeoptimizationOutputData::Allocate(isolate(), - deopt_entry_count, - pretenure), - DeoptimizationOutputData); -} - - Handle Factory::NewAccessorPair() { Handle accessors = Handle::cast(NewStruct(ACCESSOR_PAIR_TYPE)); @@ -977,38 +953,43 @@ Handle Factory::NewFunctionPrototype(Handle function) { } -Handle Factory::CopyFixedArray(Handle array) { - CALL_HEAP_FUNCTION(isolate(), array->Copy(), FixedArray); +Handle Factory::CopyFixedArrayWithMap(Handle array, + Handle map) { + CALL_HEAP_FUNCTION(isolate(), + isolate()->heap()->CopyFixedArrayWithMap(*array, *map), + FixedArray); } -Handle Factory::CopyAndTenureFixedCOWArray( - Handle array) { - ASSERT(isolate()->heap()->InNewSpace(*array)); +Handle Factory::CopyFixedArray(Handle array) { CALL_HEAP_FUNCTION(isolate(), - isolate()->heap()->CopyAndTenureFixedCOWArray(*array), + isolate()->heap()->CopyFixedArray(*array), FixedArray); } -Handle Factory::CopySizeFixedArray(Handle array, - int new_length, - PretenureFlag pretenure) { +Handle Factory::CopyAndTenureFixedCOWArray( + Handle array) { + ASSERT(isolate()->heap()->InNewSpace(*array)); CALL_HEAP_FUNCTION(isolate(), - array->CopySize(new_length, pretenure), + isolate()->heap()->CopyAndTenureFixedCOWArray(*array), FixedArray); } Handle Factory::CopyFixedDoubleArray( Handle array) { - CALL_HEAP_FUNCTION(isolate(), array->Copy(), FixedDoubleArray); + CALL_HEAP_FUNCTION(isolate(), + isolate()->heap()->CopyFixedDoubleArray(*array), + FixedDoubleArray); } Handle Factory::CopyConstantPoolArray( Handle array) { - CALL_HEAP_FUNCTION(isolate(), array->Copy(), ConstantPoolArray); + CALL_HEAP_FUNCTION(isolate(), + isolate()->heap()->CopyConstantPoolArray(*array), + ConstantPoolArray); } diff --git a/src/factory.h b/src/factory.h index 041c986..ccd0a57 100644 --- a/src/factory.h +++ b/src/factory.h @@ -53,13 +53,6 @@ class Factory V8_FINAL { Handle NewOrderedHashSet(); Handle NewOrderedHashMap(); - Handle NewDeoptimizationInputData( - int deopt_entry_count, - PretenureFlag pretenure); - Handle NewDeoptimizationOutputData( - int deopt_entry_count, - PretenureFlag pretenure); - // Create a new boxed value. Handle NewBox(Handle value); @@ -307,16 +300,15 @@ class Factory V8_FINAL { Handle NewFunctionPrototype(Handle function); + Handle CopyFixedArrayWithMap(Handle array, + Handle map); + Handle CopyFixedArray(Handle array); // This method expects a COW array in new space, and creates a copy // of it in old space. Handle CopyAndTenureFixedCOWArray(Handle array); - Handle CopySizeFixedArray(Handle array, - int new_length, - PretenureFlag pretenure = NOT_TENURED); - Handle CopyFixedDoubleArray( Handle array); diff --git a/src/full-codegen.cc b/src/full-codegen.cc index db6da90..db37e98 100644 --- a/src/full-codegen.cc +++ b/src/full-codegen.cc @@ -401,8 +401,8 @@ void FullCodeGenerator::PopulateDeoptimizationData(Handle code) { ASSERT(info_->HasDeoptimizationSupport() || bailout_entries_.is_empty()); if (!info_->HasDeoptimizationSupport()) return; int length = bailout_entries_.length(); - Handle data = isolate()->factory()-> - NewDeoptimizationOutputData(length, TENURED); + Handle data = + DeoptimizationOutputData::New(isolate(), length, TENURED); for (int i = 0; i < length; i++) { data->SetAstId(i, bailout_entries_[i].id); data->SetPcAndState(i, Smi::FromInt(bailout_entries_[i].pc_and_state)); diff --git a/src/ia32/lithium-codegen-ia32.cc b/src/ia32/lithium-codegen-ia32.cc index 9b60bc5..38e506c 100644 --- a/src/ia32/lithium-codegen-ia32.cc +++ b/src/ia32/lithium-codegen-ia32.cc @@ -1176,7 +1176,7 @@ void LCodeGen::PopulateDeoptimizationData(Handle code) { int length = deoptimizations_.length(); if (length == 0) return; Handle data = - factory()->NewDeoptimizationInputData(length, TENURED); + DeoptimizationInputData::New(isolate(), length, TENURED); Handle translations = translations_.CreateByteArray(isolate()->factory()); diff --git a/src/ic.cc b/src/ic.cc index 09444b3..32efa5f 100644 --- a/src/ic.cc +++ b/src/ic.cc @@ -1945,8 +1945,7 @@ RUNTIME_FUNCTION(SharedStoreIC_ExtendStorage) { int new_unused = transition->unused_property_fields(); int new_size = old_storage->length() + new_unused + 1; - Handle new_storage = isolate->factory()->CopySizeFixedArray( - old_storage, new_size); + Handle new_storage = FixedArray::CopySize(old_storage, new_size); Handle to_store = value; diff --git a/src/mips/lithium-codegen-mips.cc b/src/mips/lithium-codegen-mips.cc index bb9134a..eabd4fc 100644 --- a/src/mips/lithium-codegen-mips.cc +++ b/src/mips/lithium-codegen-mips.cc @@ -861,7 +861,7 @@ void LCodeGen::PopulateDeoptimizationData(Handle code) { int length = deoptimizations_.length(); if (length == 0) return; Handle data = - factory()->NewDeoptimizationInputData(length, TENURED); + DeoptimizationInputData::New(isolate(), length, TENURED); Handle translations = translations_.CreateByteArray(isolate()->factory()); diff --git a/src/objects-inl.h b/src/objects-inl.h index 49b1b3c..1234725 100644 --- a/src/objects-inl.h +++ b/src/objects-inl.h @@ -6251,24 +6251,6 @@ bool JSObject::HasIndexedInterceptor() { } -MaybeObject* JSObject::EnsureWritableFastElements() { - ASSERT(HasFastSmiOrObjectElements()); - FixedArray* elems = FixedArray::cast(elements()); - Isolate* isolate = GetIsolate(); - if (elems->map() != isolate->heap()->fixed_cow_array_map()) return elems; - Object* writable_elems; - { MaybeObject* maybe_writable_elems = isolate->heap()->CopyFixedArrayWithMap( - elems, isolate->heap()->fixed_array_map()); - if (!maybe_writable_elems->ToObject(&writable_elems)) { - return maybe_writable_elems; - } - } - set_elements(FixedArray::cast(writable_elems)); - isolate->counters()->cow_arrays_converted()->Increment(); - return writable_elems; -} - - NameDictionary* JSObject::property_dictionary() { ASSERT(!HasFastProperties()); return NameDictionary::cast(properties()); @@ -6810,24 +6792,6 @@ void JSArray::SetContent(Handle array, } -MaybeObject* FixedArray::Copy() { - if (length() == 0) return this; - return GetHeap()->CopyFixedArray(this); -} - - -MaybeObject* FixedDoubleArray::Copy() { - if (length() == 0) return this; - return GetHeap()->CopyFixedDoubleArray(this); -} - - -MaybeObject* ConstantPoolArray::Copy() { - if (length() == 0) return this; - return GetHeap()->CopyConstantPoolArray(this); -} - - Handle TypeFeedbackInfo::UninitializedSentinel(Isolate* isolate) { return isolate->factory()->uninitialized_symbol(); } diff --git a/src/objects.cc b/src/objects.cc index 0defde3..bbf6979 100644 --- a/src/objects.cc +++ b/src/objects.cc @@ -371,9 +371,15 @@ static Handle GetDeclaredAccessorProperty( Handle JSObject::EnsureWritableFastElements( Handle object) { - CALL_HEAP_FUNCTION(object->GetIsolate(), - object->EnsureWritableFastElements(), - FixedArray); + ASSERT(object->HasFastSmiOrObjectElements()); + Isolate* isolate = object->GetIsolate(); + Handle elems(FixedArray::cast(object->elements()), isolate); + if (elems->map() != isolate->heap()->fixed_cow_array_map()) return elems; + Handle writable_elems = isolate->factory()->CopyFixedArrayWithMap( + elems, isolate->factory()->fixed_array_map()); + object->set_elements(*writable_elems); + isolate->counters()->cow_arrays_converted()->Increment(); + return writable_elems; } @@ -8416,38 +8422,27 @@ MaybeHandle FixedArray::UnionOfKeys(Handle first, } -MaybeObject* FixedArray::CopySize(int new_length, PretenureFlag pretenure) { - Heap* heap = GetHeap(); - if (new_length == 0) return heap->empty_fixed_array(); - Object* obj; - { MaybeObject* maybe_obj = heap->AllocateFixedArray(new_length, pretenure); - if (!maybe_obj->ToObject(&obj)) return maybe_obj; - } - FixedArray* result = FixedArray::cast(obj); +Handle FixedArray::CopySize( + Handle array, int new_length, PretenureFlag pretenure) { + Isolate* isolate = array->GetIsolate(); + if (new_length == 0) return isolate->factory()->empty_fixed_array(); + Handle result = + isolate->factory()->NewFixedArray(new_length, pretenure); // Copy the content DisallowHeapAllocation no_gc; - int len = length(); + int len = array->length(); if (new_length < len) len = new_length; // We are taking the map from the old fixed array so the map is sure to // be an immortal immutable object. - result->set_map_no_write_barrier(map()); + result->set_map_no_write_barrier(array->map()); WriteBarrierMode mode = result->GetWriteBarrierMode(no_gc); for (int i = 0; i < len; i++) { - result->set(i, get(i), mode); + result->set(i, array->get(i), mode); } return result; } -Handle FixedArray::CopySize( - Handle array, int new_length, PretenureFlag pretenure) { - Isolate* isolate = array->GetIsolate(); - CALL_HEAP_FUNCTION(isolate, - array->CopySize(new_length, pretenure), - FixedArray); -} - - void FixedArray::CopyTo(int pos, FixedArray* dest, int dest_pos, int len) { DisallowHeapAllocation no_gc; WriteBarrierMode mode = dest->GetWriteBarrierMode(no_gc); @@ -8596,21 +8591,29 @@ Object* AccessorPair::GetComponent(AccessorComponent component) { } -MaybeObject* DeoptimizationInputData::Allocate(Isolate* isolate, - int deopt_entry_count, - PretenureFlag pretenure) { +Handle DeoptimizationInputData::New( + Isolate* isolate, + int deopt_entry_count, + PretenureFlag pretenure) { ASSERT(deopt_entry_count > 0); - return isolate->heap()->AllocateFixedArray(LengthFor(deopt_entry_count), - pretenure); + return Handle::cast( + isolate->factory()->NewFixedArray( + LengthFor(deopt_entry_count), pretenure)); } -MaybeObject* DeoptimizationOutputData::Allocate(Isolate* isolate, - int number_of_deopt_points, - PretenureFlag pretenure) { - if (number_of_deopt_points == 0) return isolate->heap()->empty_fixed_array(); - return isolate->heap()->AllocateFixedArray( - LengthOfFixedArray(number_of_deopt_points), pretenure); +Handle DeoptimizationOutputData::New( + Isolate* isolate, + int number_of_deopt_points, + PretenureFlag pretenure) { + Handle result; + if (number_of_deopt_points == 0) { + result = isolate->factory()->empty_fixed_array(); + } else { + result = isolate->factory()->NewFixedArray( + LengthOfFixedArray(number_of_deopt_points), pretenure); + } + return Handle::cast(result); } @@ -10055,7 +10058,7 @@ void SharedFunctionInfo::AddToOptimizedCodeMap( Handle old_code_map = Handle::cast(value); ASSERT_EQ(-1, shared->SearchOptimizedCodeMap(*native_context, osr_ast_id)); old_length = old_code_map->length(); - new_code_map = isolate->factory()->CopySizeFixedArray( + new_code_map = FixedArray::CopySize( old_code_map, old_length + kEntryLength); // Zap the old map for the sake of the heap verifier. if (Heap::ShouldZapGarbage()) { @@ -12106,8 +12109,7 @@ Handle Map::PutPrototypeTransition(Handle map, if (capacity > kMaxCachedPrototypeTransitions) return map; // Grow array by factor 2 over and above what we need. - Factory* factory = map->GetIsolate()->factory(); - cache = factory->CopySizeFixedArray(cache, transitions * 2 * step + header); + cache = FixedArray::CopySize(cache, transitions * 2 * step + header); SetPrototypeTransitions(map, cache); } @@ -12223,11 +12225,10 @@ Handle DependentCode::Insert(Handle entries, if (entries->object_at(i) == *object) return entries; } if (entries->length() < kCodesStartIndex + number_of_entries + 1) { - Factory* factory = entries->GetIsolate()->factory(); int capacity = kCodesStartIndex + number_of_entries + 1; if (capacity > 5) capacity = capacity * 5 / 4; Handle new_entries = Handle::cast( - factory->CopySizeFixedArray(entries, capacity, TENURED)); + FixedArray::CopySize(entries, capacity, TENURED)); // The number of codes can change after GC. starts.Recompute(*entries); start = starts.at(group); diff --git a/src/objects.h b/src/objects.h index b1f8607..55025ef 100644 --- a/src/objects.h +++ b/src/objects.h @@ -1502,7 +1502,6 @@ class Object : public MaybeObject { inline bool HasSpecificClassOf(String* name); - MUST_USE_RESULT MaybeObject* ToObject(Isolate* isolate); // ECMA-262 9.9. bool BooleanValue(); // ECMA-262 9.2. // Convert to a JSObject if needed. @@ -2225,7 +2224,6 @@ class JSObject: public JSReceiver { // Requires: HasFastElements(). static Handle EnsureWritableFastElements( Handle object); - MUST_USE_RESULT inline MaybeObject* EnsureWritableFastElements(); // Collects elements starting at index 0. // Undefined values are placed after non-undefined values. @@ -2509,9 +2507,6 @@ class JSObject: public JSReceiver { Handle object, int capacity, int length); - MUST_USE_RESULT MaybeObject* SetFastDoubleElementsCapacityAndLength( - int capacity, - int length); // Lookup interceptors are used for handling properties controlled by host // objects. @@ -3065,10 +3060,7 @@ class FixedArray: public FixedArrayBase { // Shrink length and insert filler objects. void Shrink(int length); - // Copy operations. - MUST_USE_RESULT inline MaybeObject* Copy(); - MUST_USE_RESULT MaybeObject* CopySize(int new_length, - PretenureFlag pretenure = NOT_TENURED); + // Copy operation. static Handle CopySize(Handle array, int new_length, PretenureFlag pretenure = NOT_TENURED); @@ -3167,9 +3159,6 @@ class FixedDoubleArray: public FixedArrayBase { // Checking for the hole. inline bool is_the_hole(int index); - // Copy operations - MUST_USE_RESULT inline MaybeObject* Copy(); - // Garbage collection support. inline static int SizeFor(int length) { return kHeaderSize + length * kDoubleSize; @@ -3259,9 +3248,6 @@ class ConstantPoolArray: public FixedArrayBase { int number_of_heap_ptr_entries, int number_of_int32_entries); - // Copy operations - MUST_USE_RESULT inline MaybeObject* Copy(); - // Garbage collection support. inline static int SizeFor(int number_of_int64_entries, int number_of_code_ptr_entries, @@ -5296,9 +5282,9 @@ class DeoptimizationInputData: public FixedArray { } // Allocates a DeoptimizationInputData. - MUST_USE_RESULT static MaybeObject* Allocate(Isolate* isolate, - int deopt_entry_count, - PretenureFlag pretenure); + static Handle New(Isolate* isolate, + int deopt_entry_count, + PretenureFlag pretenure); // Casting. static inline DeoptimizationInputData* cast(Object* obj); @@ -5343,9 +5329,9 @@ class DeoptimizationOutputData: public FixedArray { } // Allocates a DeoptimizationOutputData. - MUST_USE_RESULT static MaybeObject* Allocate(Isolate* isolate, - int number_of_deopt_points, - PretenureFlag pretenure); + static Handle New(Isolate* isolate, + int number_of_deopt_points, + PretenureFlag pretenure); // Casting. static inline DeoptimizationOutputData* cast(Object* obj); diff --git a/src/x64/lithium-codegen-x64.cc b/src/x64/lithium-codegen-x64.cc index 0dd4bc6..fc94a43 100644 --- a/src/x64/lithium-codegen-x64.cc +++ b/src/x64/lithium-codegen-x64.cc @@ -813,7 +813,7 @@ void LCodeGen::PopulateDeoptimizationData(Handle code) { int length = deoptimizations_.length(); if (length == 0) return; Handle data = - factory()->NewDeoptimizationInputData(length, TENURED); + DeoptimizationInputData::New(isolate(), length, TENURED); Handle translations = translations_.CreateByteArray(isolate()->factory()); -- 2.7.4