Bug 1085597 - Simplify the allocation of nursery objects; r=jonco
authorTerrence Cole <terrence@mozilla.com>
Wed, 31 Dec 2014 15:58:49 -0800
changeset 223068 cc46a830c58daee491985d863741eee781221904
parent 223067 2dc60df56da1e3de58531b3abc418acb470ce3a4
child 223069 f0503a20819c61910864f7c3d62113db37053e85
push id28082
push usercbook@mozilla.com
push dateMon, 12 Jan 2015 10:44:52 +0000
treeherdermozilla-central@643589c3ef94 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjonco
bugs1085597
milestone37.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 1085597 - Simplify the allocation of nursery objects; r=jonco
js/src/gc/Nursery.cpp
--- a/js/src/gc/Nursery.cpp
+++ b/js/src/gc/Nursery.cpp
@@ -155,41 +155,40 @@ js::Nursery::leaveZealMode() {
 #endif // JS_GC_ZEAL
 
 JSObject *
 js::Nursery::allocateObject(JSContext *cx, size_t size, size_t numDynamic)
 {
     /* Ensure there's enough space to replace the contents with a RelocationOverlay. */
     MOZ_ASSERT(size >= sizeof(RelocationOverlay));
 
-    /* Attempt to allocate slots contiguously after object, if possible. */
-    if (numDynamic && numDynamic <= MaxNurserySlots) {
-        size_t totalSize = size + sizeof(HeapSlot) * numDynamic;
-        JSObject *obj = static_cast<JSObject *>(allocate(totalSize));
-        if (obj) {
-            obj->setInitialSlotsMaybeNonNative(reinterpret_cast<HeapSlot *>(size_t(obj) + size));
-            TraceNurseryAlloc(obj, size);
-            return obj;
-        }
-        /* If we failed to allocate as a block, retry with out-of-line slots. */
-    }
+    /* Make the object allocation. */
+    JSObject *obj = static_cast<JSObject *>(allocate(size));
+    if (!obj)
+        return nullptr;
 
+    /* If we want external slots, add them. */
     HeapSlot *slots = nullptr;
     if (numDynamic) {
-        slots = allocateHugeSlots(cx->zone(), numDynamic);
-        if (MOZ_UNLIKELY(!slots))
+        /* Try to allocate in the nursery first. */
+        if (numDynamic <= MaxNurserySlots)
+            slots = static_cast<HeapSlot *>(allocate(numDynamic * sizeof(HeapSlot)));
+
+        /* If we are out of space or too large, use the malloc heap. */
+        if (!slots)
+            slots = allocateHugeSlots(cx->zone(), numDynamic);
+
+        /* It is safe to leave the allocated object uninitialized, since we do
+         * not visit unallocated things. */
+        if (!slots)
             return nullptr;
     }
 
-    JSObject *obj = static_cast<JSObject *>(allocate(size));
-
-    if (obj)
-        obj->setInitialSlotsMaybeNonNative(slots);
-    else
-        freeSlots(slots);
+    /* Always initialize the slots field to match the JIT behavior. */
+    obj->setInitialSlotsMaybeNonNative(slots);
 
     TraceNurseryAlloc(obj, size);
     return obj;
 }
 
 void *
 js::Nursery::allocate(size_t size)
 {