]>
Commit | Line | Data |
---|---|---|
81345200 A |
1 | /* |
2 | * Copyright (C) 2013, 2014 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 CodeBlockSet_h | |
27 | #define CodeBlockSet_h | |
28 | ||
29 | #include "GCSegmentedArray.h" | |
30 | #include "HeapOperation.h" | |
31 | #include <wtf/HashSet.h> | |
32 | #include <wtf/Noncopyable.h> | |
33 | #include <wtf/PassRefPtr.h> | |
34 | #include <wtf/PrintStream.h> | |
35 | #include <wtf/RefPtr.h> | |
36 | ||
37 | namespace JSC { | |
38 | ||
81345200 A |
39 | class CodeBlock; |
40 | class Heap; | |
41 | class JSCell; | |
42 | class SlotVisitor; | |
43 | ||
44 | // CodeBlockSet tracks all CodeBlocks. Every CodeBlock starts out with one | |
45 | // reference coming in from GC. The GC is responsible for freeing CodeBlocks | |
46 | // once they hasOneRef() and nobody is running code from that CodeBlock. | |
47 | ||
48 | class CodeBlockSet { | |
49 | WTF_MAKE_NONCOPYABLE(CodeBlockSet); | |
50 | ||
51 | public: | |
ed1e77d3 | 52 | CodeBlockSet(); |
81345200 A |
53 | ~CodeBlockSet(); |
54 | ||
55 | // Add a CodeBlock. This is only called by CodeBlock constructors. | |
56 | void add(PassRefPtr<CodeBlock>); | |
57 | ||
58 | // Clear mark bits for certain CodeBlocks depending on the type of collection. | |
59 | void clearMarksForEdenCollection(const Vector<const JSCell*>&); | |
60 | ||
61 | // Clear all mark bits for all CodeBlocks. | |
62 | void clearMarksForFullCollection(); | |
63 | ||
64 | // Mark a pointer that may be a CodeBlock that belongs to the set of DFG | |
65 | // blocks. This is defined in CodeBlock.h. | |
66 | void mark(CodeBlock* candidateCodeBlock); | |
67 | void mark(void* candidateCodeBlock); | |
68 | ||
69 | // Delete all code blocks that are only referenced by this set (i.e. owned | |
70 | // by this set), and that have not been marked. | |
71 | void deleteUnmarkedAndUnreferenced(HeapOperation); | |
72 | ||
73 | void remove(CodeBlock*); | |
74 | ||
75 | // Trace all marked code blocks. The CodeBlock is free to make use of | |
76 | // mayBeExecuting. | |
77 | void traceMarked(SlotVisitor&); | |
78 | ||
79 | // Add all currently executing CodeBlocks to the remembered set to be | |
80 | // re-scanned during the next collection. | |
81 | void rememberCurrentlyExecutingCodeBlocks(Heap*); | |
82 | ||
83 | // Visits each CodeBlock in the heap until the visitor function returns true | |
84 | // to indicate that it is done iterating, or until every CodeBlock has been | |
85 | // visited. | |
86 | template<typename Functor> void iterate(Functor& functor) | |
87 | { | |
88 | for (auto& codeBlock : m_oldCodeBlocks) { | |
89 | bool done = functor(codeBlock); | |
90 | if (done) | |
91 | return; | |
92 | } | |
93 | ||
94 | for (auto& codeBlock : m_newCodeBlocks) { | |
95 | bool done = functor(codeBlock); | |
96 | if (done) | |
97 | return; | |
98 | } | |
99 | } | |
100 | ||
101 | void dump(PrintStream&) const; | |
102 | ||
103 | private: | |
104 | void clearMarksForCodeBlocksInRememberedExecutables(const Vector<const JSCell*>&); | |
105 | void promoteYoungCodeBlocks(); | |
106 | ||
107 | // This is not a set of RefPtr<CodeBlock> because we need to be able to find | |
108 | // arbitrary bogus pointers. I could have written a thingy that had peek types | |
109 | // and all, but that seemed like overkill. | |
110 | HashSet<CodeBlock*> m_oldCodeBlocks; | |
111 | HashSet<CodeBlock*> m_newCodeBlocks; | |
ed1e77d3 | 112 | Vector<CodeBlock*> m_currentlyExecuting; |
81345200 A |
113 | }; |
114 | ||
115 | } // namespace JSC | |
116 | ||
117 | #endif // CodeBlockSet_h | |
118 |