oliver@apple.com | 9397e00 | 2013-07-25 03:58:49 +0000 | [diff] [blame] | 1 | /* |
fpizlo@apple.com | 3a2fa4c | 2015-04-13 22:13:12 +0000 | [diff] [blame] | 2 | * Copyright (C) 2013-2015 Apple Inc. All rights reserved. |
oliver@apple.com | 9397e00 | 2013-07-25 03:58:49 +0000 | [diff] [blame] | 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 | |
oliver@apple.com | 9397e00 | 2013-07-25 03:58:49 +0000 | [diff] [blame] | 29 | #if ENABLE(DFG_JIT) |
| 30 | |
fpizlo@apple.com | d84425d | 2013-10-30 19:58:08 +0000 | [diff] [blame] | 31 | #include "CodeOrigin.h" |
| 32 | #include "DFGCommonData.h" |
fpizlo@apple.com | 1283577 | 2015-09-21 20:49:04 +0000 | [diff] [blame] | 33 | #include "DFGDesiredInferredType.h" |
fpizlo@apple.com | 3a2fa4c | 2015-04-13 22:13:12 +0000 | [diff] [blame] | 34 | #include "InferredValue.h" |
fpizlo@apple.com | ee327c8 | 2013-12-05 02:05:35 +0000 | [diff] [blame] | 35 | #include "JSArrayBufferView.h" |
fpizlo@apple.com | 6b62eaf | 2015-08-03 23:13:56 +0000 | [diff] [blame] | 36 | #include "ObjectPropertyCondition.h" |
oliver@apple.com | 9397e00 | 2013-07-25 03:58:49 +0000 | [diff] [blame] | 37 | #include "Watchpoint.h" |
fpizlo@apple.com | 6b62eaf | 2015-08-03 23:13:56 +0000 | [diff] [blame] | 38 | #include <wtf/CommaPrinter.h> |
fpizlo@apple.com | d84425d | 2013-10-30 19:58:08 +0000 | [diff] [blame] | 39 | #include <wtf/HashSet.h> |
oliver@apple.com | 9397e00 | 2013-07-25 03:58:49 +0000 | [diff] [blame] | 40 | |
| 41 | namespace JSC { namespace DFG { |
| 42 | |
fpizlo@apple.com | 0728b8a | 2014-07-23 01:19:50 +0000 | [diff] [blame] | 43 | class Graph; |
oliver@apple.com | 9397e00 | 2013-07-25 03:58:49 +0000 | [diff] [blame] | 44 | |
fpizlo@apple.com | ee327c8 | 2013-12-05 02:05:35 +0000 | [diff] [blame] | 45 | template<typename T> |
fpizlo@apple.com | 6b62eaf | 2015-08-03 23:13:56 +0000 | [diff] [blame] | 46 | struct SetPointerAdaptor { |
| 47 | static void add(CodeBlock* codeBlock, T set, CommonData& common) |
fpizlo@apple.com | ee327c8 | 2013-12-05 02:05:35 +0000 | [diff] [blame] | 48 | { |
fpizlo@apple.com | 6b62eaf | 2015-08-03 23:13:56 +0000 | [diff] [blame] | 49 | return set->add(common.watchpoints.add(codeBlock)); |
fpizlo@apple.com | ee327c8 | 2013-12-05 02:05:35 +0000 | [diff] [blame] | 50 | } |
fpizlo@apple.com | 117408c | 2015-07-11 06:41:25 +0000 | [diff] [blame] | 51 | static bool hasBeenInvalidated(T set) { return set->hasBeenInvalidated(); } |
fpizlo@apple.com | 6b62eaf | 2015-08-03 23:13:56 +0000 | [diff] [blame] | 52 | static void dumpInContext(PrintStream& out, T set, DumpContext*) |
| 53 | { |
| 54 | out.print(RawPointer(set)); |
| 55 | } |
fpizlo@apple.com | ee327c8 | 2013-12-05 02:05:35 +0000 | [diff] [blame] | 56 | }; |
| 57 | |
fpizlo@apple.com | 3a2fa4c | 2015-04-13 22:13:12 +0000 | [diff] [blame] | 58 | struct InferredValueAdaptor { |
fpizlo@apple.com | 6b62eaf | 2015-08-03 23:13:56 +0000 | [diff] [blame] | 59 | static void add(CodeBlock*, InferredValue*, CommonData&); |
fpizlo@apple.com | 3a2fa4c | 2015-04-13 22:13:12 +0000 | [diff] [blame] | 60 | static bool hasBeenInvalidated(InferredValue* inferredValue) |
| 61 | { |
| 62 | return inferredValue->hasBeenInvalidated(); |
| 63 | } |
fpizlo@apple.com | 6b62eaf | 2015-08-03 23:13:56 +0000 | [diff] [blame] | 64 | static void dumpInContext(PrintStream& out, InferredValue* inferredValue, DumpContext*) |
fpizlo@apple.com | ee327c8 | 2013-12-05 02:05:35 +0000 | [diff] [blame] | 65 | { |
fpizlo@apple.com | 6b62eaf | 2015-08-03 23:13:56 +0000 | [diff] [blame] | 66 | out.print(RawPointer(inferredValue)); |
fpizlo@apple.com | ee327c8 | 2013-12-05 02:05:35 +0000 | [diff] [blame] | 67 | } |
| 68 | }; |
| 69 | |
fpizlo@apple.com | 6b62eaf | 2015-08-03 23:13:56 +0000 | [diff] [blame] | 70 | struct ArrayBufferViewWatchpointAdaptor { |
| 71 | static void add(CodeBlock*, JSArrayBufferView*, CommonData&); |
| 72 | static bool hasBeenInvalidated(JSArrayBufferView* view) |
| 73 | { |
| 74 | return !view->length(); |
| 75 | } |
| 76 | static void dumpInContext(PrintStream& out, JSArrayBufferView* view, DumpContext* context) |
| 77 | { |
| 78 | out.print(inContext(JSValue(view), context)); |
| 79 | } |
| 80 | }; |
| 81 | |
| 82 | struct AdaptiveStructureWatchpointAdaptor { |
| 83 | static void add(CodeBlock*, const ObjectPropertyCondition&, CommonData&); |
| 84 | static bool hasBeenInvalidated(const ObjectPropertyCondition& key) |
| 85 | { |
| 86 | return !key.isWatchable(); |
| 87 | } |
| 88 | static void dumpInContext( |
| 89 | PrintStream& out, const ObjectPropertyCondition& key, DumpContext* context) |
| 90 | { |
| 91 | out.print(inContext(key, context)); |
| 92 | } |
| 93 | }; |
| 94 | |
fpizlo@apple.com | 1283577 | 2015-09-21 20:49:04 +0000 | [diff] [blame] | 95 | struct InferredTypeAdaptor { |
| 96 | static void add(CodeBlock*, const DesiredInferredType&, CommonData&); |
| 97 | static bool hasBeenInvalidated(const DesiredInferredType& key) |
| 98 | { |
| 99 | return !key.isStillValid(); |
| 100 | } |
| 101 | static void dumpInContext(PrintStream& out, const DesiredInferredType& key, DumpContext* context) |
| 102 | { |
| 103 | out.print(inContext(key, context)); |
| 104 | } |
| 105 | }; |
| 106 | |
fpizlo@apple.com | 6b62eaf | 2015-08-03 23:13:56 +0000 | [diff] [blame] | 107 | template<typename WatchpointSetType, typename Adaptor = SetPointerAdaptor<WatchpointSetType>> |
oliver@apple.com | 9397e00 | 2013-07-25 03:58:49 +0000 | [diff] [blame] | 108 | class GenericDesiredWatchpoints { |
oliver@apple.com | 67e0f33 | 2013-07-25 03:59:00 +0000 | [diff] [blame] | 109 | #if !ASSERT_DISABLED |
fpizlo@apple.com | 117408c | 2015-07-11 06:41:25 +0000 | [diff] [blame] | 110 | typedef HashMap<WatchpointSetType, bool> StateMap; |
oliver@apple.com | 67e0f33 | 2013-07-25 03:59:00 +0000 | [diff] [blame] | 111 | #endif |
oliver@apple.com | 9397e00 | 2013-07-25 03:58:49 +0000 | [diff] [blame] | 112 | public: |
| 113 | GenericDesiredWatchpoints() |
| 114 | : m_reallyAdded(false) |
| 115 | { |
| 116 | } |
| 117 | |
fpizlo@apple.com | 117408c | 2015-07-11 06:41:25 +0000 | [diff] [blame] | 118 | void addLazily(const WatchpointSetType& set) |
oliver@apple.com | 9397e00 | 2013-07-25 03:58:49 +0000 | [diff] [blame] | 119 | { |
fpizlo@apple.com | d84425d | 2013-10-30 19:58:08 +0000 | [diff] [blame] | 120 | m_sets.add(set); |
oliver@apple.com | 9397e00 | 2013-07-25 03:58:49 +0000 | [diff] [blame] | 121 | } |
| 122 | |
fpizlo@apple.com | d84425d | 2013-10-30 19:58:08 +0000 | [diff] [blame] | 123 | void reallyAdd(CodeBlock* codeBlock, CommonData& common) |
oliver@apple.com | 9397e00 | 2013-07-25 03:58:49 +0000 | [diff] [blame] | 124 | { |
| 125 | RELEASE_ASSERT(!m_reallyAdded); |
fpizlo@apple.com | d84425d | 2013-10-30 19:58:08 +0000 | [diff] [blame] | 126 | |
fpizlo@apple.com | 117408c | 2015-07-11 06:41:25 +0000 | [diff] [blame] | 127 | for (auto& set : m_sets) |
fpizlo@apple.com | 6b62eaf | 2015-08-03 23:13:56 +0000 | [diff] [blame] | 128 | Adaptor::add(codeBlock, set, common); |
fpizlo@apple.com | d84425d | 2013-10-30 19:58:08 +0000 | [diff] [blame] | 129 | |
oliver@apple.com | 9397e00 | 2013-07-25 03:58:49 +0000 | [diff] [blame] | 130 | m_reallyAdded = true; |
| 131 | } |
| 132 | |
| 133 | bool areStillValid() const |
| 134 | { |
fpizlo@apple.com | 117408c | 2015-07-11 06:41:25 +0000 | [diff] [blame] | 135 | for (auto& set : m_sets) { |
| 136 | if (Adaptor::hasBeenInvalidated(set)) |
oliver@apple.com | 9397e00 | 2013-07-25 03:58:49 +0000 | [diff] [blame] | 137 | return false; |
| 138 | } |
fpizlo@apple.com | d84425d | 2013-10-30 19:58:08 +0000 | [diff] [blame] | 139 | |
oliver@apple.com | 9397e00 | 2013-07-25 03:58:49 +0000 | [diff] [blame] | 140 | return true; |
| 141 | } |
oliver@apple.com | 67e0f33 | 2013-07-25 03:59:00 +0000 | [diff] [blame] | 142 | |
fpizlo@apple.com | 117408c | 2015-07-11 06:41:25 +0000 | [diff] [blame] | 143 | bool isWatched(const WatchpointSetType& set) const |
oliver@apple.com | 67e0f33 | 2013-07-25 03:59:00 +0000 | [diff] [blame] | 144 | { |
fpizlo@apple.com | 0728b8a | 2014-07-23 01:19:50 +0000 | [diff] [blame] | 145 | return m_sets.contains(set); |
oliver@apple.com | 67e0f33 | 2013-07-25 03:59:00 +0000 | [diff] [blame] | 146 | } |
oliver@apple.com | 9397e00 | 2013-07-25 03:58:49 +0000 | [diff] [blame] | 147 | |
fpizlo@apple.com | 6b62eaf | 2015-08-03 23:13:56 +0000 | [diff] [blame] | 148 | void dumpInContext(PrintStream& out, DumpContext* context) const |
| 149 | { |
| 150 | CommaPrinter comma; |
| 151 | for (const WatchpointSetType& entry : m_sets) { |
| 152 | out.print(comma); |
| 153 | Adaptor::dumpInContext(out, entry, context); |
| 154 | } |
| 155 | } |
| 156 | |
oliver@apple.com | 9397e00 | 2013-07-25 03:58:49 +0000 | [diff] [blame] | 157 | private: |
fpizlo@apple.com | 117408c | 2015-07-11 06:41:25 +0000 | [diff] [blame] | 158 | HashSet<WatchpointSetType> m_sets; |
oliver@apple.com | 9397e00 | 2013-07-25 03:58:49 +0000 | [diff] [blame] | 159 | bool m_reallyAdded; |
| 160 | }; |
| 161 | |
| 162 | class DesiredWatchpoints { |
| 163 | public: |
| 164 | DesiredWatchpoints(); |
| 165 | ~DesiredWatchpoints(); |
| 166 | |
fpizlo@apple.com | d84425d | 2013-10-30 19:58:08 +0000 | [diff] [blame] | 167 | void addLazily(WatchpointSet*); |
| 168 | void addLazily(InlineWatchpointSet&); |
fpizlo@apple.com | 3a2fa4c | 2015-04-13 22:13:12 +0000 | [diff] [blame] | 169 | void addLazily(InferredValue*); |
fpizlo@apple.com | ee327c8 | 2013-12-05 02:05:35 +0000 | [diff] [blame] | 170 | void addLazily(JSArrayBufferView*); |
fpizlo@apple.com | 0728b8a | 2014-07-23 01:19:50 +0000 | [diff] [blame] | 171 | |
fpizlo@apple.com | 6b62eaf | 2015-08-03 23:13:56 +0000 | [diff] [blame] | 172 | // It's recommended that you don't call this directly. Use Graph::watchCondition(), which does |
| 173 | // the required GC magic as well as some other bookkeeping. |
| 174 | void addLazily(const ObjectPropertyCondition&); |
fpizlo@apple.com | 1283577 | 2015-09-21 20:49:04 +0000 | [diff] [blame] | 175 | |
| 176 | // It's recommended that you don't call this directly. Use Graph::inferredTypeFor(), which does |
| 177 | // the required GC magic. |
| 178 | void addLazily(const DesiredInferredType&); |
fpizlo@apple.com | 6b62eaf | 2015-08-03 23:13:56 +0000 | [diff] [blame] | 179 | |
fpizlo@apple.com | 0728b8a | 2014-07-23 01:19:50 +0000 | [diff] [blame] | 180 | bool consider(Structure*); |
oliver@apple.com | 9397e00 | 2013-07-25 03:58:49 +0000 | [diff] [blame] | 181 | |
fpizlo@apple.com | d84425d | 2013-10-30 19:58:08 +0000 | [diff] [blame] | 182 | void reallyAdd(CodeBlock*, CommonData&); |
oliver@apple.com | 9397e00 | 2013-07-25 03:58:49 +0000 | [diff] [blame] | 183 | |
| 184 | bool areStillValid() const; |
| 185 | |
fpizlo@apple.com | 0728b8a | 2014-07-23 01:19:50 +0000 | [diff] [blame] | 186 | bool isWatched(WatchpointSet* set) |
oliver@apple.com | 67e0f33 | 2013-07-25 03:59:00 +0000 | [diff] [blame] | 187 | { |
fpizlo@apple.com | 0728b8a | 2014-07-23 01:19:50 +0000 | [diff] [blame] | 188 | return m_sets.isWatched(set); |
oliver@apple.com | 67e0f33 | 2013-07-25 03:59:00 +0000 | [diff] [blame] | 189 | } |
fpizlo@apple.com | 0728b8a | 2014-07-23 01:19:50 +0000 | [diff] [blame] | 190 | bool isWatched(InlineWatchpointSet& set) |
oliver@apple.com | 67e0f33 | 2013-07-25 03:59:00 +0000 | [diff] [blame] | 191 | { |
fpizlo@apple.com | 0728b8a | 2014-07-23 01:19:50 +0000 | [diff] [blame] | 192 | return m_inlineSets.isWatched(&set); |
oliver@apple.com | 67e0f33 | 2013-07-25 03:59:00 +0000 | [diff] [blame] | 193 | } |
fpizlo@apple.com | 3a2fa4c | 2015-04-13 22:13:12 +0000 | [diff] [blame] | 194 | bool isWatched(InferredValue* inferredValue) |
| 195 | { |
| 196 | return m_inferredValues.isWatched(inferredValue); |
| 197 | } |
fpizlo@apple.com | 0728b8a | 2014-07-23 01:19:50 +0000 | [diff] [blame] | 198 | bool isWatched(JSArrayBufferView* view) |
fpizlo@apple.com | ee327c8 | 2013-12-05 02:05:35 +0000 | [diff] [blame] | 199 | { |
fpizlo@apple.com | 0728b8a | 2014-07-23 01:19:50 +0000 | [diff] [blame] | 200 | return m_bufferViews.isWatched(view); |
fpizlo@apple.com | ee327c8 | 2013-12-05 02:05:35 +0000 | [diff] [blame] | 201 | } |
fpizlo@apple.com | 6b62eaf | 2015-08-03 23:13:56 +0000 | [diff] [blame] | 202 | bool isWatched(const ObjectPropertyCondition& key) |
| 203 | { |
| 204 | return m_adaptiveStructureSets.isWatched(key); |
| 205 | } |
fpizlo@apple.com | 1283577 | 2015-09-21 20:49:04 +0000 | [diff] [blame] | 206 | bool isWatched(const DesiredInferredType& key) |
| 207 | { |
| 208 | return m_inferredTypes.isWatched(key); |
| 209 | } |
fpizlo@apple.com | 6b62eaf | 2015-08-03 23:13:56 +0000 | [diff] [blame] | 210 | |
| 211 | void dumpInContext(PrintStream&, DumpContext*) const; |
| 212 | void dump(PrintStream&) const; |
oliver@apple.com | 67e0f33 | 2013-07-25 03:59:00 +0000 | [diff] [blame] | 213 | |
oliver@apple.com | 9397e00 | 2013-07-25 03:58:49 +0000 | [diff] [blame] | 214 | private: |
fpizlo@apple.com | 117408c | 2015-07-11 06:41:25 +0000 | [diff] [blame] | 215 | GenericDesiredWatchpoints<WatchpointSet*> m_sets; |
| 216 | GenericDesiredWatchpoints<InlineWatchpointSet*> m_inlineSets; |
| 217 | GenericDesiredWatchpoints<InferredValue*, InferredValueAdaptor> m_inferredValues; |
| 218 | GenericDesiredWatchpoints<JSArrayBufferView*, ArrayBufferViewWatchpointAdaptor> m_bufferViews; |
fpizlo@apple.com | 6b62eaf | 2015-08-03 23:13:56 +0000 | [diff] [blame] | 219 | GenericDesiredWatchpoints<ObjectPropertyCondition, AdaptiveStructureWatchpointAdaptor> m_adaptiveStructureSets; |
fpizlo@apple.com | 1283577 | 2015-09-21 20:49:04 +0000 | [diff] [blame] | 220 | GenericDesiredWatchpoints<DesiredInferredType, InferredTypeAdaptor> m_inferredTypes; |
oliver@apple.com | 9397e00 | 2013-07-25 03:58:49 +0000 | [diff] [blame] | 221 | }; |
| 222 | |
| 223 | } } // namespace JSC::DFG |
| 224 | |
| 225 | #endif // ENABLE(DFG_JIT) |
| 226 | |
| 227 | #endif // DFGDesiredWatchpoints_h |
| 228 | |