blob: 4af18fe7337ab71d16ded9d302906e2c88c0522a [file] [log] [blame]
fpizlo@apple.com6b62eaf2015-08-03 23:13:56 +00001/*
2 * Copyright (C) 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
ryanhaddad@apple.com22104f52016-09-28 17:08:17 +000026#pragma once
fpizlo@apple.com6b62eaf2015-08-03 23:13:56 +000027
28#include "ObjectPropertyCondition.h"
29#include <wtf/FastMalloc.h>
fpizlo@apple.com6b62eaf2015-08-03 23:13:56 +000030#include <wtf/Vector.h>
31
32namespace JSC {
33
34// An object property condition set is used to represent the set of additional conditions
35// that need to be met for some heap access to be valid. The set can have the following
36// interesting states:
37//
38// Empty: There are no special conditions that need to be met.
39// Invalid: The heap access is never valid.
40// Non-empty: The heap access is valid if all the ObjectPropertyConditions in the set are valid.
41
42class ObjectPropertyConditionSet {
43public:
44 ObjectPropertyConditionSet() { }
45
46 static ObjectPropertyConditionSet invalid()
47 {
48 ObjectPropertyConditionSet result;
49 result.m_data = adoptRef(new Data());
50 return result;
51 }
52
53 static ObjectPropertyConditionSet create(const Vector<ObjectPropertyCondition>& vector)
54 {
55 if (vector.isEmpty())
56 return ObjectPropertyConditionSet();
57
58 ObjectPropertyConditionSet result;
59 result.m_data = adoptRef(new Data());
60 result.m_data->vector = vector;
61 return result;
62 }
63
64 bool isValid() const
65 {
66 return !m_data || !m_data->vector.isEmpty();
67 }
keith_miller@apple.com30e90262016-06-02 21:24:21 +000068
69 bool isValidAndWatchable() const;
fpizlo@apple.com6b62eaf2015-08-03 23:13:56 +000070
71 bool isEmpty() const
72 {
73 return !m_data;
74 }
75
76 typedef const ObjectPropertyCondition* iterator;
77
78 iterator begin() const
79 {
80 if (!m_data)
81 return nullptr;
82 return m_data->vector.begin();
83 }
84 iterator end() const
85 {
86 if (!m_data)
87 return nullptr;
88 return m_data->vector.end();
89 }
90
91 ObjectPropertyCondition forObject(JSObject*) const;
92 ObjectPropertyCondition forConditionKind(PropertyCondition::Kind) const;
93
94 unsigned numberOfConditionsWithKind(PropertyCondition::Kind) const;
95
96 bool hasOneSlotBaseCondition() const;
97
98 // If this is a condition set for a prototype hit, then this is guaranteed to return the
99 // condition on the prototype itself. This allows you to get the object, offset, and
100 // attributes for the prototype. This will RELEASE_ASSERT that there is exactly one Presence
101 // in the set, and it will return that presence.
102 ObjectPropertyCondition slotBaseCondition() const;
103
104 // Attempt to create a new condition set by merging this one with the other one. This will
105 // fail if any of the conditions are incompatible with each other. When if fails, it returns
106 // invalid().
107 ObjectPropertyConditionSet mergedWith(const ObjectPropertyConditionSet& other) const;
108
109 bool structuresEnsureValidity() const;
110 bool structuresEnsureValidityAssumingImpurePropertyWatchpoint() const;
111
112 bool needImpurePropertyWatchpoint() const;
113 bool areStillLive() const;
114
115 void dumpInContext(PrintStream&, DumpContext*) const;
116 void dump(PrintStream&) const;
117
118 // Helpers for using this in a union.
119 void* releaseRawPointer()
120 {
121 return static_cast<void*>(m_data.leakRef());
122 }
123 static ObjectPropertyConditionSet adoptRawPointer(void* rawPointer)
124 {
125 ObjectPropertyConditionSet result;
126 result.m_data = adoptRef(static_cast<Data*>(rawPointer));
127 return result;
128 }
129 static ObjectPropertyConditionSet fromRawPointer(void* rawPointer)
130 {
131 ObjectPropertyConditionSet result;
132 result.m_data = static_cast<Data*>(rawPointer);
133 return result;
134 }
fpizlo@apple.com3fca21b2015-08-03 23:45:57 +0000135
136 // FIXME: Everything below here should be private, but cannot be because of a bug in VS.
fpizlo@apple.com6b62eaf2015-08-03 23:13:56 +0000137
fpizlo@apple.com6b62eaf2015-08-03 23:13:56 +0000138 // Internally, this represents Invalid using a pointer to a Data that has an empty vector.
139
140 // FIXME: This could be made more compact by having it internally use a vector that just has
141 // the non-uid portion of ObjectPropertyCondition, and then requiring that the callers of all
142 // of the APIs supply the uid.
143
144 class Data : public ThreadSafeRefCounted<Data> {
145 WTF_MAKE_NONCOPYABLE(Data);
146 WTF_MAKE_FAST_ALLOCATED;
147
148 public:
149 Data() { }
150
151 Vector<ObjectPropertyCondition> vector;
152 };
153
fpizlo@apple.com3fca21b2015-08-03 23:45:57 +0000154private:
fpizlo@apple.com6b62eaf2015-08-03 23:13:56 +0000155 RefPtr<Data> m_data;
156};
157
sbarati@apple.com99ed4792016-11-12 02:58:11 +0000158ObjectPropertyCondition generateConditionForSelfEquivalence(
159 VM&, JSCell* owner, JSObject* object, UniquedStringImpl* uid);
160
fpizlo@apple.com6b62eaf2015-08-03 23:13:56 +0000161ObjectPropertyConditionSet generateConditionsForPropertyMiss(
162 VM&, JSCell* owner, ExecState*, Structure* headStructure, UniquedStringImpl* uid);
163ObjectPropertyConditionSet generateConditionsForPropertySetterMiss(
164 VM&, JSCell* owner, ExecState*, Structure* headStructure, UniquedStringImpl* uid);
165ObjectPropertyConditionSet generateConditionsForPrototypePropertyHit(
166 VM&, JSCell* owner, ExecState*, Structure* headStructure, JSObject* prototype,
167 UniquedStringImpl* uid);
168ObjectPropertyConditionSet generateConditionsForPrototypePropertyHitCustom(
169 VM&, JSCell* owner, ExecState*, Structure* headStructure, JSObject* prototype,
170 UniquedStringImpl* uid);
171
keith_miller@apple.com3c27a5e2016-06-02 03:18:16 +0000172ObjectPropertyConditionSet generateConditionsForPrototypeEquivalenceConcurrently(
173 VM&, JSGlobalObject*, Structure* headStructure, JSObject* prototype,
174 UniquedStringImpl* uid);
keith_miller@apple.comb22f8f82016-03-04 00:47:55 +0000175ObjectPropertyConditionSet generateConditionsForPropertyMissConcurrently(
176 VM&, JSGlobalObject*, Structure* headStructure, UniquedStringImpl* uid);
fpizlo@apple.com6b62eaf2015-08-03 23:13:56 +0000177ObjectPropertyConditionSet generateConditionsForPropertySetterMissConcurrently(
178 VM&, JSGlobalObject*, Structure* headStructure, UniquedStringImpl* uid);
179
180} // namespace JSC