]> git.saurik.com Git - apple/javascriptcore.git/blame - heap/MarkStack.h
JavaScriptCore-1218.tar.gz
[apple/javascriptcore.git] / heap / MarkStack.h
CommitLineData
f9bf01c6 1/*
14957cd0 2 * Copyright (C) 2009, 2011 Apple Inc. All rights reserved.
f9bf01c6
A
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#ifndef MarkStack_h
27#define MarkStack_h
28
93a37866
A
29#if ENABLE(OBJECT_MARK_LOGGING)
30#define MARK_LOG_MESSAGE0(message) dataLogF(message)
31#define MARK_LOG_MESSAGE1(message, arg1) dataLogF(message, arg1)
32#define MARK_LOG_MESSAGE2(message, arg1, arg2) dataLogF(message, arg1, arg2)
33#define MARK_LOG_ROOT(visitor, rootName) \
34 dataLogF("\n%s: ", rootName); \
35 (visitor).resetChildCount()
36#define MARK_LOG_PARENT(visitor, parent) \
37 dataLogF("\n%p (%s): ", parent, parent->className() ? parent->className() : "unknown"); \
38 (visitor).resetChildCount()
39#define MARK_LOG_CHILD(visitor, child) \
40 if ((visitor).childCount()) \
41 dataLogFString(", "); \
42 dataLogF("%p", child); \
43 (visitor).incrementChildCount()
6fe7ccc8 44#else
93a37866
A
45#define MARK_LOG_MESSAGE0(message) do { } while (false)
46#define MARK_LOG_MESSAGE1(message, arg1) do { } while (false)
47#define MARK_LOG_MESSAGE2(message, arg1, arg2) do { } while (false)
48#define MARK_LOG_ROOT(visitor, rootName) do { } while (false)
49#define MARK_LOG_PARENT(visitor, parent) do { } while (false)
50#define MARK_LOG_CHILD(visitor, child) do { } while (false)
6fe7ccc8
A
51#endif
52
93a37866
A
53#include "HeapBlock.h"
54#include <wtf/StdLibExtras.h>
6fe7ccc8 55
93a37866 56namespace JSC {
6fe7ccc8 57
93a37866
A
58class BlockAllocator;
59class DeadBlock;
60class JSCell;
14957cd0 61
93a37866
A
62class MarkStackSegment : public HeapBlock<MarkStackSegment> {
63public:
64 MarkStackSegment(Region* region)
65 : HeapBlock<MarkStackSegment>(region)
14957cd0 66#if !ASSERT_DISABLED
93a37866 67 , m_top(0)
f9bf01c6 68#endif
6fe7ccc8
A
69 {
70 }
71
93a37866 72 static MarkStackSegment* create(DeadBlock*);
14957cd0 73
93a37866 74 const JSCell** data()
14957cd0 75 {
93a37866 76 return bitwise_cast<const JSCell**>(this + 1);
14957cd0 77 }
6fe7ccc8 78
93a37866 79 static const size_t blockSize = 4 * KB;
14957cd0 80
93a37866
A
81#if !ASSERT_DISABLED
82 size_t m_top;
6fe7ccc8 83#endif
93a37866 84};
14957cd0 85
93a37866
A
86class MarkStackArray {
87public:
88 MarkStackArray(BlockAllocator&);
89 ~MarkStackArray();
14957cd0 90
93a37866 91 void append(const JSCell*);
14957cd0 92
93a37866
A
93 bool canRemoveLast();
94 const JSCell* removeLast();
95 bool refill();
96
97 void donateSomeCellsTo(MarkStackArray& other);
98 void stealSomeCellsFrom(MarkStackArray& other, size_t idleThreadCount);
14957cd0 99
93a37866
A
100 size_t size();
101 bool isEmpty();
14957cd0 102
93a37866
A
103private:
104 template <size_t size> struct CapacityFromSize {
105 static const size_t value = (size - sizeof(MarkStackSegment)) / sizeof(const JSCell*);
106 };
14957cd0 107
93a37866 108 JS_EXPORT_PRIVATE void expand();
6fe7ccc8 109
93a37866
A
110 size_t postIncTop();
111 size_t preDecTop();
112 void setTopForFullSegment();
113 void setTopForEmptySegment();
114 size_t top();
115
116 void validatePrevious();
14957cd0 117
93a37866
A
118 DoublyLinkedList<MarkStackSegment> m_segments;
119 BlockAllocator& m_blockAllocator;
6fe7ccc8 120
93a37866
A
121 JS_EXPORT_PRIVATE static const size_t s_segmentCapacity = CapacityFromSize<MarkStackSegment::blockSize>::value;
122 size_t m_top;
123 size_t m_numberOfSegments;
124
125};
6fe7ccc8 126
14957cd0 127} // namespace JSC
f9bf01c6
A
128
129#endif