]> git.saurik.com Git - apple/javascriptcore.git/blame - heap/DFGCodeBlocks.h
JavaScriptCore-1097.3.tar.gz
[apple/javascriptcore.git] / heap / DFGCodeBlocks.h
CommitLineData
6fe7ccc8
A
1/*
2 * Copyright (C) 2011 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#ifndef DFGCodeBlocks_h
27#define DFGCodeBlocks_h
28
29#include <wtf/FastAllocBase.h>
30#include <wtf/HashSet.h>
31#include <wtf/PassOwnPtr.h>
32
33namespace JSC {
34
35class CodeBlock;
36class SlotVisitor;
37
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.
48
49#if ENABLE(DFG_JIT)
50class DFGCodeBlocks {
51 WTF_MAKE_FAST_ALLOCATED;
52
53public:
54 DFGCodeBlocks();
55 ~DFGCodeBlocks();
56
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>);
63
64 // Clear all mark bits associated with DFG code blocks.
65 void clearMarks();
66
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);
70
71 // Delete all jettisoned code blocks that have not been marked (i.e. are not referenced
72 // from call frames).
73 void deleteUnmarkedJettisonedCodeBlocks();
74
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&);
78
79private:
80 friend class CodeBlock;
81
82 HashSet<CodeBlock*> m_set;
83};
84#else
85class DFGCodeBlocks {
86 WTF_MAKE_FAST_ALLOCATED;
87
88public:
89 void jettison(PassOwnPtr<CodeBlock>);
90 void clearMarks() { }
91 void mark(void*) { }
92 void deleteUnmarkedJettisonedCodeBlocks() { }
93 void traceMarkedCodeBlocks(SlotVisitor&) { }
94};
95#endif
96
97} // namespace JSC
98
99#endif