1 | /* |
2 | * Copyright (C) 2016-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 "FTLPatchpointExceptionHandle.h" |
28 | |
29 | #if ENABLE(FTL_JIT) |
30 | |
31 | #include "B3StackmapGenerationParams.h" |
32 | #include "FTLExceptionTarget.h" |
33 | #include "FTLOSRExit.h" |
34 | #include "FTLOSRExitHandle.h" |
35 | #include "FTLState.h" |
36 | |
37 | namespace JSC { namespace FTL { |
38 | |
39 | using namespace DFG; |
40 | |
41 | Ref<PatchpointExceptionHandle> PatchpointExceptionHandle::create( |
42 | State& state, OSRExitDescriptor* descriptor, NodeOrigin origin, unsigned offset, |
43 | const HandlerInfo& handler) |
44 | { |
45 | return adoptRef(*new PatchpointExceptionHandle(state, descriptor, origin, offset, handler)); |
46 | } |
47 | |
48 | RefPtr<PatchpointExceptionHandle> PatchpointExceptionHandle::defaultHandle(State& state) |
49 | { |
50 | if (!state.defaultExceptionHandle) { |
51 | state.defaultExceptionHandle = adoptRef( |
52 | new PatchpointExceptionHandle(state, nullptr, NodeOrigin(), 0, HandlerInfo())); |
53 | } |
54 | return state.defaultExceptionHandle; |
55 | } |
56 | |
57 | PatchpointExceptionHandle::~PatchpointExceptionHandle() |
58 | { |
59 | } |
60 | |
61 | RefPtr<ExceptionTarget> PatchpointExceptionHandle::scheduleExitCreation( |
62 | const B3::StackmapGenerationParams& params) |
63 | { |
64 | if (!m_descriptor) { |
65 | // NOTE: This object could be a singleton, however usually we toss the ExceptionHandler |
66 | // object shortly after creation. |
67 | bool isDefaultHandler = true; |
68 | return adoptRef( |
69 | new ExceptionTarget(isDefaultHandler, m_state.exceptionHandler, nullptr)); |
70 | } |
71 | bool isDefaultHandler = false; |
72 | return adoptRef(new ExceptionTarget(isDefaultHandler, { }, createHandle(ExceptionCheck, params))); |
73 | } |
74 | |
75 | void PatchpointExceptionHandle::scheduleExitCreationForUnwind( |
76 | const B3::StackmapGenerationParams& params, CallSiteIndex callSiteIndex) |
77 | { |
78 | if (!m_descriptor) |
79 | return; |
80 | |
81 | RefPtr<OSRExitHandle> handle = createHandle(GenericUnwind, params); |
82 | |
83 | handle->exit.m_exceptionHandlerCallSiteIndex = callSiteIndex; |
84 | |
85 | HandlerInfo handler = m_handler; |
86 | params.addLatePath( |
87 | [handle, handler, callSiteIndex] (CCallHelpers& jit) { |
88 | CodeBlock* codeBlock = jit.codeBlock(); |
89 | jit.addLinkTask( |
90 | [=] (LinkBuffer& linkBuffer) { |
91 | HandlerInfo newHandler = handler; |
92 | newHandler.start = callSiteIndex.bits(); |
93 | newHandler.end = callSiteIndex.bits() + 1; |
94 | newHandler.nativeCode = linkBuffer.locationOf<ExceptionHandlerPtrTag>(handle->label); |
95 | codeBlock->appendExceptionHandler(newHandler); |
96 | }); |
97 | }); |
98 | } |
99 | |
100 | PatchpointExceptionHandle::PatchpointExceptionHandle( |
101 | State& state, OSRExitDescriptor* descriptor, NodeOrigin origin, unsigned offset, |
102 | const HandlerInfo& handler) |
103 | : m_state(state) |
104 | , m_descriptor(descriptor) |
105 | , m_origin(origin) |
106 | , m_offset(offset) |
107 | , m_handler(handler) |
108 | { |
109 | } |
110 | |
111 | Ref<OSRExitHandle> PatchpointExceptionHandle::createHandle( |
112 | ExitKind kind, const B3::StackmapGenerationParams& params) |
113 | { |
114 | return m_descriptor->emitOSRExitLater( |
115 | m_state, kind, m_origin, params, m_offset); |
116 | } |
117 | |
118 | } } // namespace JSC::FTL |
119 | |
120 | #endif // ENABLE(FTL_JIT) |
121 | |
122 | |