]>
git.saurik.com Git - apple/javascriptcore.git/blob - heap/CodeBlockSet.h
2 * Copyright (C) 2013, 2014 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 CodeBlockSet_h
27 #define CodeBlockSet_h
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>
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.
49 WTF_MAKE_NONCOPYABLE(CodeBlockSet
);
55 // Add a CodeBlock. This is only called by CodeBlock constructors.
56 void add(PassRefPtr
<CodeBlock
>);
58 // Clear mark bits for certain CodeBlocks depending on the type of collection.
59 void clearMarksForEdenCollection(const Vector
<const JSCell
*>&);
61 // Clear all mark bits for all CodeBlocks.
62 void clearMarksForFullCollection();
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
);
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
);
73 void remove(CodeBlock
*);
75 // Trace all marked code blocks. The CodeBlock is free to make use of
77 void traceMarked(SlotVisitor
&);
79 // Add all currently executing CodeBlocks to the remembered set to be
80 // re-scanned during the next collection.
81 void rememberCurrentlyExecutingCodeBlocks(Heap
*);
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
86 template<typename Functor
> void iterate(Functor
& functor
)
88 for (auto& codeBlock
: m_oldCodeBlocks
) {
89 bool done
= functor(codeBlock
);
94 for (auto& codeBlock
: m_newCodeBlocks
) {
95 bool done
= functor(codeBlock
);
101 void dump(PrintStream
&) const;
104 void clearMarksForCodeBlocksInRememberedExecutables(const Vector
<const JSCell
*>&);
105 void promoteYoungCodeBlocks();
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
;
112 Vector
<CodeBlock
*> m_currentlyExecuting
;
117 #endif // CodeBlockSet_h