1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 * vim: set ts=4 sw=4 et tw=99:
4 * ***** BEGIN LICENSE BLOCK *****
5 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
7 * The contents of this file are subject to the Mozilla Public License Version
8 * 1.1 (the "License"); you may not use this file except in compliance with
9 * the License. You may obtain a copy of the License at
10 * http://www.mozilla.org/MPL/
12 * Software distributed under the License is distributed on an "AS IS" basis,
13 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
14 * for the specific language governing rights and limitations under the
17 * The Original Code is Mozilla SpiderMonkey JavaScript 1.9 code, released
20 * The Initial Developer of the Original Code is
21 * Brendan Eich <brendan@mozilla.org>
24 * David Anderson <danderson@mozilla.com>
25 * David Mandelin <dmandelin@mozilla.com>
27 * Alternatively, the contents of this file may be used under the terms of
28 * either of the GNU General Public License Version 2 or later (the "GPL"),
29 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
30 * in which case the provisions of the GPL or the LGPL are applicable instead
31 * of those above. If you wish to allow use of your version of this file only
32 * under the terms of either the GPL or the LGPL, and not to allow others to
33 * use your version of this file under the terms of the MPL, indicate your
34 * decision by deleting the provisions above and replace them with the notice
35 * and other provisions required by the GPL or the LGPL. If you do not delete
36 * the provisions above, a recipient may use your version of this file under
37 * the terms of any one of the MPL, the GPL or the LGPL.
39 * ***** END LICENSE BLOCK ***** */
41 #if !defined jsjaeger_mono_ic_h__ && defined JS_METHODJIT && defined JS_MONOIC
42 #define jsjaeger_mono_ic_h__
44 #include "assembler/assembler/MacroAssembler.h"
45 #include "assembler/assembler/CodeLocation.h"
46 #include "assembler/moco/MocoStubs.h"
47 #include "methodjit/MethodJIT.h"
48 #include "CodeGenIncludes.h"
49 #include "methodjit/ICRepatcher.h"
56 uint32 frameDepth_ : 16;
59 void initStatic(uint32 frameDepth, uint32 argc) {
60 JS_ASSERT(frameDepth > 0);
61 frameDepth_ = frameDepth;
67 argc_ = -1; /* quiet gcc */
70 bool isStatic() const {
71 return frameDepth_ > 0;
74 bool isDynamic() const {
75 return frameDepth_ == 0;
78 uint32 staticLocalSlots() const {
79 JS_ASSERT(isStatic());
83 uint32 staticArgc() const {
84 JS_ASSERT(isStatic());
88 uint32 getArgc(VMFrame &f) const {
89 return isStatic() ? staticArgc() : f.u.call.dynamicArgc;
97 typedef JSC::MacroAssembler::RegisterID RegisterID;
99 JSC::CodeLocationLabel fastPathStart;
100 JSC::CodeLocationCall slowPathCall;
103 * - ARM and x64 always emit exactly one instruction which needs to be
104 * patched. On ARM, the label points to the patched instruction, whilst
105 * on x64 it points to the instruction after it.
106 * - For x86, the label "load" points to the start of the load/store
107 * sequence, which may consist of one or two "mov" instructions. Because
108 * of this, x86 is the only platform which requires non-trivial patching
111 int32 loadStoreOffset : 15;
112 int32 shapeOffset : 15;
113 bool usePropertyCache : 1;
116 struct GetGlobalNameIC : public GlobalNameIC
120 struct SetGlobalNameIC : public GlobalNameIC
122 JSC::CodeLocationLabel slowPathStart;
124 /* Dynamically generted stub for method-write checks. */
125 JSC::JITCode extraStub;
127 /* SET only, if we had to generate an out-of-line path. */
128 int inlineShapeJump : 10; /* Offset into inline path for shape jump. */
129 int extraShapeGuard : 6; /* Offset into stub for shape guard. */
130 bool objConst : 1; /* True if the object is constant. */
131 RegisterID objReg : 5; /* Register for object, if objConst is false. */
132 RegisterID shapeReg : 5; /* Register for shape; volatile. */
133 bool hasExtraStub : 1; /* Extra stub is preset. */
135 int fastRejoinOffset : 16; /* Offset from fastPathStart to rejoin. */
136 int extraStoreOffset : 16; /* Offset into store code. */
139 ValueRemat vr; /* RHS value. */
141 void patchInlineShapeGuard(Repatcher &repatcher, int32 shape);
142 void patchExtraShapeGuard(Repatcher &repatcher, int32 shape);
148 JSC::CodeLocationLabel stubEntry;
149 JSC::CodeLocationLabel jumpTarget;
150 JSC::CodeLocationJump traceHint;
151 JSC::CodeLocationJump slowTraceHint;
153 jsbytecode *jumpTargetPC;
156 /* This data is used by the tracing JIT. */
160 uint32 loopCounterStart;
162 bool initialized : 1;
163 bool hasSlowTraceHint : 1;
166 static const uint16 BAD_TRACEIC_INDEX = (uint16)0xffff;
168 void JS_FASTCALL GetGlobalName(VMFrame &f, ic::GetGlobalNameIC *ic);
169 void JS_FASTCALL SetGlobalName(VMFrame &f, ic::SetGlobalNameIC *ic);
171 struct EqualityICInfo {
172 typedef JSC::MacroAssembler::RegisterID RegisterID;
174 JSC::CodeLocationLabel stubEntry;
175 JSC::CodeLocationCall stubCall;
177 JSC::CodeLocationLabel target;
178 JSC::CodeLocationLabel fallThrough;
179 JSC::CodeLocationJump jumpToStub;
184 JSC::MacroAssembler::RegisterID tempReg : 5;
185 Assembler::Condition cond;
188 JSBool JS_FASTCALL Equality(VMFrame &f, ic::EqualityICInfo *ic);
190 /* See MonoIC.cpp, CallCompiler for more information on call ICs. */
192 typedef JSC::MacroAssembler::RegisterID RegisterID;
201 JSC::ExecutablePool *pools[Total_Pools];
203 /* Used for rooting and reification. */
204 JSObject *fastGuardedObject;
205 JSObject *fastGuardedNative;
207 /* PC at the call site. */
212 /* Function object identity guard. */
213 JSC::CodeLocationDataLabelPtr funGuard;
215 /* Starting point for all slow call paths. */
216 JSC::CodeLocationLabel slowPathStart;
218 /* Inline to OOL jump, redirected by stubs. */
219 JSC::CodeLocationJump funJump;
221 /* Offset to inline scripted call, from funGuard. */
222 uint32 hotJumpOffset : 16;
223 uint32 joinPointOffset : 16;
225 /* Out of line slow call. */
226 uint32 oolCallOffset : 16;
228 /* Jump to patch for out-of-line scripted calls. */
229 uint32 oolJumpOffset : 16;
231 /* Label for out-of-line call to IC function. */
232 uint32 icCallOffset : 16;
234 /* Offset for deep-fun check to rejoin at. */
235 uint32 hotPathOffset : 16;
237 /* Join point for all slow call paths. */
238 uint32 slowJoinOffset : 16;
240 RegisterID funObjReg : 5;
241 RegisterID funPtrReg : 5;
243 bool hasJsFunCheck : 1;
245 inline void reset() {
246 fastGuardedObject = NULL;
247 fastGuardedNative = NULL;
249 hasJsFunCheck = false;
250 pools[0] = pools[1] = pools[2] = NULL;
253 inline void releasePools() {
254 releasePool(Pool_ScriptStub);
255 releasePool(Pool_ClosureStub);
256 releasePool(Pool_NativeStub);
259 inline void releasePool(PoolIndex index) {
261 pools[index]->release();
267 void * JS_FASTCALL New(VMFrame &f, ic::CallICInfo *ic);
268 void * JS_FASTCALL Call(VMFrame &f, ic::CallICInfo *ic);
269 void JS_FASTCALL NativeNew(VMFrame &f, ic::CallICInfo *ic);
270 void JS_FASTCALL NativeCall(VMFrame &f, ic::CallICInfo *ic);
271 JSBool JS_FASTCALL SplatApplyArgs(VMFrame &f);
273 void PurgeMICs(JSContext *cx, JSScript *script);
274 void SweepCallICs(JSContext *cx, JSScript *script, bool purgeAll);
277 } /* namespace mjit */
280 #endif /* jsjaeger_mono_ic_h__ */