]> git.saurik.com Git - apple/javascriptcore.git/blob - bytecode/PutByIdVariant.h
JavaScriptCore-7601.1.46.3.tar.gz
[apple/javascriptcore.git] / bytecode / PutByIdVariant.h
1 /*
2 * Copyright (C) 2014 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 PutByIdVariant_h
27 #define PutByIdVariant_h
28
29 #include "IntendedStructureChain.h"
30 #include "PropertyOffset.h"
31 #include "StructureSet.h"
32
33 namespace JSC {
34
35 class CallLinkStatus;
36
37 class PutByIdVariant {
38 public:
39 enum Kind {
40 NotSet,
41 Replace,
42 Transition,
43 Setter
44 };
45
46 PutByIdVariant()
47 : m_kind(NotSet)
48 , m_newStructure(nullptr)
49 , m_alternateBase(nullptr)
50 , m_offset(invalidOffset)
51 {
52 }
53
54 PutByIdVariant(const PutByIdVariant&);
55 PutByIdVariant& operator=(const PutByIdVariant&);
56
57 static PutByIdVariant replace(
58 const StructureSet& structure, PropertyOffset offset);
59
60 static PutByIdVariant transition(
61 const StructureSet& oldStructure, Structure* newStructure,
62 const IntendedStructureChain* structureChain, PropertyOffset offset);
63
64 static PutByIdVariant setter(
65 const StructureSet& structure, PropertyOffset offset,
66 IntendedStructureChain* chain, std::unique_ptr<CallLinkStatus> callLinkStatus);
67
68 Kind kind() const { return m_kind; }
69
70 bool isSet() const { return kind() != NotSet; }
71 bool operator!() const { return !isSet(); }
72
73 const StructureSet& structure() const
74 {
75 ASSERT(kind() == Replace || kind() == Setter);
76 return m_oldStructure;
77 }
78
79 const StructureSet& oldStructure() const
80 {
81 ASSERT(kind() == Transition || kind() == Replace || kind() == Setter);
82 return m_oldStructure;
83 }
84
85 StructureSet& oldStructure()
86 {
87 ASSERT(kind() == Transition || kind() == Replace || kind() == Setter);
88 return m_oldStructure;
89 }
90
91 Structure* oldStructureForTransition() const;
92
93 Structure* newStructure() const
94 {
95 ASSERT(kind() == Transition);
96 return m_newStructure;
97 }
98
99 bool writesStructures() const;
100 bool reallocatesStorage() const;
101 bool makesCalls() const;
102
103 const ConstantStructureCheckVector& constantChecks() const
104 {
105 return m_constantChecks;
106 }
107
108 PropertyOffset offset() const
109 {
110 ASSERT(isSet());
111 return m_offset;
112 }
113
114 JSObject* alternateBase() const
115 {
116 ASSERT(kind() == Setter);
117 return m_alternateBase;
118 }
119
120 StructureSet baseStructure() const;
121
122 CallLinkStatus* callLinkStatus() const
123 {
124 ASSERT(kind() == Setter);
125 return m_callLinkStatus.get();
126 }
127
128 bool attemptToMerge(const PutByIdVariant& other);
129
130 void dump(PrintStream&) const;
131 void dumpInContext(PrintStream&, DumpContext*) const;
132
133 private:
134 bool attemptToMergeTransitionWithReplace(const PutByIdVariant& replace);
135
136 Kind m_kind;
137 StructureSet m_oldStructure;
138 Structure* m_newStructure;
139 ConstantStructureCheckVector m_constantChecks;
140 JSObject* m_alternateBase;
141 PropertyOffset m_offset;
142 std::unique_ptr<CallLinkStatus> m_callLinkStatus;
143 };
144
145 } // namespace JSC
146
147 #endif // PutByIdVariant_h
148