1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CallbackStack_h
6 #define CallbackStack_h
8 #include "platform/heap/ThreadState.h"
9 #include "wtf/Assertions.h"
13 // The CallbackStack contains all the visitor callbacks used to trace and mark
14 // objects. A specific CallbackStack instance contains at most bufferSize elements.
15 // If more space is needed a new CallbackStack instance is created and chained
16 // together with the former instance. I.e. a logical CallbackStack can be made of
17 // multiple chained CallbackStack object instances.
23 Item(void* object
, VisitorCallback callback
)
25 , m_callback(callback
)
28 void* object() { return m_object
; }
29 VisitorCallback
callback() { return m_callback
; }
30 void call(Visitor
* visitor
) { m_callback(visitor
, m_object
); }
34 VisitorCallback m_callback
;
42 Item
* allocateEntry();
47 void invokeEphemeronCallbacks(Visitor
*);
50 bool hasCallbackForObject(const void*);
54 static const size_t blockSize
= 8192;
58 explicit Block(Block
* next
)
59 : m_limit(&(m_buffer
[blockSize
]))
60 , m_current(&(m_buffer
[0]))
73 Block
* next() const { return m_next
; }
74 void setNext(Block
* next
) { m_next
= next
; }
76 bool isEmptyBlock() const
78 return m_current
== &(m_buffer
[0]);
83 return blockSize
- (m_limit
- m_current
);
88 if (LIKELY(m_current
< m_limit
))
95 if (UNLIKELY(isEmptyBlock()))
100 void invokeEphemeronCallbacks(Visitor
*);
102 bool hasCallbackForObject(const void*);
108 Item m_buffer
[blockSize
];
115 Item
* allocateEntrySlow();
116 void invokeOldestCallbacks(Block
*, Block
*, Visitor
*);
117 bool hasJustOneBlock() const;
123 ALWAYS_INLINE
CallbackStack::Item
* CallbackStack::allocateEntry()
125 Item
* item
= m_first
->allocateEntry();
129 return allocateEntrySlow();
132 ALWAYS_INLINE
CallbackStack::Item
* CallbackStack::pop()
134 Item
* item
= m_first
->pop();
143 #endif // CallbackStack_h