]>
git.saurik.com Git - apple/javascriptcore.git/blob - heap/MarkStack.h
2 * Copyright (C) 2009, 2011 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
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.
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()
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)
53 #include "HeapBlock.h"
54 #include <wtf/StdLibExtras.h>
62 class MarkStackSegment
: public HeapBlock
<MarkStackSegment
> {
64 MarkStackSegment(Region
* region
)
65 : HeapBlock
<MarkStackSegment
>(region
)
72 static MarkStackSegment
* create(DeadBlock
*);
76 return bitwise_cast
<const JSCell
**>(this + 1);
79 static const size_t blockSize
= 4 * KB
;
86 class MarkStackArray
{
88 MarkStackArray(BlockAllocator
&);
91 void append(const JSCell
*);
94 const JSCell
* removeLast();
97 void donateSomeCellsTo(MarkStackArray
& other
);
98 void stealSomeCellsFrom(MarkStackArray
& other
, size_t idleThreadCount
);
104 template <size_t size
> struct CapacityFromSize
{
105 static const size_t value
= (size
- sizeof(MarkStackSegment
)) / sizeof(const JSCell
*);
108 JS_EXPORT_PRIVATE
void expand();
112 void setTopForFullSegment();
113 void setTopForEmptySegment();
116 void validatePrevious();
118 DoublyLinkedList
<MarkStackSegment
> m_segments
;
119 BlockAllocator
& m_blockAllocator
;
121 JS_EXPORT_PRIVATE
static const size_t s_segmentCapacity
= CapacityFromSize
<MarkStackSegment::blockSize
>::value
;
123 size_t m_numberOfSegments
;