1/*
2 * Copyright (C) 2016-2019 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 "CellContainer.h"
29#include "JSCast.h"
30#include "MarkedBlock.h"
31#include "PreciseAllocation.h"
32#include "VM.h"
33
34namespace JSC {
35
36inline VM& CellContainer::vm() const
37{
38 if (isPreciseAllocation())
39 return preciseAllocation().vm();
40 return markedBlock().vm();
41}
42
43inline Heap* CellContainer::heap() const
44{
45 return &vm().heap;
46}
47
48inline bool CellContainer::isMarked(HeapCell* cell) const
49{
50 if (isPreciseAllocation())
51 return preciseAllocation().isMarked();
52 return markedBlock().isMarked(cell);
53}
54
55inline bool CellContainer::isMarked(HeapVersion markingVersion, HeapCell* cell) const
56{
57 if (isPreciseAllocation())
58 return preciseAllocation().isMarked();
59 return markedBlock().isMarked(markingVersion, cell);
60}
61
62inline void CellContainer::noteMarked()
63{
64 if (!isPreciseAllocation())
65 markedBlock().noteMarked();
66}
67
68inline void CellContainer::assertValidCell(VM& vm, HeapCell* cell) const
69{
70 if (isPreciseAllocation())
71 preciseAllocation().assertValidCell(vm, cell);
72 else
73 markedBlock().assertValidCell(vm, cell);
74}
75
76inline size_t CellContainer::cellSize() const
77{
78 if (isPreciseAllocation())
79 return preciseAllocation().cellSize();
80 return markedBlock().cellSize();
81}
82
83inline WeakSet& CellContainer::weakSet() const
84{
85 if (isPreciseAllocation())
86 return preciseAllocation().weakSet();
87 return markedBlock().weakSet();
88}
89
90inline void CellContainer::aboutToMark(HeapVersion markingVersion)
91{
92 if (!isPreciseAllocation())
93 markedBlock().aboutToMark(markingVersion);
94}
95
96inline bool CellContainer::areMarksStale() const
97{
98 if (isPreciseAllocation())
99 return false;
100 return markedBlock().areMarksStale();
101}
102
103} // namespace JSC
104
105