Correctly account for two-byte source text allocation when XPCJSSourceHook allocates it, to return a count of bytes, not of two-byte code units. No bug, rs=bz over IRC
authorJeff Walden <jwalden@mit.edu>
Fri, 12 Apr 2019 18:52:22 -0700
changeset 530452 9eeeb4f28ddc43ee8b15b13ccc2ceb21b1af7bbb
parent 530451 f31fa29b2a08aa51ed1a917444b9780483523111
child 530453 7bdb46cc5ec6221c8df10f0a239dc4faf457488d
child 530472 2a2a6da7e8990127f5dfa5a2e12d30bb627357a9
push id11265
push userffxbld-merge
push dateMon, 13 May 2019 10:53:39 +0000
treeherdermozilla-beta@77e0fe8dbdd3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz
milestone68.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
Correctly account for two-byte source text allocation when XPCJSSourceHook allocates it, to return a count of bytes, not of two-byte code units. No bug, rs=bz over IRC
js/xpconnect/src/XPCJSRuntime.cpp
--- a/js/xpconnect/src/XPCJSRuntime.cpp
+++ b/js/xpconnect/src/XPCJSRuntime.cpp
@@ -2875,42 +2875,43 @@ static nsresult ReadSourceFromFilename(J
     rv = scriptStream->Read(ptr, PointerRangeSize(ptr, end), &bytesRead);
     if (NS_FAILED(rv)) {
       return rv;
     }
     MOZ_ASSERT(bytesRead > 0, "stream promised more bytes before EOF");
     ptr += bytesRead;
   }
 
+  size_t bytesAllocated;
   if (utf8Source) {
     // |buf| is already UTF-8, so we can directly return it.
-    *len = rawLen;
+    *len = bytesAllocated = rawLen;
     *utf8Source = buf.release();
   } else {
     MOZ_ASSERT(twoByteSource != nullptr);
 
     // |buf| can't be directly returned -- convert it to UTF-16.
 
     // On success this overwrites |*twoByteSource| and |*len|.
     rv = ScriptLoader::ConvertToUTF16(
         scriptChannel, reinterpret_cast<const unsigned char*>(buf.get()),
         rawLen, NS_LITERAL_STRING("UTF-8"), nullptr, *twoByteSource, *len);
     NS_ENSURE_SUCCESS(rv, rv);
 
     if (!*twoByteSource) {
       return NS_ERROR_FAILURE;
     }
+
+    bytesAllocated = *len * sizeof(char16_t);
   }
 
   // Historically this method used JS_malloc() which updates the GC memory
   // accounting.  Since ConvertToUTF16() and js::MakeUnique now use js_malloc()
   // instead we update the accounting manually after the fact.
-  //
-  // XXX jwalden Should this be |*len * sizeof(char16_t)| in the UTF-16 case?
-  JS_updateMallocCounter(cx, *len);
+  JS_updateMallocCounter(cx, bytesAllocated);
 
   return NS_OK;
 }
 
 // The JS engine calls this object's 'load' member function when it needs
 // the source for a chrome JS function. See the comment in the XPCJSRuntime
 // constructor.
 class XPCJSSourceHook : public js::SourceHook {