]> git.saurik.com Git - apple/javascriptcore.git/blob - dfg/DFGJITCode.h
JavaScriptCore-7601.1.46.3.tar.gz
[apple/javascriptcore.git] / dfg / DFGJITCode.h
1 /*
2 * Copyright (C) 2013-2015 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 #ifndef DFGJITCode_h
27 #define DFGJITCode_h
28
29 #if ENABLE(DFG_JIT)
30
31 #include "CompilationResult.h"
32 #include "DFGCommonData.h"
33 #include "DFGMinifiedGraph.h"
34 #include "DFGOSREntry.h"
35 #include "DFGOSRExit.h"
36 #include "DFGVariableEventStream.h"
37 #include "ExecutionCounter.h"
38 #include "JITCode.h"
39 #include <wtf/SegmentedVector.h>
40
41 namespace JSC {
42
43 class TrackedReferences;
44
45 namespace DFG {
46
47 class JITCompiler;
48
49 class JITCode : public DirectJITCode {
50 public:
51 JITCode();
52 virtual ~JITCode();
53
54 virtual CommonData* dfgCommon() override;
55 virtual JITCode* dfg() override;
56
57 OSREntryData* appendOSREntryData(unsigned bytecodeIndex, unsigned machineCodeOffset)
58 {
59 DFG::OSREntryData entry;
60 entry.m_bytecodeIndex = bytecodeIndex;
61 entry.m_machineCodeOffset = machineCodeOffset;
62 osrEntry.append(entry);
63 return &osrEntry.last();
64 }
65
66 OSREntryData* osrEntryDataForBytecodeIndex(unsigned bytecodeIndex)
67 {
68 return tryBinarySearch<OSREntryData, unsigned>(
69 osrEntry, osrEntry.size(), bytecodeIndex,
70 getOSREntryDataBytecodeIndex);
71 }
72
73 unsigned appendOSRExit(const OSRExit& exit)
74 {
75 unsigned result = osrExit.size();
76 osrExit.append(exit);
77 return result;
78 }
79
80 OSRExit& lastOSRExit()
81 {
82 return osrExit.last();
83 }
84
85 unsigned appendSpeculationRecovery(const SpeculationRecovery& recovery)
86 {
87 unsigned result = speculationRecovery.size();
88 speculationRecovery.append(recovery);
89 return result;
90 }
91
92 void reconstruct(
93 CodeBlock*, CodeOrigin, unsigned streamIndex, Operands<ValueRecovery>& result);
94
95 // This is only applicable if we're at a point where all values are spilled to the
96 // stack. Currently, it also has the restriction that the values must be in their
97 // bytecode-designated stack slots.
98 void reconstruct(
99 ExecState*, CodeBlock*, CodeOrigin, unsigned streamIndex, Operands<JSValue>& result);
100
101 #if ENABLE(FTL_JIT)
102 // NB. All of these methods take CodeBlock* because they may want to use
103 // CodeBlock's logic about scaling thresholds. It should be a DFG CodeBlock.
104
105 bool checkIfOptimizationThresholdReached(CodeBlock*);
106 void optimizeNextInvocation(CodeBlock*);
107 void dontOptimizeAnytimeSoon(CodeBlock*);
108 void optimizeAfterWarmUp(CodeBlock*);
109 void optimizeSoon(CodeBlock*);
110 void forceOptimizationSlowPathConcurrently(CodeBlock*);
111 void setOptimizationThresholdBasedOnCompilationResult(CodeBlock*, CompilationResult);
112 #endif // ENABLE(FTL_JIT)
113
114 void validateReferences(const TrackedReferences&) override;
115
116 void shrinkToFit();
117
118 private:
119 friend class JITCompiler; // Allow JITCompiler to call setCodeRef().
120
121 public:
122 CommonData common;
123 Vector<DFG::OSREntryData> osrEntry;
124 SegmentedVector<DFG::OSRExit, 8> osrExit;
125 Vector<DFG::SpeculationRecovery> speculationRecovery;
126 DFG::VariableEventStream variableEventStream;
127 DFG::MinifiedGraph minifiedDFG;
128 #if ENABLE(FTL_JIT)
129 uint8_t nestedTriggerIsSet { 0 };
130 UpperTierExecutionCounter tierUpCounter;
131 RefPtr<CodeBlock> osrEntryBlock;
132 unsigned osrEntryRetry;
133 bool abandonOSREntry;
134 #endif // ENABLE(FTL_JIT)
135 };
136
137 } } // namespace JSC::DFG
138
139 #endif // ENABLE(DFG_JIT)
140
141 #endif // DFGJITCode_h
142