summaryrefslogtreecommitdiff
path: root/deps/v8/src/heap/heap-verifier.h
blob: d64c6f9c3ff52455f6bbbc84c5d7c317c73b71f4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
// 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/flags/flags.h"
#include "src/heap/basic-memory-chunk.h"
#include "src/heap/read-only-heap.h"
#include "src/objects/map.h"

namespace v8 {
namespace internal {

class Heap;
class ReadOnlyHeap;

// Interface for verifying spaces in the heap.
class SpaceVerificationVisitor {
 public:
  virtual ~SpaceVerificationVisitor() = default;

  // This method will be invoked for every object in the space.
  virtual void VerifyObject(HeapObject object) = 0;

  // This method will be invoked for each page in the space before verifying an
  // object on it.
  virtual void VerifyPage(const BasicMemoryChunk* chunk) = 0;

  // This method will be invoked after verifying all objects on that page.
  virtual void VerifyPageDone(const BasicMemoryChunk* chunk) = 0;
};

class HeapVerifier final {
 public:
#ifdef VERIFY_HEAP
  // 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);

  // 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);

  // Verifies that that the object is allowed to change layout. Checks that if
  // the object is in shared space, it must be a string as no other objects in
  // shared space change layouts.
  static void VerifyObjectLayoutChangeIsAllowed(Heap* heap, HeapObject object);

  static void SetPendingLayoutChangeObject(Heap* heap, HeapObject object);

#else
  static void VerifyHeap(Heap* heap) {}
  static void VerifyReadOnlyHeap(Heap* heap) {}
  static void VerifySharedHeap(Heap* heap, Isolate* initiator) {}
  static void VerifyRememberedSetFor(Heap* heap, HeapObject object) {}
  static void VerifySafeMapTransition(Heap* heap, HeapObject object,
                                      Map new_map) {}
  static void VerifyObjectLayoutChange(Heap* heap, HeapObject object,
                                       Map new_map) {}
  static void VerifyObjectLayoutChangeIsAllowed(Heap* heap, HeapObject object) {
  }
#endif

  V8_INLINE static void VerifyHeapIfEnabled(Heap* heap) {
    if (v8_flags.verify_heap) {
      VerifyHeap(heap);
    }
  }

 private:
  HeapVerifier();
};

}  // namespace internal
}  // namespace v8

#endif  // V8_HEAP_HEAP_VERIFIER_H_