Bug 701584 - Move various offsetof uses into static offsetOf* methods. r=cdleary
authorJeff Walden <jwalden@mit.edu>
Wed, 02 Nov 2011 12:57:59 -0700
changeset 80163 f4183f93f844d145ed0bab21b89edb1179b356d9
parent 80162 8b9d5d2c4d49afd901120d0c971da93b7f5eb370
child 80164 c3a965a12bc891e0b898f9e6c7c8cc000e2ffe43
push id21467
push usermak77@bonardo.net
push dateFri, 11 Nov 2011 10:10:59 +0000
treeherdermozilla-central@50c1bcb49c76 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerscdleary
bugs701584
milestone11.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 701584 - Move various offsetof uses into static offsetOf* methods. r=cdleary
js/src/jsfun.h
js/src/methodjit/BaseAssembler.h
js/src/methodjit/Compiler.cpp
js/src/methodjit/InlineFrameAssembler.h
js/src/methodjit/MethodJIT.h
js/src/methodjit/MonoIC.cpp
js/src/vm/String.h
--- a/js/src/jsfun.h
+++ b/js/src/jsfun.h
@@ -105,17 +105,17 @@
 struct JSFunction : public JSObject_Slots2
 {
     /* Functions always have two fixed slots (FUN_CLASS_RESERVED_SLOTS). */
 
     uint16          nargs;        /* maximum number of specified arguments,
                                      reflected as f.length/f.arity */
     uint16          flags;        /* flags, see JSFUN_* below and in jsapi.h */
     union U {
-        struct {
+        struct Native {
             js::Native  native;   /* native method pointer or null */
             js::Class   *clasp;   /* class of objects constructed
                                      by this function */
             JSNativeTraceInfo *trcinfo;
         } n;
         struct Scripted {
             JSScript    *script_; /* interpreted bytecode descriptor or null;
                                      use the setter! */
--- a/js/src/methodjit/BaseAssembler.h
+++ b/js/src/methodjit/BaseAssembler.h
@@ -619,17 +619,17 @@ static const JSC::MacroAssembler::Regist
         // |frameDepth < 0| implies ic::SplatApplyArgs has been called which
         // means regs.sp has already been set in the VMFrame.
         if (frameDepth >= 0) {
             // sp = fp->slots() + frameDepth
             // regs->sp = sp
             addPtr(Imm32(sizeof(StackFrame) + frameDepth * sizeof(jsval)),
                    JSFrameReg,
                    Registers::ClobberInCall);
-            storePtr(Registers::ClobberInCall, FrameAddress(offsetof(VMFrame, regs.sp)));
+            storePtr(Registers::ClobberInCall, FrameAddress(VMFrame::offsetOfRegsSp()));
         }
     }
 
     void setupInfallibleVMFrame(int32 frameDepth) {
         setupFrameDepth(frameDepth);
 
         // The JIT has moved Arg1 already, and we've guaranteed to not clobber
         // it. Move ArgReg0 into place now. setupFallibleVMFrame will not
@@ -640,17 +640,17 @@ static const JSC::MacroAssembler::Regist
     void setupFallibleVMFrame(bool inlining, jsbytecode *pc,
                               DataLabelPtr *pinlined, int32 frameDepth) {
         setupInfallibleVMFrame(frameDepth);
 
         /* regs->fp = fp */
         storePtr(JSFrameReg, FrameAddress(VMFrame::offsetOfFp));
 
         /* PC -> regs->pc :( */
-        storePtr(ImmPtr(pc), FrameAddress(offsetof(VMFrame, regs.pc)));
+        storePtr(ImmPtr(pc), FrameAddress(VMFrame::offsetOfRegsPc()));
 
         if (inlining) {
             /* inlined -> regs->inlined :( */
             DataLabelPtr ptr = storePtrWithPatch(ImmPtr(NULL),
                                                  FrameAddress(VMFrame::offsetOfInlined));
             if (pinlined)
                 *pinlined = ptr;
         }
@@ -658,17 +658,17 @@ static const JSC::MacroAssembler::Regist
         restoreStackBase();
     }
 
     void setupFallibleABICall(bool inlining, jsbytecode *pc, int32 frameDepth) {
         setupFrameDepth(frameDepth);
 
         /* Store fp and pc */
         storePtr(JSFrameReg, FrameAddress(VMFrame::offsetOfFp));
-        storePtr(ImmPtr(pc), FrameAddress(offsetof(VMFrame, regs.pc)));
+        storePtr(ImmPtr(pc), FrameAddress(VMFrame::offsetOfRegsPc()));
 
         if (inlining) {
             /* ABI calls cannot be made from inlined frames. */
             storePtr(ImmPtr(NULL), FrameAddress(VMFrame::offsetOfInlined));
         }
     }
 
     void restoreStackBase() {
--- a/js/src/methodjit/Compiler.cpp
+++ b/js/src/methodjit/Compiler.cpp
@@ -3587,17 +3587,17 @@ mjit::Compiler::emitUncachedCall(uint32 
 
     frame.syncAndKill(Uses(argc + 2));
     prepareStubCall(Uses(argc + 2));
     masm.move(Imm32(argc), Registers::ArgReg1);
     INLINE_STUBCALL(stub, REJOIN_CALL_PROLOGUE);
 
     Jump notCompiled = masm.branchTestPtr(Assembler::Zero, r0, r0);
 
-    masm.loadPtr(FrameAddress(offsetof(VMFrame, regs.sp)), JSFrameReg);
+    masm.loadPtr(FrameAddress(VMFrame::offsetOfRegsSp()), JSFrameReg);
     callPatch.hasFastNcode = true;
     callPatch.fastNcodePatch =
         masm.storePtrWithPatch(ImmPtr(NULL),
                                Address(JSFrameReg, StackFrame::offsetOfNcode()));
 
     masm.jump(r0);
     callPatch.joinPoint = masm.label();
     addReturnSite();
@@ -3694,17 +3694,17 @@ mjit::Compiler::checkCallApplySpeculatio
 
     /*
      * For simplicity, we don't statically specialize calls to
      * ic::SplatApplyArgs based on applyTricks. Rather, this state is
      * communicated dynamically through the VMFrame.
      */
     if (*PC == JSOP_FUNAPPLY) {
         masm.store32(Imm32(applyTricks == LazyArgsObj),
-                     FrameAddress(offsetof(VMFrame, u.call.lazyArgsObj)));
+                     FrameAddress(VMFrame::offsetOfLazyArgsObj()));
     }
 }
 
 /* This predicate must be called before the current op mutates the FrameState. */
 bool
 mjit::Compiler::canUseApplyTricks()
 {
     JS_ASSERT(*PC == JSOP_ARGUMENTS);
@@ -3973,18 +3973,18 @@ mjit::Compiler::inlineCallHelper(uint32 
          * The IC call either returns NULL, meaning call completed, or a
          * function pointer to jump to.
          */
         rejoin1 = stubcc.masm.branchTestPtr(Assembler::Zero, Registers::ReturnReg,
                                             Registers::ReturnReg);
         if (callIC.frameSize.isStatic())
             stubcc.masm.move(Imm32(callIC.frameSize.staticArgc()), JSParamReg_Argc);
         else
-            stubcc.masm.load32(FrameAddress(offsetof(VMFrame, u.call.dynamicArgc)), JSParamReg_Argc);
-        stubcc.masm.loadPtr(FrameAddress(offsetof(VMFrame, regs.sp)), JSFrameReg);
+            stubcc.masm.load32(FrameAddress(VMFrame::offsetOfDynamicArgc()), JSParamReg_Argc);
+        stubcc.masm.loadPtr(FrameAddress(VMFrame::offsetOfRegsSp()), JSFrameReg);
         callPatch.hasSlowNcode = true;
         callPatch.slowNcodePatch =
             stubcc.masm.storePtrWithPatch(ImmPtr(NULL),
                                           Address(JSFrameReg, StackFrame::offsetOfNcode()));
         stubcc.masm.jump(Registers::ReturnReg);
 
 
 
--- a/js/src/methodjit/InlineFrameAssembler.h
+++ b/js/src/methodjit/InlineFrameAssembler.h
@@ -132,17 +132,17 @@ class InlineFrameAssembler {
              * If the frame size is dynamic, then the fast path generated by
              * generateFullCallStub must be used. Thus, this code is executed
              * after stubs::SplatApplyArgs has been called. SplatApplyArgs
              * stores the dynamic stack pointer (i.e., regs.sp after pushing a
              * dynamic number of arguments) to VMFrame.regs, so we just load it
              * here to get the new frame pointer.
              */
             RegisterID newfp = tempRegs.takeAnyReg().reg();
-            masm.loadPtr(FrameAddress(offsetof(VMFrame, regs.sp)), newfp);
+            masm.loadPtr(FrameAddress(VMFrame::offsetOfRegsSp()), newfp);
 
             Address flagsAddr(newfp, StackFrame::offsetOfFlags());
             masm.store32(Imm32(flags), flagsAddr);
             Address prevAddr(newfp, StackFrame::offsetOfPrev());
             masm.storePtr(JSFrameReg, prevAddr);
             Address ncodeAddr(newfp, StackFrame::offsetOfNcode());
             ncodePatch = masm.storePtrWithPatch(ImmPtr(ncode), ncodeAddr);
 
--- a/js/src/methodjit/MethodJIT.h
+++ b/js/src/methodjit/MethodJIT.h
@@ -105,19 +105,36 @@ struct VMFrame
             void *ptr2;
         } x;
         struct {
             uint32 lazyArgsObj;
             uint32 dynamicArgc;
         } call;
     } u;
 
+    static size_t offsetOfLazyArgsObj() {
+        return offsetof(VMFrame, u.call.lazyArgsObj);
+    }
+
+    static size_t offsetOfDynamicArgc() {
+        return offsetof(VMFrame, u.call.dynamicArgc);
+    }
+
     VMFrame      *previous;
     void         *scratch;
     FrameRegs    regs;
+
+    static size_t offsetOfRegsSp() {
+        return offsetof(VMFrame, regs.sp);
+    }
+
+    static size_t offsetOfRegsPc() {
+        return offsetof(VMFrame, regs.pc);
+    }
+
     JSContext    *cx;
     Value        *stackLimit;
     StackFrame   *entryfp;
     FrameRegs    *oldregs;
     JSRejoinState stubRejoin;  /* How to rejoin if inside a call from an IC stub. */
 
 #if defined(JS_CPU_X86)
     void         *unused0, *unused1;  /* For 16 byte alignment */
--- a/js/src/methodjit/MonoIC.cpp
+++ b/js/src/methodjit/MonoIC.cpp
@@ -763,38 +763,38 @@ class CallCompiler : public BaseCompiler
         /* Try and compile. On success we get back the nmap pointer. */
         void *compilePtr = JS_FUNC_TO_DATA_PTR(void *, stubs::CompileFunction);
         DataLabelPtr inlined;
         if (ic.frameSize.isStatic()) {
             masm.move(Imm32(ic.frameSize.staticArgc()), Registers::ArgReg1);
             masm.fallibleVMCall(cx->typeInferenceEnabled(),
                                 compilePtr, f.regs.pc, &inlined, ic.frameSize.staticLocalSlots());
         } else {
-            masm.load32(FrameAddress(offsetof(VMFrame, u.call.dynamicArgc)), Registers::ArgReg1);
+            masm.load32(FrameAddress(VMFrame::offsetOfDynamicArgc()), Registers::ArgReg1);
             masm.fallibleVMCall(cx->typeInferenceEnabled(),
                                 compilePtr, f.regs.pc, &inlined, -1);
         }
 
         Jump notCompiled = masm.branchTestPtr(Assembler::Zero, Registers::ReturnReg,
                                               Registers::ReturnReg);
-        masm.loadPtr(FrameAddress(offsetof(VMFrame, regs.sp)), JSFrameReg);
+        masm.loadPtr(FrameAddress(VMFrame::offsetOfRegsSp()), JSFrameReg);
 
         /* Compute the value of ncode to use at this call site. */
         ncode = (uint8 *) f.jit()->code.m_code.executableAddress() + ic.call->codeOffset;
         masm.storePtr(ImmPtr(ncode), Address(JSFrameReg, StackFrame::offsetOfNcode()));
 
         masm.jump(Registers::ReturnReg);
 
         hasCode.linkTo(masm.label(), &masm);
 
         /* Get nmap[ARITY], set argc, call. */
         if (ic.frameSize.isStatic())
             masm.move(Imm32(ic.frameSize.staticArgc()), JSParamReg_Argc);
         else
-            masm.load32(FrameAddress(offsetof(VMFrame, u.call.dynamicArgc)), JSParamReg_Argc);
+            masm.load32(FrameAddress(VMFrame::offsetOfDynamicArgc()), JSParamReg_Argc);
         masm.jump(t0);
 
         LinkerHelper linker(masm, JSC::METHOD_CODE);
         JSC::ExecutablePool *ep = poolForSize(linker, CallICInfo::Pool_ScriptStub);
         if (!ep)
             return false;
 
         if (!linker.verifyRange(from)) {
@@ -1018,17 +1018,17 @@ class CallCompiler : public BaseCompiler
 #endif
         uint32 vpOffset = (uint32) ((char *) args.base() - (char *) f.fp());
         masm.addPtr(Imm32(vpOffset), JSFrameReg, vpReg);
 
         /* Compute argc. */
         MaybeRegisterID argcReg;
         if (!ic.frameSize.isStatic()) {
             argcReg = tempRegs.takeAnyReg().reg();
-            masm.load32(FrameAddress(offsetof(VMFrame, u.call.dynamicArgc)), argcReg.reg());
+            masm.load32(FrameAddress(VMFrame::offsetOfDynamicArgc()), argcReg.reg());
         }
 
         /* Mark vp[1] as magic for |new|. */
         if (callingNew) {
             Value v;
             v.setMagicWithObjectOrNullPayload(NULL);
             masm.storeValue(v, Address(vpReg, sizeof(Value)));
         }
--- a/js/src/vm/String.h
+++ b/js/src/vm/String.h
@@ -270,18 +270,17 @@ class JSString : public js::gc::Cell
      */
     static inline bool validateLength(JSContext *cx, size_t length);
 
     static void staticAsserts() {
         JS_STATIC_ASSERT(JS_BITS_PER_WORD >= 32);
         JS_STATIC_ASSERT(((JSString::MAX_LENGTH << JSString::LENGTH_SHIFT) >>
                            JSString::LENGTH_SHIFT) == JSString::MAX_LENGTH);
         JS_STATIC_ASSERT(sizeof(JSString) ==
-                         offsetof(JSString, d.inlineStorage) +
-                         NUM_INLINE_CHARS * sizeof(jschar));
+                         offsetof(JSString, d.inlineStorage) + NUM_INLINE_CHARS * sizeof(jschar));
     }
 
     /* Avoid lame compile errors in JSRope::flatten */
     friend class JSRope;
 
   public:
     /* All strings have length. */