v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
conservative-stack-visitor.h
Go to the documentation of this file.
1// Copyright 2020 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_CONSERVATIVE_STACK_VISITOR_H_
6#define V8_HEAP_CONSERVATIVE_STACK_VISITOR_H_
7
10#include "src/common/globals.h"
11#include "src/heap/base/stack.h"
12#include "src/heap/marking.h"
14#include "src/objects/objects.h"
15
16namespace v8 {
17namespace internal {
18
19class MemoryAllocator;
20class RootVisitor;
21
22// `ConcreteVisitor` must implement the following methods:
23// 1) FilterPage(const MemoryChunk*) - returns true if a page may contain
24// interesting objects for the GC (e.g. a young page in a young gen GC).
25// 2) FilterLargeObject(Tagged<HeapObject>, MapWord) - returns true if the
26// object should be handled by conservative stack scanning.
27// 3) FilterNormalObject(Tagged<HeapObject>, MapWord, MarkingBitmap*) - returns
28// true if the
29// object should be handled by conservative stack scanning.
30// 4) HandleObjectFound(Tagged<HeapObject>, size_t, MarkingBitmap*) - Callback
31// whenever
32// FindBasePtr finds a new object.
33// 5) OnlyScanMainV8Heap() - returns true if the visitor does not handle the
34// external code and trusted spaces.
35template <typename ConcreteVisitor>
38 public:
39 ConservativeStackVisitorBase(Isolate* isolate, RootVisitor* root_visitor);
40
41 void VisitPointer(const void* pointer) final;
42
43 // This method finds an object header based on a `maybe_inner_ptr`. It returns
44 // `kNullAddress` if the parameter does not point to (the interior of) a valid
45 // heap object. The allocator_ field is used to provide the set of valid heap
46 // pages. The collector_ field is used to determine which kind of heap objects
47 // we are interested in. For MARK_COMPACTOR all heap objects are considered,
48 // whereas for young generation collectors we only consider objects in the
49 // young generation.
50 Address FindBasePtr(Address maybe_inner_ptr,
51 PtrComprCageBase cage_base) const;
52
53 private:
54 void VisitConservativelyIfPointer(Address address);
55 void VisitConservativelyIfPointer(Address address,
56 PtrComprCageBase cage_base);
57
58#ifdef V8_COMPRESS_POINTERS
59 bool IsInterestingCage(PtrComprCageBase cage_base) const;
60#endif
61
62 // The "interesting" cages where we conservatively scan pointers are:
63 // - The regular cage for the V8 heap.
64 // - The cage used for code objects, if an external code space is used.
65 // - The trusted space cage.
67#ifdef V8_EXTERNAL_CODE_SPACE
68 const PtrComprCageBase code_cage_base_;
69 base::AddressRegion code_address_region_;
70#endif
71#ifdef V8_ENABLE_SANDBOX
72 const PtrComprCageBase trusted_cage_base_;
73#endif
74
77};
78
80 : public ConservativeStackVisitorBase<ConservativeStackVisitor> {
81 public:
83 : ConservativeStackVisitorBase(isolate, root_visitor) {}
84
85 private:
86 static constexpr bool kOnlyVisitMainV8Cage = false;
87
88 static bool FilterPage(const MemoryChunk* chunk) {
89 return v8_flags.sticky_mark_bits || !chunk->IsFromPage();
90 }
91 static bool FilterLargeObject(Tagged<HeapObject>, MapWord) { return true; }
93 return true;
94 }
95 static void HandleObjectFound(Tagged<HeapObject>, size_t, MarkingBitmap*) {}
96
98};
99
100} // namespace internal
101} // namespace v8
102
103#endif // V8_HEAP_CONSERVATIVE_STACK_VISITOR_H_
static bool FilterPage(const MemoryChunk *chunk)
static bool FilterLargeObject(Tagged< HeapObject >, MapWord)
static bool FilterNormalObject(Tagged< HeapObject >, MapWord, MarkingBitmap *)
ConservativeStackVisitor(Isolate *isolate, RootVisitor *root_visitor)
static constexpr bool kOnlyVisitMainV8Cage
V8_EXPORT_PRIVATE FlagValues v8_flags
#define V8_EXPORT_PRIVATE
Definition macros.h:460