Commit 6663ed49 authored by Igor Sheludko's avatar Igor Sheludko Committed by Commit Bot

[ptr-compr] Remove default implementation of ObjectVisitor::VisitEmbeddedPointer()

which used to treat off-heap slots as on-heap ones and implement embedded objects
visitation in derived visitor classes.

Bug: v8:8518
Change-Id: Ia40d8135078379cca990e9167d3f1bebb3b5be0a
Reviewed-on: https://chromium-review.googlesource.com/c/1367747Reviewed-by: 's avatarUlan Degenbaev <ulan@chromium.org>
Commit-Queue: Igor Sheludko <ishell@chromium.org>
Cr-Commit-Position: refs/heads/master@{#58123}
parent 0c0d4c39
......@@ -447,6 +447,12 @@ class ConcurrentMarkingVisitor final
UNREACHABLE();
}
void VisitEmbeddedPointer(Code host, RelocInfo* rinfo) final {
// This should never happen, because snapshotting is performed only on
// JSObjects (and derived classes).
UNREACHABLE();
}
void VisitCustomWeakPointers(HeapObject* host, ObjectSlot start,
ObjectSlot end) override {
DCHECK(host->IsJSWeakCell());
......
......@@ -1477,6 +1477,10 @@ class StringTableVerifier : public ObjectVisitor {
void VisitCodeTarget(Code host, RelocInfo* rinfo) override { UNREACHABLE(); }
void VisitEmbeddedPointer(Code host, RelocInfo* rinfo) override {
UNREACHABLE();
}
private:
Isolate* isolate_;
};
......@@ -2998,6 +3002,10 @@ class SlotCollectingVisitor final : public ObjectVisitor {
void VisitCodeTarget(Code host, RelocInfo* rinfo) final { UNREACHABLE(); }
void VisitEmbeddedPointer(Code host, RelocInfo* rinfo) override {
UNREACHABLE();
}
int number_of_slots() { return static_cast<int>(slots_.size()); }
MaybeObjectSlot slot(int i) { return slots_[i]; }
......@@ -5039,6 +5047,9 @@ class UnreachableObjectsFilter : public HeapObjectsFilter {
Code target = Code::GetCodeFromTargetAddress(rinfo->target_address());
MarkHeapObject(target);
}
void VisitEmbeddedPointer(Code host, RelocInfo* rinfo) final {
MarkHeapObject(rinfo->target_object());
}
void VisitRootPointers(Root root, const char* description,
FullObjectSlot start, FullObjectSlot end) override {
......@@ -5442,6 +5453,10 @@ void VerifyPointersVisitor::VisitCodeTarget(Code host, RelocInfo* rinfo) {
VerifyHeapObjectImpl(target);
}
void VerifyPointersVisitor::VisitEmbeddedPointer(Code host, RelocInfo* rinfo) {
VerifyHeapObjectImpl(rinfo->target_object());
}
void VerifySmisVisitor::VisitRootPointers(Root root, const char* description,
FullObjectSlot start,
FullObjectSlot end) {
......
......@@ -2162,6 +2162,7 @@ class VerifyPointersVisitor : public ObjectVisitor, public RootVisitor {
void VisitPointers(HeapObject* host, MaybeObjectSlot start,
MaybeObjectSlot end) override;
void VisitCodeTarget(Code host, RelocInfo* rinfo) override;
void VisitEmbeddedPointer(Code host, RelocInfo* rinfo) override;
void VisitRootPointers(Root root, const char* description,
FullObjectSlot start, FullObjectSlot end) override;
......
......@@ -346,6 +346,9 @@ class FullEvacuationVerifier : public EvacuationVerifier {
Code target = Code::GetCodeFromTargetAddress(rinfo->target_address());
VerifyHeapObjectImpl(target);
}
void VisitEmbeddedPointer(Code host, RelocInfo* rinfo) override {
VerifyHeapObjectImpl(rinfo->target_object());
}
void VerifyRootPointers(FullObjectSlot start, FullObjectSlot end) override {
VerifyPointersImpl(start, end);
}
......@@ -942,6 +945,9 @@ class MarkCompactCollector::CustomRootBodyMarkingVisitor final
Code target = Code::GetCodeFromTargetAddress(rinfo->target_address());
MarkObject(host, target);
}
void VisitEmbeddedPointer(Code host, RelocInfo* rinfo) override {
MarkObject(host, rinfo->target_object());
}
private:
V8_INLINE void MarkObject(HeapObject* host, Object* object) {
......@@ -987,6 +993,10 @@ class InternalizedStringTableCleaner : public ObjectVisitor {
void VisitCodeTarget(Code host, RelocInfo* rinfo) final { UNREACHABLE(); }
void VisitEmbeddedPointer(Code host, RelocInfo* rinfo) final {
UNREACHABLE();
}
int PointersRemoved() {
return pointers_removed_;
}
......@@ -3668,7 +3678,9 @@ class YoungGenerationMarkingVerifier : public MarkingVerifier {
Code target = Code::GetCodeFromTargetAddress(rinfo->target_address());
VerifyHeapObjectImpl(target);
}
void VisitEmbeddedPointer(Code host, RelocInfo* rinfo) override {
VerifyHeapObjectImpl(rinfo->target_object());
}
void VerifyRootPointers(FullObjectSlot start, FullObjectSlot end) override {
VerifyPointersImpl(start, end);
}
......@@ -3732,6 +3744,9 @@ class YoungGenerationEvacuationVerifier : public EvacuationVerifier {
Code target = Code::GetCodeFromTargetAddress(rinfo->target_address());
VerifyHeapObjectImpl(target);
}
void VisitEmbeddedPointer(Code host, RelocInfo* rinfo) override {
VerifyHeapObjectImpl(rinfo->target_object());
}
void VerifyRootPointers(FullObjectSlot start, FullObjectSlot end) override {
VerifyPointersImpl(start, end);
}
......@@ -3793,6 +3808,11 @@ class YoungGenerationMarkingVisitor final
UNREACHABLE();
}
V8_INLINE void VisitEmbeddedPointer(Code host, RelocInfo* rinfo) final {
// Code objects are not expected in new space.
UNREACHABLE();
}
private:
template <typename TSlot>
V8_INLINE void VisitPointersImpl(HeapObject* host, TSlot start, TSlot end) {
......
......@@ -82,6 +82,10 @@ class FieldStatsCollector : public ObjectVisitor {
// as a full tagged value, so there's nothing to count.
}
void VisitEmbeddedPointer(Code host, RelocInfo* rinfo) override {
*tagged_fields_count_ += 1;
}
private:
struct JSObjectFieldStats {
JSObjectFieldStats()
......
......@@ -425,8 +425,32 @@ void ScavengeVisitor::VisitPointers(HeapObject* host, MaybeObjectSlot start,
void ScavengeVisitor::VisitCodeTarget(Code host, RelocInfo* rinfo) {
Code target = Code::GetCodeFromTargetAddress(rinfo->target_address());
#ifdef DEBUG
Code old_target = target;
#endif
FullObjectSlot slot(&target);
VisitPointersImpl(host, slot, slot + 1);
VisitHeapObjectImpl(slot, target);
// Code objects are never in new-space, so the slot contents must not change.
DCHECK_EQ(old_target, target);
}
void ScavengeVisitor::VisitEmbeddedPointer(Code host, RelocInfo* rinfo) {
HeapObject* heap_object = rinfo->target_object();
#ifdef DEBUG
HeapObject* old_heap_object = heap_object;
#endif
FullObjectSlot slot(&heap_object);
VisitHeapObjectImpl(slot, heap_object);
// We don't embed new-space objects into code, so the slot contents must not
// change.
DCHECK_EQ(old_heap_object, heap_object);
}
template <typename TSlot>
void ScavengeVisitor::VisitHeapObjectImpl(TSlot slot, HeapObject* heap_object) {
if (Heap::InNewSpace(heap_object)) {
scavenger_->ScavengeObject(HeapObjectSlot(slot), heap_object);
}
}
template <typename TSlot>
......@@ -436,8 +460,8 @@ void ScavengeVisitor::VisitPointersImpl(HeapObject* host, TSlot start,
typename TSlot::TObject object = slot.load();
HeapObject* heap_object;
// Treat weak references as strong.
if (object.GetHeapObject(&heap_object) && Heap::InNewSpace(heap_object)) {
scavenger_->ScavengeObject(HeapObjectSlot(slot), heap_object);
if (object.GetHeapObject(&heap_object)) {
VisitHeapObjectImpl(slot, heap_object);
}
}
}
......
......@@ -76,12 +76,12 @@ class IterateAndScavengePromotedObjectsVisitor final : public ObjectVisitor {
bool record_slots)
: heap_(heap), scavenger_(scavenger), record_slots_(record_slots) {}
inline void VisitPointers(HeapObject* host, ObjectSlot start,
V8_INLINE void VisitPointers(HeapObject* host, ObjectSlot start,
ObjectSlot end) final {
VisitPointersImpl(host, start, end);
}
inline void VisitPointers(HeapObject* host, MaybeObjectSlot start,
V8_INLINE void VisitPointers(HeapObject* host, MaybeObjectSlot start,
MaybeObjectSlot end) final {
VisitPointersImpl(host, start, end);
}
......@@ -90,6 +90,10 @@ class IterateAndScavengePromotedObjectsVisitor final : public ObjectVisitor {
Code target = Code::GetCodeFromTargetAddress(rinfo->target_address());
HandleSlot(host, FullHeapObjectSlot(&target), target);
}
V8_INLINE void VisitEmbeddedPointer(Code host, RelocInfo* rinfo) final {
HeapObject* heap_object = rinfo->target_object();
HandleSlot(host, FullHeapObjectSlot(&heap_object), heap_object);
}
private:
template <typename TSlot>
......@@ -105,7 +109,7 @@ class IterateAndScavengePromotedObjectsVisitor final : public ObjectVisitor {
}
}
inline void HandleSlot(HeapObject* host, HeapObjectSlot slot,
V8_INLINE void HandleSlot(HeapObject* host, HeapObjectSlot slot,
HeapObject* target) {
scavenger_->PageMemoryFence(MaybeObject::FromObject(target));
......
......@@ -236,8 +236,12 @@ class ScavengeVisitor final : public NewSpaceVisitor<ScavengeVisitor> {
MaybeObjectSlot end) final;
V8_INLINE void VisitCodeTarget(Code host, RelocInfo* rinfo) final;
V8_INLINE void VisitEmbeddedPointer(Code host, RelocInfo* rinfo) final;
private:
template <typename TSlot>
V8_INLINE void VisitHeapObjectImpl(TSlot slot, HeapObject* heap_object);
template <typename TSlot>
V8_INLINE void VisitPointersImpl(HeapObject* host, TSlot start, TSlot end);
......
......@@ -14488,16 +14488,6 @@ void Map::StartInobjectSlackTracking() {
set_construction_counter(Map::kSlackTrackingCounterStart);
}
void ObjectVisitor::VisitEmbeddedPointer(Code host, RelocInfo* rinfo) {
DCHECK(rinfo->rmode() == RelocInfo::EMBEDDED_OBJECT);
Object* old_pointer = rinfo->target_object();
Object* new_pointer = old_pointer;
// TODO(ishell): we are actually visiting off-heap slot here.
STATIC_ASSERT(kTaggedSize == kSystemPointerSize);
VisitPointer(host, FullObjectSlot(&new_pointer));
DCHECK_EQ(old_pointer, new_pointer);
}
void ObjectVisitor::VisitRelocInfo(RelocIterator* it) {
for (; !it->done(); it->next()) {
it->rinfo()->Visit(this);
......
......@@ -104,6 +104,8 @@ class FullObjectSlot
inline explicit FullObjectSlot(ObjectPtr* object);
explicit FullObjectSlot(Object const* const* ptr)
: SlotBase(reinterpret_cast<Address>(ptr)) {}
explicit FullObjectSlot(HeapObject** ptr)
: SlotBase(reinterpret_cast<Address>(ptr)) {}
template <typename T>
explicit FullObjectSlot(SlotBase<T, TData, kSlotDataSize> slot)
: SlotBase(slot.address()) {}
......@@ -181,6 +183,8 @@ class FullHeapObjectSlot
explicit FullHeapObjectSlot(Address ptr) : SlotBase(ptr) {}
explicit FullHeapObjectSlot(ObjectPtr* ptr)
: SlotBase(reinterpret_cast<Address>(ptr)) {}
explicit FullHeapObjectSlot(HeapObject** ptr)
: SlotBase(reinterpret_cast<Address>(ptr)) {}
template <typename T>
explicit FullHeapObjectSlot(SlotBase<T, TData, kSlotDataSize> slot)
: SlotBase(slot.address()) {}
......
......@@ -678,17 +678,16 @@ class IndexedReferencesExtractor : public ObjectVisitor {
}
void VisitPointers(HeapObject* host, MaybeObjectSlot start,
MaybeObjectSlot end) override {
// [start,end) must be a sub-region of [parent_start_, parent_end), i.e.
// all the slots must point inside the object.
CHECK_LE(parent_start_, start);
CHECK_LE(end, parent_end_);
for (MaybeObjectSlot p = start; p < end; ++p) {
int field_index = -1;
// |p| could be outside of the object, e.g., while visiting RelocInfo of
// code objects.
if (parent_start_ <= p && p < parent_end_) {
field_index = static_cast<int>(p - parent_start_);
int field_index = static_cast<int>(p - parent_start_);
if (generator_->visited_fields_[field_index]) {
generator_->visited_fields_[field_index] = false;
continue;
}
}
HeapObject* heap_object;
if ((*p)->GetHeapObject(&heap_object)) {
VisitHeapObjectImpl(heap_object, field_index);
......@@ -701,6 +700,10 @@ class IndexedReferencesExtractor : public ObjectVisitor {
VisitHeapObjectImpl(target, -1);
}
void VisitEmbeddedPointer(Code host, RelocInfo* rinfo) override {
VisitHeapObjectImpl(rinfo->target_object(), -1);
}
private:
V8_INLINE void VisitHeapObjectImpl(HeapObject* heap_object, int field_index) {
DCHECK_LE(-1, field_index);
......
......@@ -123,12 +123,12 @@ class ObjectVisitor {
// Visits a code target in the instruction stream.
virtual void VisitCodeTarget(Code host, RelocInfo* rinfo) = 0;
// Visit pointer embedded into a code object.
virtual void VisitEmbeddedPointer(Code host, RelocInfo* rinfo) = 0;
// Visits a runtime entry in the instruction stream.
virtual void VisitRuntimeEntry(Code host, RelocInfo* rinfo) {}
// Visit pointer embedded into a code object.
virtual void VisitEmbeddedPointer(Code host, RelocInfo* rinfo);
// Visits an external reference embedded into a code object.
virtual void VisitExternalReference(Code host, RelocInfo* rinfo) {}
......
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