2 * Copyright (C) 2013-2015 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 DFGDesiredWatchpoints_h
27 #define DFGDesiredWatchpoints_h
31 #include "CodeOrigin.h"
32 #include "DFGCommonData.h"
33 #include "InferredValue.h"
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>
41 namespace JSC
{ namespace DFG
{
46 struct GenericSetAdaptor
{
47 static void add(CodeBlock
*, T
* set
, Watchpoint
* watchpoint
)
49 return set
->add(watchpoint
);
51 static bool hasBeenInvalidated(T
* set
) { return set
->hasBeenInvalidated(); }
54 struct InferredValueAdaptor
{
55 static void add(CodeBlock
*, InferredValue
*, Watchpoint
*);
56 static bool hasBeenInvalidated(InferredValue
* inferredValue
)
58 return inferredValue
->hasBeenInvalidated();
62 struct ArrayBufferViewWatchpointAdaptor
{
63 static void add(CodeBlock
*, JSArrayBufferView
*, Watchpoint
*);
64 static bool hasBeenInvalidated(JSArrayBufferView
* view
)
66 bool result
= !view
->length();
72 template<typename WatchpointSetType
, typename Adaptor
= GenericSetAdaptor
<WatchpointSetType
>>
73 class GenericDesiredWatchpoints
{
75 typedef HashMap
<WatchpointSetType
*, bool> StateMap
;
78 GenericDesiredWatchpoints()
79 : m_reallyAdded(false)
83 void addLazily(WatchpointSetType
* set
)
88 void reallyAdd(CodeBlock
* codeBlock
, CommonData
& common
)
90 RELEASE_ASSERT(!m_reallyAdded
);
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());
102 bool areStillValid() const
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
))
114 bool isWatched(WatchpointSetType
* set
) const
116 return m_sets
.contains(set
);
120 HashSet
<WatchpointSetType
*> m_sets
;
124 class DesiredWatchpoints
{
126 DesiredWatchpoints();
127 ~DesiredWatchpoints();
129 void addLazily(WatchpointSet
*);
130 void addLazily(InlineWatchpointSet
&);
131 void addLazily(InferredValue
*);
132 void addLazily(JSArrayBufferView
*);
134 bool consider(Structure
*);
136 void reallyAdd(CodeBlock
*, CommonData
&);
138 bool areStillValid() const;
140 bool isWatched(WatchpointSet
* set
)
142 return m_sets
.isWatched(set
);
144 bool isWatched(InlineWatchpointSet
& set
)
146 return m_inlineSets
.isWatched(&set
);
148 bool isWatched(InferredValue
* inferredValue
)
150 return m_inferredValues
.isWatched(inferredValue
);
152 bool isWatched(JSArrayBufferView
* view
)
154 return m_bufferViews
.isWatched(view
);
158 GenericDesiredWatchpoints
<WatchpointSet
> m_sets
;
159 GenericDesiredWatchpoints
<InlineWatchpointSet
> m_inlineSets
;
160 GenericDesiredWatchpoints
<InferredValue
, InferredValueAdaptor
> m_inferredValues
;
161 GenericDesiredWatchpoints
<JSArrayBufferView
, ArrayBufferViewWatchpointAdaptor
> m_bufferViews
;
164 } } // namespace JSC::DFG
166 #endif // ENABLE(DFG_JIT)
168 #endif // DFGDesiredWatchpoints_h