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.
27 #include "DFGWatchpointCollectionPhase.h"
31 #include "ArrayPrototype.h"
32 #include "DFGClobberize.h"
35 #include "JSCInlines.h"
37 // FIXME: Remove this phase entirely by moving the addLazily() calls into either the backend or
38 // into the phase that performs the optimization. Moving the calls into the backend makes the most
39 // sense when the intermediate phases don't need to know that the watchpoint was set. Moving the
40 // calls earlier usually only makes sense if the node's only purpose was to convey the need for
41 // the watchpoint (like VarInjectionWatchpoint). But, it can also make sense if the fact that the
42 // watchpoint was set enables other optimizations.
43 // https://bugs.webkit.org/show_bug.cgi?id=144669
45 namespace JSC
{ namespace DFG
{
47 class WatchpointCollectionPhase
: public Phase
{
48 static const bool verbose
= false;
51 WatchpointCollectionPhase(Graph
& graph
)
52 : Phase(graph
, "watchpoint collection")
58 for (BlockIndex blockIndex
= m_graph
.numBlocks(); blockIndex
--;) {
59 BasicBlock
* block
= m_graph
.block(blockIndex
);
63 for (unsigned nodeIndex
= block
->size(); nodeIndex
--;) {
64 m_node
= block
->at(nodeIndex
);
75 switch (m_node
->op()) {
76 case CompareEqConstant
:
78 handleMasqueradesAsUndefined();
82 if (m_node
->isBinaryUseKind(ObjectUse
)
83 || (m_node
->child1().useKind() == ObjectUse
&& m_node
->child2().useKind() == ObjectOrOtherUse
)
84 || (m_node
->child1().useKind() == ObjectOrOtherUse
&& m_node
->child2().useKind() == ObjectUse
))
85 handleMasqueradesAsUndefined();
90 switch (m_node
->child1().useKind()) {
91 case ObjectOrOtherUse
:
93 handleMasqueradesAsUndefined();
101 case NewArrayWithSize
:
103 if (!globalObject()->isHavingABadTime() && !hasAnyArrayStorage(m_node
->indexingType()))
104 addLazily(globalObject()->havingABadTimeWatchpoint());
107 case VarInjectionWatchpoint
:
108 addLazily(globalObject()->varInjectionWatchpoint());
116 void handleMasqueradesAsUndefined()
118 if (m_graph
.masqueradesAsUndefinedWatchpointIsStillValid(m_node
->origin
.semantic
))
119 addLazily(globalObject()->masqueradesAsUndefinedWatchpoint());
122 void addLazily(WatchpointSet
* set
)
124 m_graph
.watchpoints().addLazily(set
);
126 void addLazily(InlineWatchpointSet
& set
)
128 m_graph
.watchpoints().addLazily(set
);
131 JSGlobalObject
* globalObject()
133 return m_graph
.globalObjectFor(m_node
->origin
.semantic
);
139 bool performWatchpointCollection(Graph
& graph
)
141 SamplingRegion
samplingRegion("DFG Watchpoint Collection Phase");
142 return runPhase
<WatchpointCollectionPhase
>(graph
);
145 } } // namespace JSC::DFG
147 #endif // ENABLE(DFG_JIT)