oliver@apple.com | ea77149 | 2013-07-25 03:58:38 +0000 | [diff] [blame] | 1 | /* |
mark.lam@apple.com | de0dba7 | 2018-04-18 03:31:09 +0000 | [diff] [blame] | 2 | * Copyright (C) 2013-2018 Apple Inc. All rights reserved. |
oliver@apple.com | ea77149 | 2013-07-25 03:58:38 +0000 | [diff] [blame] | 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 | |
fpizlo@apple.com | e362fbc | 2015-12-03 20:01:57 +0000 | [diff] [blame] | 31 | #include "AirGenerationContext.h" |
fpizlo@apple.com | 9ed1b63 | 2015-12-07 19:17:56 +0000 | [diff] [blame] | 32 | #include "B3StackmapGenerationParams.h" |
fpizlo@apple.com | e362fbc | 2015-12-03 20:01:57 +0000 | [diff] [blame] | 33 | #include "B3StackmapValue.h" |
oliver@apple.com | ea77149 | 2013-07-25 03:58:38 +0000 | [diff] [blame] | 34 | #include "CodeBlock.h" |
| 35 | #include "DFGBasicBlock.h" |
| 36 | #include "DFGNode.h" |
| 37 | #include "FTLExitArgument.h" |
oliver@apple.com | ea77149 | 2013-07-25 03:58:38 +0000 | [diff] [blame] | 38 | #include "FTLJITCode.h" |
sbarati@apple.com | 5bebda7 | 2015-11-10 07:48:54 +0000 | [diff] [blame] | 39 | #include "FTLLocation.h" |
fpizlo@apple.com | e362fbc | 2015-12-03 20:01:57 +0000 | [diff] [blame] | 40 | #include "FTLState.h" |
fpizlo@apple.com | fb7eff2 | 2014-02-11 01:45:50 +0000 | [diff] [blame] | 41 | #include "JSCInlines.h" |
oliver@apple.com | ea77149 | 2013-07-25 03:58:38 +0000 | [diff] [blame] | 42 | |
| 43 | namespace JSC { namespace FTL { |
| 44 | |
fpizlo@apple.com | e362fbc | 2015-12-03 20:01:57 +0000 | [diff] [blame] | 45 | using namespace B3; |
oliver@apple.com | ea77149 | 2013-07-25 03:58:38 +0000 | [diff] [blame] | 46 | using namespace DFG; |
| 47 | |
sbarati@apple.com | cda241d | 2015-10-19 20:29:45 +0000 | [diff] [blame] | 48 | OSRExitDescriptor::OSRExitDescriptor( |
sbarati@apple.com | 936707d | 2015-12-03 21:09:41 +0000 | [diff] [blame] | 49 | DataFormat profileDataFormat, MethodOfGettingAValueProfile valueProfile, |
| 50 | unsigned numberOfArguments, unsigned numberOfLocals) |
| 51 | : m_profileDataFormat(profileDataFormat) |
oliver@apple.com | ea77149 | 2013-07-25 03:58:38 +0000 | [diff] [blame] | 52 | , m_valueProfile(valueProfile) |
oliver@apple.com | ea77149 | 2013-07-25 03:58:38 +0000 | [diff] [blame] | 53 | , m_values(numberOfArguments, numberOfLocals) |
sbarati@apple.com | cda241d | 2015-10-19 20:29:45 +0000 | [diff] [blame] | 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 | |
yusukesuzuki@slowstart.org | a4f027e | 2018-10-10 18:29:44 +0000 | [diff] [blame] | 66 | Ref<OSRExitHandle> OSRExitDescriptor::emitOSRExit( |
fpizlo@apple.com | 9ed1b63 | 2015-12-07 19:17:56 +0000 | [diff] [blame] | 67 | State& state, ExitKind exitKind, const NodeOrigin& nodeOrigin, CCallHelpers& jit, |
sbarati@apple.com | fb6a8e2 | 2016-01-29 19:46:01 +0000 | [diff] [blame] | 68 | const StackmapGenerationParams& params, unsigned offset) |
oliver@apple.com | ea77149 | 2013-07-25 03:58:38 +0000 | [diff] [blame] | 69 | { |
yusukesuzuki@slowstart.org | a4f027e | 2018-10-10 18:29:44 +0000 | [diff] [blame] | 70 | Ref<OSRExitHandle> handle = |
sbarati@apple.com | fb6a8e2 | 2016-01-29 19:46:01 +0000 | [diff] [blame] | 71 | prepareOSRExitHandle(state, exitKind, nodeOrigin, params, offset); |
fpizlo@apple.com | 28c7100 | 2016-01-15 19:41:56 +0000 | [diff] [blame] | 72 | handle->emitExitThunk(state, jit); |
fpizlo@apple.com | e362fbc | 2015-12-03 20:01:57 +0000 | [diff] [blame] | 73 | return handle; |
| 74 | } |
| 75 | |
yusukesuzuki@slowstart.org | a4f027e | 2018-10-10 18:29:44 +0000 | [diff] [blame] | 76 | Ref<OSRExitHandle> OSRExitDescriptor::emitOSRExitLater( |
fpizlo@apple.com | 9ed1b63 | 2015-12-07 19:17:56 +0000 | [diff] [blame] | 77 | State& state, ExitKind exitKind, const NodeOrigin& nodeOrigin, |
sbarati@apple.com | fb6a8e2 | 2016-01-29 19:46:01 +0000 | [diff] [blame] | 78 | const StackmapGenerationParams& params, unsigned offset) |
fpizlo@apple.com | e362fbc | 2015-12-03 20:01:57 +0000 | [diff] [blame] | 79 | { |
fpizlo@apple.com | 9ed1b63 | 2015-12-07 19:17:56 +0000 | [diff] [blame] | 80 | RefPtr<OSRExitHandle> handle = |
sbarati@apple.com | fb6a8e2 | 2016-01-29 19:46:01 +0000 | [diff] [blame] | 81 | prepareOSRExitHandle(state, exitKind, nodeOrigin, params, offset); |
fpizlo@apple.com | 9ed1b63 | 2015-12-07 19:17:56 +0000 | [diff] [blame] | 82 | params.addLatePath( |
fpizlo@apple.com | 28c7100 | 2016-01-15 19:41:56 +0000 | [diff] [blame] | 83 | [handle, &state] (CCallHelpers& jit) { |
| 84 | handle->emitExitThunk(state, jit); |
fpizlo@apple.com | 9ed1b63 | 2015-12-07 19:17:56 +0000 | [diff] [blame] | 85 | }); |
yusukesuzuki@slowstart.org | a4f027e | 2018-10-10 18:29:44 +0000 | [diff] [blame] | 86 | return handle.releaseNonNull(); |
fpizlo@apple.com | e362fbc | 2015-12-03 20:01:57 +0000 | [diff] [blame] | 87 | } |
| 88 | |
yusukesuzuki@slowstart.org | a4f027e | 2018-10-10 18:29:44 +0000 | [diff] [blame] | 89 | Ref<OSRExitHandle> OSRExitDescriptor::prepareOSRExitHandle( |
fpizlo@apple.com | 9ed1b63 | 2015-12-07 19:17:56 +0000 | [diff] [blame] | 90 | State& state, ExitKind exitKind, const NodeOrigin& nodeOrigin, |
sbarati@apple.com | fb6a8e2 | 2016-01-29 19:46:01 +0000 | [diff] [blame] | 91 | const StackmapGenerationParams& params, unsigned offset) |
fpizlo@apple.com | e362fbc | 2015-12-03 20:01:57 +0000 | [diff] [blame] | 92 | { |
| 93 | unsigned index = state.jitCode->osrExit.size(); |
fpizlo@apple.com | 9ed1b63 | 2015-12-07 19:17:56 +0000 | [diff] [blame] | 94 | OSRExit& exit = state.jitCode->osrExit.alloc( |
fpizlo@apple.com | 25fcaeb | 2016-05-19 21:25:29 +0000 | [diff] [blame] | 95 | this, exitKind, nodeOrigin.forExit, nodeOrigin.semantic, nodeOrigin.wasHoisted); |
yusukesuzuki@slowstart.org | a4f027e | 2018-10-10 18:29:44 +0000 | [diff] [blame] | 96 | Ref<OSRExitHandle> handle = adoptRef(*new OSRExitHandle(index, exit)); |
fpizlo@apple.com | 9ed1b63 | 2015-12-07 19:17:56 +0000 | [diff] [blame] | 97 | for (unsigned i = offset; i < params.size(); ++i) |
| 98 | exit.m_valueReps.append(params[i]); |
| 99 | exit.m_valueReps.shrinkToFit(); |
fpizlo@apple.com | e362fbc | 2015-12-03 20:01:57 +0000 | [diff] [blame] | 100 | return handle; |
| 101 | } |
fpizlo@apple.com | e362fbc | 2015-12-03 20:01:57 +0000 | [diff] [blame] | 102 | |
| 103 | OSRExit::OSRExit( |
fpizlo@apple.com | 25fcaeb | 2016-05-19 21:25:29 +0000 | [diff] [blame] | 104 | OSRExitDescriptor* descriptor, ExitKind exitKind, CodeOrigin codeOrigin, |
| 105 | CodeOrigin codeOriginForExitProfile, bool wasHoisted) |
| 106 | : OSRExitBase(exitKind, codeOrigin, codeOriginForExitProfile, wasHoisted) |
fpizlo@apple.com | 9ed1b63 | 2015-12-07 19:17:56 +0000 | [diff] [blame] | 107 | , m_descriptor(descriptor) |
| 108 | { |
fpizlo@apple.com | 9ed1b63 | 2015-12-07 19:17:56 +0000 | [diff] [blame] | 109 | } |
oliver@apple.com | ea77149 | 2013-07-25 03:58:38 +0000 | [diff] [blame] | 110 | |
mark.lam@apple.com | de0dba7 | 2018-04-18 03:31:09 +0000 | [diff] [blame] | 111 | CodeLocationJump<JSInternalPtrTag> OSRExit::codeLocationForRepatch(CodeBlock* ftlCodeBlock) const |
oliver@apple.com | ea77149 | 2013-07-25 03:58:38 +0000 | [diff] [blame] | 112 | { |
fpizlo@apple.com | e362fbc | 2015-12-03 20:01:57 +0000 | [diff] [blame] | 113 | UNUSED_PARAM(ftlCodeBlock); |
| 114 | return m_patchableJump; |
oliver@apple.com | ea77149 | 2013-07-25 03:58:38 +0000 | [diff] [blame] | 115 | } |
| 116 | |
oliver@apple.com | ea77149 | 2013-07-25 03:58:38 +0000 | [diff] [blame] | 117 | } } // namespace JSC::FTL |
| 118 | |
| 119 | #endif // ENABLE(FTL_JIT) |
| 120 | |
mark.lam@apple.com | ce1c89f | 2018-01-23 20:39:34 +0000 | [diff] [blame] | 121 | |