Bug 1401099 - Move hard_purge_arena to a method of arena_t. r?njn draft
authorMike Hommey <mh+mozilla@glandium.org>
Fri, 15 Sep 2017 17:34:53 +0900
changeset 667402 008caca6121af3deb15e16a95a20e765dc487e9f
parent 667401 f1cd6b08a294758d0a501c89f8e14fa9e9f6f8c5
child 667403 28ac2d3fa60e0d793f47aaff2db1e0ca01a97b57
push id80694
push userbmo:mh+mozilla@glandium.org
push dateWed, 20 Sep 2017 02:07:21 +0000
reviewersnjn
bugs1401099
milestone57.0a1
Bug 1401099 - Move hard_purge_arena to a method of arena_t. r?njn
memory/build/mozjemalloc.cpp
--- a/memory/build/mozjemalloc.cpp
+++ b/memory/build/mozjemalloc.cpp
@@ -765,16 +765,18 @@ struct arena_t {
    *   --------+------+
    *       35  | 1024 |
    *       36  | 2048 |
    *   --------+------+
    */
   arena_bin_t mBins[1]; /* Dynamically sized. */
 
   void Purge(bool aAll);
+
+  void HardPurge();
 };
 
 /******************************************************************************/
 /*
  * Data.
  */
 
 /*
@@ -5070,38 +5072,38 @@ hard_purge_chunk(arena_chunk_t *chunk)
 			pages_decommit(((char*)chunk) + (i << pagesize_2pow), npages << pagesize_2pow);
 			pages_commit(((char*)chunk) + (i << pagesize_2pow), npages << pagesize_2pow);
 		}
 		i += npages;
 	}
 }
 
 /* Explicitly remove all of this arena's MADV_FREE'd pages from memory. */
-static void
-hard_purge_arena(arena_t *arena)
+void
+arena_t::HardPurge()
 {
-	malloc_spin_lock(&arena->mLock);
-
-	while (!arena->mChunksMAdvised.isEmpty()) {
-		arena_chunk_t *chunk = arena->mChunksMAdvised.popFront();
-		hard_purge_chunk(chunk);
-	}
-
-	malloc_spin_unlock(&arena->mLock);
+  malloc_spin_lock(&mLock);
+
+  while (!mChunksMAdvised.isEmpty()) {
+    arena_chunk_t* chunk = mChunksMAdvised.popFront();
+    hard_purge_chunk(chunk);
+  }
+
+  malloc_spin_unlock(&mLock);
 }
 
 template<> inline void
 MozJemalloc::jemalloc_purge_freed_pages()
 {
   size_t i;
   malloc_spin_lock(&arenas_lock);
   for (i = 0; i < narenas; i++) {
     arena_t* arena = arenas[i];
     if (arena) {
-      hard_purge_arena(arena);
+      arena->HardPurge();
     }
   }
   malloc_spin_unlock(&arenas_lock);
 }
 
 #else /* !defined MALLOC_DOUBLE_PURGE */
 
 template<> inline void