Bug 1562550 - (part 2) Don't poison memory unnecessarily during Nursery::init r=jonco
authorPaul Bone <pbone@mozilla.com>
Thu, 11 Jul 2019 02:31:51 +0000
changeset 482332 111838e2b22f9dcbf64f56e522360126ff16735c
parent 482331 9c274e3d473bdd3bb917ff34fabefd555db2d2cd
child 482333 0e662f79db6c8c33dc99714b15a0d6367693578f
push id89701
push userpbone@mozilla.com
push dateThu, 11 Jul 2019 04:30:54 +0000
treeherderautoland@6cc26a5b9fe2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjonco
bugs1562550
milestone70.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 1562550 - (part 2) Don't poison memory unnecessarily during Nursery::init r=jonco Differential Revision: https://phabricator.services.mozilla.com/D36876
js/src/gc/Nursery.cpp
js/src/gc/Nursery.h
--- a/js/src/gc/Nursery.cpp
+++ b/js/src/gc/Nursery.cpp
@@ -247,17 +247,17 @@ bool js::Nursery::init(uint32_t maxNurse
     return false;
   }
   capacity_ = roundSize(tunables().gcMinNurseryBytes());
   MOZ_ASSERT(capacity_ >= ArenaSize);
   /* After this point the Nursery has been enabled */
 
   setCurrentChunk(0);
   setStartPosition();
-  poisonAndInitCurrentChunk(true);
+  poisonAndInitCurrentChunk();
 
   char* env = getenv("JS_GC_PROFILE_NURSERY");
   if (env) {
     if (0 == strcmp(env, "help")) {
       fprintf(stderr,
               "JS_GC_PROFILE_NURSERY=N\n"
               "\tReport minor GC's taking at least N microseconds.\n");
       exit(0);
@@ -301,17 +301,17 @@ void js::Nursery::enable() {
       return;
     }
     capacity_ = roundSize(tunables().gcMinNurseryBytes());
     MOZ_ASSERT(capacity_ >= ArenaSize);
   }
 
   setCurrentChunk(0);
   setStartPosition();
-  poisonAndInitCurrentChunk(true);
+  poisonAndInitCurrentChunk();
 #ifdef JS_GC_ZEAL
   if (runtime()->hasZealMode(ZealMode::GenerationalGC)) {
     enterZealMode();
   }
 #endif
 
   MOZ_ALWAYS_TRUE(runtime()->gc.storeBuffer().enable());
 }
@@ -357,27 +357,34 @@ bool js::Nursery::isEmpty() const {
     MOZ_ASSERT(currentStartPosition_ == chunk(0).start());
   }
   return position() == currentStartPosition_;
 }
 
 #ifdef JS_GC_ZEAL
 void js::Nursery::enterZealMode() {
   if (isEnabled()) {
+    if (isSubChunkMode()) {
+      // It'd be simplier to poison the whole chunk, but we can't do that
+      // because the nursery might be partily used.
+      chunk(0).poisonRange(capacity_, NurseryChunkUsableSize - capacity_,
+                           JS_FRESH_NURSERY_PATTERN,
+                           MemCheckKind::MakeUndefined);
+    }
     capacity_ = chunkCountLimit() * ChunkSize;
     setCurrentEnd();
   }
 }
 
 void js::Nursery::leaveZealMode() {
   if (isEnabled()) {
     MOZ_ASSERT(isEmpty());
     setCurrentChunk(0);
     setStartPosition();
-    poisonAndInitCurrentChunk(true);
+    poisonAndInitCurrentChunk();
   }
 }
 #endif  // JS_GC_ZEAL
 
 JSObject* js::Nursery::allocateObject(JSContext* cx, size_t size,
                                       size_t nDynamicSlots,
                                       const js::Class* clasp) {
   // Ensure there's enough space to replace the contents with a
@@ -1250,22 +1257,21 @@ MOZ_ALWAYS_INLINE void js::Nursery::setC
   MOZ_ASSERT(chunkno < chunkCountLimit());
   MOZ_ASSERT(chunkno < allocatedChunkCount());
 
   currentChunk_ = chunkno;
   position_ = chunk(chunkno).start();
   setCurrentEnd();
 }
 
-void js::Nursery::poisonAndInitCurrentChunk(bool fullPoison) {
-  if (fullPoison || runtime()->hasZealMode(ZealMode::GenerationalGC) ||
-      !isSubChunkMode()) {
+void js::Nursery::poisonAndInitCurrentChunk() {
+  if (runtime()->hasZealMode(ZealMode::GenerationalGC) || !isSubChunkMode()) {
     chunk(currentChunk_).poisonAndInit(runtime());
   } else {
-    MOZ_ASSERT(isSubChunkMode());
+    MOZ_ASSERT(capacity_ <= NurseryChunkUsableSize);
     chunk(currentChunk_).poisonAndInit(runtime(), capacity_);
   }
 }
 
 MOZ_ALWAYS_INLINE void js::Nursery::setCurrentEnd() {
   MOZ_ASSERT_IF(isSubChunkMode(),
                 currentChunk_ == 0 && currentEnd_ <= chunk(0).end());
   currentEnd_ =
--- a/js/src/gc/Nursery.h
+++ b/js/src/gc/Nursery.h
@@ -589,17 +589,17 @@ class Nursery {
   /*
    * Set the current chunk. This updates the currentChunk_, position_
    * currentEnd_ and currentStringEnd_ values as approprite. It'll also
    * poison the chunk, either a portion of the chunk if it is already the
    * current chunk, or the whole chunk if fullPoison is true or it is not
    * the current chunk.
    */
   void setCurrentChunk(unsigned chunkno);
-  void poisonAndInitCurrentChunk(bool fullPoison = false);
+  void poisonAndInitCurrentChunk();
   void setCurrentEnd();
   void setStartPosition();
 
   /*
    * Allocate the next chunk, or the first chunk for initialization.
    * Callers will probably want to call setCurrentChunk(0) next.
    */
   MOZ_MUST_USE bool allocateNextChunk(unsigned chunkno,