1 | /* |
2 | * Copyright (C) 2016 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 | #pragma once |
27 | |
28 | #include "DFGCommon.h" |
29 | |
30 | #if ENABLE(FTL_JIT) |
31 | |
32 | #include "CallFrame.h" |
33 | #include "DFGNodeOrigin.h" |
34 | #include "ExitKind.h" |
35 | #include "HandlerInfo.h" |
36 | #include <wtf/Ref.h> |
37 | #include <wtf/ThreadSafeRefCounted.h> |
38 | |
39 | namespace JSC { |
40 | |
41 | namespace B3 { |
42 | class StackmapGenerationParams; |
43 | } // namespace B3 |
44 | |
45 | namespace FTL { |
46 | |
47 | class ExceptionTarget; |
48 | class State; |
49 | struct OSRExitDescriptor; |
50 | struct OSRExitHandle; |
51 | |
52 | class PatchpointExceptionHandle : public ThreadSafeRefCounted<PatchpointExceptionHandle> { |
53 | public: |
54 | static Ref<PatchpointExceptionHandle> create( |
55 | State&, OSRExitDescriptor*, DFG::NodeOrigin, unsigned offset, const HandlerInfo&); |
56 | |
57 | static RefPtr<PatchpointExceptionHandle> defaultHandle(State&); |
58 | |
59 | ~PatchpointExceptionHandle(); |
60 | |
61 | // Note that you can use this handle to schedule any number of exits. This capability is here for |
62 | // two reasons: |
63 | // |
64 | // - B3 code duplication. B3 could take a patchpoint and turn it into multiple patchpoints if it |
65 | // duplicates code. Duplicating code is legal since you can do it without changing the behavior |
66 | // of the program. One example is tail duplication. Another is jump threading. Yet another is |
67 | // path specialization. You will have one PatchpointExceptionHandle per patchpoint you create |
68 | // during DFG->B3 lowering, and that patchpoint will have a generator that calls |
69 | // handle->scheduleBlah(). That generator will be called multiple times if your patchpoint got |
70 | // duplicated. |
71 | // |
72 | // - Combination of unwind and non-unwind exception handlers inside one patchpoint. A GetById may |
73 | // need both an exception handler that serves as an unwind target and an exception handler that |
74 | // is branched to directly for operation calls emitted inside the patchpoint. In that case, |
75 | // you'll call both scheduleExitCreation() and scheduleExitCreationForUnwind() on the same |
76 | // handle. |
77 | |
78 | // Schedules the creation of an OSR exit jump destination. You don't know when this will be |
79 | // created, but it will happen before linking. You can link jumps to it during link time. That's |
80 | // why this returns an ExceptionTarget. That will contain the jump destination (target->label()) |
81 | // at link time. This function should be used for exceptions from C calls. |
82 | RefPtr<ExceptionTarget> scheduleExitCreation(const B3::StackmapGenerationParams&); |
83 | |
84 | // Schedules the creation of an OSR exit jump destination, and ensures that it gets associated |
85 | // with the handler for some callsite index. This function should be used for exceptions from JS. |
86 | void scheduleExitCreationForUnwind(const B3::StackmapGenerationParams&, CallSiteIndex); |
87 | |
88 | private: |
89 | PatchpointExceptionHandle( |
90 | State&, OSRExitDescriptor*, DFG::NodeOrigin, unsigned offset, const HandlerInfo&); |
91 | |
92 | Ref<OSRExitHandle> createHandle(ExitKind, const B3::StackmapGenerationParams&); |
93 | |
94 | State& m_state; |
95 | OSRExitDescriptor* m_descriptor; |
96 | DFG::NodeOrigin m_origin; |
97 | unsigned m_offset; |
98 | HandlerInfo m_handler; |
99 | }; |
100 | |
101 | } } // namespace JSC::FTL |
102 | |
103 | #endif // ENABLE(FTL_JIT) |
104 | |