Commit 810a0b5f authored by Dominik Inführ's avatar Dominik Inführ Committed by V8 LUCI CQ

[heap] Move Verify* methods out of the heap class

Methods are now defined in heap-verifier.h in the HeapVerifier class.

Bug: v8:11708
Change-Id: I13e7f1760598f3659ad6aa31082840caf2e44038
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3857558Reviewed-by: 's avatarMichael Lippautz <mlippautz@chromium.org>
Reviewed-by: 's avatarJakob Linke <jgruber@chromium.org>
Reviewed-by: 's avatarCamillo Bruni <cbruni@chromium.org>
Commit-Queue: Dominik Inführ <dinfuehr@chromium.org>
Cr-Commit-Position: refs/heads/main@{#82810}
parent c9c49089
......@@ -1461,6 +1461,8 @@ filegroup(
"src/heap/heap-inl.h",
"src/heap/heap-layout-tracer.cc",
"src/heap/heap-layout-tracer.h",
"src/heap/heap-verifier.cc",
"src/heap/heap-verifier.h",
"src/heap/heap-write-barrier-inl.h",
"src/heap/heap-write-barrier.cc",
"src/heap/heap-write-barrier.h",
......
......@@ -24,6 +24,7 @@ include_rules = [
# TODO(v8:10496): Don't expose so much (through transitive includes) outside
# of heap/.
"+src/heap/heap.h",
"+src/heap/heap-verifier.h",
"+src/heap/heap-inl.h",
"+src/heap/heap-write-barrier-inl.h",
"+src/heap/heap-write-barrier.h",
......
......@@ -63,7 +63,7 @@
#include "src/handles/persistent-handles.h"
#include "src/handles/shared-object-conveyors.h"
#include "src/heap/heap-inl.h"
#include "src/heap/heap.h"
#include "src/heap/heap-verifier.h"
#include "src/heap/local-heap.h"
#include "src/heap/parked-scope.h"
#include "src/heap/read-only-heap.h"
......@@ -4364,7 +4364,7 @@ bool Isolate::Init(SnapshotData* startup_snapshot_data,
#ifdef VERIFY_HEAP
if (FLAG_verify_heap) {
heap_.VerifyReadOnlyHeap();
HeapVerifier::VerifyReadOnlyHeap(&heap_);
}
#endif
......
This diff is collapsed.
// Copyright 2022 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef V8_HEAP_HEAP_VERIFIER_H_
#define V8_HEAP_HEAP_VERIFIER_H_
#include "src/common/globals.h"
#include "src/heap/read-only-heap.h"
#ifdef VERIFY_HEAP
namespace v8 {
namespace internal {
class Heap;
class ReadOnlyHeap;
class HeapVerifier final {
public:
// Verify the heap is in its normal state before or after a GC.
V8_EXPORT_PRIVATE static void VerifyHeap(Heap* heap);
// Verify the read-only heap after all read-only heap objects have been
// created.
static void VerifyReadOnlyHeap(Heap* heap);
// Verify the shared heap, initiating from a client heap. This performs a
// global safepoint, then the normal heap verification.
static void VerifySharedHeap(Heap* heap, Isolate* initiator);
// Verifies OLD_TO_NEW and OLD_TO_SHARED remembered sets for this object.
static void VerifyRememberedSetFor(Heap* heap, HeapObject object);
// Checks that this is a safe map transition.
V8_EXPORT_PRIVATE static void VerifySafeMapTransition(Heap* heap,
HeapObject object,
Map new_map);
// This function checks that either
// - the map transition is safe,
// - or it was communicated to GC using NotifyObjectLayoutChange.
V8_EXPORT_PRIVATE static void VerifyObjectLayoutChange(Heap* heap,
HeapObject object,
Map new_map);
private:
HeapVerifier();
};
} // namespace internal
} // namespace v8
#endif // VERIFY_HEAP
#endif // V8_HEAP_HEAP_VERIFIER_H_
......@@ -2309,7 +2309,7 @@ size_t Heap::PerformGarbageCollection(
// We don't really perform a GC here but need this scope for the nested
// SafepointScope inside Verify().
AllowGarbageCollection allow_gc;
Verify();
HeapVerifier::VerifyHeap(this);
}
#endif // VERIFY_HEAP
......@@ -2393,7 +2393,7 @@ size_t Heap::PerformGarbageCollection(
// We don't really perform a GC here but need this scope for the nested
// SafepointScope inside Verify().
AllowGarbageCollection allow_gc;
Verify();
HeapVerifier::VerifyHeap(this);
}
#endif // VERIFY_HEAP
......@@ -5709,13 +5709,13 @@ void Heap::StartTearDown() {
// tear down parts of the Isolate.
if (FLAG_verify_heap) {
AllowGarbageCollection allow_gc;
Verify();
HeapVerifier::VerifyHeap(this);
// If this is a client Isolate of a shared Isolate, verify that there are no
// shared-to-local pointers before tearing down the client Isolate and
// creating dangling pointers.
if (Isolate* shared_isolate = isolate()->shared_isolate()) {
shared_isolate->heap()->VerifySharedHeap(isolate());
HeapVerifier::VerifySharedHeap(shared_isolate->heap(), isolate());
}
}
#endif
......
......@@ -1151,17 +1151,6 @@ class Heap {
void NotifyObjectSizeChange(HeapObject, int old_size, int new_size,
ClearRecordedSlots clear_recorded_slots);
#ifdef VERIFY_HEAP
// This function checks that either
// - the map transition is safe,
// - or it was communicated to GC using NotifyObjectLayoutChange.
V8_EXPORT_PRIVATE void VerifyObjectLayoutChange(HeapObject object,
Map new_map);
// Checks that this is a safe map transition.
V8_EXPORT_PRIVATE void VerifySafeMapTransition(HeapObject object,
Map new_map);
#endif
// ===========================================================================
// Deoptimization support API. ===============================================
// ===========================================================================
......@@ -1631,24 +1620,7 @@ class Heap {
// it supports a forwarded map. Fails if the map is not the code map.
Map GcSafeMapOfCodeSpaceObject(HeapObject object);
// =============================================================================
#ifdef VERIFY_HEAP
// Verify the heap is in its normal state before or after a GC.
V8_EXPORT_PRIVATE void Verify();
// Verify the read-only heap after all read-only heap objects have been
// created.
void VerifyReadOnlyHeap();
// Verify the shared heap, initiating from a client heap. This performs a
// global safepoint, then the normal heap verification.
void VerifySharedHeap(Isolate* initiator);
void VerifyRememberedSetFor(HeapObject object);
// Verify that cached size of invalidated object is up-to-date.
void VerifyInvalidatedObjectSize();
#endif
// =============================================================================
#ifdef V8_ENABLE_ALLOCATION_TIMEOUT
void V8_EXPORT_PRIVATE set_allocation_timeout(int allocation_timeout);
......@@ -2464,6 +2436,7 @@ class Heap {
friend class GlobalHandleMarkingVisitor;
friend class HeapAllocator;
friend class HeapObjectIterator;
friend class HeapVerifier;
friend class ScavengeTaskObserver;
friend class IgnoreLocalGCRequests;
friend class IncrementalMarking;
......
......@@ -409,7 +409,7 @@ void LargeObjectSpace::Verify(Isolate* isolate) {
object.ObjectVerify(isolate);
if (!FLAG_verify_heap_skip_remembered_set) {
heap()->VerifyRememberedSetFor(object);
HeapVerifier::VerifyRememberedSetFor(heap(), object);
}
// Byte arrays and strings don't have interior pointers.
......
......@@ -809,7 +809,7 @@ void PagedSpaceBase::Verify(Isolate* isolate, ObjectVisitor* visitor) const {
object.ObjectVerify(isolate);
if (identity() != RO_SPACE && !FLAG_verify_heap_skip_remembered_set) {
isolate->heap()->VerifyRememberedSetFor(object);
HeapVerifier::VerifyRememberedSetFor(isolate->heap(), object);
}
// All the interior pointers should be contained in the heap.
......
......@@ -20,6 +20,7 @@
#include "src/common/ptr-compr-inl.h"
#include "src/handles/handles-inl.h"
#include "src/heap/factory.h"
#include "src/heap/heap-verifier.h"
#include "src/heap/heap-write-barrier-inl.h"
#include "src/heap/read-only-heap-inl.h"
#include "src/numbers/conversions-inl.h"
......@@ -833,10 +834,10 @@ void HeapObject::set_map(Map value, MemoryOrder order, VerificationMode mode) {
if (FLAG_verify_heap && !value.is_null()) {
Heap* heap = GetHeapFromWritableObject(*this);
if (mode == VerificationMode::kSafeMapTransition) {
heap->VerifySafeMapTransition(*this, value);
HeapVerifier::VerifySafeMapTransition(heap, *this, value);
} else {
DCHECK_EQ(mode, VerificationMode::kPotentialLayoutChange);
heap->VerifyObjectLayoutChange(*this, value);
HeapVerifier::VerifyObjectLayoutChange(heap, *this, value);
}
}
#endif
......
......@@ -2727,7 +2727,7 @@ bool HeapSnapshotGenerator::GenerateSnapshot() {
#ifdef VERIFY_HEAP
Heap* debug_heap = heap_;
if (FLAG_verify_heap) {
debug_heap->Verify();
HeapVerifier::VerifyHeap(debug_heap);
}
#endif
......@@ -2735,7 +2735,7 @@ bool HeapSnapshotGenerator::GenerateSnapshot() {
#ifdef VERIFY_HEAP
if (FLAG_verify_heap) {
debug_heap->Verify();
HeapVerifier::VerifyHeap(debug_heap);
}
#endif
......
......@@ -354,7 +354,7 @@ void Snapshot::SerializeDeserializeAndVerifyForTesting(
CHECK(new_native_context->IsNativeContext());
#ifdef VERIFY_HEAP
if (FLAG_verify_heap) new_isolate->heap()->Verify();
if (FLAG_verify_heap) HeapVerifier::VerifyHeap(new_isolate->heap());
#endif // VERIFY_HEAP
}
new_isolate->Exit();
......
......@@ -45,6 +45,7 @@
#include "src/heap/factory.h"
#include "src/heap/gc-tracer.h"
#include "src/heap/heap-inl.h"
#include "src/heap/heap-verifier.h"
#include "src/heap/incremental-marking.h"
#include "src/heap/large-spaces.h"
#include "src/heap/mark-compact.h"
......@@ -4339,7 +4340,7 @@ TEST(NewSpaceObjectsInOptimizedCode) {
CcTest::CollectGarbage(OLD_SPACE);
CHECK(!Heap::InYoungGeneration(*foo));
#ifdef VERIFY_HEAP
CcTest::heap()->Verify();
HeapVerifier::VerifyHeap(CcTest::heap());
#endif
CHECK(!bar->code().marked_for_deoptimization());
code = handle(FromCodeT(bar->code()), isolate);
......
......@@ -17,6 +17,7 @@
#include "src/debug/debug.h"
#include "src/execution/isolate.h"
#include "src/heap/heap-inl.h"
#include "src/heap/heap-verifier.h"
#include "src/numbers/hash-seed-inl.h"
#include "src/objects/js-array-inl.h"
#include "src/objects/js-promise-inl.h"
......@@ -1877,7 +1878,7 @@ TEST(AllocateJSObjectFromMap) {
CHECK_EQ(result->elements(), *empty_fixed_array);
CHECK(result->HasFastProperties());
#ifdef VERIFY_HEAP
isolate->heap()->Verify();
HeapVerifier::VerifyHeap(isolate->heap());
#endif
}
}
......@@ -1906,7 +1907,7 @@ TEST(AllocateJSObjectFromMap) {
}
CHECK(!result->HasFastProperties());
#ifdef VERIFY_HEAP
isolate->heap()->Verify();
HeapVerifier::VerifyHeap(isolate->heap());
#endif
}
}
......@@ -3803,7 +3804,7 @@ TEST(SmallOrderedHashMapAllocate) {
capacity = capacity << 1;
}
#ifdef VERIFY_HEAP
isolate->heap()->Verify();
HeapVerifier::VerifyHeap(isolate->heap());
#endif
}
......@@ -3841,7 +3842,7 @@ TEST(SmallOrderedHashSetAllocate) {
capacity = capacity << 1;
}
#ifdef VERIFY_HEAP
isolate->heap()->Verify();
HeapVerifier::VerifyHeap(isolate->heap());
#endif
}
......
......@@ -264,7 +264,7 @@ static void SanityCheck(v8::Isolate* v8_isolate) {
Isolate* isolate = reinterpret_cast<Isolate*>(v8_isolate);
v8::HandleScope scope(v8_isolate);
#ifdef VERIFY_HEAP
isolate->heap()->Verify();
HeapVerifier::VerifyHeap(isolate->heap());
#endif
CHECK(isolate->global_object()->IsJSObject());
CHECK(isolate->native_context()->IsContext());
......
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