Bug 684111 - use a limit instead of a mask to detect when the srcnotes buffer is full. r=cdleary.
authorNicholas Nethercote <nnethercote@mozilla.com>
Tue, 06 Sep 2011 19:12:09 -0700
changeset 77949 4c0087b808de61bcaf667097ace016a2a4d253d4
parent 77948 054b9cf30cd13f3e6e20449cf5a28f408da9693e
child 77950 5ddb67d5a424f6f457dac8ee9bd9ff96f849b3ca
push id78
push userclegnitto@mozilla.com
push dateFri, 16 Dec 2011 17:32:24 +0000
treeherdermozilla-release@79d24e644fdd [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerscdleary
bugs684111
milestone9.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 684111 - use a limit instead of a mask to detect when the srcnotes buffer is full. r=cdleary.
js/src/jsemit.cpp
js/src/jsemit.h
--- a/js/src/jsemit.cpp
+++ b/js/src/jsemit.cpp
@@ -130,17 +130,16 @@ JSCodeGenerator::JSCodeGenerator(Parser 
     traceIndex(0),
     typesetCount(0)
 {
     flags = TCF_COMPILING;
     memset(&prolog, 0, sizeof prolog);
     memset(&main, 0, sizeof main);
     current = &main;
     firstLine = prolog.currentLine = main.currentLine = lineno;
-    prolog.noteMask = main.noteMask = SRCNOTE_CHUNK - 1;
 }
 
 bool
 JSCodeGenerator::init(JSContext *cx, JSTreeContext::InitBehavior ib)
 {
     roLexdeps.init();
     return JSTreeContext::init(cx, ib) && constMap.init() && atomIndices.ensureMap(cx);
 }
@@ -7440,32 +7439,30 @@ JS_FRIEND_DATA(JSSrcNoteSpec) js_SrcNote
     {"newline",         0,      0,      0},
     {"setline",         1,      0,      0},
     {"xdelta",          0,      0,      0},
 };
 
 static intN
 AllocSrcNote(JSContext *cx, JSCodeGenerator *cg)
 {
-    intN index;
-    JSArenaPool *pool;
-    size_t size;
-
-    index = CG_NOTE_COUNT(cg);
-    if (((uintN)index & CG_NOTE_MASK(cg)) == 0) {
-        pool = cg->notePool;
-        size = SRCNOTE_SIZE(CG_NOTE_MASK(cg) + 1);
+    intN index = CG_NOTE_COUNT(cg);
+    if ((uintN)index == CG_NOTE_LIMIT(cg)) {
         if (!CG_NOTES(cg)) {
-            /* Allocate the first note array lazily; leave noteMask alone. */
-            JS_ARENA_ALLOCATE_CAST(CG_NOTES(cg), jssrcnote *, pool, size);
+            /* Allocate the first note array lazily. */
+            size_t size = SRCNOTE_SIZE(SRCNOTE_CHUNK);
+            JS_ARENA_ALLOCATE_CAST(CG_NOTES(cg), jssrcnote *, cg->notePool, size);
+            if (CG_NOTES(cg))
+                CG_NOTE_LIMIT(cg) = SRCNOTE_CHUNK;
         } else {
-            /* Grow by doubling note array size; update noteMask on success. */
-            JS_ARENA_GROW_CAST(CG_NOTES(cg), jssrcnote *, pool, size, size);
+            /* Grow by doubling note array size. */
+            size_t size = SRCNOTE_SIZE(CG_NOTE_LIMIT(cg));
+            JS_ARENA_GROW_CAST(CG_NOTES(cg), jssrcnote *, cg->notePool, size, size);
             if (CG_NOTES(cg))
-                CG_NOTE_MASK(cg) = (CG_NOTE_MASK(cg) << 1) | 1;
+                CG_NOTE_LIMIT(cg) *= 2;
         }
         if (!CG_NOTES(cg)) {
             js_ReportOutOfMemory(cx);
             return -1;
         }
     }
 
     CG_NOTE_COUNT(cg) = index + 1;
@@ -7551,25 +7548,25 @@ js_NewSrcNote3(JSContext *cx, JSCodeGene
 }
 
 static JSBool
 GrowSrcNotes(JSContext *cx, JSCodeGenerator *cg)
 {
     JSArenaPool *pool;
     size_t size;
 
-    /* Grow by doubling note array size; update noteMask on success. */
+    /* Grow by doubling note array size; update noteLimit on success. */
     pool = cg->notePool;
-    size = SRCNOTE_SIZE(CG_NOTE_MASK(cg) + 1);
+    size = SRCNOTE_SIZE(CG_NOTE_LIMIT(cg));
     JS_ARENA_GROW_CAST(CG_NOTES(cg), jssrcnote *, pool, size, size);
     if (!CG_NOTES(cg)) {
         js_ReportOutOfMemory(cx);
         return JS_FALSE;
     }
-    CG_NOTE_MASK(cg) = (CG_NOTE_MASK(cg) << 1) | 1;
+    CG_NOTE_LIMIT(cg) *= 2;
     return JS_TRUE;
 }
 
 jssrcnote *
 js_AddToSrcNoteDelta(JSContext *cx, JSCodeGenerator *cg, jssrcnote *sn,
                      ptrdiff_t delta)
 {
     ptrdiff_t base, limit, newdelta, diff;
@@ -7584,17 +7581,17 @@ js_AddToSrcNoteDelta(JSContext *cx, JSCo
 
     base = SN_DELTA(sn);
     limit = SN_IS_XDELTA(sn) ? SN_XDELTA_LIMIT : SN_DELTA_LIMIT;
     newdelta = base + delta;
     if (newdelta < limit) {
         SN_SET_DELTA(sn, newdelta);
     } else {
         index = sn - cg->main.notes;
-        if ((cg->main.noteCount & cg->main.noteMask) == 0) {
+        if (cg->main.noteCount == cg->main.noteLimit) {
             if (!GrowSrcNotes(cx, cg))
                 return NULL;
             sn = cg->main.notes + index;
         }
         diff = cg->main.noteCount - index;
         cg->main.noteCount++;
         memmove(sn + 1, sn, SRCNOTE_SIZE(diff));
         SN_MAKE_XDELTA(sn, delta);
@@ -7659,21 +7656,21 @@ js_SetSrcNoteOffset(JSContext *cx, JSCod
     /* See if the new offset requires three bytes. */
     if (offset > (ptrdiff_t)SN_3BYTE_OFFSET_MASK) {
         /* Maybe this offset was already set to a three-byte value. */
         if (!(*sn & SN_3BYTE_OFFSET_FLAG)) {
             /* Losing, need to insert another two bytes for this offset. */
             index = sn - CG_NOTES(cg);
 
             /*
-             * Simultaneously test to see if the source note array must grow to
-             * accommodate either the first or second byte of additional storage
-             * required by this 3-byte offset.
+             * Test to see if the source note array must grow to accommodate
+             * either the first or second byte of additional storage required
+             * by this 3-byte offset.
              */
-            if (((CG_NOTE_COUNT(cg) + 1) & CG_NOTE_MASK(cg)) <= 1) {
+            if (CG_NOTE_COUNT(cg) + 1 >= CG_NOTE_LIMIT(cg)) {
                 if (!GrowSrcNotes(cx, cg))
                     return JS_FALSE;
                 sn = CG_NOTES(cg) + index;
             }
             CG_NOTE_COUNT(cg) += 2;
 
             diff = CG_NOTE_COUNT(cg) - (index + 3);
             JS_ASSERT(diff >= 0);
--- a/js/src/jsemit.h
+++ b/js/src/jsemit.h
@@ -607,17 +607,17 @@ struct JSCodeGenerator : public JSTreeCo
     void            *noteMark;      /* low watermark in cg->notePool */
 
     struct {
         jsbytecode  *base;          /* base of JS bytecode vector */
         jsbytecode  *limit;         /* one byte beyond end of bytecode */
         jsbytecode  *next;          /* pointer to next free bytecode */
         jssrcnote   *notes;         /* source notes, see below */
         uintN       noteCount;      /* number of source notes so far */
-        uintN       noteMask;       /* growth increment for notes */
+        uintN       noteLimit;      /* limit number for source notes in notePool */
         ptrdiff_t   lastNoteOffset; /* code offset for last source note */
         uintN       currentLine;    /* line number for tree-based srcnote gen */
     } prolog, main, *current;
 
     js::OwnedAtomIndexMapPtr atomIndices; /* literals indexed for mapping */
     js::AtomDefnMapPtr roLexdeps;
     uintN           firstLine;      /* first line, for js_NewScriptFromCG */
 
@@ -756,17 +756,17 @@ struct JSCodeGenerator : public JSTreeCo
 #define CG_BASE(cg)             ((cg)->current->base)
 #define CG_LIMIT(cg)            ((cg)->current->limit)
 #define CG_NEXT(cg)             ((cg)->current->next)
 #define CG_CODE(cg,offset)      (CG_BASE(cg) + (offset))
 #define CG_OFFSET(cg)           (CG_NEXT(cg) - CG_BASE(cg))
 
 #define CG_NOTES(cg)            ((cg)->current->notes)
 #define CG_NOTE_COUNT(cg)       ((cg)->current->noteCount)
-#define CG_NOTE_MASK(cg)        ((cg)->current->noteMask)
+#define CG_NOTE_LIMIT(cg)       ((cg)->current->noteLimit)
 #define CG_LAST_NOTE_OFFSET(cg) ((cg)->current->lastNoteOffset)
 #define CG_CURRENT_LINE(cg)     ((cg)->current->currentLine)
 
 #define CG_PROLOG_BASE(cg)      ((cg)->prolog.base)
 #define CG_PROLOG_LIMIT(cg)     ((cg)->prolog.limit)
 #define CG_PROLOG_NEXT(cg)      ((cg)->prolog.next)
 #define CG_PROLOG_CODE(cg,poff) (CG_PROLOG_BASE(cg) + (poff))
 #define CG_PROLOG_OFFSET(cg)    (CG_PROLOG_NEXT(cg) - CG_PROLOG_BASE(cg))