DFG should have adaptive structure watchpoints
[WebKit-https.git] / Source / JavaScriptCore / bytecode / StructureStubClearingWatchpoint.h
1 /*
2  * Copyright (C) 2012, 2015 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. ``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 StructureStubClearingWatchpoint_h
27 #define StructureStubClearingWatchpoint_h
28
29 #include "ObjectPropertyCondition.h"
30 #include "Watchpoint.h"
31
32 #if ENABLE(JIT)
33
34 #include <wtf/FastMalloc.h>
35 #include <wtf/Noncopyable.h>
36 #include <wtf/RefCounted.h>
37 #include <wtf/RefPtr.h>
38
39 namespace JSC {
40
41 class CodeBlock;
42 class WatchpointsOnStructureStubInfo;
43 struct StructureStubInfo;
44
45 class StructureStubClearingWatchpoint : public Watchpoint {
46     WTF_MAKE_NONCOPYABLE(StructureStubClearingWatchpoint);
47     WTF_MAKE_FAST_ALLOCATED;
48 public:
49     StructureStubClearingWatchpoint(
50         const ObjectPropertyCondition& key,
51         WatchpointsOnStructureStubInfo& holder,
52         std::unique_ptr<StructureStubClearingWatchpoint> next)
53         : m_key(key)
54         , m_holder(holder)
55         , m_next(WTF::move(next))
56     {
57     }
58     
59     virtual ~StructureStubClearingWatchpoint();
60     
61     static StructureStubClearingWatchpoint* push(
62         const ObjectPropertyCondition& key,
63         WatchpointsOnStructureStubInfo& holder,
64         std::unique_ptr<StructureStubClearingWatchpoint>& head);
65
66 protected:
67     virtual void fireInternal(const FireDetail&) override;
68
69 private:
70     ObjectPropertyCondition m_key;
71     WatchpointsOnStructureStubInfo& m_holder;
72     std::unique_ptr<StructureStubClearingWatchpoint> m_next;
73 };
74
75 class WatchpointsOnStructureStubInfo : public RefCounted<WatchpointsOnStructureStubInfo> {
76 public:
77     WatchpointsOnStructureStubInfo(CodeBlock* codeBlock, StructureStubInfo* stubInfo)
78         : m_codeBlock(codeBlock)
79         , m_stubInfo(stubInfo)
80     {
81     }
82     
83     ~WatchpointsOnStructureStubInfo();
84     
85     StructureStubClearingWatchpoint* addWatchpoint(const ObjectPropertyCondition& key);
86     
87     static StructureStubClearingWatchpoint* ensureReferenceAndAddWatchpoint(
88         RefPtr<WatchpointsOnStructureStubInfo>& holderRef,
89         CodeBlock*, StructureStubInfo*, const ObjectPropertyCondition& key);
90     
91     CodeBlock* codeBlock() const { return m_codeBlock; }
92     StructureStubInfo* stubInfo() const { return m_stubInfo; }
93     
94 private:
95     CodeBlock* m_codeBlock;
96     StructureStubInfo* m_stubInfo;
97     std::unique_ptr<StructureStubClearingWatchpoint> m_head;
98 };
99
100 } // namespace JSC
101
102 #endif // ENABLE(JIT)
103
104 #endif // StructureStubClearingWatchpoint_h
105