[JAEGER] Added common call functionality to BaseAssembler.
authorDavid Anderson <danderson@mozilla.com>
Wed, 26 May 2010 17:49:34 -0700
changeset 52610 bc48920f686328efa2cf293305feb79bdb214ace
parent 52609 a6edb3f0d569ec5e339047cf800abd04c96d4dfc
child 52611 4b73e56e7acba439f9119356c9d0e68862609546
push id1
push userroot
push dateTue, 26 Apr 2011 22:38:44 +0000
treeherdermozilla-beta@bfdb6e623a36 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
milestone1.9.3a5pre
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
[JAEGER] Added common call functionality to BaseAssembler.
js/src/methodjit/BaseAssembler.h
js/src/methodjit/StubCompiler.cpp
js/src/methodjit/StubCompiler.h
--- a/js/src/methodjit/BaseAssembler.h
+++ b/js/src/methodjit/BaseAssembler.h
@@ -35,22 +35,60 @@
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 #if !defined jsjaeger_baseassembler_h__ && defined JS_METHODJIT
 #define jsjaeger_baseassembler_h__
 
+#include "jscntxt.h"
+#include "jstl.h"
+#include "assembler/assembler/MacroAssemblerCodeRef.h"
 #include "assembler/assembler/MacroAssembler.h"
 
 namespace js {
 namespace mjit {
 
 class BaseAssembler : public JSC::MacroAssembler
 {
+    struct CallPatch {
+        CallPatch(ptrdiff_t distance, void *fun)
+          : distance(distance), fun(fun)
+        { }
+
+        ptrdiff_t distance;
+        JSC::FunctionPtr fun;
+    };
+
+    /* :TODO: OOM */
+    Label startLabel;
+    Vector<CallPatch, 64, SystemAllocPolicy> callPatches;
+
   public:
+    BaseAssembler()
+      : callPatches(SystemAllocPolicy())
+    {
+        startLabel = label();
+    }
+
+    Call call(void *fun) {
+#if defined(_MSC_VER) && defined(_M_X64)
+        masm.subPtr(JSC::MacroAssembler::Imm32(32),
+                    JSC::MacroAssembler::stackPointerRegister);
+#endif
+
+        Call cl = JSC::MacroAssembler::call();
+
+#if defined(_MSC_VER) && defined(_M_X64)
+        masm.addPtr(JSC::MacroAssembler::Imm32(32),
+                    JSC::MacroAssembler::stackPointerRegister);
+#endif
+
+        callPatches.append(CallPatch(differenceBetween(startLabel, cl), fun));
+        return cl;
+    }
 };
 
 } /* namespace js */
 } /* namespace mjit */
 
 #endif
--- a/js/src/methodjit/StubCompiler.cpp
+++ b/js/src/methodjit/StubCompiler.cpp
@@ -40,17 +40,17 @@
 
 #include "StubCompiler.h"
 #include "Compiler.h"
 
 using namespace js;
 using namespace mjit;
 
 StubCompiler::StubCompiler(JSContext *cx, mjit::Compiler &cc, FrameState &frame, JSScript *script)
-  : cx(cx), cc(cc), frame(frame), script(script), exits(ContextAllocPolicy(cx))
+  : cx(cx), cc(cc), frame(frame), script(script), exits(SystemAllocPolicy())
 {
 }
 
 void
 StubCompiler::linkExit(Jump j)
 {
     /* :TODO: oom check */
     exits.append(ExitPatch(j, masm.label()));
@@ -104,28 +104,32 @@ typedef JSC::MacroAssembler::Imm32 Imm32
 #if defined(JS_CPU_X86) || defined(JS_CPU_ARM)
 static const RegisterID ClobberInCall = JSC::X86Registers::ecx;
 #elif defined(JS_CPU_ARM)
 static const RegisterID ClobberInCall = JSC::ARMRegisters::r2;
 #endif
 
 JS_STATIC_ASSERT(ClobberInCall != Registers::ArgReg1);
 
-void
+JSC::MacroAssembler::Call
 StubCompiler::scall(void *ptr)
 {
+    void *pfun = getCallTarget(ptr);
+
     /* PC -> regs->pc :( */
     masm.storePtr(ImmPtr(cc.getPC()),
                   FrameAddress(offsetof(VMFrame, regs) + offsetof(JSFrameRegs, pc)));
 
     /* sp = fp + slots() + stackDepth */
     masm.addPtr(Imm32(sizeof(JSStackFrame) +
                 (frame.stackDepth() + script->nfixed) * sizeof(jsval)),
                 FrameState::FpReg, ClobberInCall);
 
     /* regs->sp = sp */
     masm.storePtr(ClobberInCall,
                   FrameAddress(offsetof(VMFrame, regs) + offsetof(JSFrameRegs, sp)));
     
     /* VMFrame -> ArgReg0 */
     masm.move(Assembler::stackPointerRegister, Registers::ArgReg0);
+
+    return masm.call(pfun);
 }
 
--- a/js/src/methodjit/StubCompiler.h
+++ b/js/src/methodjit/StubCompiler.h
@@ -53,16 +53,17 @@ namespace mjit {
 class Compiler;
 
 struct StubCallInfo {
     uint32 numSpills;
 };
 
 class StubCompiler
 {
+    typedef JSC::MacroAssembler::Call Call;
     typedef JSC::MacroAssembler::Jump Jump;
     typedef JSC::MacroAssembler::Label Label;
 
     struct ExitPatch {
         ExitPatch(Jump from, Label to)
           : from(from), to(to)
         { }
 
@@ -70,26 +71,28 @@ class StubCompiler
         Label to;
     };
 
     JSContext *cx;
     Compiler &cc;
     FrameState &frame;
     JSScript *script;
     Assembler masm;
-    Vector<ExitPatch, 64, ContextAllocPolicy> exits;
+    Vector<ExitPatch, 64, SystemAllocPolicy> exits;
 
   public:
     StubCompiler(JSContext *cx, mjit::Compiler &cc, FrameState &frame, JSScript *script);
     void linkExit(Jump j);
     void syncAndSpill();
-    void call(JSObjStub stub) { scall(JS_FUNC_TO_DATA_PTR(void *, stub)); }
+    Call call(JSObjStub stub) {
+        return scall(JS_FUNC_TO_DATA_PTR(void *, stub));
+    }
 
   private:
-    void scall(void *ptr);
+    Call scall(void *ptr);
     void *getCallTarget(void *fun);
 };
 
 } /* namepsace mjit */
 } /* namespace js */
 
 #endif /* jsstub_compiler_h__ */