Replace WTF::move with WTFMove
[WebKit-https.git] / Source / JavaScriptCore / ftl / FTLJITCode.cpp
1 /*
2  * Copyright (C) 2013, 2015 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 "FTLJITCode.h"
28
29 #if ENABLE(FTL_JIT)
30
31 #include "FTLState.h"
32
33 namespace JSC { namespace FTL {
34
35 using namespace B3;
36
37 JITCode::JITCode()
38     : JSC::JITCode(FTLJIT)
39 {
40 }
41
42 JITCode::~JITCode()
43 {
44     if (FTL::shouldDumpDisassembly()) {
45         dataLog("Destroying FTL JIT code at ");
46         CommaPrinter comma;
47 #if FTL_USES_B3
48         dataLog(comma, m_b3Code);
49         dataLog(comma, m_arityCheckEntrypoint);
50 #else
51         for (auto& handle : m_handles)
52             dataLog(comma, pointerDump(handle.get()));
53         dataLog(comma, pointerDump(m_arityCheckEntrypoint.executableMemory()));
54         dataLog(comma, pointerDump(m_exitThunks.executableMemory()));
55         dataLog("\n");
56 #endif
57     }
58 }
59
60 #if FTL_USES_B3
61 void JITCode::initializeB3Code(CodeRef b3Code)
62 {
63     m_b3Code = b3Code;
64 }
65
66 void JITCode::initializeB3Byproducts(std::unique_ptr<OpaqueByproducts> byproducts)
67 {
68     m_b3Byproducts = WTFMove(byproducts);
69 }
70 #else // FTL_USES_B3
71 void JITCode::initializeExitThunks(CodeRef exitThunks)
72 {
73     m_exitThunks = exitThunks;
74 }
75
76 void JITCode::addHandle(PassRefPtr<ExecutableMemoryHandle> handle)
77 {
78     m_handles.append(handle);
79 }
80
81 void JITCode::addDataSection(PassRefPtr<DataSection> dataSection)
82 {
83     m_dataSections.append(dataSection);
84 }
85 #endif // FTL_USES_B3
86
87 void JITCode::initializeAddressForCall(CodePtr address)
88 {
89     m_addressForCall = address;
90 }
91
92 void JITCode::initializeArityCheckEntrypoint(CodeRef entrypoint)
93 {
94     m_arityCheckEntrypoint = entrypoint;
95 }
96
97 JITCode::CodePtr JITCode::addressForCall(ArityCheckMode arityCheck)
98 {
99     switch (arityCheck) {
100     case ArityCheckNotRequired:
101         return m_addressForCall;
102     case MustCheckArity:
103         return m_arityCheckEntrypoint.code();
104     }
105     RELEASE_ASSERT_NOT_REACHED();
106     return CodePtr();
107 }
108
109 void* JITCode::executableAddressAtOffset(size_t offset)
110 {
111     return reinterpret_cast<char*>(m_addressForCall.executableAddress()) + offset;
112 }
113
114 void* JITCode::dataAddressAtOffset(size_t)
115 {
116     // We can't patch FTL code, yet. Even if we did, it's not clear that we would do so
117     // through this API.
118     RELEASE_ASSERT_NOT_REACHED();
119     return 0;
120 }
121
122 unsigned JITCode::offsetOf(void*)
123 {
124     // We currently don't have visibility into the FTL code.
125     RELEASE_ASSERT_NOT_REACHED();
126     return 0;
127 }
128
129 size_t JITCode::size()
130 {
131     // We don't know the size of FTL code, yet. Make a wild guess. This is mostly used for
132     // GC load estimates.
133     return 1000;
134 }
135
136 bool JITCode::contains(void*)
137 {
138     // We have no idea what addresses the FTL code contains, yet.
139     RELEASE_ASSERT_NOT_REACHED();
140     return false;
141 }
142
143 #if !FTL_USES_B3
144 JITCode::CodePtr JITCode::exitThunks()
145 {
146     return m_exitThunks.code();
147 }
148 #endif
149
150 JITCode* JITCode::ftl()
151 {
152     return this;
153 }
154
155 DFG::CommonData* JITCode::dfgCommon()
156 {
157     return &common;
158 }
159
160 void JITCode::validateReferences(const TrackedReferences& trackedReferences)
161 {
162     common.validateReferences(trackedReferences);
163     
164     for (OSRExit& exit : osrExit)
165         exit.m_descriptor->validateReferences(trackedReferences);
166 }
167
168 RegisterSet JITCode::liveRegistersToPreserveAtExceptionHandlingCallSite(CodeBlock*, CallSiteIndex callSiteIndex)
169 {
170 #if FTL_USES_B3
171     UNUSED_PARAM(callSiteIndex);
172 #else // FTL_USES_B3
173     for (OSRExit& exit : osrExit) {
174         if (exit.m_exceptionHandlerCallSiteIndex.bits() == callSiteIndex.bits()) {
175             RELEASE_ASSERT(exit.m_isExceptionHandler);
176             return stackmaps.records[exit.m_stackmapRecordIndex].usedRegisterSet();
177         }
178     }
179 #endif // FTL_USES_B3
180     return RegisterSet();
181 }
182
183 } } // namespace JSC::FTL
184
185 #endif // ENABLE(FTL_JIT)
186