2 * Copyright (C) 2013-2015 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
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.
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"
39 #include <wtf/SegmentedVector.h>
43 class TrackedReferences
;
49 class JITCode
: public DirectJITCode
{
54 virtual CommonData
* dfgCommon() override
;
55 virtual JITCode
* dfg() override
;
57 OSREntryData
* appendOSREntryData(unsigned bytecodeIndex
, unsigned machineCodeOffset
)
59 DFG::OSREntryData entry
;
60 entry
.m_bytecodeIndex
= bytecodeIndex
;
61 entry
.m_machineCodeOffset
= machineCodeOffset
;
62 osrEntry
.append(entry
);
63 return &osrEntry
.last();
66 OSREntryData
* osrEntryDataForBytecodeIndex(unsigned bytecodeIndex
)
68 return tryBinarySearch
<OSREntryData
, unsigned>(
69 osrEntry
, osrEntry
.size(), bytecodeIndex
,
70 getOSREntryDataBytecodeIndex
);
73 unsigned appendOSRExit(const OSRExit
& exit
)
75 unsigned result
= osrExit
.size();
80 OSRExit
& lastOSRExit()
82 return osrExit
.last();
85 unsigned appendSpeculationRecovery(const SpeculationRecovery
& recovery
)
87 unsigned result
= speculationRecovery
.size();
88 speculationRecovery
.append(recovery
);
93 CodeBlock
*, CodeOrigin
, unsigned streamIndex
, Operands
<ValueRecovery
>& result
);
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.
99 ExecState
*, CodeBlock
*, CodeOrigin
, unsigned streamIndex
, Operands
<JSValue
>& result
);
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.
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)
114 void validateReferences(const TrackedReferences
&) override
;
119 friend class JITCompiler
; // Allow JITCompiler to call setCodeRef().
123 Vector
<DFG::OSREntryData
> osrEntry
;
124 SegmentedVector
<DFG::OSRExit
, 8> osrExit
;
125 Vector
<DFG::SpeculationRecovery
> speculationRecovery
;
126 DFG::VariableEventStream variableEventStream
;
127 DFG::MinifiedGraph minifiedDFG
;
129 uint8_t nestedTriggerIsSet
{ 0 };
130 UpperTierExecutionCounter tierUpCounter
;
131 RefPtr
<CodeBlock
> osrEntryBlock
;
132 unsigned osrEntryRetry
;
133 bool abandonOSREntry
;
134 #endif // ENABLE(FTL_JIT)
137 } } // namespace JSC::DFG
139 #endif // ENABLE(DFG_JIT)
141 #endif // DFGJITCode_h