| 1 | /* |
| 2 | * Copyright (C) 2018 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 | #pragma once |
| 27 | |
| 28 | #include "ConcurrentJSLock.h" |
| 29 | #include "ICStatusMap.h" |
| 30 | #include "InstanceOfVariant.h" |
| 31 | #include "StubInfoSummary.h" |
| 32 | |
| 33 | namespace JSC { |
| 34 | |
| 35 | class AccessCase; |
| 36 | class CodeBlock; |
| 37 | class StructureStubInfo; |
| 38 | |
| 39 | class InstanceOfStatus { |
| 40 | public: |
| 41 | enum State { |
| 42 | // It's uncached so we have no information. |
| 43 | NoInformation, |
| 44 | |
| 45 | // It's cached in a simple way. |
| 46 | Simple, |
| 47 | |
| 48 | // It's known to often take slow path. |
| 49 | TakesSlowPath |
| 50 | }; |
| 51 | |
| 52 | InstanceOfStatus() |
| 53 | : m_state(NoInformation) |
| 54 | { |
| 55 | } |
| 56 | |
| 57 | InstanceOfStatus(State state) |
| 58 | : m_state(state) |
| 59 | { |
| 60 | ASSERT(state == NoInformation || state == TakesSlowPath); |
| 61 | } |
| 62 | |
| 63 | explicit InstanceOfStatus(StubInfoSummary summary) |
| 64 | { |
| 65 | switch (summary) { |
| 66 | case StubInfoSummary::NoInformation: |
| 67 | m_state = NoInformation; |
| 68 | return; |
| 69 | case StubInfoSummary::Simple: |
| 70 | case StubInfoSummary::MakesCalls: |
| 71 | RELEASE_ASSERT_NOT_REACHED(); |
| 72 | return; |
| 73 | case StubInfoSummary::TakesSlowPath: |
| 74 | case StubInfoSummary::TakesSlowPathAndMakesCalls: |
| 75 | m_state = TakesSlowPath; |
| 76 | return; |
| 77 | } |
| 78 | RELEASE_ASSERT_NOT_REACHED(); |
| 79 | } |
| 80 | |
| 81 | static InstanceOfStatus computeFor(CodeBlock*, ICStatusMap&, unsigned bytecodeIndex); |
| 82 | |
| 83 | #if ENABLE(DFG_JIT) |
| 84 | static InstanceOfStatus computeForStubInfo(const ConcurrentJSLocker&, StructureStubInfo*); |
| 85 | #endif |
| 86 | |
| 87 | State state() const { return m_state; } |
| 88 | |
| 89 | bool isSet() const { return m_state != NoInformation; } |
| 90 | explicit operator bool() const { return isSet(); } |
| 91 | |
| 92 | bool isSimple() const { return m_state == Simple; } |
| 93 | bool takesSlowPath() const { return m_state == TakesSlowPath; } |
| 94 | |
| 95 | JSObject* commonPrototype() const; |
| 96 | |
| 97 | size_t numVariants() const { return m_variants.size(); } |
| 98 | const Vector<InstanceOfVariant, 2>& variants() const { return m_variants; } |
| 99 | const InstanceOfVariant& at(size_t index) const { return m_variants[index]; } |
| 100 | const InstanceOfVariant& operator[](size_t index) const { return at(index); } |
| 101 | |
| 102 | void filter(const StructureSet&); |
| 103 | |
| 104 | void dump(PrintStream&) const; |
| 105 | |
| 106 | private: |
| 107 | void appendVariant(const InstanceOfVariant&); |
| 108 | |
| 109 | State m_state; |
| 110 | Vector<InstanceOfVariant, 2> m_variants; |
| 111 | }; |
| 112 | |
| 113 | } // namespace JSC |
| 114 | |
| 115 | |