From a0bc7651aba787426bae456a9217fd80b03b55c5 Mon Sep 17 00:00:00 2001 From: mstarzinger Date: Mon, 14 Sep 2015 05:28:34 -0700 Subject: [PATCH] [heap] No leakage of objects-visiting.h outside of heap. This prevents the internal objects-visiting.h to be usable outisde of the "heap" directory. The static object visitation is only usefull within the GC and is now properly encapsulated. R=hpayer@chromium.org,mlippautz@chromium.org Review URL: https://codereview.chromium.org/1328003002 Cr-Commit-Position: refs/heads/master@{#30716} --- src/heap/heap-inl.h | 1 - src/heap/heap.cc | 8 +++++++- src/heap/heap.h | 10 +++++++++- src/heap/mark-compact.cc | 5 +++++ src/heap/mark-compact.h | 4 ---- src/heap/objects-visiting.h | 13 ++++++------- src/objects-debug.cc | 2 +- src/objects-inl.h | 8 ++++---- src/objects.cc | 6 +++--- 9 files changed, 35 insertions(+), 22 deletions(-) diff --git a/src/heap/heap-inl.h b/src/heap/heap-inl.h index aeaea80d1..6f7c060d7 100644 --- a/src/heap/heap-inl.h +++ b/src/heap/heap-inl.h @@ -11,7 +11,6 @@ #include "src/counters.h" #include "src/heap/heap.h" #include "src/heap/incremental-marking-inl.h" -#include "src/heap/objects-visiting.h" #include "src/heap/spaces-inl.h" #include "src/heap/store-buffer.h" #include "src/heap/store-buffer-inl.h" diff --git a/src/heap/heap.cc b/src/heap/heap.cc index d88117819..671d46269 100644 --- a/src/heap/heap.cc +++ b/src/heap/heap.cc @@ -2037,7 +2037,7 @@ AllocationResult Heap::AllocateMap(InstanceType instance_type, } // Must be called only after |instance_type|, |instance_size| and // |layout_descriptor| are set. - map->set_visitor_id(StaticVisitorBase::GetVisitorId(map)); + map->set_visitor_id(Heap::GetStaticVisitorIdForMap(map)); map->set_bit_field(0); map->set_bit_field2(1 << Map::kIsExtensible); int bit_field3 = Map::EnumLengthBits::encode(kInvalidEnumCacheSentinel) | @@ -6104,5 +6104,11 @@ bool Heap::GetObjectTypeName(size_t index, const char** object_type, return false; } + +// static +int Heap::GetStaticVisitorIdForMap(Map* map) { + return StaticVisitorBase::GetVisitorId(map); +} + } // namespace internal } // namespace v8 diff --git a/src/heap/heap.h b/src/heap/heap.h index bb901f1c6..366afd0bc 100644 --- a/src/heap/heap.h +++ b/src/heap/heap.h @@ -698,6 +698,9 @@ class Heap { // The roots that have an index less than this are always in old space. static const int kOldSpaceRoots = 0x20; + // The minimum size of a HeapObject on the heap. + static const int kMinObjectSizeInWords = 2; + STATIC_ASSERT(kUndefinedValueRootIndex == Internals::kUndefinedValueRootIndex); STATIC_ASSERT(kNullValueRootIndex == Internals::kNullValueRootIndex); @@ -756,6 +759,10 @@ class Heap { // pointer size aligned addresses. static inline void MoveBlock(Address dst, Address src, int byte_size); + // Determines a static visitor id based on the given {map} that can then be + // stored on the map to facilitate fast dispatch for {StaticVisitorBase}. + static int GetStaticVisitorIdForMap(Map* map); + // Notifies the heap that is ok to start marking or other activities that // should not happen during deserialization. void NotifyDeserializationComplete(); @@ -1495,8 +1502,9 @@ class Heap { AllocationAlignment alignment); // =========================================================================== - // ArrayBufferTracker. ======================================================= + // ArrayBuffer tracking. ===================================================== // =========================================================================== + void RegisterNewArrayBuffer(JSArrayBuffer* buffer); void UnregisterArrayBuffer(JSArrayBuffer* buffer); diff --git a/src/heap/mark-compact.cc b/src/heap/mark-compact.cc index ce8a13683..7757b2cef 100644 --- a/src/heap/mark-compact.cc +++ b/src/heap/mark-compact.cc @@ -37,6 +37,11 @@ const char* Marking::kGreyBitPattern = "11"; const char* Marking::kImpossibleBitPattern = "01"; +// The following has to hold in order for {Marking::MarkBitFrom} to not produce +// invalid {kImpossibleBitPattern} in the marking bitmap by overlapping. +STATIC_ASSERT(Heap::kMinObjectSizeInWords >= 2); + + // ------------------------------------------------------------------------- // MarkCompactCollector diff --git a/src/heap/mark-compact.h b/src/heap/mark-compact.h index f6df6f4a2..7c438132b 100644 --- a/src/heap/mark-compact.h +++ b/src/heap/mark-compact.h @@ -117,10 +117,6 @@ class Marking : public AllStatic { markbit.Next().Set(); } - static void SetAllMarkBitsInRange(MarkBit start, MarkBit end); - static void ClearAllMarkBitsOfCellsContainedInRange(MarkBit start, - MarkBit end); - static void TransferMark(Heap* heap, Address old_start, Address new_start); #ifdef DEBUG diff --git a/src/heap/objects-visiting.h b/src/heap/objects-visiting.h index ff2e7df0f..1eba88731 100644 --- a/src/heap/objects-visiting.h +++ b/src/heap/objects-visiting.h @@ -6,6 +6,7 @@ #define V8_OBJECTS_VISITING_H_ #include "src/allocation.h" +#include "src/heap/heap.h" #include "src/heap/spaces.h" #include "src/layout-descriptor.h" @@ -99,7 +100,6 @@ class StaticVisitorBase : public AllStatic { kVisitDataObject = kVisitDataObject2, kVisitJSObject = kVisitJSObject2, kVisitStruct = kVisitStruct2, - kMinObjectSizeInWords = 2 }; // Visitor ID should fit in one byte. @@ -121,15 +121,15 @@ class StaticVisitorBase : public AllStatic { DCHECK((base == kVisitDataObject) || (base == kVisitStruct) || (base == kVisitJSObject)); DCHECK(IsAligned(object_size, kPointerSize)); - DCHECK(kMinObjectSizeInWords * kPointerSize <= object_size); + DCHECK(Heap::kMinObjectSizeInWords * kPointerSize <= object_size); DCHECK(object_size <= Page::kMaxRegularHeapObjectSize); DCHECK(!has_unboxed_fields || (base == kVisitJSObject)); if (has_unboxed_fields) return generic; - int visitor_id = - Min(base + (object_size >> kPointerSizeLog2) - kMinObjectSizeInWords, - static_cast(generic)); + int visitor_id = Min( + base + (object_size >> kPointerSizeLog2) - Heap::kMinObjectSizeInWords, + static_cast(generic)); return static_cast(visitor_id); } @@ -171,8 +171,7 @@ class VisitorDispatchTable { template void RegisterSpecializations() { - STATIC_ASSERT((generic - base + StaticVisitorBase::kMinObjectSizeInWords) == - 10); + STATIC_ASSERT((generic - base + Heap::kMinObjectSizeInWords) == 10); RegisterSpecialization(); RegisterSpecialization(); RegisterSpecialization(); diff --git a/src/objects-debug.cc b/src/objects-debug.cc index 12b4ec7ba..8209774d1 100644 --- a/src/objects-debug.cc +++ b/src/objects-debug.cc @@ -343,7 +343,7 @@ void Map::DictionaryMapVerify() { CHECK(is_dictionary_map()); CHECK(instance_descriptors()->IsEmpty()); CHECK_EQ(0, unused_property_fields()); - CHECK_EQ(StaticVisitorBase::GetVisitorId(this), visitor_id()); + CHECK_EQ(Heap::GetStaticVisitorIdForMap(this), visitor_id()); } diff --git a/src/objects-inl.h b/src/objects-inl.h index 9ddaa81af..f37671bed 100644 --- a/src/objects-inl.h +++ b/src/objects-inl.h @@ -1812,7 +1812,7 @@ inline void AllocationSite::set_memento_found_count(int count) { // Verify that we can count more mementos than we can possibly find in one // new space collection. DCHECK((GetHeap()->MaxSemiSpaceSize() / - (StaticVisitorBase::kMinObjectSizeInWords * kPointerSize + + (Heap::kMinObjectSizeInWords * kPointerSize + AllocationMemento::kSize)) < MementoFoundCountBits::kMax); DCHECK(count < MementoFoundCountBits::kMax); set_pretenure_data( @@ -5362,11 +5362,11 @@ void Map::UpdateDescriptors(DescriptorArray* descriptors, // TODO(ishell): remove these checks from VERIFY_HEAP mode. if (FLAG_verify_heap) { CHECK(layout_descriptor()->IsConsistentWithMap(this)); - CHECK(visitor_id() == StaticVisitorBase::GetVisitorId(this)); + CHECK(visitor_id() == Heap::GetStaticVisitorIdForMap(this)); } #else SLOW_DCHECK(layout_descriptor()->IsConsistentWithMap(this)); - DCHECK(visitor_id() == StaticVisitorBase::GetVisitorId(this)); + DCHECK(visitor_id() == Heap::GetStaticVisitorIdForMap(this)); #endif } } @@ -5388,7 +5388,7 @@ void Map::InitializeDescriptors(DescriptorArray* descriptors, #else SLOW_DCHECK(layout_descriptor()->IsConsistentWithMap(this)); #endif - set_visitor_id(StaticVisitorBase::GetVisitorId(this)); + set_visitor_id(Heap::GetStaticVisitorIdForMap(this)); } } diff --git a/src/objects.cc b/src/objects.cc index 96b1031c3..a7c3d7610 100644 --- a/src/objects.cc +++ b/src/objects.cc @@ -7103,7 +7103,7 @@ Handle Map::CopyInstallDescriptors( #else SLOW_DCHECK(result->layout_descriptor()->IsConsistentWithMap(*result)); #endif - result->set_visitor_id(StaticVisitorBase::GetVisitorId(*result)); + result->set_visitor_id(Heap::GetStaticVisitorIdForMap(*result)); } Handle name = handle(descriptors->GetKey(new_descriptor)); @@ -7240,7 +7240,7 @@ Handle Map::Create(Isolate* isolate, int inobject_properties) { copy->SetInObjectProperties(inobject_properties); copy->set_unused_property_fields(inobject_properties); copy->set_instance_size(new_instance_size); - copy->set_visitor_id(StaticVisitorBase::GetVisitorId(*copy)); + copy->set_visitor_id(Heap::GetStaticVisitorIdForMap(*copy)); return copy; } @@ -10009,7 +10009,7 @@ static void ShrinkInstanceSize(Map* map, void* data) { map->set_instance_size(map->instance_size() - slack * kPointerSize); // Visitor id might depend on the instance size, recalculate it. - map->set_visitor_id(StaticVisitorBase::GetVisitorId(map)); + map->set_visitor_id(Heap::GetStaticVisitorIdForMap(map)); } -- 2.34.1