1 | /* |
2 | * Copyright (C) 2016-2018 Apple Inc. All rights reserved. |
3 | * |
4 | * Redistribution and use in source and binary forms, with or without |
5 | * modification, are permitted provided that the following conditions |
6 | * are met: |
7 | * 1. Redistributions of source code must retain the above copyright |
8 | * notice, this list of conditions and the following disclaimer. |
9 | * 2. Redistributions in binary form must reproduce the above copyright |
10 | * notice, this list of conditions and the following disclaimer in the |
11 | * documentation and/or other materials provided with the distribution. |
12 | * |
13 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY |
14 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
15 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
16 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR |
17 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
18 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
19 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
20 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
21 | * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
24 | */ |
25 | |
26 | #pragma once |
27 | |
28 | #include "DestructionMode.h" |
29 | |
30 | namespace JSC { |
31 | |
32 | class CellContainer; |
33 | class Heap; |
34 | class LargeAllocation; |
35 | class MarkedBlock; |
36 | class Subspace; |
37 | class VM; |
38 | struct CellAttributes; |
39 | |
40 | class HeapCell { |
41 | public: |
42 | enum Kind : int8_t { |
43 | JSCell, |
44 | JSCellWithInteriorPointers, |
45 | Auxiliary |
46 | }; |
47 | |
48 | HeapCell() { } |
49 | |
50 | void zap() { *reinterpret_cast_ptr<uintptr_t**>(this) = 0; } |
51 | bool isZapped() const { return !*reinterpret_cast_ptr<uintptr_t* const*>(this); } |
52 | |
53 | bool isLive(); |
54 | |
55 | bool isLargeAllocation() const; |
56 | CellContainer cellContainer() const; |
57 | MarkedBlock& markedBlock() const; |
58 | LargeAllocation& largeAllocation() const; |
59 | |
60 | // If you want performance and you know that your cell is small, you can do this instead: |
61 | // ASSERT(!cell->isLargeAllocation()); |
62 | // cell->markedBlock().vm() |
63 | // We currently only use this hack for callees to make ExecState::vm() fast. It's not |
64 | // recommended to use it for too many other things, since the large allocation cutoff is |
65 | // a runtime option and its default value is small (400 bytes). |
66 | Heap* heap() const; |
67 | VM* vm() const; |
68 | |
69 | size_t cellSize() const; |
70 | CellAttributes cellAttributes() const; |
71 | DestructionMode destructionMode() const; |
72 | Kind cellKind() const; |
73 | Subspace* subspace() const; |
74 | |
75 | // Call use() after the last point where you need `this` pointer to be kept alive. You usually don't |
76 | // need to use this, but it might be necessary if you're otherwise referring to an object's innards |
77 | // but not the object itself. |
78 | #if COMPILER(GCC_COMPATIBLE) |
79 | void use() const |
80 | { |
81 | asm volatile ("" : : "r" (this) : "memory" ); |
82 | } |
83 | #else |
84 | void use() const; |
85 | #endif |
86 | }; |
87 | |
88 | inline bool isJSCellKind(HeapCell::Kind kind) |
89 | { |
90 | return kind == HeapCell::JSCell || kind == HeapCell::JSCellWithInteriorPointers; |
91 | } |
92 | |
93 | inline bool hasInteriorPointers(HeapCell::Kind kind) |
94 | { |
95 | return kind == HeapCell::Auxiliary || kind == HeapCell::JSCellWithInteriorPointers; |
96 | } |
97 | |
98 | } // namespace JSC |
99 | |
100 | namespace WTF { |
101 | |
102 | class PrintStream; |
103 | |
104 | void printInternal(PrintStream&, JSC::HeapCell::Kind); |
105 | |
106 | } // namespace WTF |
107 | |
108 | |