Bug 1011350 - Use TaggedAnonymousMemory to distinguish our various mmap call sites. r=njn
authorJed Davis <jld@mozilla.com>
Tue, 17 Jun 2014 17:55:00 +0200
changeset 189309 df4bfca6f533060c5ad4b9176d1768b490a59f19
parent 189308 7958c801c56ae9b74aac24d854b6cc37a28376ad
child 189310 6a2f8dead92bd79fcb8ccccb53f012b399720585
push id26984
push userryanvm@gmail.com
push dateWed, 18 Jun 2014 19:48:29 +0000
treeherdermozilla-central@b83f5f1d25b4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnjn
bugs1011350
milestone33.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 1011350 - Use TaggedAnonymousMemory to distinguish our various mmap call sites. r=njn We can probably get more granular information than this, given that we can re-tag memory after the initial mapping, or tag subregions of an individual mmap() call differently. But this is a start.
js/src/assembler/jit/ExecutableAllocatorPosix.cpp
js/src/gc/Memory.cpp
js/src/jit/AsmJSModule.cpp
js/src/vm/ArrayBufferObject.cpp
memory/mozjemalloc/jemalloc.c
mfbt/Poison.cpp
--- a/js/src/assembler/jit/ExecutableAllocatorPosix.cpp
+++ b/js/src/assembler/jit/ExecutableAllocatorPosix.cpp
@@ -25,30 +25,32 @@
 
 #include "assembler/jit/ExecutableAllocator.h"
 
 #if ENABLE_ASSEMBLER && WTF_OS_UNIX && !WTF_OS_SYMBIAN
 
 #include <sys/mman.h>
 #include <unistd.h>
 
+#include "mozilla/TaggedAnonymousMemory.h"
+
 #include "assembler/wtf/Assertions.h"
 #include "assembler/wtf/VMTags.h"
 #include "js/Utility.h"
 
 namespace JSC {
 
 size_t ExecutableAllocator::determinePageSize()
 {
     return getpagesize();
 }
 
 ExecutablePool::Allocation ExecutableAllocator::systemAlloc(size_t n)
 {
-    void *allocation = mmap(NULL, n, INITIAL_PROTECTION_FLAGS, MAP_PRIVATE | MAP_ANON, VM_TAG_FOR_EXECUTABLEALLOCATOR_MEMORY, 0);
+    void *allocation = MozTaggedAnonymousMmap(NULL, n, INITIAL_PROTECTION_FLAGS, MAP_PRIVATE | MAP_ANON, VM_TAG_FOR_EXECUTABLEALLOCATOR_MEMORY, 0, "js-jit-code");
     if (allocation == MAP_FAILED)
         allocation = NULL;
     ExecutablePool::Allocation alloc = { reinterpret_cast<char*>(allocation), n };
     return alloc;
 }
 
 void ExecutableAllocator::systemRelease(const ExecutablePool::Allocation& alloc)
 {
--- a/js/src/gc/Memory.cpp
+++ b/js/src/gc/Memory.cpp
@@ -1,16 +1,18 @@
 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  * vim: set ts=8 sts=4 et sw=4 tw=99:
  * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "gc/Memory.h"
 
+#include "mozilla/TaggedAnonymousMemory.h"
+
 #include "js/HeapAPI.h"
 #include "vm/Runtime.h"
 
 using namespace js;
 using namespace js::gc;
 
 bool
 SystemPageAllocator::decommitEnabled()
@@ -373,17 +375,17 @@ MapMemory(size_t length, int prot = PROT
      */
     if ((uintptr_t(region) + (length - 1)) & 0xffff800000000000) {
         if (munmap(region, length))
             MOZ_ASSERT(errno == ENOMEM);
         return nullptr;
     }
     return region;
 #else
-    void *region = mmap(nullptr, length, prot, flags, fd, offset);
+    void *region = MozTaggedAnonymousMmap(nullptr, length, prot, flags, fd, offset, "js-gc-heap");
     if (region == MAP_FAILED)
         return nullptr;
     return region;
 #endif
 }
 
 void *
 SystemPageAllocator::mapAlignedPages(size_t size, size_t alignment)
--- a/js/src/jit/AsmJSModule.cpp
+++ b/js/src/jit/AsmJSModule.cpp
@@ -9,16 +9,17 @@
 #include <errno.h>
 
 #ifndef XP_WIN
 # include <sys/mman.h>
 #endif
 
 #include "mozilla/Compression.h"
 #include "mozilla/PodOperations.h"
+#include "mozilla/TaggedAnonymousMemory.h"
 
 #include "jslibmath.h"
 #include "jsmath.h"
 #include "jsprf.h"
 #ifdef XP_WIN
 # include "jswin.h"
 #endif
 #include "prmjtime.h"
@@ -76,19 +77,19 @@ AllocateExecutableMemory(ExclusiveContex
 
 #ifdef XP_WIN
     void *p = VirtualAlloc(nullptr, totalBytes, MEM_COMMIT, PAGE_EXECUTE_READWRITE);
     if (!p) {
         js_ReportOutOfMemory(cx);
         return nullptr;
     }
 #else  // assume Unix
-    void *p = mmap(nullptr, totalBytes,
-                   PROT_READ | PROT_WRITE | PROT_EXEC, MAP_PRIVATE | MAP_ANON,
-                   -1, 0);
+    void *p = MozTaggedAnonymousMmap(nullptr, totalBytes,
+                                     PROT_READ | PROT_WRITE | PROT_EXEC, MAP_PRIVATE | MAP_ANON,
+                                     -1, 0, "asm-js-code");
     if (p == MAP_FAILED) {
         js_ReportOutOfMemory(cx);
         return nullptr;
     }
 #endif
 
     return (uint8_t *)p;
 }
--- a/js/src/vm/ArrayBufferObject.cpp
+++ b/js/src/vm/ArrayBufferObject.cpp
@@ -4,16 +4,17 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "vm/ArrayBufferObject.h"
 
 #include "mozilla/Alignment.h"
 #include "mozilla/FloatingPoint.h"
 #include "mozilla/PodOperations.h"
+#include "mozilla/TaggedAnonymousMemory.h"
 
 #include <string.h>
 #ifndef XP_WIN
 # include <sys/mman.h>
 #endif
 
 #ifdef MOZ_VALGRIND
 # include <valgrind/memcheck.h>
@@ -426,17 +427,17 @@ ArrayBufferObject::prepareForAsmJS(JSCon
 
     // Get the entire reserved region (with all pages inaccessible).
     void *data;
 # ifdef XP_WIN
     data = VirtualAlloc(nullptr, AsmJSMappedSize, MEM_RESERVE, PAGE_NOACCESS);
     if (!data)
         return false;
 # else
-    data = mmap(nullptr, AsmJSMappedSize, PROT_NONE, MAP_PRIVATE | MAP_ANON, -1, 0);
+    data = MozTaggedAnonymousMmap(nullptr, AsmJSMappedSize, PROT_NONE, MAP_PRIVATE | MAP_ANON, -1, 0, "asm-js-reserved");
     if (data == MAP_FAILED)
         return false;
 # endif
 
     // Enable access to the valid region.
     JS_ASSERT(buffer->byteLength() % AsmJSAllocationGranularity == 0);
 # ifdef XP_WIN
     if (!VirtualAlloc(data, buffer->byteLength(), MEM_COMMIT, PAGE_READWRITE)) {
--- a/memory/mozjemalloc/jemalloc.c
+++ b/memory/mozjemalloc/jemalloc.c
@@ -1554,18 +1554,21 @@ void	(*_malloc_message)(const char *p1, 
 		_malloc_message("\"", #e, "\"\n", "");			\
 		abort();						\
 	}								\
 } while (0)
 #else
 #define assert(e)
 #endif
 
-#include <mozilla/Assertions.h>
-#include <mozilla/Attributes.h>
+#include "mozilla/Assertions.h"
+#include "mozilla/Attributes.h"
+#include "mozilla/TaggedAnonymousMemory.h"
+// Note: MozTaggedAnonymousMmap() could call an LD_PRELOADed mmap
+// instead of the one defined here; use only MozTagAnonymousMemory().
 
 /* RELEASE_ASSERT calls jemalloc_crash() instead of calling MOZ_CRASH()
  * directly because we want crashing to add a frame to the stack.  This makes
  * it easier to find the failing assertion in crash stacks. */
 MOZ_NEVER_INLINE static void
 jemalloc_crash()
 {
 	MOZ_CRASH();
@@ -1974,30 +1977,32 @@ pages_decommit(void *addr, size_t size)
 {
 
 #ifdef MOZ_MEMORY_WINDOWS
 	VirtualFree(addr, size, MEM_DECOMMIT);
 #else
 	if (mmap(addr, size, PROT_NONE, MAP_FIXED | MAP_PRIVATE | MAP_ANON, -1,
 	    0) == MAP_FAILED)
 		abort();
+	MozTagAnonymousMemory(addr, size, "jemalloc-decommitted");
 #endif
 }
 
 static inline void
 pages_commit(void *addr, size_t size)
 {
 
 #  ifdef MOZ_MEMORY_WINDOWS
 	if (!VirtualAlloc(addr, size, MEM_COMMIT, PAGE_READWRITE))
 		abort();
 #  else
 	if (mmap(addr, size, PROT_READ | PROT_WRITE, MAP_FIXED | MAP_PRIVATE |
 	    MAP_ANON, -1, 0) == MAP_FAILED)
 		abort();
+	MozTagAnonymousMemory(addr, size, "jemalloc");
 #  endif
 }
 
 static bool
 base_pages_alloc_mmap(size_t minsize)
 {
 	bool ret;
 	size_t csize;
@@ -2358,16 +2363,18 @@ pages_map_align(size_t size, int pfd, si
 	       {
 		ret = mmap((void *)alignment, size, PROT_READ | PROT_WRITE, MAP_PRIVATE |
 		    MAP_NOSYNC | MAP_ALIGN | MAP_ANON, -1, 0);
 	}
 	assert(ret != NULL);
 
 	if (ret == MAP_FAILED)
 		ret = NULL;
+	else
+		MozTagAnonymousMemory(ret, size, "jemalloc");
 	return (ret);
 }
 #endif
 
 static void *
 pages_map(void *addr, size_t size, int pfd)
 {
 	void *ret;
@@ -2405,17 +2412,17 @@ pages_map(void *addr, size_t size, int p
 	       {
 		ret = mmap(addr, size, PROT_READ | PROT_WRITE, MAP_PRIVATE |
 		    MAP_ANON, -1, 0);
 	}
 	assert(ret != NULL);
 
 	if (ret == MAP_FAILED) {
 		ret = NULL;
-        }
+	}
 #if defined(__ia64__)
         /* 
          * If the allocated memory doesn't have its upper 17 bits clear, consider it 
          * as out of memory.
         */
         else if ((long long)ret & 0xffff800000000000) {
 		munmap(ret, size);
                 ret = NULL;
@@ -2434,16 +2441,19 @@ pages_map(void *addr, size_t size, int p
 			strerror_r(errno, buf, sizeof(buf));
 			_malloc_message(_getprogname(),
 			    ": (malloc) Error in munmap(): ", buf, "\n");
 			if (opt_abort)
 				abort();
 		}
 		ret = NULL;
 	}
+	if (ret != NULL) {
+		MozTagAnonymousMemory(ret, size, "jemalloc");
+	}
 
 #if defined(__ia64__)
 	assert(ret == NULL || (!check_placement && ret != NULL)
 	    || (check_placement && ret == addr));
 #else
 	assert(ret == NULL || (addr == NULL && ret != addr)
 	    || (addr != NULL && ret == addr));
 #endif
--- a/mfbt/Poison.cpp
+++ b/mfbt/Poison.cpp
@@ -105,20 +105,22 @@ GetDesiredRegionSize()
   // Page size is fixed at 4k.
   return 0x1000;
 }
 
 #define RESERVE_FAILED 0
 
 #else // Unix
 
+#include "mozilla/TaggedAnonymousMemory.h"
+
 static void *
 ReserveRegion(uintptr_t region, uintptr_t size)
 {
-  return mmap(reinterpret_cast<void*>(region), size, PROT_NONE, MAP_PRIVATE|MAP_ANON, -1, 0);
+  return MozTaggedAnonymousMmap(reinterpret_cast<void*>(region), size, PROT_NONE, MAP_PRIVATE|MAP_ANON, -1, 0, "poison");
 }
 
 static void
 ReleaseRegion(void *region, uintptr_t size)
 {
   munmap(region, size);
 }