Bug 1123237 - Part 4. Monitoring allocations and frees for ArrayBuffer. r=terrence,sfink
authorKan-Ru Chen <kanru@kanru.info>
Fri, 08 May 2015 11:16:24 +0800
changeset 295331 86316ff02d2bf864340a4fc97b1c243b08a89677
parent 295330 3763bf7faffd3bd88f24abcdb2082fda5a9ff85a
child 295332 99ea1dafe05f7cb5f1b7a39ce479eed269433510
push id5245
push userraliiev@mozilla.com
push dateThu, 29 Oct 2015 11:30:51 +0000
treeherdermozilla-beta@dac831dc1bd0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersterrence, sfink
bugs1123237
milestone43.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 1123237 - Part 4. Monitoring allocations and frees for ArrayBuffer. r=terrence,sfink Based on patch from Ting-Yuan Huang <laszio.bugzilla@gmail.com>
js/src/vm/ArrayBufferObject.cpp
--- a/js/src/vm/ArrayBufferObject.cpp
+++ b/js/src/vm/ArrayBufferObject.cpp
@@ -249,16 +249,17 @@ ReleaseAsmJSMappedData(void* base)
 #   if defined(MOZ_VALGRIND) && defined(VALGRIND_ENABLE_ADDR_ERROR_REPORTING_IN_RANGE)
     // Tell Valgrind/Memcheck to recommence reporting accesses in the
     // previously-inaccessible region.
     if (AsmJSMappedSize > 0) {
         VALGRIND_ENABLE_ADDR_ERROR_REPORTING_IN_RANGE(base, AsmJSMappedSize);
     }
 #   endif
 #  endif
+    MemProfiler::RemoveNative(base);
 }
 #else
 static void
 ReleaseAsmJSMappedData(void* base)
 {
     MOZ_CRASH("asm.js only uses mapped buffers when using signal-handler OOB checking");
 }
 #endif
@@ -295,16 +296,17 @@ TransferAsmJSMappedBuffer(JSContext* cx,
         // with zero pages.
         int flags = MAP_FIXED | MAP_PRIVATE | MAP_ANON;
         if (mmap(diffStart, diffLength, PROT_READ | PROT_WRITE, flags, -1, 0) == MAP_FAILED) {
             ReleaseAsmJSMappedData(data);
             ReportOutOfMemory(cx);
             return false;
         }
 #  endif
+        MemProfiler::SampleNative(diffStart, diffLength);
     } else if (newByteLength < oldByteLength) {
         void* diffStart = data + newByteLength;
         size_t diffLength = oldByteLength - newByteLength;
 #  ifdef XP_WIN
         if (!VirtualFree(diffStart, diffLength, MEM_DECOMMIT)) {
             ReleaseAsmJSMappedData(data);
             ReportOutOfMemory(cx);
             return false;
@@ -657,22 +659,24 @@ ArrayBufferObject::prepareForAsmJS(JSCon
         return false;
 # endif
 
     // Enable access to the valid region.
     MOZ_ASSERT(buffer->byteLength() % AsmJSPageSize == 0);
 # ifdef XP_WIN
     if (!VirtualAlloc(data, buffer->byteLength(), MEM_COMMIT, PAGE_READWRITE)) {
         VirtualFree(data, 0, MEM_RELEASE);
+        MemProfiler::RemoveNative(data);
         return false;
     }
 # else
     size_t validLength = buffer->byteLength();
     if (mprotect(data, validLength, PROT_READ | PROT_WRITE)) {
         munmap(data, AsmJSMappedSize);
+        MemProfiler::RemoveNative(data);
         return false;
     }
 #   if defined(MOZ_VALGRIND) && defined(VALGRIND_DISABLE_ADDR_ERROR_REPORTING_IN_RANGE)
     // Tell Valgrind/Memcheck to not report accesses in the inaccessible region.
     VALGRIND_DISABLE_ADDR_ERROR_REPORTING_IN_RANGE((unsigned char*)data + validLength,
                                                    AsmJSMappedSize-validLength);
 #   endif
 # endif
@@ -698,16 +702,17 @@ ArrayBufferObject::prepareForAsmJS(JSCon
     return prepareForAsmJSNoSignals(cx, buffer);
 }
 #endif
 
 ArrayBufferObject::BufferContents
 ArrayBufferObject::createMappedContents(int fd, size_t offset, size_t length)
 {
     void* data = AllocateMappedContent(fd, offset, length, ARRAY_BUFFER_ALIGNMENT);
+    MemProfiler::SampleNative(data, length);
     return BufferContents::create<MAPPED>(data);
 }
 
 uint8_t*
 ArrayBufferObject::inlineDataPointer() const
 {
     return static_cast<uint8_t*>(fixedData(JSCLASS_RESERVED_SLOTS(&class_)));
 }
@@ -724,16 +729,17 @@ ArrayBufferObject::releaseData(FreeOp* f
     MOZ_ASSERT(ownsData());
 
     switch (bufferKind()) {
       case PLAIN:
       case ASMJS_MALLOCED:
         fop->free_(dataPointer());
         break;
       case MAPPED:
+        MemProfiler::RemoveNative(dataPointer());
         DeallocateMappedContent(dataPointer(), byteLength());
         break;
       case ASMJS_MAPPED:
         ReleaseAsmJSMappedData(dataPointer());
         break;
     }
 }
 
@@ -1450,16 +1456,17 @@ JS_PUBLIC_API(void*)
 JS_CreateMappedArrayBufferContents(int fd, size_t offset, size_t length)
 {
     return ArrayBufferObject::createMappedContents(fd, offset, length).data();
 }
 
 JS_PUBLIC_API(void)
 JS_ReleaseMappedArrayBufferContents(void* contents, size_t length)
 {
+    MemProfiler::RemoveNative(contents);
     DeallocateMappedContent(contents, length);
 }
 
 JS_FRIEND_API(bool)
 JS_IsMappedArrayBufferObject(JSObject* obj)
 {
     obj = CheckedUnwrap(obj);
     if (!obj)