1 | /* |
2 | * Copyright (C) 2013-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 | #include "config.h" |
27 | #include "FTLOSRExit.h" |
28 | |
29 | #if ENABLE(FTL_JIT) |
30 | |
31 | #include "AirGenerationContext.h" |
32 | #include "B3StackmapGenerationParams.h" |
33 | #include "B3StackmapValue.h" |
34 | #include "CodeBlock.h" |
35 | #include "DFGBasicBlock.h" |
36 | #include "DFGNode.h" |
37 | #include "FTLExitArgument.h" |
38 | #include "FTLJITCode.h" |
39 | #include "FTLLocation.h" |
40 | #include "FTLState.h" |
41 | #include "JSCInlines.h" |
42 | |
43 | namespace JSC { namespace FTL { |
44 | |
45 | using namespace B3; |
46 | using namespace DFG; |
47 | |
48 | OSRExitDescriptor::OSRExitDescriptor( |
49 | DataFormat profileDataFormat, MethodOfGettingAValueProfile valueProfile, |
50 | unsigned numberOfArguments, unsigned numberOfLocals) |
51 | : m_profileDataFormat(profileDataFormat) |
52 | , m_valueProfile(valueProfile) |
53 | , m_values(numberOfArguments, numberOfLocals) |
54 | { |
55 | } |
56 | |
57 | void OSRExitDescriptor::validateReferences(const TrackedReferences& trackedReferences) |
58 | { |
59 | for (unsigned i = m_values.size(); i--;) |
60 | m_values[i].validateReferences(trackedReferences); |
61 | |
62 | for (ExitTimeObjectMaterialization* materialization : m_materializations) |
63 | materialization->validateReferences(trackedReferences); |
64 | } |
65 | |
66 | Ref<OSRExitHandle> OSRExitDescriptor::emitOSRExit( |
67 | State& state, ExitKind exitKind, const NodeOrigin& nodeOrigin, CCallHelpers& jit, |
68 | const StackmapGenerationParams& params, unsigned offset) |
69 | { |
70 | Ref<OSRExitHandle> handle = |
71 | prepareOSRExitHandle(state, exitKind, nodeOrigin, params, offset); |
72 | handle->emitExitThunk(state, jit); |
73 | return handle; |
74 | } |
75 | |
76 | Ref<OSRExitHandle> OSRExitDescriptor::emitOSRExitLater( |
77 | State& state, ExitKind exitKind, const NodeOrigin& nodeOrigin, |
78 | const StackmapGenerationParams& params, unsigned offset) |
79 | { |
80 | RefPtr<OSRExitHandle> handle = |
81 | prepareOSRExitHandle(state, exitKind, nodeOrigin, params, offset); |
82 | params.addLatePath( |
83 | [handle, &state] (CCallHelpers& jit) { |
84 | handle->emitExitThunk(state, jit); |
85 | }); |
86 | return handle.releaseNonNull(); |
87 | } |
88 | |
89 | Ref<OSRExitHandle> OSRExitDescriptor::prepareOSRExitHandle( |
90 | State& state, ExitKind exitKind, const NodeOrigin& nodeOrigin, |
91 | const StackmapGenerationParams& params, unsigned offset) |
92 | { |
93 | unsigned index = state.jitCode->osrExit.size(); |
94 | OSRExit& exit = state.jitCode->osrExit.alloc( |
95 | this, exitKind, nodeOrigin.forExit, nodeOrigin.semantic, nodeOrigin.wasHoisted); |
96 | Ref<OSRExitHandle> handle = adoptRef(*new OSRExitHandle(index, exit)); |
97 | for (unsigned i = offset; i < params.size(); ++i) |
98 | exit.m_valueReps.append(params[i]); |
99 | exit.m_valueReps.shrinkToFit(); |
100 | return handle; |
101 | } |
102 | |
103 | OSRExit::OSRExit( |
104 | OSRExitDescriptor* descriptor, ExitKind exitKind, CodeOrigin codeOrigin, |
105 | CodeOrigin codeOriginForExitProfile, bool wasHoisted) |
106 | : OSRExitBase(exitKind, codeOrigin, codeOriginForExitProfile, wasHoisted) |
107 | , m_descriptor(descriptor) |
108 | { |
109 | } |
110 | |
111 | CodeLocationJump<JSInternalPtrTag> OSRExit::codeLocationForRepatch(CodeBlock* ftlCodeBlock) const |
112 | { |
113 | UNUSED_PARAM(ftlCodeBlock); |
114 | return m_patchableJump; |
115 | } |
116 | |
117 | } } // namespace JSC::FTL |
118 | |
119 | #endif // ENABLE(FTL_JIT) |
120 | |
121 | |
122 | |