1 | /* |
2 | * Copyright (C) 2018 Yusuke Suzuki <[email protected]>. |
3 | * Copyright (C) 2018 Apple Inc. All rights reserved. |
4 | * |
5 | * Redistribution and use in source and binary forms, with or without |
6 | * modification, are permitted provided that the following conditions |
7 | * are met: |
8 | * 1. Redistributions of source code must retain the above copyright |
9 | * notice, this list of conditions and the following disclaimer. |
10 | * 2. Redistributions in binary form must reproduce the above copyright |
11 | * notice, this list of conditions and the following disclaimer in the |
12 | * documentation and/or other materials provided with the distribution. |
13 | * |
14 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY |
15 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
17 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR |
18 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
19 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
20 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
21 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
22 | * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
23 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
24 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
25 | */ |
26 | |
27 | #pragma once |
28 | |
29 | #include "CallLinkStatus.h" |
30 | #include "CodeOrigin.h" |
31 | #include "ConcurrentJSLock.h" |
32 | #include "ICStatusMap.h" |
33 | #include "InByIdVariant.h" |
34 | #include "StubInfoSummary.h" |
35 | |
36 | namespace JSC { |
37 | |
38 | class AccessCase; |
39 | class CodeBlock; |
40 | class StructureStubInfo; |
41 | |
42 | class InByIdStatus { |
43 | public: |
44 | enum State { |
45 | // It's uncached so we have no information. |
46 | NoInformation, |
47 | // It's cached for a simple access to a known object property with |
48 | // a possible structure chain and a possible specific value. |
49 | Simple, |
50 | // It's known to often take slow path. |
51 | TakesSlowPath, |
52 | }; |
53 | |
54 | InByIdStatus() = default; |
55 | |
56 | InByIdStatus(State state, const InByIdVariant& variant = InByIdVariant()) |
57 | : m_state(state) |
58 | { |
59 | ASSERT((state == Simple) == variant.isSet()); |
60 | if (variant.isSet()) |
61 | m_variants.append(variant); |
62 | } |
63 | |
64 | explicit InByIdStatus(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 InByIdStatus computeFor(CodeBlock*, ICStatusMap&, unsigned bytecodeIndex, UniquedStringImpl* uid); |
83 | static InByIdStatus computeFor(CodeBlock*, ICStatusMap&, unsigned bytecodeIndex, UniquedStringImpl* uid, ExitFlag); |
84 | static InByIdStatus computeFor(CodeBlock* baselineBlock, ICStatusMap& baselineMap, ICStatusContextStack& contextStack, CodeOrigin, UniquedStringImpl* uid); |
85 | |
86 | #if ENABLE(DFG_JIT) |
87 | static InByIdStatus computeForStubInfo(const ConcurrentJSLocker&, CodeBlock* baselineBlock, StructureStubInfo*, CodeOrigin, UniquedStringImpl* uid); |
88 | #endif |
89 | |
90 | State state() const { return m_state; } |
91 | |
92 | bool isSet() const { return m_state != NoInformation; } |
93 | explicit operator bool() const { return isSet(); } |
94 | bool isSimple() const { return m_state == Simple; } |
95 | |
96 | size_t numVariants() const { return m_variants.size(); } |
97 | const Vector<InByIdVariant, 1>& variants() const { return m_variants; } |
98 | const InByIdVariant& at(size_t index) const { return m_variants[index]; } |
99 | const InByIdVariant& operator[](size_t index) const { return at(index); } |
100 | |
101 | bool takesSlowPath() const { return m_state == TakesSlowPath; } |
102 | |
103 | void merge(const InByIdStatus&); |
104 | |
105 | // Attempts to reduce the set of variants to fit the given structure set. This may be approximate. |
106 | void filter(const StructureSet&); |
107 | |
108 | void markIfCheap(SlotVisitor&); |
109 | bool finalize(VM&); |
110 | |
111 | void dump(PrintStream&) const; |
112 | |
113 | private: |
114 | #if ENABLE(DFG_JIT) |
115 | static InByIdStatus computeForStubInfoWithoutExitSiteFeedback(const ConcurrentJSLocker&, StructureStubInfo*, UniquedStringImpl* uid); |
116 | #endif |
117 | bool appendVariant(const InByIdVariant&); |
118 | |
119 | State m_state { NoInformation }; |
120 | Vector<InByIdVariant, 1> m_variants; |
121 | }; |
122 | |
123 | } // namespace JSC |
124 | |