]> git.saurik.com Git - apple/javascriptcore.git/blob - dfg/DFGDesiredWriteBarriers.h
JavaScriptCore-7600.1.4.13.1.tar.gz
[apple/javascriptcore.git] / dfg / DFGDesiredWriteBarriers.h
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. AND ITS CONTRIBUTORS ``AS IS''
14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23 * THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26 #ifndef DFGDesiredWriteBarriers_h
27 #define DFGDesiredWriteBarriers_h
28
29 #include "WriteBarrier.h"
30 #include <wtf/Vector.h>
31
32 #if ENABLE(DFG_JIT)
33
34 namespace JSC {
35
36 class JSFunction;
37 class ScriptExecutable;
38 class SlotVisitor;
39 class VM;
40 struct InlineCallFrame;
41
42 namespace DFG {
43
44 class DesiredWriteBarrier {
45 public:
46 enum Type {
47 ConstantType,
48 InlineCallFrameExecutableType,
49 };
50 DesiredWriteBarrier(Type, CodeBlock*, unsigned index, JSCell* owner);
51 DesiredWriteBarrier(Type, CodeBlock*, InlineCallFrame*, JSCell* owner);
52
53 void trigger(VM&);
54
55 void visitChildren(SlotVisitor&);
56
57 private:
58 JSCell* m_owner;
59 Type m_type;
60 CodeBlock* m_codeBlock;
61 union {
62 unsigned index;
63 InlineCallFrame* inlineCallFrame;
64 } m_which;
65 };
66
67 class DesiredWriteBarriers {
68 public:
69 DesiredWriteBarriers();
70 ~DesiredWriteBarriers();
71
72 DesiredWriteBarrier& add(DesiredWriteBarrier::Type type, CodeBlock* codeBlock, unsigned index, JSCell* owner)
73 {
74 m_barriers.append(DesiredWriteBarrier(type, codeBlock, index, owner));
75 return m_barriers.last();
76 }
77 DesiredWriteBarrier& add(DesiredWriteBarrier::Type type, CodeBlock* codeBlock, InlineCallFrame* inlineCallFrame, JSCell* owner)
78 {
79 m_barriers.append(DesiredWriteBarrier(type, codeBlock, inlineCallFrame, owner));
80 return m_barriers.last();
81 }
82
83 void trigger(VM&);
84
85 void visitChildren(SlotVisitor&);
86
87 private:
88 Vector<DesiredWriteBarrier> m_barriers;
89 };
90
91 inline void initializeLazyWriteBarrierForInlineCallFrameExecutable(DesiredWriteBarriers& barriers, WriteBarrier<ScriptExecutable>& barrier, CodeBlock* codeBlock, InlineCallFrame* inlineCallFrame, JSCell* owner, ScriptExecutable* value)
92 {
93 DesiredWriteBarrier& desiredBarrier = barriers.add(DesiredWriteBarrier::InlineCallFrameExecutableType, codeBlock, inlineCallFrame, owner);
94 barrier = WriteBarrier<ScriptExecutable>(desiredBarrier, value);
95 }
96
97 inline void initializeLazyWriteBarrierForConstant(DesiredWriteBarriers& barriers, WriteBarrier<Unknown>& barrier, CodeBlock* codeBlock, unsigned index, JSCell* owner, JSValue value)
98 {
99 DesiredWriteBarrier& desiredBarrier = barriers.add(DesiredWriteBarrier::ConstantType, codeBlock, index, owner);
100 barrier = WriteBarrier<Unknown>(desiredBarrier, value);
101 }
102
103 } } // namespace JSC::DFG
104
105 #endif // ENABLE(DFG_JIT)
106
107 #endif // DFGDesiredWriteBarriers_h