Try to keep 64-bit portability via size_t instead of unsigned, jsuword for uintptr instead of long, etc.
authorBrendan Eich <brendan@mozilla.org>
Sat, 05 Jul 2008 11:18:26 -0700
changeset 17424 a03f8c8930e6ddabfc4b8828ac9cd2d94983dccf
parent 17423 c527aa0c12110e8a28723197be273bc57926fbff
child 17425 84e68fc5d54329770eaa6f12c3c0801cb65a3be4
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.1a1pre
Try to keep 64-bit portability via size_t instead of unsigned, jsuword for uintptr instead of long, etc.
js/src/jstracer.cpp
js/src/jstracer.h
--- a/js/src/jstracer.cpp
+++ b/js/src/jstracer.cpp
@@ -1,10 +1,10 @@
 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
- * vim: set ts=8 sw=4 et tw=79:
+ * vim: set ts=8 sw=4 et tw=99:
  *
  * ***** BEGIN LICENSE BLOCK *****
  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  *
  * The contents of this file are subject to the Mozilla Public License Version
  * 1.1 (the "License"); you may not use this file except in compliance with
  * the License. You may obtain a copy of the License at
  * http://www.mozilla.org/MPL/
@@ -61,39 +61,39 @@ Tracker::Tracker()
     pagelist = 0;
 }
 
 Tracker::~Tracker()
 {
     clear();
 }
 
-long
+jsuword
 Tracker::getPageBase(const void* v) const
 {
-    return ((long)v) & (~(NJ_PAGE_SIZE-1));
+    return jsuword(v) & ~jsuword(NJ_PAGE_SIZE-1);
 }
 
 struct Tracker::Page*
 Tracker::findPage(const void* v) const
 {
-    long base = getPageBase(v);
+    jsuword base = getPageBase(v);
     struct Tracker::Page* p = pagelist;
     while (p) {
         if (p->base == base) {
             return p;
         }
         p = p->next;
     }
     return 0;
 }
 
 struct Tracker::Page*
 Tracker::addPage(const void* v) {
-    long base = getPageBase(v);
+    jsuword base = getPageBase(v);
     struct Tracker::Page* p = (struct Tracker::Page*)
         GC::Alloc(sizeof(struct Tracker::Page) + (NJ_PAGE_SIZE >> 2) * sizeof(LInsp));
     p->base = base;
     p->next = pagelist;
     pagelist = p;
     return p;
 }
 
@@ -107,28 +107,28 @@ Tracker::clear()
     }
 }
 
 LIns*
 Tracker::get(const void* v) const
 {
     struct Tracker::Page* p = findPage(v);
     JS_ASSERT(p != 0); /* we must have a page for the slot we are looking for */
-    LIns* i = p->map[(((long)v) & 0xfff) >> 2];
+    LIns* i = p->map[(jsuword(v) & 0xfff) >> 2];
     JS_ASSERT(i != 0);
     return i;
 }
 
 void
 Tracker::set(const void* v, LIns* ins)
 {
     struct Tracker::Page* p = findPage(v);
     if (!p)
         p = addPage(v);
-    p->map[(((long)v) & 0xfff) >> 2] = ins;
+    p->map[(jsuword(v) & 0xfff) >> 2] = ins;
 }
 
 #define LO ARGSIZE_LO
 #define F  ARGSIZE_F
 #define Q  ARGSIZE_Q
 
 #ifdef DEBUG
 #define NAME(op) ,#op
@@ -223,17 +223,17 @@ TraceRecorder::TraceRecorder(JSContext* 
 #endif
 
     JSStackFrame* fp = cx->fp;
     unsigned n;
     for (n = 0; n < fp->argc; ++n)
         import(&fp->argv[n], "arg", n);
     for (n = 0; n < fp->nvars; ++n)
         import(&fp->vars[n], "var", n);
-    for (n = 0; n < (unsigned)(fp->regs->sp - fp->spbase); ++n)
+    for (n = 0; n < unsigned(fp->regs->sp - fp->spbase); ++n)
         import(&fp->spbase[n], "stack", n);
 }
 
 TraceRecorder::~TraceRecorder()
 {
 #ifdef DEBUG
     delete lirbuf->names;
     delete verbose_filter;
@@ -255,64 +255,65 @@ TraceRecorder::calldepth() const
     }
     return depth;
 }
 
 /* Find the frame that this address belongs to (if any). */
 JSStackFrame*
 TraceRecorder::findFrame(void* p) const
 {
-    JSStackFrame* fp = cx->fp;
-    while (1) {
-        if ((p >= &fp->argv[0] && p < &fp->argv[fp->argc]) ||
-            (p >= &fp->vars[0] && p < &fp->vars[fp->nvars]) ||
-            (p >= &fp->spbase[0] && p < &fp->spbase[fp->script->depth]))
+    jsval* vp = (jsval*) p;
+    for (JSStackFrame* fp = cx->fp; fp != entryFrame; fp = fp->down) {
+        // FIXME: fixing bug 441686 collapses the last two tests here
+        if (size_t(vp - fp->argv) < fp->argc ||
+            size_t(vp - fp->vars) < fp->nvars ||
+            size_t(vp - fp->spbase) < fp->script->depth) {
             return fp;
-        if (fp == entryFrame)
-            return NULL;
-        fp = fp->down;
+        }
     }
+    return NULL;
 }
 
 /* Determine whether an address is part of a currently active frame. */
 bool
 TraceRecorder::onFrame(void* p) const
 {
     return findFrame(p) != NULL;
 }
 
 /* Calculate the total number of native frame slots we need from this frame
    all the way back to the entry frame, including the current stack usage. */
 unsigned
 TraceRecorder::nativeFrameSlots(JSStackFrame* fp, JSFrameRegs& regs) const
 {
-    unsigned size = 0;
-    while (1) {
-        size += fp->argc + fp->nvars + (regs.sp - fp->spbase);
-        if (fp == entryFrame)
-            return size;
+    unsigned slots = 0;
+    while (fp != entryFrame) {
+        slots += fp->argc + fp->nvars + (regs.sp - fp->spbase);
         fp = fp->down;
     }
+    return slots;
 }
 
 /* Determine the offset in the native frame (marshal) for an address
    that is part of a currently active frame. */
-unsigned
+size_t
 TraceRecorder::nativeFrameOffset(void* p) const
 {
+    jsval* vp = (jsval*) p;
     JSStackFrame* fp = findFrame(p);
     JS_ASSERT(fp != NULL); // must be on the frame somewhere
-    unsigned offset = 0;
-    if (p >= &fp->argv[0] && p < &fp->argv[fp->argc])
-        offset = unsigned((jsval*)p - &fp->argv[0]);
-    else if (p >= &fp->vars[0] && p < &fp->vars[fp->nvars])
-        offset = (fp->argc + unsigned((jsval*)p - &fp->vars[0]));
-    else {
-        JS_ASSERT((p >= &fp->spbase[0] && p < &fp->spbase[fp->script->depth]));
-        offset = (fp->argc + fp->nvars + unsigned((jsval*)p - &fp->spbase[0]));
+    size_t offset = size_t(vp - fp->argv);
+    if (offset >= fp->argc) {
+        // FIXME: fixing bug 441686 collapses the vars and spbase cases
+        offset = size_t(vp - fp->vars);
+        if (offset >= fp->nvars) {
+            JS_ASSERT(size_t(vp - fp->spbase) < fp->script->depth);
+            offset = fp->nvars + size_t(vp - fp->spbase);
+        }
+        offset += fp->argc;
     }
     if (fp != entryFrame)
         offset += nativeFrameSlots(fp->down, *fp->regs);
     return offset * sizeof(double);
 }
 
 /* Track the maximum number of native frame slots we need during
    execution. */
@@ -774,22 +775,22 @@ TraceRecorder::ibinary(LOpcode op, bool 
     return false;
 }
 
 bool
 TraceRecorder::map_is_native(JSObjectMap* map, LIns* map_ins)
 {
     LIns* ops = lir->insLoadi(map_ins, offsetof(JSObjectMap, ops));
     if (map->ops == &js_ObjectOps) {
-        guard(true, lir->ins2i(LIR_eq, ops, (long)&js_ObjectOps));
+        guard(true, lir->ins2i(LIR_eq, ops, (jsword)&js_ObjectOps));
         return true;
     }
     LIns* n = lir->insLoadi(ops, offsetof(JSObjectOps, newObjectMap));
     if (map->ops->newObjectMap == js_ObjectOps.newObjectMap) {
-        guard(true, lir->ins2i(LIR_eq, n, (long)js_ObjectOps.newObjectMap));
+        guard(true, lir->ins2i(LIR_eq, n, (jsword)js_ObjectOps.newObjectMap));
         return true;
     }
     return false;
 }
 
 LIns*
 TraceRecorder::loadObjectClass(LIns* objld)
 {
--- a/js/src/jstracer.h
+++ b/js/src/jstracer.h
@@ -49,37 +49,37 @@
 
 /*
  * Tracker is used to keep track of values being manipulated by the 
  * interpreter during trace recording.
  */
 class Tracker 
 {
     struct Page {
-        struct Page* next;
-        long base;
-        nanojit::LIns* map[0];
+        struct Page*    next;
+        jsuword         base;
+        nanojit::LIns*  map[0];
     };
     struct Page* pagelist;
     
-    long            getPageBase(const void* v) const;
+    jsuword         getPageBase(const void* v) const;
     struct Page*    findPage(const void* v) const;
     struct Page*    addPage(const void* v);
 public:    
     Tracker();
     ~Tracker();
     
     nanojit::LIns*  get(const void* v) const;
     void            set(const void* v, nanojit::LIns* ins);
     void            clear();
 };
 
 struct VMFragmentInfo {
     unsigned                maxNativeFrameSlots;
-    unsigned                nativeStackBase;
+    size_t                  nativeStackBase;
     char                    typeMap[0];
 };
 
 struct VMSideExitInfo {
     char                    typeMap[0];
 };
 
 class TraceRecorder {
@@ -99,17 +99,17 @@ class TraceRecorder {
     nanojit::LirWriter*     cse_filter;
     nanojit::LirWriter*     expr_filter;
     nanojit::LIns*          cx_ins;
     nanojit::SideExit       exit;
     
     JSStackFrame* findFrame(void* p) const;
     bool onFrame(void* p) const;
     unsigned nativeFrameSlots(JSStackFrame* fp, JSFrameRegs& regs) const;
-    unsigned nativeFrameOffset(void* p) const;
+    size_t   nativeFrameOffset(void* p) const;
     void import(jsval*, char *prefix = NULL, int index = 0);
     void trackNativeFrameUse(unsigned slots);
     
     nanojit::SideExit* snapshot();
 
     unsigned calldepth() const;
 
     void set(void* p, nanojit::LIns* l);