2 * Copyright (C) 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.
26 #ifndef DFGCodeBlocks_h
27 #define DFGCodeBlocks_h
29 #include <wtf/FastAllocBase.h>
30 #include <wtf/HashSet.h>
31 #include <wtf/PassOwnPtr.h>
38 // DFGCodeBlocks notifies the garbage collector about optimized code blocks that
39 // have different marking behavior depending on whether or not they are on the
40 // stack, and that may be jettisoned. Jettisoning is the process of discarding
41 // a code block after all calls to it have been unlinked. This class takes special
42 // care to ensure that if there are still call frames that are using the code
43 // block, then it should not be immediately deleted, but rather, it should be
44 // deleted once we know that there are no longer any references to it from any
45 // call frames. This class takes its name from the DFG compiler; only code blocks
46 // compiled by the DFG need special marking behavior if they are on the stack, and
47 // only those code blocks may be jettisoned.
51 WTF_MAKE_FAST_ALLOCATED
;
57 // Inform the collector that a code block has been jettisoned form its
58 // executable and should only be kept alive if there are call frames that use
59 // it. This is typically called either from a recompilation trigger, or from
60 // an unconditional finalizer associated with a CodeBlock that had weak
61 // references, where some subset of those references were dead.
62 void jettison(PassOwnPtr
<CodeBlock
>);
64 // Clear all mark bits associated with DFG code blocks.
67 // Mark a pointer that may be a CodeBlock that belongs to the set of DFG code
68 // blocks. This is defined inline in CodeBlock.h
69 void mark(void* candidateCodeBlock
);
71 // Delete all jettisoned code blocks that have not been marked (i.e. are not referenced
73 void deleteUnmarkedJettisonedCodeBlocks();
75 // Trace all marked code blocks (i.e. are referenced from call frames). The CodeBlock
76 // is free to make use of m_dfgData->isMarked and m_dfgData->isJettisoned.
77 void traceMarkedCodeBlocks(SlotVisitor
&);
80 friend class CodeBlock
;
82 HashSet
<CodeBlock
*> m_set
;
86 WTF_MAKE_FAST_ALLOCATED
;
89 void jettison(PassOwnPtr
<CodeBlock
>);
92 void deleteUnmarkedJettisonedCodeBlocks() { }
93 void traceMarkedCodeBlocks(SlotVisitor
&) { }