Bug 1461556 - Add member initializers to the function pointers in JS::AsmJSCacheOps so that JSRuntime::asmJSCacheOps, a js::UnprotectedData<JS::AsmJSCacheOps>, will have its members nulled out automatically when the JSRuntime field is initialized. r=jandem
authorJeff Walden <jwalden@mit.edu>
Wed, 16 May 2018 20:11:59 -0700
changeset 418916 5c09010d054e
parent 418915 d642657c6d7a
child 418917 6ceb0b9f6c80
push id103419
push userjwalden@mit.edu
push dateFri, 18 May 2018 19:33:51 +0000
treeherdermozilla-inbound@7658d2d1e0d7 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjandem
bugs1461556
milestone62.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 1461556 - Add member initializers to the function pointers in JS::AsmJSCacheOps so that JSRuntime::asmJSCacheOps, a js::UnprotectedData<JS::AsmJSCacheOps>, will have its members nulled out automatically when the JSRuntime field is initialized. r=jandem
js/src/jsapi.h
js/src/vm/Runtime.cpp
--- a/js/src/jsapi.h
+++ b/js/src/jsapi.h
@@ -5889,21 +5889,21 @@ namespace JS {
  * This callback represents a request by the JS engine to open for reading the
  * existing cache entry for the given global and char range that may contain a
  * module. If a cache entry exists, the callback shall return 'true' and return
  * the size, base address and an opaque file handle as outparams. If the
  * callback returns 'true', the JS engine guarantees a call to
  * CloseAsmJSCacheEntryForReadOp, passing the same base address, size and
  * handle.
  */
-typedef bool
-(* OpenAsmJSCacheEntryForReadOp)(HandleObject global, const char16_t* begin, const char16_t* limit,
-                                 size_t* size, const uint8_t** memory, intptr_t* handle);
-typedef void
-(* CloseAsmJSCacheEntryForReadOp)(size_t size, const uint8_t* memory, intptr_t handle);
+using OpenAsmJSCacheEntryForReadOp =
+    bool (*)(HandleObject global, const char16_t* begin, const char16_t* limit, size_t* size,
+             const uint8_t** memory, intptr_t* handle);
+using CloseAsmJSCacheEntryForReadOp =
+    void (*)(size_t size, const uint8_t* memory, intptr_t handle);
 
 /** The list of reasons why an asm.js module may not be stored in the cache. */
 enum AsmJSCacheResult
 {
     AsmJSCache_Success,
     AsmJSCache_MIN = AsmJSCache_Success,
     AsmJSCache_ModuleTooSmall,
     AsmJSCache_SynchronousScript,
@@ -5921,29 +5921,28 @@ enum AsmJSCacheResult
  * This callback represents a request by the JS engine to open for writing a
  * cache entry of the given size for the given global and char range containing
  * the just-compiled module. If cache entry space is available, the callback
  * shall return 'true' and return the base address and an opaque file handle as
  * outparams. If the callback returns 'true', the JS engine guarantees a call
  * to CloseAsmJSCacheEntryForWriteOp passing the same base address, size and
  * handle.
  */
-typedef AsmJSCacheResult
-(* OpenAsmJSCacheEntryForWriteOp)(HandleObject global, const char16_t* begin,
-                                  const char16_t* end, size_t size,
-                                  uint8_t** memory, intptr_t* handle);
-typedef void
-(* CloseAsmJSCacheEntryForWriteOp)(size_t size, uint8_t* memory, intptr_t handle);
+using OpenAsmJSCacheEntryForWriteOp =
+    AsmJSCacheResult (*)(HandleObject global, const char16_t* begin, const char16_t* end,
+                         size_t size, uint8_t** memory, intptr_t* handle);
+using CloseAsmJSCacheEntryForWriteOp =
+    void (*)(size_t size, uint8_t* memory, intptr_t handle);
 
 struct AsmJSCacheOps
 {
-    OpenAsmJSCacheEntryForReadOp openEntryForRead;
-    CloseAsmJSCacheEntryForReadOp closeEntryForRead;
-    OpenAsmJSCacheEntryForWriteOp openEntryForWrite;
-    CloseAsmJSCacheEntryForWriteOp closeEntryForWrite;
+    OpenAsmJSCacheEntryForReadOp openEntryForRead = nullptr;
+    CloseAsmJSCacheEntryForReadOp closeEntryForRead = nullptr;
+    OpenAsmJSCacheEntryForWriteOp openEntryForWrite = nullptr;
+    CloseAsmJSCacheEntryForWriteOp closeEntryForWrite = nullptr;
 };
 
 extern JS_PUBLIC_API(void)
 SetAsmJSCacheOps(JSContext* cx, const AsmJSCacheOps* callbacks);
 
 /**
  * Return the buildId (represented as a sequence of characters) associated with
  * the currently-executing build. If the JS engine is embedded such that a
--- a/js/src/vm/Runtime.cpp
+++ b/js/src/vm/Runtime.cpp
@@ -175,19 +175,16 @@ JSRuntime::JSRuntime(JSRuntime* parentRu
     stackFormat_(parentRuntime ? js::StackFormat::Default
                                : js::StackFormat::SpiderMonkey),
     wasmInstances(mutexid::WasmRuntimeInstances),
     moduleResolveHook()
 {
     JS_COUNT_CTOR(JSRuntime);
     liveRuntimesCount++;
 
-    /* Initialize infallibly first, so we can goto bad and JS_DestroyRuntime. */
-
-    PodZero(&asmJSCacheOps);
     lcovOutput().init();
 }
 
 JSRuntime::~JSRuntime()
 {
     JS_COUNT_DTOR(JSRuntime);
     MOZ_ASSERT(!initialized_);