1 | /* |
2 | * Copyright (C) 2012-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 "CallLinkStatus.h" |
29 | #include "CodeOrigin.h" |
30 | #include "ConcurrentJSLock.h" |
31 | #include "ExitFlag.h" |
32 | #include "GetByIdVariant.h" |
33 | #include "ICStatusMap.h" |
34 | #include "ScopeOffset.h" |
35 | #include "StubInfoSummary.h" |
36 | |
37 | namespace JSC { |
38 | |
39 | class AccessCase; |
40 | class CodeBlock; |
41 | class JSModuleEnvironment; |
42 | class JSModuleNamespaceObject; |
43 | class ModuleNamespaceAccessCase; |
44 | class StructureStubInfo; |
45 | |
46 | class GetByStatus { |
47 | WTF_MAKE_FAST_ALLOCATED; |
48 | public: |
49 | enum State : uint8_t { |
50 | // It's uncached so we have no information. |
51 | NoInformation, |
52 | // It's cached for a simple access to a known object property with |
53 | // a possible structure chain and a possible specific value. |
54 | Simple, |
55 | // It's cached for a custom accessor with a possible structure chain. |
56 | Custom, |
57 | // It's cached for an access to a module namespace object's binding. |
58 | ModuleNamespace, |
59 | // It will likely take the slow path. |
60 | LikelyTakesSlowPath, |
61 | // It's known to take slow path. We also observed that the slow path was taken on StructureStubInfo. |
62 | ObservedTakesSlowPath, |
63 | // It will likely take the slow path and will make calls. |
64 | MakesCalls, |
65 | // It known to take paths that make calls. We also observed that the slow path was taken on StructureStubInfo. |
66 | ObservedSlowPathAndMakesCalls , |
67 | }; |
68 | |
69 | enum class TrackIdentifiers : uint8_t { |
70 | No, // Used for get_by_id |
71 | Yes, // Used for get_by_val |
72 | }; |
73 | |
74 | GetByStatus() |
75 | : m_state(NoInformation) |
76 | { |
77 | } |
78 | |
79 | explicit GetByStatus(State state) |
80 | : m_state(state) |
81 | { |
82 | ASSERT(state == NoInformation || state == LikelyTakesSlowPath || state == ObservedTakesSlowPath || state == MakesCalls || state == ObservedSlowPathAndMakesCalls); |
83 | } |
84 | |
85 | explicit GetByStatus(StubInfoSummary, StructureStubInfo&); |
86 | |
87 | GetByStatus( |
88 | State state, bool wasSeenInJIT) |
89 | : m_state(state) |
90 | , m_wasSeenInJIT(wasSeenInJIT) |
91 | { |
92 | } |
93 | |
94 | static GetByStatus computeFor(CodeBlock* baselineBlock, ICStatusMap& baselineMap, ICStatusContextStack& dfgContextStack, CodeOrigin, TrackIdentifiers); |
95 | static GetByStatus computeFor(const StructureSet&, UniquedStringImpl*); |
96 | |
97 | State state() const { return m_state; } |
98 | |
99 | bool isSet() const { return m_state != NoInformation; } |
100 | explicit operator bool() const { return isSet(); } |
101 | bool isSimple() const { return m_state == Simple; } |
102 | bool isCustom() const { return m_state == Custom; } |
103 | bool isModuleNamespace() const { return m_state == ModuleNamespace; } |
104 | |
105 | size_t numVariants() const { return m_variants.size(); } |
106 | const Vector<GetByIdVariant, 1>& variants() const { return m_variants; } |
107 | const GetByIdVariant& at(size_t index) const { return m_variants[index]; } |
108 | const GetByIdVariant& operator[](size_t index) const { return at(index); } |
109 | |
110 | bool takesSlowPath() const { return m_state == LikelyTakesSlowPath || m_state == ObservedTakesSlowPath || m_state == MakesCalls || m_state == ObservedSlowPathAndMakesCalls || m_state == Custom || m_state == ModuleNamespace; } |
111 | bool observedStructureStubInfoSlowPath() const { return m_state == ObservedTakesSlowPath || m_state == ObservedSlowPathAndMakesCalls; } |
112 | bool makesCalls() const; |
113 | |
114 | GetByStatus slowVersion() const; |
115 | |
116 | bool wasSeenInJIT() const { return m_wasSeenInJIT; } |
117 | |
118 | // Attempts to reduce the set of variants to fit the given structure set. This may be approximate. |
119 | void filter(const StructureSet&); |
120 | |
121 | JSModuleNamespaceObject* moduleNamespaceObject() const { return m_moduleNamespaceData->m_moduleNamespaceObject; } |
122 | JSModuleEnvironment* moduleEnvironment() const { return m_moduleNamespaceData->m_moduleEnvironment; } |
123 | ScopeOffset scopeOffset() const { return m_moduleNamespaceData->m_scopeOffset; } |
124 | |
125 | void markIfCheap(SlotVisitor&); |
126 | bool finalize(VM&); // Return true if this gets to live. |
127 | |
128 | bool appendVariant(const GetByIdVariant&); |
129 | |
130 | void dump(PrintStream&) const; |
131 | |
132 | Box<Identifier> singleIdentifier() const; |
133 | |
134 | private: |
135 | void merge(const GetByStatus&); |
136 | |
137 | #if ENABLE(JIT) |
138 | GetByStatus(const ModuleNamespaceAccessCase&); |
139 | static GetByStatus computeForStubInfoWithoutExitSiteFeedback( |
140 | const ConcurrentJSLocker&, CodeBlock* profiledBlock, StructureStubInfo*, CallLinkStatus::ExitSiteData, TrackIdentifiers); |
141 | #endif |
142 | static GetByStatus computeFromLLInt(CodeBlock*, BytecodeIndex, TrackIdentifiers); |
143 | static GetByStatus computeFor(CodeBlock*, ICStatusMap&, BytecodeIndex, ExitFlag, CallLinkStatus::ExitSiteData, TrackIdentifiers); |
144 | |
145 | struct ModuleNamespaceData { |
146 | JSModuleNamespaceObject* m_moduleNamespaceObject { nullptr }; |
147 | JSModuleEnvironment* m_moduleEnvironment { nullptr }; |
148 | ScopeOffset m_scopeOffset { }; |
149 | Box<Identifier> m_identifier; |
150 | }; |
151 | |
152 | Vector<GetByIdVariant, 1> m_variants; |
153 | Box<ModuleNamespaceData> m_moduleNamespaceData; |
154 | State m_state; |
155 | bool m_wasSeenInJIT { false }; |
156 | }; |
157 | |
158 | } // namespace JSC |
159 | |