]>
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>
45 // CodeBlockSet tracks all CodeBlocks. Every CodeBlock starts out with one
46 // reference coming in from GC. The GC is responsible for freeing CodeBlocks
47 // once they hasOneRef() and nobody is running code from that CodeBlock.
50 WTF_MAKE_NONCOPYABLE(CodeBlockSet
);
53 CodeBlockSet(BlockAllocator
&);
56 // Add a CodeBlock. This is only called by CodeBlock constructors.
57 void add(PassRefPtr
<CodeBlock
>);
59 // Clear mark bits for certain CodeBlocks depending on the type of collection.
60 void clearMarksForEdenCollection(const Vector
<const JSCell
*>&);
62 // Clear all mark bits for all CodeBlocks.
63 void clearMarksForFullCollection();
65 // Mark a pointer that may be a CodeBlock that belongs to the set of DFG
66 // blocks. This is defined in CodeBlock.h.
67 void mark(CodeBlock
* candidateCodeBlock
);
68 void mark(void* candidateCodeBlock
);
70 // Delete all code blocks that are only referenced by this set (i.e. owned
71 // by this set), and that have not been marked.
72 void deleteUnmarkedAndUnreferenced(HeapOperation
);
74 void remove(CodeBlock
*);
76 // Trace all marked code blocks. The CodeBlock is free to make use of
78 void traceMarked(SlotVisitor
&);
80 // Add all currently executing CodeBlocks to the remembered set to be
81 // re-scanned during the next collection.
82 void rememberCurrentlyExecutingCodeBlocks(Heap
*);
84 // Visits each CodeBlock in the heap until the visitor function returns true
85 // to indicate that it is done iterating, or until every CodeBlock has been
87 template<typename Functor
> void iterate(Functor
& functor
)
89 for (auto& codeBlock
: m_oldCodeBlocks
) {
90 bool done
= functor(codeBlock
);
95 for (auto& codeBlock
: m_newCodeBlocks
) {
96 bool done
= functor(codeBlock
);
102 void dump(PrintStream
&) const;
105 void clearMarksForCodeBlocksInRememberedExecutables(const Vector
<const JSCell
*>&);
106 void promoteYoungCodeBlocks();
108 // This is not a set of RefPtr<CodeBlock> because we need to be able to find
109 // arbitrary bogus pointers. I could have written a thingy that had peek types
110 // and all, but that seemed like overkill.
111 HashSet
<CodeBlock
*> m_oldCodeBlocks
;
112 HashSet
<CodeBlock
*> m_newCodeBlocks
;
113 GCSegmentedArray
<CodeBlock
*> m_currentlyExecuting
;
118 #endif // CodeBlockSet_h