Bug 1183754, part 3 - Use a UniquePtr for XPCWrappedNativeChunk::mNextChunk. r=bholley
authorAndrew McCreight <continuation@gmail.com>
Wed, 03 Feb 2016 08:30:14 -0800
changeset 321157 f9da131e369097693b0e17a192ff54eee9c04399
parent 321156 18fee9ad98e589ddade2bb14697b9d4d301b97fe
child 321158 b3cad29ae5d7f715b203a2a764a351deb0f5fe96
push id1128
push userjlund@mozilla.com
push dateWed, 01 Jun 2016 01:31:59 +0000
treeherdermozilla-release@fe0d30de989d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbholley
bugs1183754
milestone47.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 1183754, part 3 - Use a UniquePtr for XPCWrappedNativeChunk::mNextChunk. r=bholley
js/xpconnect/src/XPCInlines.h
js/xpconnect/src/XPCWrappedNative.cpp
js/xpconnect/src/xpcprivate.h
--- a/js/xpconnect/src/XPCInlines.h
+++ b/js/xpconnect/src/XPCInlines.h
@@ -533,17 +533,17 @@ XPCWrappedNative::HasInterfaceNoQI(const
 {
     return nullptr != GetSet()->FindInterfaceWithIID(iid);
 }
 
 inline void
 XPCWrappedNative::SweepTearOffs()
 {
     XPCWrappedNativeTearOffChunk* chunk;
-    for (chunk = &mFirstChunk; chunk; chunk = chunk->mNextChunk) {
+    for (chunk = &mFirstChunk; chunk; chunk = chunk->mNextChunk.get()) {
         XPCWrappedNativeTearOff* to = &chunk->mTearOff;
         bool marked = to->IsMarked();
         to->Unmark();
         if (marked)
             continue;
 
         // If this tearoff does not have a live dedicated JSObject,
         // then let's recycle it.
--- a/js/xpconnect/src/XPCWrappedNative.cpp
+++ b/js/xpconnect/src/XPCWrappedNative.cpp
@@ -109,17 +109,17 @@ void
 XPCWrappedNative::NoteTearoffs(nsCycleCollectionTraversalCallback& cb)
 {
     // Tearoffs hold their native object alive. If their JS object hasn't been
     // finalized yet we'll note the edge between the JS object and the native
     // (see nsXPConnect::Traverse), but if their JS object has been finalized
     // then the tearoff is only reachable through the XPCWrappedNative, so we
     // record an edge here.
     XPCWrappedNativeTearOffChunk* chunk;
-    for (chunk = &mFirstChunk; chunk; chunk = chunk->mNextChunk) {
+    for (chunk = &mFirstChunk; chunk; chunk = chunk->mNextChunk.get()) {
         XPCWrappedNativeTearOff* to = &chunk->mTearOff;
         JSObject* jso = to->GetJSObjectPreserveColor();
         if (!jso) {
             NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "tearoff's mNative");
             cb.NoteXPCOMChild(to->GetNative());
         }
     }
 }
@@ -894,17 +894,17 @@ XPCWrappedNative::FlatJSObjectFinalized(
         return;
 
     // Iterate the tearoffs and null out each of their JSObject's privates.
     // This will keep them from trying to access their pointers to the
     // dying tearoff object. We can safely assume that those remaining
     // JSObjects are about to be finalized too.
 
     XPCWrappedNativeTearOffChunk* chunk;
-    for (chunk = &mFirstChunk; chunk; chunk = chunk->mNextChunk) {
+    for (chunk = &mFirstChunk; chunk; chunk = chunk->mNextChunk.get()) {
         XPCWrappedNativeTearOff* to = &chunk->mTearOff;
         JSObject* jso = to->GetJSObjectPreserveColor();
         if (jso) {
             JS_SetPrivate(jso, nullptr);
 #ifdef DEBUG
             JS_UpdateWeakPointerAfterGCUnbarriered(&jso);
             MOZ_ASSERT(!jso);
 #endif
@@ -984,17 +984,17 @@ XPCWrappedNative::SystemIsBeingShutDown(
     if (mScriptableInfo &&
         (!HasProto() ||
          (proto && proto->GetScriptableInfo() != mScriptableInfo))) {
         delete mScriptableInfo;
     }
 
     // Cleanup the tearoffs.
     XPCWrappedNativeTearOffChunk* chunk;
-    for (chunk = &mFirstChunk; chunk; chunk = chunk->mNextChunk) {
+    for (chunk = &mFirstChunk; chunk; chunk = chunk->mNextChunk.get()) {
         XPCWrappedNativeTearOff* to = &chunk->mTearOff;
         if (JSObject* jso = to->GetJSObjectPreserveColor()) {
             JS_SetPrivate(jso, nullptr);
             to->SetJSObject(nullptr);
         }
         // We leak the tearoff mNative
         // (for the same reason we leak mIdentity - see above).
         Unused << to->TakeNative().take();
@@ -1051,17 +1051,17 @@ XPCWrappedNative::FindTearOff(XPCNativeI
     nsresult rv = NS_OK;
     XPCWrappedNativeTearOff* to;
     XPCWrappedNativeTearOff* firstAvailable = nullptr;
 
     XPCWrappedNativeTearOffChunk* lastChunk;
     XPCWrappedNativeTearOffChunk* chunk;
     for (lastChunk = chunk = &mFirstChunk;
          chunk;
-         lastChunk = chunk, chunk = chunk->mNextChunk) {
+         lastChunk = chunk, chunk = chunk->mNextChunk.get()) {
         to = &chunk->mTearOff;
         if (to->GetInterface() == aInterface) {
             if (needJSObject && !to->GetJSObjectPreserveColor()) {
                 AutoMarkingWrappedNativeTearOffPtr tearoff(cx, to);
                 bool ok = InitTearOffJSObject(to);
                 // During shutdown, we don't sweep tearoffs.  So make sure
                 // to unmark manually in case the auto-marker marked us.
                 // We shouldn't ever be getting here _during_ our
@@ -1078,19 +1078,18 @@ XPCWrappedNative::FindTearOff(XPCNativeI
         }
         if (!firstAvailable && to->IsAvailable())
             firstAvailable = to;
     }
 
     to = firstAvailable;
 
     if (!to) {
-        auto newChunk = new XPCWrappedNativeTearOffChunk();
-        lastChunk->mNextChunk = newChunk;
-        to = &newChunk->mTearOff;
+        lastChunk->mNextChunk = MakeUnique<XPCWrappedNativeTearOffChunk>();
+        to = &lastChunk->mNextChunk->mTearOff;
     }
 
     {
         // Scope keeps |tearoff| from leaking across the rest of the function.
         AutoMarkingWrappedNativeTearOffPtr tearoff(cx, to);
         rv = InitTearOff(to, aInterface, needJSObject);
         // During shutdown, we don't sweep tearoffs.  So make sure to unmark
         // manually in case the auto-marker marked us.  We shouldn't ever be
--- a/js/xpconnect/src/xpcprivate.h
+++ b/js/xpconnect/src/xpcprivate.h
@@ -80,16 +80,17 @@
 #include "mozilla/Atomics.h"
 #include "mozilla/Attributes.h"
 #include "mozilla/CycleCollectedJSRuntime.h"
 #include "mozilla/GuardObjects.h"
 #include "mozilla/Maybe.h"
 #include "mozilla/MemoryReporting.h"
 #include "mozilla/Preferences.h"
 #include "mozilla/TimeStamp.h"
+#include "mozilla/UniquePtr.h"
 
 #include "mozilla/dom/ScriptSettings.h"
 
 #include <math.h>
 #include <stdint.h>
 #include <stdlib.h>
 #include <string.h>
 
@@ -1987,23 +1988,23 @@ private:
 // XPCWrappedNativeTearOffChunk is a linked list of XPCWrappedNativeTearOff
 // objects. It lets us allocate a set of XPCWrappedNativeTearOff objects and
 // link the sets - rather than only having the option of linking single
 // XPCWrappedNativeTearOff objects.
 
 class XPCWrappedNativeTearOffChunk
 {
 friend class XPCWrappedNative;
-private:
-    XPCWrappedNativeTearOffChunk() : mNextChunk(nullptr) {}
-    ~XPCWrappedNativeTearOffChunk() {delete mNextChunk;}
+public:
+    XPCWrappedNativeTearOffChunk() {}
+    ~XPCWrappedNativeTearOffChunk() {}
 
 private:
     XPCWrappedNativeTearOff mTearOff;
-    XPCWrappedNativeTearOffChunk* mNextChunk;
+    mozilla::UniquePtr<XPCWrappedNativeTearOffChunk> mNextChunk;
 };
 
 /***************************************************************************/
 // XPCWrappedNative the wrapper around one instance of a native xpcom object
 // to be used from JavaScript.
 
 class XPCWrappedNative final : public nsIXPConnectWrappedNative
 {