Bug 956434 - Apply gczeal to object cache allocations, r=terrence
authorSteve Fink <sfink@mozilla.com>
Mon, 06 Jan 2014 14:43:19 -0800
changeset 162479 a443aaba92c06e117ac3e01559e944a88fbcc3fb
parent 162478 0f5f6f400d978d97457f6bde0333dfeecb712b66
child 162480 b73bf63d70c82fda2062109cf12eed553e100702
push id38213
push usersfink@mozilla.com
push dateWed, 08 Jan 2014 08:25:38 +0000
treeherdermozilla-inbound@a443aaba92c0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersterrence
bugs956434
milestone29.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 956434 - Apply gczeal to object cache allocations, r=terrence
js/src/jit-test/tests/basic/testArrayBufferSlice.js
js/src/jit-test/tests/basic/testTypedArrayInit.js
js/src/vm/Runtime-inl.h
js/src/vm/Runtime.h
--- a/js/src/jit-test/tests/basic/testArrayBufferSlice.js
+++ b/js/src/jit-test/tests/basic/testArrayBufferSlice.js
@@ -1,11 +1,8 @@
-// Bug 956434 - Disable test due to unpredictable failures on ggc builds
-quit(0);
-
 function testSlice() {
     function test(subBuf, starts, size) {
         var byteLength = size;
         var subBuffer = eval(subBuf);
         var subArray = new Int8Array(subBuffer);
         assertEq(subBuffer.byteLength, byteLength);
         for (var i = 0; i < size; ++i)
             assertEq(starts + i, subArray[i]);
@@ -38,11 +35,23 @@ function testSlice() {
 
     test("buffer.slice(16, -8)", 16, 8);
     test("buffer.slice(-20, 30)", 12, 18);
 
     test("buffer.slice(-8, -20)", 24, 0);
     test("buffer.slice(-20, -8)", 12, 12);
     test("buffer.slice(-40, 16)", 0, 16);
     test("buffer.slice(-40, 40)", 0, 32);
+
+    gczeal(7, 100000);
+    var nurseryBuf = new ArrayBuffer(32);
+    var arr = new Int8Array(nurseryBuf);
+    arr[0] = 77;
+
+    // tenure nurseryBuf during the slice operation
+    nurseryBuf.slice; // Creates an object
+    schedulegc(1);
+    var newbuf = nurseryBuf.slice(0);
+    var arr2 = new Int8Array(newbuf);
+    assertEq(arr2[0], 77);
 }
 
 testSlice();
new file mode 100644
--- /dev/null
+++ b/js/src/jit-test/tests/basic/testTypedArrayInit.js
@@ -0,0 +1,23 @@
+// Arrays should be initialized to zero
+
+function f() {
+  for (var ctor of [ Int8Array,
+                     Uint8Array,
+                     Uint8ClampedArray,
+                     Int16Array,
+                     Uint16Array,
+                     Int32Array,
+                     Uint32Array,
+                     Float32Array,
+                     Float64Array ])
+  {
+    for (var len of [ 3, 30, 300, 3000, 30000 ]) {
+      var arr = ctor(len);
+      for (var i = 0; i < arr.length; i++)
+        assertEq(arr[i], 0);
+    }
+  }
+}
+
+f();
+f();
--- a/js/src/vm/Runtime-inl.h
+++ b/js/src/vm/Runtime-inl.h
@@ -50,16 +50,19 @@ NewObjectCache::newObjectFromHit(JSConte
 
     // Do an end run around JSObject::type() to avoid doing AutoUnprotectCell
     // on the templateObj, which is not a GC thing and can't use runtimeFromAnyThread.
     types::TypeObject *type = templateObj->type_;
 
     if (type->shouldPreTenure())
         heap = gc::TenuredHeap;
 
+    if (cx->runtime()->upcomingZealousGC())
+        return nullptr;
+
     JSObject *obj = js_NewGCObject<NoGC>(cx, entry->kind, heap);
     if (obj) {
         copyCachedToObject(obj, templateObj, entry->kind);
         probes::CreateObject(cx, obj);
         return obj;
     }
 
     return nullptr;
--- a/js/src/vm/Runtime.h
+++ b/js/src/vm/Runtime.h
@@ -1283,31 +1283,36 @@ struct JSRuntime : public JS::shadow::Ru
     int                 gcNextScheduled;
     bool                gcDeterministicOnly;
     int                 gcIncrementalLimit;
 
     js::Vector<JSObject *, 0, js::SystemAllocPolicy> gcSelectedForMarking;
 
     int gcZeal() { return gcZeal_; }
 
+    bool upcomingZealousGC() {
+        return gcNextScheduled == 1;
+    }
+
     bool needZealousGC() {
         if (gcNextScheduled > 0 && --gcNextScheduled == 0) {
             if (gcZeal() == js::gc::ZealAllocValue ||
                 gcZeal() == js::gc::ZealGenerationalGCValue ||
                 (gcZeal() >= js::gc::ZealIncrementalRootsThenFinish &&
                  gcZeal() <= js::gc::ZealIncrementalMultipleSlices))
             {
                 gcNextScheduled = gcZealFrequency;
             }
             return true;
         }
         return false;
     }
 #else
     int gcZeal() { return 0; }
+    bool upcomingZealousGC() { return false; }
     bool needZealousGC() { return false; }
 #endif
 
     bool                gcValidate;
     bool                gcFullCompartmentChecks;
 
     JSGCCallback        gcCallback;
     JS::GCSliceCallback gcSliceCallback;