The DFG should be able to tier-up and OSR enter into the FTL
[WebKit-https.git] / Source / JavaScriptCore / jit / JITCode.cpp
1 /*
2  * Copyright (C) 2008, 2012, 2013 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 "JITCode.h"
28
29 #include "Operations.h"
30 #include <wtf/PrintStream.h>
31
32 namespace JSC {
33
34 JITCode::JITCode(JITType jitType)
35     : m_jitType(jitType)
36 {
37 }
38
39 JITCode::~JITCode()
40 {
41 }
42
43 #if ENABLE(JIT)
44 JSValue JITCode::execute(JSStack* stack, CallFrame* callFrame, VM* vm)
45 {
46     JSValue result = JSValue::decode(ctiTrampoline(executableAddress(), stack, callFrame, 0, 0, vm));
47     return vm->exception() ? jsNull() : result;
48 }
49 #endif
50
51 DFG::CommonData* JITCode::dfgCommon()
52 {
53     RELEASE_ASSERT_NOT_REACHED();
54     return 0;
55 }
56
57 DFG::JITCode* JITCode::dfg()
58 {
59     RELEASE_ASSERT_NOT_REACHED();
60     return 0;
61 }
62
63 FTL::JITCode* JITCode::ftl()
64 {
65     RELEASE_ASSERT_NOT_REACHED();
66     return 0;
67 }
68
69 FTL::ForOSREntryJITCode* JITCode::ftlForOSREntry()
70 {
71     RELEASE_ASSERT_NOT_REACHED();
72     return 0;
73 }
74
75 PassRefPtr<JITCode> JITCode::hostFunction(JITCode::CodeRef code)
76 {
77     return adoptRef(new DirectJITCode(code, HostCallThunk));
78 }
79
80 DirectJITCode::DirectJITCode(JITType jitType)
81     : JITCode(jitType)
82 {
83 }
84
85 DirectJITCode::DirectJITCode(const JITCode::CodeRef ref, JITType jitType)
86     : JITCode(jitType)
87     , m_ref(ref)
88 {
89 }
90
91 DirectJITCode::~DirectJITCode()
92 {
93 }
94
95 void DirectJITCode::initializeCodeRef(const JITCode::CodeRef ref)
96 {
97     RELEASE_ASSERT(!m_ref);
98     m_ref = ref;
99 }
100
101 JITCode::CodePtr DirectJITCode::addressForCall()
102 {
103     RELEASE_ASSERT(m_ref);
104     return m_ref.code();
105 }
106
107 void* DirectJITCode::executableAddressAtOffset(size_t offset)
108 {
109     RELEASE_ASSERT(m_ref);
110     return reinterpret_cast<char*>(m_ref.code().executableAddress()) + offset;
111 }
112
113 void* DirectJITCode::dataAddressAtOffset(size_t offset)
114 {
115     RELEASE_ASSERT(m_ref);
116     ASSERT(offset <= size()); // use <= instead of < because it is valid to ask for an address at the exclusive end of the code.
117     return reinterpret_cast<char*>(m_ref.code().dataLocation()) + offset;
118 }
119
120 unsigned DirectJITCode::offsetOf(void* pointerIntoCode)
121 {
122     RELEASE_ASSERT(m_ref);
123     intptr_t result = reinterpret_cast<intptr_t>(pointerIntoCode) - reinterpret_cast<intptr_t>(m_ref.code().executableAddress());
124     ASSERT(static_cast<intptr_t>(static_cast<unsigned>(result)) == result);
125     return static_cast<unsigned>(result);
126 }
127
128 size_t DirectJITCode::size()
129 {
130     RELEASE_ASSERT(m_ref);
131     return m_ref.size();
132 }
133
134 bool DirectJITCode::contains(void* address)
135 {
136     RELEASE_ASSERT(m_ref);
137     return m_ref.executableMemory()->contains(address);
138 }
139
140 } // namespace JSC
141
142 namespace WTF {
143
144 void printInternal(PrintStream& out, JSC::JITCode::JITType type)
145 {
146     switch (type) {
147     case JSC::JITCode::None:
148         out.print("None");
149         return;
150     case JSC::JITCode::HostCallThunk:
151         out.print("Host");
152         return;
153     case JSC::JITCode::InterpreterThunk:
154         out.print("LLInt");
155         return;
156     case JSC::JITCode::BaselineJIT:
157         out.print("Baseline");
158         return;
159     case JSC::JITCode::DFGJIT:
160         out.print("DFG");
161         return;
162     case JSC::JITCode::FTLJIT:
163         out.print("FTL");
164         return;
165     default:
166         CRASH();
167         return;
168     }
169 }
170
171 } // namespace WTF
172