]> git.saurik.com Git - apple/javascriptcore.git/blob - jit/JITStubs.h
JavaScriptCore-621.1.tar.gz
[apple/javascriptcore.git] / jit / JITStubs.h
1 /*
2 * Copyright (C) 2008 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 *
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
14 * its contributors may be used to endorse or promote products derived
15 * from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
18 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29 #ifndef JITStubs_h
30 #define JITStubs_h
31
32 #include "MacroAssemblerCodeRef.h"
33 #include "Register.h"
34 #include "ThunkGenerators.h"
35 #include <wtf/HashMap.h>
36
37 #if ENABLE(JIT)
38
39 namespace JSC {
40
41 struct StructureStubInfo;
42
43 class CodeBlock;
44 class ExecutablePool;
45 class FunctionExecutable;
46 class Identifier;
47 class JSGlobalData;
48 class JSGlobalObject;
49 class JSObject;
50 class JSPropertyNameIterator;
51 class JSValue;
52 class JSValueEncodedAsPointer;
53 class NativeExecutable;
54 class Profiler;
55 class PropertySlot;
56 class PutPropertySlot;
57 class RegisterFile;
58 class RegExp;
59
60 union JITStubArg {
61 void* asPointer;
62 EncodedJSValue asEncodedJSValue;
63 int32_t asInt32;
64
65 JSValue jsValue() { return JSValue::decode(asEncodedJSValue); }
66 JSObject* jsObject() { return static_cast<JSObject*>(asPointer); }
67 Identifier& identifier() { return *static_cast<Identifier*>(asPointer); }
68 int32_t int32() { return asInt32; }
69 CodeBlock* codeBlock() { return static_cast<CodeBlock*>(asPointer); }
70 FunctionExecutable* function() { return static_cast<FunctionExecutable*>(asPointer); }
71 RegExp* regExp() { return static_cast<RegExp*>(asPointer); }
72 JSPropertyNameIterator* propertyNameIterator() { return static_cast<JSPropertyNameIterator*>(asPointer); }
73 JSGlobalObject* globalObject() { return static_cast<JSGlobalObject*>(asPointer); }
74 JSString* jsString() { return static_cast<JSString*>(asPointer); }
75 ReturnAddressPtr returnAddress() { return ReturnAddressPtr(asPointer); }
76 };
77
78 struct TrampolineStructure {
79 MacroAssemblerCodePtr ctiStringLengthTrampoline;
80 MacroAssemblerCodePtr ctiVirtualCallLink;
81 MacroAssemblerCodePtr ctiVirtualCall;
82 RefPtr<NativeExecutable> ctiNativeCallThunk;
83 MacroAssemblerCodePtr ctiSoftModulo;
84 };
85
86 #if CPU(X86_64)
87 struct JITStackFrame {
88 void* reserved; // Unused
89 JITStubArg args[6];
90 void* padding[2]; // Maintain 32-byte stack alignment (possibly overkill).
91
92 void* code;
93 RegisterFile* registerFile;
94 CallFrame* callFrame;
95 JSValue* exception;
96 Profiler** enabledProfilerReference;
97 JSGlobalData* globalData;
98
99 void* savedRBX;
100 void* savedR15;
101 void* savedR14;
102 void* savedR13;
103 void* savedR12;
104 void* savedRBP;
105 void* savedRIP;
106
107 // When JIT code makes a call, it pushes its return address just below the rest of the stack.
108 ReturnAddressPtr* returnAddressSlot() { return reinterpret_cast<ReturnAddressPtr*>(this) - 1; }
109 };
110 #elif CPU(X86)
111 #if COMPILER(MSVC) || (OS(WINDOWS) && COMPILER(GCC))
112 #pragma pack(push)
113 #pragma pack(4)
114 #endif // COMPILER(MSVC) || (OS(WINDOWS) && COMPILER(GCC))
115 struct JITStackFrame {
116 void* reserved; // Unused
117 JITStubArg args[6];
118 #if USE(JSVALUE32_64)
119 void* padding[2]; // Maintain 16-byte stack alignment.
120 #endif
121
122 void* savedEBX;
123 void* savedEDI;
124 void* savedESI;
125 void* savedEBP;
126 void* savedEIP;
127
128 void* code;
129 RegisterFile* registerFile;
130 CallFrame* callFrame;
131 JSValue* exception;
132 Profiler** enabledProfilerReference;
133 JSGlobalData* globalData;
134
135 // When JIT code makes a call, it pushes its return address just below the rest of the stack.
136 ReturnAddressPtr* returnAddressSlot() { return reinterpret_cast<ReturnAddressPtr*>(this) - 1; }
137 };
138 #if COMPILER(MSVC) || (OS(WINDOWS) && COMPILER(GCC))
139 #pragma pack(pop)
140 #endif // COMPILER(MSVC) || (OS(WINDOWS) && COMPILER(GCC))
141 #elif CPU(ARM_THUMB2)
142 struct JITStackFrame {
143 void* reserved; // Unused
144 JITStubArg args[6];
145 #if USE(JSVALUE32_64)
146 void* padding[2]; // Maintain 16-byte stack alignment.
147 #endif
148
149 ReturnAddressPtr thunkReturnAddress;
150
151 void* preservedReturnAddress;
152 void* preservedR4;
153 void* preservedR5;
154 void* preservedR6;
155
156 // These arguments passed in r1..r3 (r0 contained the entry code pointed, which is not preserved)
157 RegisterFile* registerFile;
158 CallFrame* callFrame;
159 JSValue* exception;
160
161 void* padding2;
162
163 // These arguments passed on the stack.
164 Profiler** enabledProfilerReference;
165 JSGlobalData* globalData;
166
167 ReturnAddressPtr* returnAddressSlot() { return &thunkReturnAddress; }
168 };
169 #elif CPU(ARM_TRADITIONAL)
170 struct JITStackFrame {
171 JITStubArg padding; // Unused
172 JITStubArg args[7];
173
174 ReturnAddressPtr thunkReturnAddress;
175
176 void* preservedR4;
177 void* preservedR5;
178 void* preservedR6;
179 void* preservedR7;
180 void* preservedR8;
181 void* preservedLink;
182
183 RegisterFile* registerFile;
184 CallFrame* callFrame;
185 JSValue* exception;
186
187 // These arguments passed on the stack.
188 Profiler** enabledProfilerReference;
189 JSGlobalData* globalData;
190
191 // When JIT code makes a call, it pushes its return address just below the rest of the stack.
192 ReturnAddressPtr* returnAddressSlot() { return &thunkReturnAddress; }
193 };
194 #elif CPU(MIPS)
195 struct JITStackFrame {
196 void* reserved; // Unused
197 JITStubArg args[6];
198
199 void* preservedGP; // store GP when using PIC code
200 void* preservedS0;
201 void* preservedS1;
202 void* preservedS2;
203 void* preservedReturnAddress;
204
205 ReturnAddressPtr thunkReturnAddress;
206
207 // These arguments passed in a1..a3 (a0 contained the entry code pointed, which is not preserved)
208 RegisterFile* registerFile;
209 CallFrame* callFrame;
210 JSValue* exception;
211
212 // These arguments passed on the stack.
213 Profiler** enabledProfilerReference;
214 JSGlobalData* globalData;
215
216 ReturnAddressPtr* returnAddressSlot() { return &thunkReturnAddress; }
217 };
218 #else
219 #error "JITStackFrame not defined for this platform."
220 #endif
221
222 #define JITSTACKFRAME_ARGS_INDEX (OBJECT_OFFSETOF(JITStackFrame, args) / sizeof(void*))
223
224 #if USE(JIT_STUB_ARGUMENT_VA_LIST)
225 #define STUB_ARGS_DECLARATION void* args, ...
226 #define STUB_ARGS (reinterpret_cast<void**>(vl_args) - 1)
227
228 #if COMPILER(MSVC)
229 #define JIT_STUB __cdecl
230 #else
231 #define JIT_STUB
232 #endif
233 #else
234 #define STUB_ARGS_DECLARATION void** args
235 #define STUB_ARGS (args)
236
237 #if CPU(X86) && COMPILER(MSVC)
238 #define JIT_STUB __fastcall
239 #elif CPU(X86) && COMPILER(GCC)
240 #define JIT_STUB __attribute__ ((fastcall))
241 #else
242 #define JIT_STUB
243 #endif
244 #endif
245
246 #if CPU(X86_64)
247 struct VoidPtrPair {
248 void* first;
249 void* second;
250 };
251 #define RETURN_POINTER_PAIR(a,b) VoidPtrPair pair = { a, b }; return pair
252 #else
253 // MSVC doesn't support returning a two-value struct in two registers, so
254 // we cast the struct to int64_t instead.
255 typedef uint64_t VoidPtrPair;
256 union VoidPtrPairUnion {
257 struct { void* first; void* second; } s;
258 VoidPtrPair i;
259 };
260 #define RETURN_POINTER_PAIR(a,b) VoidPtrPairUnion pair = {{ a, b }}; return pair.i
261 #endif
262
263 extern "C" void ctiVMThrowTrampoline();
264 extern "C" void ctiOpThrowNotCaught();
265 extern "C" EncodedJSValue ctiTrampoline(void* code, RegisterFile*, CallFrame*, JSValue* exception, Profiler**, JSGlobalData*);
266
267 class JITThunks {
268 public:
269 JITThunks(JSGlobalData*);
270 ~JITThunks();
271
272 static void tryCacheGetByID(CallFrame*, CodeBlock*, ReturnAddressPtr returnAddress, JSValue baseValue, const Identifier& propertyName, const PropertySlot&, StructureStubInfo* stubInfo);
273 static void tryCachePutByID(CallFrame*, CodeBlock*, ReturnAddressPtr returnAddress, JSValue baseValue, const PutPropertySlot&, StructureStubInfo* stubInfo, bool direct);
274
275 MacroAssemblerCodePtr ctiStringLengthTrampoline() { return m_trampolineStructure.ctiStringLengthTrampoline; }
276 MacroAssemblerCodePtr ctiVirtualCallLink() { return m_trampolineStructure.ctiVirtualCallLink; }
277 MacroAssemblerCodePtr ctiVirtualCall() { return m_trampolineStructure.ctiVirtualCall; }
278 NativeExecutable* ctiNativeCallThunk() { return m_trampolineStructure.ctiNativeCallThunk.get(); }
279 MacroAssemblerCodePtr ctiSoftModulo() { return m_trampolineStructure.ctiSoftModulo; }
280
281 NativeExecutable* specializedThunk(JSGlobalData* globalData, ThunkGenerator generator);
282 private:
283 typedef HashMap<ThunkGenerator, RefPtr<NativeExecutable> > ThunkMap;
284 ThunkMap m_thunkMap;
285 RefPtr<ExecutablePool> m_executablePool;
286
287 TrampolineStructure m_trampolineStructure;
288 };
289
290 extern "C" {
291 EncodedJSValue JIT_STUB cti_op_add(STUB_ARGS_DECLARATION);
292 EncodedJSValue JIT_STUB cti_op_bitand(STUB_ARGS_DECLARATION);
293 EncodedJSValue JIT_STUB cti_op_bitnot(STUB_ARGS_DECLARATION);
294 EncodedJSValue JIT_STUB cti_op_bitor(STUB_ARGS_DECLARATION);
295 EncodedJSValue JIT_STUB cti_op_bitxor(STUB_ARGS_DECLARATION);
296 EncodedJSValue JIT_STUB cti_op_call_NotJSFunction(STUB_ARGS_DECLARATION);
297 EncodedJSValue JIT_STUB cti_op_call_eval(STUB_ARGS_DECLARATION);
298 EncodedJSValue JIT_STUB cti_op_construct_NotJSConstruct(STUB_ARGS_DECLARATION);
299 EncodedJSValue JIT_STUB cti_op_convert_this(STUB_ARGS_DECLARATION);
300 EncodedJSValue JIT_STUB cti_op_del_by_id(STUB_ARGS_DECLARATION);
301 EncodedJSValue JIT_STUB cti_op_del_by_val(STUB_ARGS_DECLARATION);
302 EncodedJSValue JIT_STUB cti_op_div(STUB_ARGS_DECLARATION);
303 EncodedJSValue JIT_STUB cti_op_get_by_id(STUB_ARGS_DECLARATION);
304 EncodedJSValue JIT_STUB cti_op_get_by_id_array_fail(STUB_ARGS_DECLARATION);
305 EncodedJSValue JIT_STUB cti_op_get_by_id_generic(STUB_ARGS_DECLARATION);
306 EncodedJSValue JIT_STUB cti_op_get_by_id_method_check(STUB_ARGS_DECLARATION);
307 EncodedJSValue JIT_STUB cti_op_get_by_id_getter_stub(STUB_ARGS_DECLARATION);
308 EncodedJSValue JIT_STUB cti_op_get_by_id_custom_stub(STUB_ARGS_DECLARATION);
309 EncodedJSValue JIT_STUB cti_op_get_by_id_proto_fail(STUB_ARGS_DECLARATION);
310 EncodedJSValue JIT_STUB cti_op_get_by_id_proto_list(STUB_ARGS_DECLARATION);
311 EncodedJSValue JIT_STUB cti_op_get_by_id_proto_list_full(STUB_ARGS_DECLARATION);
312 EncodedJSValue JIT_STUB cti_op_get_by_id_self_fail(STUB_ARGS_DECLARATION);
313 EncodedJSValue JIT_STUB cti_op_get_by_id_string_fail(STUB_ARGS_DECLARATION);
314 EncodedJSValue JIT_STUB cti_op_get_by_val(STUB_ARGS_DECLARATION);
315 EncodedJSValue JIT_STUB cti_op_get_by_val_byte_array(STUB_ARGS_DECLARATION);
316 EncodedJSValue JIT_STUB cti_op_get_by_val_string(STUB_ARGS_DECLARATION);
317 EncodedJSValue JIT_STUB cti_op_in(STUB_ARGS_DECLARATION);
318 EncodedJSValue JIT_STUB cti_op_instanceof(STUB_ARGS_DECLARATION);
319 EncodedJSValue JIT_STUB cti_op_is_boolean(STUB_ARGS_DECLARATION);
320 EncodedJSValue JIT_STUB cti_op_is_function(STUB_ARGS_DECLARATION);
321 EncodedJSValue JIT_STUB cti_op_is_number(STUB_ARGS_DECLARATION);
322 EncodedJSValue JIT_STUB cti_op_is_object(STUB_ARGS_DECLARATION);
323 EncodedJSValue JIT_STUB cti_op_is_string(STUB_ARGS_DECLARATION);
324 EncodedJSValue JIT_STUB cti_op_is_undefined(STUB_ARGS_DECLARATION);
325 EncodedJSValue JIT_STUB cti_op_less(STUB_ARGS_DECLARATION);
326 EncodedJSValue JIT_STUB cti_op_lesseq(STUB_ARGS_DECLARATION);
327 EncodedJSValue JIT_STUB cti_op_lshift(STUB_ARGS_DECLARATION);
328 EncodedJSValue JIT_STUB cti_op_mod(STUB_ARGS_DECLARATION);
329 EncodedJSValue JIT_STUB cti_op_mul(STUB_ARGS_DECLARATION);
330 EncodedJSValue JIT_STUB cti_op_negate(STUB_ARGS_DECLARATION);
331 EncodedJSValue JIT_STUB cti_op_not(STUB_ARGS_DECLARATION);
332 EncodedJSValue JIT_STUB cti_op_nstricteq(STUB_ARGS_DECLARATION);
333 EncodedJSValue JIT_STUB cti_op_post_dec(STUB_ARGS_DECLARATION);
334 EncodedJSValue JIT_STUB cti_op_post_inc(STUB_ARGS_DECLARATION);
335 EncodedJSValue JIT_STUB cti_op_pre_dec(STUB_ARGS_DECLARATION);
336 EncodedJSValue JIT_STUB cti_op_pre_inc(STUB_ARGS_DECLARATION);
337 EncodedJSValue JIT_STUB cti_op_resolve(STUB_ARGS_DECLARATION);
338 EncodedJSValue JIT_STUB cti_op_resolve_base(STUB_ARGS_DECLARATION);
339 EncodedJSValue JIT_STUB cti_op_resolve_global(STUB_ARGS_DECLARATION);
340 EncodedJSValue JIT_STUB cti_op_resolve_global_dynamic(STUB_ARGS_DECLARATION);
341 EncodedJSValue JIT_STUB cti_op_resolve_skip(STUB_ARGS_DECLARATION);
342 EncodedJSValue JIT_STUB cti_op_resolve_with_base(STUB_ARGS_DECLARATION);
343 EncodedJSValue JIT_STUB cti_op_rshift(STUB_ARGS_DECLARATION);
344 EncodedJSValue JIT_STUB cti_op_strcat(STUB_ARGS_DECLARATION);
345 EncodedJSValue JIT_STUB cti_op_stricteq(STUB_ARGS_DECLARATION);
346 EncodedJSValue JIT_STUB cti_op_sub(STUB_ARGS_DECLARATION);
347 EncodedJSValue JIT_STUB cti_op_throw(STUB_ARGS_DECLARATION);
348 EncodedJSValue JIT_STUB cti_op_to_jsnumber(STUB_ARGS_DECLARATION);
349 EncodedJSValue JIT_STUB cti_op_to_primitive(STUB_ARGS_DECLARATION);
350 EncodedJSValue JIT_STUB cti_op_typeof(STUB_ARGS_DECLARATION);
351 EncodedJSValue JIT_STUB cti_op_urshift(STUB_ARGS_DECLARATION);
352 EncodedJSValue JIT_STUB cti_vm_throw(STUB_ARGS_DECLARATION);
353 EncodedJSValue JIT_STUB cti_to_object(STUB_ARGS_DECLARATION);
354 JSObject* JIT_STUB cti_op_construct_JSConstruct(STUB_ARGS_DECLARATION);
355 JSObject* JIT_STUB cti_op_new_array(STUB_ARGS_DECLARATION);
356 JSObject* JIT_STUB cti_op_new_error(STUB_ARGS_DECLARATION);
357 JSObject* JIT_STUB cti_op_new_func(STUB_ARGS_DECLARATION);
358 JSObject* JIT_STUB cti_op_new_func_exp(STUB_ARGS_DECLARATION);
359 JSObject* JIT_STUB cti_op_new_object(STUB_ARGS_DECLARATION);
360 JSObject* JIT_STUB cti_op_new_regexp(STUB_ARGS_DECLARATION);
361 JSObject* JIT_STUB cti_op_push_activation(STUB_ARGS_DECLARATION);
362 JSObject* JIT_STUB cti_op_push_new_scope(STUB_ARGS_DECLARATION);
363 JSObject* JIT_STUB cti_op_push_scope(STUB_ARGS_DECLARATION);
364 JSObject* JIT_STUB cti_op_put_by_id_transition_realloc(STUB_ARGS_DECLARATION);
365 JSPropertyNameIterator* JIT_STUB cti_op_get_pnames(STUB_ARGS_DECLARATION);
366 VoidPtrPair JIT_STUB cti_op_call_arityCheck(STUB_ARGS_DECLARATION);
367 int JIT_STUB cti_op_eq(STUB_ARGS_DECLARATION);
368 int JIT_STUB cti_op_eq_strings(STUB_ARGS_DECLARATION);
369 int JIT_STUB cti_op_jless(STUB_ARGS_DECLARATION);
370 int JIT_STUB cti_op_jlesseq(STUB_ARGS_DECLARATION);
371 int JIT_STUB cti_op_jtrue(STUB_ARGS_DECLARATION);
372 int JIT_STUB cti_op_load_varargs(STUB_ARGS_DECLARATION);
373 int JIT_STUB cti_op_loop_if_lesseq(STUB_ARGS_DECLARATION);
374 int JIT_STUB cti_timeout_check(STUB_ARGS_DECLARATION);
375 int JIT_STUB cti_has_property(STUB_ARGS_DECLARATION);
376 void JIT_STUB cti_op_create_arguments(STUB_ARGS_DECLARATION);
377 void JIT_STUB cti_op_create_arguments_no_params(STUB_ARGS_DECLARATION);
378 void JIT_STUB cti_op_debug(STUB_ARGS_DECLARATION);
379 void JIT_STUB cti_op_end(STUB_ARGS_DECLARATION);
380 void JIT_STUB cti_op_jmp_scopes(STUB_ARGS_DECLARATION);
381 void JIT_STUB cti_op_pop_scope(STUB_ARGS_DECLARATION);
382 void JIT_STUB cti_op_profile_did_call(STUB_ARGS_DECLARATION);
383 void JIT_STUB cti_op_profile_will_call(STUB_ARGS_DECLARATION);
384 void JIT_STUB cti_op_put_by_id(STUB_ARGS_DECLARATION);
385 void JIT_STUB cti_op_put_by_id_fail(STUB_ARGS_DECLARATION);
386 void JIT_STUB cti_op_put_by_id_generic(STUB_ARGS_DECLARATION);
387 void JIT_STUB cti_op_put_by_id_direct(STUB_ARGS_DECLARATION);
388 void JIT_STUB cti_op_put_by_id_direct_fail(STUB_ARGS_DECLARATION);
389 void JIT_STUB cti_op_put_by_id_direct_generic(STUB_ARGS_DECLARATION);
390 void JIT_STUB cti_op_put_by_index(STUB_ARGS_DECLARATION);
391 void JIT_STUB cti_op_put_by_val(STUB_ARGS_DECLARATION);
392 void JIT_STUB cti_op_put_by_val_byte_array(STUB_ARGS_DECLARATION);
393 void JIT_STUB cti_op_put_getter(STUB_ARGS_DECLARATION);
394 void JIT_STUB cti_op_put_setter(STUB_ARGS_DECLARATION);
395 void JIT_STUB cti_op_ret_scopeChain(STUB_ARGS_DECLARATION);
396 void JIT_STUB cti_op_tear_off_activation(STUB_ARGS_DECLARATION);
397 void JIT_STUB cti_op_tear_off_arguments(STUB_ARGS_DECLARATION);
398 void JIT_STUB cti_register_file_check(STUB_ARGS_DECLARATION);
399 void* JIT_STUB cti_op_call_JSFunction(STUB_ARGS_DECLARATION);
400 void* JIT_STUB cti_op_switch_char(STUB_ARGS_DECLARATION);
401 void* JIT_STUB cti_op_switch_imm(STUB_ARGS_DECLARATION);
402 void* JIT_STUB cti_op_switch_string(STUB_ARGS_DECLARATION);
403 void* JIT_STUB cti_vm_lazyLinkCall(STUB_ARGS_DECLARATION);
404 } // extern "C"
405
406 } // namespace JSC
407
408 #endif // ENABLE(JIT)
409
410 #endif // JITStubs_h