]>
Commit | Line | Data |
---|---|---|
81345200 | 1 | /* |
ed1e77d3 | 2 | * Copyright (C) 2013-2015 Apple Inc. All rights reserved. |
81345200 A |
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 DFGDesiredWatchpoints_h | |
27 | #define DFGDesiredWatchpoints_h | |
28 | ||
29 | #if ENABLE(DFG_JIT) | |
30 | ||
31 | #include "CodeOrigin.h" | |
32 | #include "DFGCommonData.h" | |
ed1e77d3 | 33 | #include "InferredValue.h" |
81345200 A |
34 | #include "JSArrayBufferView.h" |
35 | #include "Watchpoint.h" | |
36 | #include <wtf/HashMap.h> | |
37 | #include <wtf/HashSet.h> | |
38 | #include <wtf/Noncopyable.h> | |
39 | #include <wtf/Vector.h> | |
40 | ||
41 | namespace JSC { namespace DFG { | |
42 | ||
ed1e77d3 | 43 | class Graph; |
81345200 A |
44 | |
45 | template<typename T> | |
46 | struct GenericSetAdaptor { | |
47 | static void add(CodeBlock*, T* set, Watchpoint* watchpoint) | |
48 | { | |
49 | return set->add(watchpoint); | |
50 | } | |
51 | static bool hasBeenInvalidated(T* set) { return set->hasBeenInvalidated(); } | |
52 | }; | |
53 | ||
ed1e77d3 A |
54 | struct InferredValueAdaptor { |
55 | static void add(CodeBlock*, InferredValue*, Watchpoint*); | |
56 | static bool hasBeenInvalidated(InferredValue* inferredValue) | |
57 | { | |
58 | return inferredValue->hasBeenInvalidated(); | |
59 | } | |
60 | }; | |
61 | ||
81345200 A |
62 | struct ArrayBufferViewWatchpointAdaptor { |
63 | static void add(CodeBlock*, JSArrayBufferView*, Watchpoint*); | |
64 | static bool hasBeenInvalidated(JSArrayBufferView* view) | |
65 | { | |
66 | bool result = !view->length(); | |
67 | WTF::loadLoadFence(); | |
68 | return result; | |
69 | } | |
70 | }; | |
71 | ||
72 | template<typename WatchpointSetType, typename Adaptor = GenericSetAdaptor<WatchpointSetType>> | |
73 | class GenericDesiredWatchpoints { | |
74 | #if !ASSERT_DISABLED | |
75 | typedef HashMap<WatchpointSetType*, bool> StateMap; | |
76 | #endif | |
77 | public: | |
78 | GenericDesiredWatchpoints() | |
79 | : m_reallyAdded(false) | |
80 | { | |
81 | } | |
82 | ||
83 | void addLazily(WatchpointSetType* set) | |
84 | { | |
85 | m_sets.add(set); | |
86 | } | |
87 | ||
81345200 A |
88 | void reallyAdd(CodeBlock* codeBlock, CommonData& common) |
89 | { | |
90 | RELEASE_ASSERT(!m_reallyAdded); | |
91 | ||
92 | typename HashSet<WatchpointSetType*>::iterator iter = m_sets.begin(); | |
93 | typename HashSet<WatchpointSetType*>::iterator end = m_sets.end(); | |
94 | for (; iter != end; ++iter) { | |
95 | common.watchpoints.append(CodeBlockJettisoningWatchpoint(codeBlock)); | |
96 | Adaptor::add(codeBlock, *iter, &common.watchpoints.last()); | |
97 | } | |
98 | ||
81345200 A |
99 | m_reallyAdded = true; |
100 | } | |
101 | ||
102 | bool areStillValid() const | |
103 | { | |
104 | typename HashSet<WatchpointSetType*>::iterator iter = m_sets.begin(); | |
105 | typename HashSet<WatchpointSetType*>::iterator end = m_sets.end(); | |
106 | for (; iter != end; ++iter) { | |
107 | if (Adaptor::hasBeenInvalidated(*iter)) | |
108 | return false; | |
109 | } | |
110 | ||
81345200 A |
111 | return true; |
112 | } | |
113 | ||
ed1e77d3 | 114 | bool isWatched(WatchpointSetType* set) const |
81345200 | 115 | { |
ed1e77d3 | 116 | return m_sets.contains(set); |
81345200 A |
117 | } |
118 | ||
119 | private: | |
81345200 | 120 | HashSet<WatchpointSetType*> m_sets; |
81345200 A |
121 | bool m_reallyAdded; |
122 | }; | |
123 | ||
124 | class DesiredWatchpoints { | |
125 | public: | |
126 | DesiredWatchpoints(); | |
127 | ~DesiredWatchpoints(); | |
128 | ||
129 | void addLazily(WatchpointSet*); | |
130 | void addLazily(InlineWatchpointSet&); | |
ed1e77d3 | 131 | void addLazily(InferredValue*); |
81345200 | 132 | void addLazily(JSArrayBufferView*); |
ed1e77d3 A |
133 | |
134 | bool consider(Structure*); | |
81345200 A |
135 | |
136 | void reallyAdd(CodeBlock*, CommonData&); | |
137 | ||
138 | bool areStillValid() const; | |
139 | ||
ed1e77d3 | 140 | bool isWatched(WatchpointSet* set) |
81345200 | 141 | { |
ed1e77d3 | 142 | return m_sets.isWatched(set); |
81345200 | 143 | } |
ed1e77d3 | 144 | bool isWatched(InlineWatchpointSet& set) |
81345200 | 145 | { |
ed1e77d3 | 146 | return m_inlineSets.isWatched(&set); |
81345200 | 147 | } |
ed1e77d3 | 148 | bool isWatched(InferredValue* inferredValue) |
81345200 | 149 | { |
ed1e77d3 | 150 | return m_inferredValues.isWatched(inferredValue); |
81345200 | 151 | } |
ed1e77d3 | 152 | bool isWatched(JSArrayBufferView* view) |
81345200 | 153 | { |
ed1e77d3 | 154 | return m_bufferViews.isWatched(view); |
81345200 A |
155 | } |
156 | ||
157 | private: | |
158 | GenericDesiredWatchpoints<WatchpointSet> m_sets; | |
159 | GenericDesiredWatchpoints<InlineWatchpointSet> m_inlineSets; | |
ed1e77d3 | 160 | GenericDesiredWatchpoints<InferredValue, InferredValueAdaptor> m_inferredValues; |
81345200 A |
161 | GenericDesiredWatchpoints<JSArrayBufferView, ArrayBufferViewWatchpointAdaptor> m_bufferViews; |
162 | }; | |
163 | ||
164 | } } // namespace JSC::DFG | |
165 | ||
166 | #endif // ENABLE(DFG_JIT) | |
167 | ||
168 | #endif // DFGDesiredWatchpoints_h | |
169 |