Bug 1413063 - Avoid divide by zero. r=jonco
authorPaul Bone <pbone@mozilla.com>
Wed, 01 Nov 2017 13:19:20 +1100
changeset 443157 b34ad88764a90f17ac65a7f648ea3809025c802f
parent 443156 c773790077bf23429361cb34df73ca21c7f2bc37
child 443158 472f2a2f55adb2b041d5332577d10d22170c525a
push id1618
push userCallek@gmail.com
push dateThu, 11 Jan 2018 17:45:48 +0000
treeherdermozilla-release@882ca853e05a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjonco
bugs1413063
milestone58.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 1413063 - Avoid divide by zero. r=jonco
js/src/gc/Nursery.cpp
--- a/js/src/gc/Nursery.cpp
+++ b/js/src/gc/Nursery.cpp
@@ -469,25 +469,34 @@ js::TenuringTracer::TenuringTracer(JSRun
 {
 }
 
 inline float
 js::Nursery::calcPromotionRate(bool *validForTenuring) const {
     float used = float(previousGC.nurseryUsedBytes);
     float capacity = float(previousGC.nurseryCapacity);
     float tenured = float(previousGC.tenuredBytes);
+    float rate;
 
-    if (validForTenuring) {
-        /*
-         * We can only use promotion rates if they're likely to be valid,
-         * they're only valid if the nursury was at least 90% full.
-         */
-        *validForTenuring = used > capacity * 0.9f;
+    if (previousGC.nurseryUsedBytes > 0) {
+        if (validForTenuring) {
+            /*
+             * We can only use promotion rates if they're likely to be valid,
+             * they're only valid if the nursury was at least 90% full.
+             */
+            *validForTenuring = used > capacity * 0.9f;
+        }
+        rate = tenured / used;
+    } else {
+        if (validForTenuring)
+            *validForTenuring = false;
+        rate = 0.0f;
     }
-    return tenured / used;
+
+    return rate;
 }
 
 void
 js::Nursery::renderProfileJSON(JSONPrinter& json) const
 {
     if (!isEnabled()) {
         json.beginObject();
         json.property("status", "nursery disabled");