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