/src/hermes/lib/VM/CheckHeapWellFormedAcceptor.cpp
Line | Count | Source |
1 | | /* |
2 | | * Copyright (c) Meta Platforms, Inc. and affiliates. |
3 | | * |
4 | | * This source code is licensed under the MIT license found in the |
5 | | * LICENSE file in the root directory of this source tree. |
6 | | */ |
7 | | |
8 | | #include "hermes/VM/CheckHeapWellFormedAcceptor.h" |
9 | | |
10 | | #include "hermes/VM/GC.h" |
11 | | #include "hermes/VM/SmallHermesValue-inline.h" |
12 | | |
13 | | namespace hermes { |
14 | | namespace vm { |
15 | | |
16 | | #ifdef HERMES_SLOW_DEBUG |
17 | | |
18 | | CheckHeapWellFormedAcceptor::CheckHeapWellFormedAcceptor(GCBase &gc) |
19 | 292 | : RootAndSlotAcceptorDefault(gc.getPointerBase()), |
20 | 292 | WeakAcceptorDefault(gc.getPointerBase()), |
21 | 292 | gc(gc) {} |
22 | | |
23 | 5.87M | void CheckHeapWellFormedAcceptor::accept(GCCell *&ptr) { |
24 | 5.87M | accept(static_cast<const GCCell *>(ptr)); |
25 | 5.87M | } |
26 | | |
27 | 6.84M | void CheckHeapWellFormedAcceptor::accept(const GCCell *ptr) { |
28 | 6.84M | assert( |
29 | 6.84M | (!ptr || gc.validPointer(ptr)) && |
30 | 6.84M | "A pointer is pointing outside of the valid region"); |
31 | 6.84M | } |
32 | | |
33 | 161k | void CheckHeapWellFormedAcceptor::acceptWeak(GCCell *&ptr) { |
34 | | // A weak pointer has the same well-formed-ness checks as a normal pointer. |
35 | 161k | accept(ptr); |
36 | 161k | } |
37 | | |
38 | 6.24M | void CheckHeapWellFormedAcceptor::acceptHV(HermesValue &hv) { |
39 | 6.24M | assert(!hv.isInvalid() && "HermesValue with InvalidTag encountered by GC."); |
40 | 6.24M | if (hv.isPointer()) { |
41 | 497k | GCCell *cell = static_cast<GCCell *>(hv.getPointer()); |
42 | 497k | accept(cell); |
43 | 5.74M | } else if (hv.isSymbol()) { |
44 | 318 | acceptSym(hv.getSymbol()); |
45 | 318 | } |
46 | 6.24M | } |
47 | | |
48 | 4.08M | void CheckHeapWellFormedAcceptor::acceptSHV(SmallHermesValue &hv) { |
49 | 4.08M | if (hv.isPointer()) { |
50 | 2.97M | GCCell *cell = static_cast<GCCell *>(hv.getPointer(pointerBase_)); |
51 | 2.97M | accept(cell); |
52 | 2.97M | } else if (hv.isSymbol()) { |
53 | 2.95k | acceptSym(hv.getSymbol()); |
54 | 2.95k | } |
55 | 4.08M | } |
56 | | |
57 | 970k | void CheckHeapWellFormedAcceptor::acceptSym(SymbolID sym) { |
58 | 970k | if (!sym.isValid()) { |
59 | 608 | return; |
60 | 608 | } |
61 | 969k | assert( |
62 | 969k | gc.getCallbacks().isSymbolLive(sym) && |
63 | 969k | "Symbol is marked but is not live"); |
64 | | // Check that the string used by this symbol is valid. |
65 | 969k | accept( |
66 | 969k | static_cast<const GCCell *>(gc.getCallbacks().getStringForSymbol(sym))); |
67 | 969k | } |
68 | | |
69 | | #endif |
70 | | |
71 | | } // namespace vm |
72 | | } // namespace hermes |