oliver@apple.com | 98fb6bf | 2013-07-25 03:59:44 +0000 | [diff] [blame] | 1 | /* |
fpizlo@apple.com | 1b84a42 | 2014-02-08 05:06:33 +0000 | [diff] [blame] | 2 | * Copyright (C) 2013, 2014 Apple Inc. All rights reserved. |
oliver@apple.com | 98fb6bf | 2013-07-25 03:59:44 +0000 | [diff] [blame] | 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 | * |
mjs@apple.com | 9204733 | 2014-03-15 04:08:27 +0000 | [diff] [blame] | 13 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY |
oliver@apple.com | 98fb6bf | 2013-07-25 03:59:44 +0000 | [diff] [blame] | 14 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 15 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
mjs@apple.com | 9204733 | 2014-03-15 04:08:27 +0000 | [diff] [blame] | 16 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR |
oliver@apple.com | 98fb6bf | 2013-07-25 03:59:44 +0000 | [diff] [blame] | 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 | #include "config.h" |
| 27 | #include "IntendedStructureChain.h" |
| 28 | |
| 29 | #include "CodeBlock.h" |
fpizlo@apple.com | fb7eff2 | 2014-02-11 01:45:50 +0000 | [diff] [blame] | 30 | #include "JSCInlines.h" |
oliver@apple.com | 98fb6bf | 2013-07-25 03:59:44 +0000 | [diff] [blame] | 31 | #include "StructureChain.h" |
fpizlo@apple.com | 51614cc | 2014-02-17 06:35:32 +0000 | [diff] [blame] | 32 | #include <wtf/CommaPrinter.h> |
oliver@apple.com | 98fb6bf | 2013-07-25 03:59:44 +0000 | [diff] [blame] | 33 | |
| 34 | namespace JSC { |
| 35 | |
fpizlo@apple.com | b41e682 | 2014-07-25 20:55:17 +0000 | [diff] [blame] | 36 | IntendedStructureChain::IntendedStructureChain(JSGlobalObject* globalObject, JSValue prototype) |
oliver@apple.com | 98fb6bf | 2013-07-25 03:59:44 +0000 | [diff] [blame] | 37 | : m_globalObject(globalObject) |
fpizlo@apple.com | b41e682 | 2014-07-25 20:55:17 +0000 | [diff] [blame] | 38 | , m_prototype(prototype) |
oliver@apple.com | 98fb6bf | 2013-07-25 03:59:44 +0000 | [diff] [blame] | 39 | { |
fpizlo@apple.com | b41e682 | 2014-07-25 20:55:17 +0000 | [diff] [blame] | 40 | ASSERT(m_prototype.isNull() || m_prototype.isObject()); |
oliver@apple.com | 98fb6bf | 2013-07-25 03:59:44 +0000 | [diff] [blame] | 41 | if (prototype.isNull()) |
| 42 | return; |
| 43 | for (Structure* current = asObject(prototype)->structure(); current; current = current->storedPrototypeStructure()) |
| 44 | m_vector.append(current); |
| 45 | } |
| 46 | |
fpizlo@apple.com | b41e682 | 2014-07-25 20:55:17 +0000 | [diff] [blame] | 47 | IntendedStructureChain::IntendedStructureChain(JSGlobalObject* globalObject, Structure* head) |
| 48 | : m_globalObject(globalObject) |
| 49 | , m_prototype(head->prototypeForLookup(m_globalObject)) |
| 50 | { |
| 51 | if (m_prototype.isNull()) |
| 52 | return; |
| 53 | for (Structure* current = asObject(m_prototype)->structure(); current; current = current->storedPrototypeStructure()) |
| 54 | m_vector.append(current); |
| 55 | } |
| 56 | |
oliver@apple.com | 98fb6bf | 2013-07-25 03:59:44 +0000 | [diff] [blame] | 57 | IntendedStructureChain::IntendedStructureChain(CodeBlock* codeBlock, Structure* head, Structure* prototypeStructure) |
| 58 | : m_globalObject(codeBlock->globalObject()) |
fpizlo@apple.com | b41e682 | 2014-07-25 20:55:17 +0000 | [diff] [blame] | 59 | , m_prototype(head->prototypeForLookup(m_globalObject)) |
oliver@apple.com | 98fb6bf | 2013-07-25 03:59:44 +0000 | [diff] [blame] | 60 | { |
| 61 | m_vector.append(prototypeStructure); |
| 62 | } |
| 63 | |
| 64 | IntendedStructureChain::IntendedStructureChain(CodeBlock* codeBlock, Structure* head, StructureChain* chain) |
| 65 | : m_globalObject(codeBlock->globalObject()) |
fpizlo@apple.com | b41e682 | 2014-07-25 20:55:17 +0000 | [diff] [blame] | 66 | , m_prototype(head->prototypeForLookup(m_globalObject)) |
oliver@apple.com | 98fb6bf | 2013-07-25 03:59:44 +0000 | [diff] [blame] | 67 | { |
| 68 | for (unsigned i = 0; chain->head()[i]; ++i) |
| 69 | m_vector.append(chain->head()[i].get()); |
| 70 | } |
| 71 | |
| 72 | IntendedStructureChain::IntendedStructureChain(CodeBlock* codeBlock, Structure* head, StructureChain* chain, unsigned count) |
| 73 | : m_globalObject(codeBlock->globalObject()) |
fpizlo@apple.com | b41e682 | 2014-07-25 20:55:17 +0000 | [diff] [blame] | 74 | , m_prototype(head->prototypeForLookup(m_globalObject)) |
oliver@apple.com | 98fb6bf | 2013-07-25 03:59:44 +0000 | [diff] [blame] | 75 | { |
| 76 | for (unsigned i = 0; i < count; ++i) |
| 77 | m_vector.append(chain->head()[i].get()); |
| 78 | } |
| 79 | |
| 80 | IntendedStructureChain::~IntendedStructureChain() |
| 81 | { |
| 82 | } |
| 83 | |
| 84 | bool IntendedStructureChain::isStillValid() const |
| 85 | { |
fpizlo@apple.com | b41e682 | 2014-07-25 20:55:17 +0000 | [diff] [blame] | 86 | JSValue currentPrototype = m_prototype; |
oliver@apple.com | 98fb6bf | 2013-07-25 03:59:44 +0000 | [diff] [blame] | 87 | for (unsigned i = 0; i < m_vector.size(); ++i) { |
| 88 | if (asObject(currentPrototype)->structure() != m_vector[i]) |
| 89 | return false; |
| 90 | currentPrototype = m_vector[i]->storedPrototype(); |
| 91 | } |
| 92 | return true; |
| 93 | } |
| 94 | |
| 95 | bool IntendedStructureChain::matches(StructureChain* chain) const |
| 96 | { |
| 97 | for (unsigned i = 0; i < m_vector.size(); ++i) { |
| 98 | if (m_vector[i] != chain->head()[i].get()) |
| 99 | return false; |
| 100 | } |
| 101 | if (chain->head()[m_vector.size()]) |
| 102 | return false; |
| 103 | return true; |
| 104 | } |
| 105 | |
utatane.tea@gmail.com | 8268d39 | 2015-05-23 18:41:53 +0000 | [diff] [blame] | 106 | bool IntendedStructureChain::mayInterceptStoreTo(UniquedStringImpl* uid) |
oliver@apple.com | 98fb6bf | 2013-07-25 03:59:44 +0000 | [diff] [blame] | 107 | { |
| 108 | for (unsigned i = 0; i < m_vector.size(); ++i) { |
| 109 | unsigned attributes; |
fpizlo@apple.com | 15ec1b2 | 2014-09-21 19:18:40 +0000 | [diff] [blame] | 110 | PropertyOffset offset = m_vector[i]->getConcurrently(uid, attributes); |
oliver@apple.com | 98fb6bf | 2013-07-25 03:59:44 +0000 | [diff] [blame] | 111 | if (!isValidOffset(offset)) |
| 112 | continue; |
| 113 | if (attributes & (ReadOnly | Accessor)) |
| 114 | return true; |
| 115 | return false; |
| 116 | } |
| 117 | return false; |
| 118 | } |
| 119 | |
| 120 | bool IntendedStructureChain::isNormalized() |
| 121 | { |
oliver@apple.com | 98fb6bf | 2013-07-25 03:59:44 +0000 | [diff] [blame] | 122 | for (unsigned i = 0; i < m_vector.size(); ++i) { |
| 123 | Structure* structure = m_vector[i]; |
mhahnenberg@apple.com | 890aa1b | 2014-04-29 22:21:04 +0000 | [diff] [blame] | 124 | if (structure->isProxy()) |
oliver@apple.com | 98fb6bf | 2013-07-25 03:59:44 +0000 | [diff] [blame] | 125 | return false; |
| 126 | if (structure->isDictionary()) |
| 127 | return false; |
| 128 | } |
| 129 | return true; |
| 130 | } |
| 131 | |
fpizlo@apple.com | 2c4a7e9 | 2014-08-06 05:27:46 +0000 | [diff] [blame] | 132 | bool IntendedStructureChain::takesSlowPathInDFGForImpureProperty() |
| 133 | { |
| 134 | for (size_t i = 0; i < size(); ++i) { |
| 135 | if (at(i)->takesSlowPathInDFGForImpureProperty()) |
| 136 | return true; |
| 137 | } |
| 138 | return false; |
| 139 | } |
| 140 | |
oliver@apple.com | 98fb6bf | 2013-07-25 03:59:44 +0000 | [diff] [blame] | 141 | JSObject* IntendedStructureChain::terminalPrototype() const |
| 142 | { |
| 143 | ASSERT(!m_vector.isEmpty()); |
| 144 | if (m_vector.size() == 1) |
fpizlo@apple.com | b41e682 | 2014-07-25 20:55:17 +0000 | [diff] [blame] | 145 | return asObject(m_prototype); |
oliver@apple.com | 98fb6bf | 2013-07-25 03:59:44 +0000 | [diff] [blame] | 146 | return asObject(m_vector[m_vector.size() - 2]->storedPrototype()); |
| 147 | } |
| 148 | |
fpizlo@apple.com | b41e682 | 2014-07-25 20:55:17 +0000 | [diff] [blame] | 149 | bool IntendedStructureChain::operator==(const IntendedStructureChain& other) const |
| 150 | { |
| 151 | return m_globalObject == other.m_globalObject |
| 152 | && m_prototype == other.m_prototype |
| 153 | && m_vector == other.m_vector; |
| 154 | } |
| 155 | |
| 156 | void IntendedStructureChain::gatherChecks(ConstantStructureCheckVector& vector) const |
| 157 | { |
| 158 | JSValue currentPrototype = m_prototype; |
| 159 | for (unsigned i = 0; i < size(); ++i) { |
| 160 | JSObject* currentObject = asObject(currentPrototype); |
| 161 | Structure* currentStructure = at(i); |
| 162 | vector.append(ConstantStructureCheck(currentObject, currentStructure)); |
| 163 | currentPrototype = currentStructure->prototypeForLookup(m_globalObject); |
| 164 | } |
| 165 | } |
| 166 | |
fpizlo@apple.com | 1b84a42 | 2014-02-08 05:06:33 +0000 | [diff] [blame] | 167 | void IntendedStructureChain::visitChildren(SlotVisitor& visitor) |
| 168 | { |
| 169 | visitor.appendUnbarrieredPointer(&m_globalObject); |
fpizlo@apple.com | b41e682 | 2014-07-25 20:55:17 +0000 | [diff] [blame] | 170 | visitor.appendUnbarrieredValue(&m_prototype); |
fpizlo@apple.com | 1b84a42 | 2014-02-08 05:06:33 +0000 | [diff] [blame] | 171 | for (unsigned i = m_vector.size(); i--;) |
| 172 | visitor.appendUnbarrieredPointer(&m_vector[i]); |
| 173 | } |
| 174 | |
fpizlo@apple.com | 51614cc | 2014-02-17 06:35:32 +0000 | [diff] [blame] | 175 | void IntendedStructureChain::dump(PrintStream& out) const |
| 176 | { |
| 177 | dumpInContext(out, 0); |
| 178 | } |
| 179 | |
| 180 | void IntendedStructureChain::dumpInContext(PrintStream& out, DumpContext* context) const |
| 181 | { |
| 182 | out.print( |
| 183 | "(global = ", RawPointer(m_globalObject), ", head = ", |
fpizlo@apple.com | b41e682 | 2014-07-25 20:55:17 +0000 | [diff] [blame] | 184 | inContext(m_prototype, context), ", vector = ["); |
fpizlo@apple.com | 51614cc | 2014-02-17 06:35:32 +0000 | [diff] [blame] | 185 | CommaPrinter comma; |
| 186 | for (unsigned i = 0; i < m_vector.size(); ++i) |
| 187 | out.print(comma, pointerDumpInContext(m_vector[i], context)); |
| 188 | out.print("])"); |
| 189 | } |
| 190 | |
oliver@apple.com | 98fb6bf | 2013-07-25 03:59:44 +0000 | [diff] [blame] | 191 | } // namespace JSC |
| 192 | |