blob: 09958d2c4f9a5d89b5fbbb65f86bb6dabcdf18e3 [file] [log] [blame]
oliver@apple.comea771492013-07-25 03:58:38 +00001/*
mark.lam@apple.comde0dba72018-04-18 03:31:09 +00002 * Copyright (C) 2013-2018 Apple Inc. All rights reserved.
oliver@apple.comea771492013-07-25 03:58:38 +00003 *
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.come362fbc2015-12-03 20:01:57 +000031#include "AirGenerationContext.h"
fpizlo@apple.com9ed1b632015-12-07 19:17:56 +000032#include "B3StackmapGenerationParams.h"
fpizlo@apple.come362fbc2015-12-03 20:01:57 +000033#include "B3StackmapValue.h"
oliver@apple.comea771492013-07-25 03:58:38 +000034#include "CodeBlock.h"
35#include "DFGBasicBlock.h"
36#include "DFGNode.h"
37#include "FTLExitArgument.h"
oliver@apple.comea771492013-07-25 03:58:38 +000038#include "FTLJITCode.h"
sbarati@apple.com5bebda72015-11-10 07:48:54 +000039#include "FTLLocation.h"
fpizlo@apple.come362fbc2015-12-03 20:01:57 +000040#include "FTLState.h"
fpizlo@apple.comfb7eff22014-02-11 01:45:50 +000041#include "JSCInlines.h"
oliver@apple.comea771492013-07-25 03:58:38 +000042
43namespace JSC { namespace FTL {
44
fpizlo@apple.come362fbc2015-12-03 20:01:57 +000045using namespace B3;
oliver@apple.comea771492013-07-25 03:58:38 +000046using namespace DFG;
47
sbarati@apple.comcda241d2015-10-19 20:29:45 +000048OSRExitDescriptor::OSRExitDescriptor(
sbarati@apple.com936707d2015-12-03 21:09:41 +000049 DataFormat profileDataFormat, MethodOfGettingAValueProfile valueProfile,
50 unsigned numberOfArguments, unsigned numberOfLocals)
51 : m_profileDataFormat(profileDataFormat)
oliver@apple.comea771492013-07-25 03:58:38 +000052 , m_valueProfile(valueProfile)
oliver@apple.comea771492013-07-25 03:58:38 +000053 , m_values(numberOfArguments, numberOfLocals)
sbarati@apple.comcda241d2015-10-19 20:29:45 +000054{
55}
56
57void 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.orga4f027e2018-10-10 18:29:44 +000066Ref<OSRExitHandle> OSRExitDescriptor::emitOSRExit(
fpizlo@apple.com9ed1b632015-12-07 19:17:56 +000067 State& state, ExitKind exitKind, const NodeOrigin& nodeOrigin, CCallHelpers& jit,
sbarati@apple.comfb6a8e22016-01-29 19:46:01 +000068 const StackmapGenerationParams& params, unsigned offset)
oliver@apple.comea771492013-07-25 03:58:38 +000069{
yusukesuzuki@slowstart.orga4f027e2018-10-10 18:29:44 +000070 Ref<OSRExitHandle> handle =
sbarati@apple.comfb6a8e22016-01-29 19:46:01 +000071 prepareOSRExitHandle(state, exitKind, nodeOrigin, params, offset);
fpizlo@apple.com28c71002016-01-15 19:41:56 +000072 handle->emitExitThunk(state, jit);
fpizlo@apple.come362fbc2015-12-03 20:01:57 +000073 return handle;
74}
75
yusukesuzuki@slowstart.orga4f027e2018-10-10 18:29:44 +000076Ref<OSRExitHandle> OSRExitDescriptor::emitOSRExitLater(
fpizlo@apple.com9ed1b632015-12-07 19:17:56 +000077 State& state, ExitKind exitKind, const NodeOrigin& nodeOrigin,
sbarati@apple.comfb6a8e22016-01-29 19:46:01 +000078 const StackmapGenerationParams& params, unsigned offset)
fpizlo@apple.come362fbc2015-12-03 20:01:57 +000079{
fpizlo@apple.com9ed1b632015-12-07 19:17:56 +000080 RefPtr<OSRExitHandle> handle =
sbarati@apple.comfb6a8e22016-01-29 19:46:01 +000081 prepareOSRExitHandle(state, exitKind, nodeOrigin, params, offset);
fpizlo@apple.com9ed1b632015-12-07 19:17:56 +000082 params.addLatePath(
fpizlo@apple.com28c71002016-01-15 19:41:56 +000083 [handle, &state] (CCallHelpers& jit) {
84 handle->emitExitThunk(state, jit);
fpizlo@apple.com9ed1b632015-12-07 19:17:56 +000085 });
yusukesuzuki@slowstart.orga4f027e2018-10-10 18:29:44 +000086 return handle.releaseNonNull();
fpizlo@apple.come362fbc2015-12-03 20:01:57 +000087}
88
yusukesuzuki@slowstart.orga4f027e2018-10-10 18:29:44 +000089Ref<OSRExitHandle> OSRExitDescriptor::prepareOSRExitHandle(
fpizlo@apple.com9ed1b632015-12-07 19:17:56 +000090 State& state, ExitKind exitKind, const NodeOrigin& nodeOrigin,
sbarati@apple.comfb6a8e22016-01-29 19:46:01 +000091 const StackmapGenerationParams& params, unsigned offset)
fpizlo@apple.come362fbc2015-12-03 20:01:57 +000092{
93 unsigned index = state.jitCode->osrExit.size();
fpizlo@apple.com9ed1b632015-12-07 19:17:56 +000094 OSRExit& exit = state.jitCode->osrExit.alloc(
fpizlo@apple.com25fcaeb2016-05-19 21:25:29 +000095 this, exitKind, nodeOrigin.forExit, nodeOrigin.semantic, nodeOrigin.wasHoisted);
yusukesuzuki@slowstart.orga4f027e2018-10-10 18:29:44 +000096 Ref<OSRExitHandle> handle = adoptRef(*new OSRExitHandle(index, exit));
fpizlo@apple.com9ed1b632015-12-07 19:17:56 +000097 for (unsigned i = offset; i < params.size(); ++i)
98 exit.m_valueReps.append(params[i]);
99 exit.m_valueReps.shrinkToFit();
fpizlo@apple.come362fbc2015-12-03 20:01:57 +0000100 return handle;
101}
fpizlo@apple.come362fbc2015-12-03 20:01:57 +0000102
103OSRExit::OSRExit(
fpizlo@apple.com25fcaeb2016-05-19 21:25:29 +0000104 OSRExitDescriptor* descriptor, ExitKind exitKind, CodeOrigin codeOrigin,
105 CodeOrigin codeOriginForExitProfile, bool wasHoisted)
106 : OSRExitBase(exitKind, codeOrigin, codeOriginForExitProfile, wasHoisted)
fpizlo@apple.com9ed1b632015-12-07 19:17:56 +0000107 , m_descriptor(descriptor)
108{
fpizlo@apple.com9ed1b632015-12-07 19:17:56 +0000109}
oliver@apple.comea771492013-07-25 03:58:38 +0000110
mark.lam@apple.comde0dba72018-04-18 03:31:09 +0000111CodeLocationJump<JSInternalPtrTag> OSRExit::codeLocationForRepatch(CodeBlock* ftlCodeBlock) const
oliver@apple.comea771492013-07-25 03:58:38 +0000112{
fpizlo@apple.come362fbc2015-12-03 20:01:57 +0000113 UNUSED_PARAM(ftlCodeBlock);
114 return m_patchableJump;
oliver@apple.comea771492013-07-25 03:58:38 +0000115}
116
oliver@apple.comea771492013-07-25 03:58:38 +0000117} } // namespace JSC::FTL
118
119#endif // ENABLE(FTL_JIT)
120
mark.lam@apple.comce1c89f2018-01-23 20:39:34 +0000121