From: verwaest@chromium.org Date: Mon, 14 Apr 2014 11:19:37 +0000 (+0000) Subject: Clean up the public interface of Map. X-Git-Tag: upstream/4.7.83~9649 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=de50f63f16bf0a3e5e33623241fc060354be6f31;p=platform%2Fupstream%2Fv8.git Clean up the public interface of Map. BUG= R=mvstanton@chromium.org Review URL: https://codereview.chromium.org/234573005 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@20716 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- diff --git a/src/objects-inl.h b/src/objects-inl.h index b0c8d17..cde3818 100644 --- a/src/objects-inl.h +++ b/src/objects-inl.h @@ -5026,19 +5026,6 @@ uint32_t Map::bit_field3() { } -void Map::ClearTransitions(Heap* heap, WriteBarrierMode mode) { - Object* back_pointer = GetBackPointer(); - - if (Heap::ShouldZapGarbage() && HasTransitionArray()) { - ZapTransitions(); - } - - WRITE_FIELD(this, kTransitionsOrBackPointerOffset, back_pointer); - CONDITIONAL_WRITE_BARRIER( - heap, this, kTransitionsOrBackPointerOffset, back_pointer, mode); -} - - void Map::AppendDescriptor(Descriptor* desc) { DescriptorArray* descriptors = instance_descriptors(); int number_of_own_descriptors = NumberOfOwnDescriptors(); @@ -5084,11 +5071,6 @@ bool Map::CanHaveMoreTransitions() { } -void Map::SetTransition(int transition_index, Map* target) { - transitions()->SetTarget(transition_index, target); -} - - Map* Map::GetTransition(int transition_index) { return transitions()->GetTarget(transition_index); } diff --git a/src/objects.cc b/src/objects.cc index 4061f61..3e5e0bd 100644 --- a/src/objects.cc +++ b/src/objects.cc @@ -2607,7 +2607,7 @@ Handle Map::GeneralizeRepresentation(Handle old_map, // Add missing transitions. Handle new_map = split_map; for (; descriptor < descriptors; descriptor++) { - new_map = Map::CopyInstallDescriptors(new_map, descriptor, new_descriptors); + new_map = CopyInstallDescriptors(new_map, descriptor, new_descriptors); } new_map->set_owns_descriptors(true); @@ -6766,7 +6766,7 @@ Handle Map::CopyNormalized(Handle map, new_instance_size -= map->inobject_properties() * kPointerSize; } - Handle result = Map::RawCopy(map, new_instance_size); + Handle result = RawCopy(map, new_instance_size); if (mode != CLEAR_INOBJECT_PROPERTIES) { result->set_inobject_properties(map->inobject_properties()); @@ -6811,7 +6811,7 @@ Handle Map::ShareDescriptor(Handle map, ASSERT(map->NumberOfOwnDescriptors() == map->instance_descriptors()->number_of_descriptors()); - Handle result = Map::CopyDropDescriptors(map); + Handle result = CopyDropDescriptors(map); Handle name = descriptor->GetKey(); Handle transitions = TransitionArray::CopyInsert(map, name, result, SIMPLE_TRANSITION); @@ -6822,7 +6822,7 @@ Handle Map::ShareDescriptor(Handle map, if (old_size == 0) { descriptors = DescriptorArray::Allocate(map->GetIsolate(), 0, 1); } else { - Map::EnsureDescriptorSlack(map, old_size < 4 ? 1 : old_size / 2); + EnsureDescriptorSlack(map, old_size < 4 ? 1 : old_size / 2); descriptors = handle(map->instance_descriptors()); } } @@ -6847,7 +6847,7 @@ Handle Map::CopyReplaceDescriptors(Handle map, Handle descriptors, TransitionFlag flag, SimpleTransitionFlag simple_flag) { - return Map::CopyReplaceDescriptors( + return CopyReplaceDescriptors( map, descriptors, flag, Handle::null(), simple_flag); } @@ -6882,7 +6882,7 @@ Handle Map::CopyInstallDescriptors(Handle map, Handle descriptors) { ASSERT(descriptors->IsSortedNoDuplicates()); - Handle result = Map::CopyDropDescriptors(map); + Handle result = CopyDropDescriptors(map); result->InitializeDescriptors(*descriptors); result->SetNumberOfOwnDescriptors(new_descriptor + 1); @@ -6930,7 +6930,7 @@ Handle Map::CopyAsElementsKind(Handle map, ElementsKind kind, if (insert_transition && map->owns_descriptors()) { // In case the map owned its own descriptors, share the descriptors and // transfer ownership to the new map. - Handle new_map = Map::CopyDropDescriptors(map); + Handle new_map = CopyDropDescriptors(map); SetElementsTransitionMap(map, new_map); @@ -6944,7 +6944,7 @@ Handle Map::CopyAsElementsKind(Handle map, ElementsKind kind, // In case the map did not own its own descriptors, a split is forced by // copying the map; creating a new descriptor array cell. // Create a new free-floating map only if we are not allowed to store it. - Handle new_map = Map::Copy(map); + Handle new_map = Copy(map); new_map->set_elements_kind(kind); @@ -6966,9 +6966,9 @@ Handle Map::CopyForObserved(Handle map) { // transfer ownership to the new map. Handle new_map; if (map->owns_descriptors()) { - new_map = Map::CopyDropDescriptors(map); + new_map = CopyDropDescriptors(map); } else { - new_map = Map::Copy(map); + new_map = Copy(map); } Handle transitions = TransitionArray::CopyInsert( @@ -6993,7 +6993,7 @@ Handle Map::Copy(Handle map) { int number_of_own_descriptors = map->NumberOfOwnDescriptors(); Handle new_descriptors = DescriptorArray::CopyUpTo(descriptors, number_of_own_descriptors); - return Map::CopyReplaceDescriptors(map, new_descriptors, OMIT_TRANSITION); + return CopyReplaceDescriptors(map, new_descriptors, OMIT_TRANSITION); } @@ -7037,14 +7037,14 @@ Handle Map::CopyAddDescriptor(Handle map, if (flag == INSERT_TRANSITION && map->owns_descriptors() && map->CanHaveMoreTransitions()) { - return Map::ShareDescriptor(map, descriptors, descriptor); + return ShareDescriptor(map, descriptors, descriptor); } Handle new_descriptors = DescriptorArray::CopyUpTo( descriptors, map->NumberOfOwnDescriptors(), 1); new_descriptors->Append(descriptor); - return Map::CopyReplaceDescriptors( + return CopyReplaceDescriptors( map, new_descriptors, flag, descriptor->GetKey(), SIMPLE_TRANSITION); } @@ -7060,10 +7060,9 @@ Handle Map::CopyInsertDescriptor(Handle map, // We replace the key if it is already present. int index = old_descriptors->SearchWithCache(*descriptor->GetKey(), *map); if (index != DescriptorArray::kNotFound) { - return Map::CopyReplaceDescriptor( - map, old_descriptors, descriptor, index, flag); + return CopyReplaceDescriptor(map, old_descriptors, descriptor, index, flag); } - return Map::CopyAddDescriptor(map, descriptor, flag); + return CopyAddDescriptor(map, descriptor, flag); } @@ -7139,8 +7138,7 @@ Handle Map::CopyReplaceDescriptor(Handle map, (insertion_index == descriptors->number_of_descriptors() - 1) ? SIMPLE_TRANSITION : FULL_TRANSITION; - return Map::CopyReplaceDescriptors( - map, new_descriptors, flag, key, simple_flag); + return CopyReplaceDescriptors(map, new_descriptors, flag, key, simple_flag); } @@ -11510,7 +11508,7 @@ Handle Map::PutPrototypeTransition(Handle map, Factory* factory = map->GetIsolate()->factory(); cache = factory->CopySizeFixedArray(cache, transitions * 2 * step + header); - Map::SetPrototypeTransitions(map, cache); + SetPrototypeTransitions(map, cache); } // Reload number of transitions as GC might shrink them. @@ -11790,6 +11788,18 @@ void DependentCode::AddToDependentICList(Handle stub) { } +Handle Map::TransitionToPrototype(Handle map, + Handle prototype) { + Handle new_map = GetPrototypeTransition(map, prototype); + if (new_map.is_null()) { + new_map = Copy(map); + PutPrototypeTransition(map, prototype, new_map); + new_map->set_prototype(*prototype); + } + return new_map; +} + + Handle JSObject::SetPrototype(Handle object, Handle value, bool skip_hidden_prototypes) { @@ -11860,12 +11870,7 @@ Handle JSObject::SetPrototype(Handle object, JSObject::OptimizeAsPrototype(Handle::cast(value)); } - Handle new_map = Map::GetPrototypeTransition(map, value); - if (new_map.is_null()) { - new_map = Map::Copy(map); - Map::PutPrototypeTransition(map, value, new_map); - new_map->set_prototype(*value); - } + Handle new_map = Map::TransitionToPrototype(map, value); ASSERT(new_map->prototype() == *value); JSObject::MigrateToMap(real_receiver, new_map); diff --git a/src/objects.h b/src/objects.h index 7624809..047f845 100644 --- a/src/objects.h +++ b/src/objects.h @@ -6209,21 +6209,13 @@ class Map: public HeapObject { inline Map* elements_transition_map(); static Handle SetElementsTransitionMap( Handle map, Handle transitioned_map); - inline void SetTransition(int transition_index, Map* target); inline Map* GetTransition(int transition_index); inline int SearchTransition(Name* name); inline FixedArrayBase* GetInitialElements(); DECL_ACCESSORS(transitions, TransitionArray) - inline void ClearTransitions(Heap* heap, - WriteBarrierMode mode = UPDATE_WRITE_BARRIER); - - void DeprecateTransitionTree(); - void DeprecateTarget(Name* key, DescriptorArray* new_descriptors); Map* FindRootMap(); - Map* FindUpdatedMap(int verbatim, int length, DescriptorArray* descriptors); - Map* FindLastMatchMap(int verbatim, int length, DescriptorArray* descriptors); inline int GetInObjectPropertyOffset(int index); @@ -6248,15 +6240,6 @@ class Map: public HeapObject { PropertyAttributes attributes, const char* reason); - void PrintGeneralization(FILE* file, - const char* reason, - int modify_index, - int split, - int descriptors, - bool constant_to_field, - Representation old_representation, - Representation new_representation); - // Returns the constructor name (the name (possibly, inferred name) of the // function that was used to instantiate the object). String* constructor_name(); @@ -6322,8 +6305,6 @@ class Map: public HeapObject { // 2 + 2 * i: prototype // 3 + 2 * i: target map inline FixedArray* GetPrototypeTransitions(); - static inline void SetPrototypeTransitions( - Handle map, Handle prototype_transitions); inline bool HasPrototypeTransitions(); static const int kProtoTransitionHeaderSize = 1; @@ -6415,7 +6396,6 @@ class Map: public HeapObject { // Same as above, but does not touch the prototype chain. static Handle CurrentMapForDeprecatedInternal(Handle map); - static Handle RawCopy(Handle map, int instance_size); static Handle CopyDropDescriptors(Handle map); static Handle CopyReplaceDescriptors( Handle map, @@ -6428,25 +6408,17 @@ class Map: public HeapObject { Handle descriptors, TransitionFlag flag, SimpleTransitionFlag simple_flag = FULL_TRANSITION); - static Handle CopyInstallDescriptors( - Handle map, - int new_descriptor, - Handle descriptors); - static Handle ShareDescriptor(Handle map, - Handle descriptors, - Descriptor* descriptor); static Handle CopyAddDescriptor(Handle map, Descriptor* descriptor, TransitionFlag flag); static Handle CopyInsertDescriptor(Handle map, Descriptor* descriptor, TransitionFlag flag); - static Handle CopyReplaceDescriptor( - Handle map, - Handle descriptors, - Descriptor* descriptor, - int index, - TransitionFlag flag); + static Handle CopyReplaceDescriptor(Handle map, + Handle descriptors, + Descriptor* descriptor, + int index, + TransitionFlag flag); static Handle AsElementsKind(Handle map, ElementsKind kind); @@ -6522,14 +6494,6 @@ class Map: public HeapObject { // Computes a hash value for this map, to be used in HashTables and such. int Hash(); - bool EquivalentToForTransition(Map* other); - - // Compares this map to another to see if they describe equivalent objects. - // If |mode| is set to CLEAR_INOBJECT_PROPERTIES, |other| is treated as if - // it had exactly zero inobject properties. - // The "shared" flags of both this map and |other| are ignored. - bool EquivalentToForNormalization(Map* other, PropertyNormalizationMode mode); - // Returns the map that this map transitions to if its elements_kind // is changed to |elements_kind|, or NULL if no such map is cached yet. // |safe_to_add_transitions| is set to false if adding transitions is not @@ -6542,15 +6506,6 @@ class Map: public HeapObject { Handle FindTransitionedMap(MapHandleList* candidates); Map* FindTransitionedMap(MapList* candidates); - // Zaps the contents of backing data structures. Note that the - // heap verifier (i.e. VerifyMarkingVisitor) relies on zapping of objects - // holding weak references when incremental marking is used, because it also - // iterates over objects that are otherwise unreachable. - // In general we only want to call these functions in release mode when - // heap verification is turned on. - void ZapPrototypeTransitions(); - void ZapTransitions(); - bool CanTransition() { // Only JSObject and subtypes have map transitions and back pointers. STATIC_ASSERT(LAST_TYPE == LAST_JS_OBJECT_TYPE); @@ -6611,11 +6566,8 @@ class Map: public HeapObject { // transitions are in the form of a map where the keys are prototype objects // and the values are the maps the are transitioned to. static const int kMaxCachedPrototypeTransitions = 256; - static Handle GetPrototypeTransition(Handle map, - Handle prototype); - static Handle PutPrototypeTransition(Handle map, - Handle prototype, - Handle target_map); + static Handle TransitionToPrototype(Handle map, + Handle prototype); static const int kMaxPreAllocatedPropertyFields = 255; @@ -6699,7 +6651,57 @@ class Map: public HeapObject { kPointerFieldsEndOffset, kSize> BodyDescriptor; + // Compares this map to another to see if they describe equivalent objects. + // If |mode| is set to CLEAR_INOBJECT_PROPERTIES, |other| is treated as if + // it had exactly zero inobject properties. + // The "shared" flags of both this map and |other| are ignored. + bool EquivalentToForNormalization(Map* other, PropertyNormalizationMode mode); + private: + bool EquivalentToForTransition(Map* other); + static Handle RawCopy(Handle map, int instance_size); + static Handle ShareDescriptor(Handle map, + Handle descriptors, + Descriptor* descriptor); + static Handle CopyInstallDescriptors( + Handle map, + int new_descriptor, + Handle descriptors); + + // Zaps the contents of backing data structures. Note that the + // heap verifier (i.e. VerifyMarkingVisitor) relies on zapping of objects + // holding weak references when incremental marking is used, because it also + // iterates over objects that are otherwise unreachable. + // In general we only want to call these functions in release mode when + // heap verification is turned on. + void ZapPrototypeTransitions(); + void ZapTransitions(); + + void DeprecateTransitionTree(); + void DeprecateTarget(Name* key, DescriptorArray* new_descriptors); + + Map* FindUpdatedMap(int verbatim, int length, DescriptorArray* descriptors); + Map* FindLastMatchMap(int verbatim, int length, DescriptorArray* descriptors); + + void PrintGeneralization(FILE* file, + const char* reason, + int modify_index, + int split, + int descriptors, + bool constant_to_field, + Representation old_representation, + Representation new_representation); + + static inline void SetPrototypeTransitions( + Handle map, + Handle prototype_transitions); + + static Handle GetPrototypeTransition(Handle map, + Handle prototype); + static Handle PutPrototypeTransition(Handle map, + Handle prototype, + Handle target_map); + DISALLOW_IMPLICIT_CONSTRUCTORS(Map); }; diff --git a/test/cctest/test-heap.cc b/test/cctest/test-heap.cc index 307e407..1a6e632 100644 --- a/test/cctest/test-heap.cc +++ b/test/cctest/test-heap.cc @@ -2072,10 +2072,6 @@ TEST(PrototypeTransitionClearing) { CHECK(!space->LastPage()->Contains( map->GetPrototypeTransitions()->address())); CHECK(space->LastPage()->Contains(prototype->address())); - JSObject::SetPrototype(baseObject, prototype, false); - CHECK(Map::GetPrototypeTransition(map, prototype)->IsMap()); - CcTest::heap()->CollectAllGarbage(Heap::kNoGCFlags); - CHECK(Map::GetPrototypeTransition(map, prototype)->IsMap()); }