v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
heap-verifier.h
Go to the documentation of this file.
1// Copyright 2022 the V8 project authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef V8_HEAP_HEAP_VERIFIER_H_
6#define V8_HEAP_HEAP_VERIFIER_H_
7
9#include "src/flags/flags.h"
12#include "src/objects/map.h"
13
14namespace v8 {
15namespace internal {
16
17class Heap;
18class ReadOnlyHeap;
19
20// Interface for verifying spaces in the heap.
22 public:
23 virtual ~SpaceVerificationVisitor() = default;
24
25 // This method will be invoked for every object in the space.
26 virtual void VerifyObject(Tagged<HeapObject> object) = 0;
27
28 // This method will be invoked for each page in the space before verifying an
29 // object on it.
30 virtual void VerifyPage(const MemoryChunkMetadata* chunk) = 0;
31
32 // This method will be invoked after verifying all objects on that page.
33 virtual void VerifyPageDone(const MemoryChunkMetadata* chunk) = 0;
34};
35
36class HeapVerifier final {
37 public:
38#ifdef VERIFY_HEAP
39 // Verify the heap is in its normal state before or after a GC.
41
42 // Verify the read-only heap after all read-only heap objects have been
43 // created.
45
46 // Checks that this is a safe map transition.
48 Heap* heap, Tagged<HeapObject> object, Tagged<Map> new_map);
49
50 // This function checks that either
51 // - the map transition is safe,
52 // - or it was communicated to GC using NotifyObjectLayoutChange.
54 Heap* heap, Tagged<HeapObject> object, Tagged<Map> new_map);
55
56 // Verifies that that the object is allowed to change layout. Checks that if
57 // the object is in shared space, it must be a string as no other objects in
58 // shared space change layouts.
60 Tagged<HeapObject> object);
61
62 static void SetPendingLayoutChangeObject(Heap* heap,
63 Tagged<HeapObject> object);
64
65#else
66 static void VerifyHeap(Heap* heap) {}
67 static void VerifyReadOnlyHeap(Heap* heap) {}
68 static void VerifySharedHeap(Heap* heap, Isolate* initiator) {}
71 Tagged<Map> new_map) {}
73 Tagged<Map> new_map) {}
76#endif
77
79 if (v8_flags.verify_heap) {
81 }
82 }
83
84 private:
86};
87
88} // namespace internal
89} // namespace v8
90
91#endif // V8_HEAP_HEAP_VERIFIER_H_
static void VerifyObjectLayoutChange(Heap *heap, Tagged< HeapObject > object, Tagged< Map > new_map)
static void VerifyReadOnlyHeap(Heap *heap)
static V8_INLINE void VerifyHeapIfEnabled(Heap *heap)
static void VerifyHeap(Heap *heap)
static void VerifyRememberedSetFor(Heap *heap, Tagged< HeapObject > object)
static void VerifyObjectLayoutChangeIsAllowed(Heap *heap, Tagged< HeapObject > object)
static void VerifySharedHeap(Heap *heap, Isolate *initiator)
static void VerifySafeMapTransition(Heap *heap, Tagged< HeapObject > object, Tagged< Map > new_map)
virtual void VerifyObject(Tagged< HeapObject > object)=0
virtual void VerifyPageDone(const MemoryChunkMetadata *chunk)=0
virtual void VerifyPage(const MemoryChunkMetadata *chunk)=0
V8_EXPORT_PRIVATE FlagValues v8_flags
#define V8_EXPORT_PRIVATE
Definition macros.h:460
#define V8_INLINE
Definition v8config.h:500