NeverDestroyed related leaks seen on bots
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 3 Aug 2017 04:46:46 +0000 (04:46 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 3 Aug 2017 04:46:46 +0000 (04:46 +0000)
https://bugs.webkit.org/show_bug.cgi?id=175113

Patch by Joseph Pecoraro <pecoraro@apple.com> on 2017-08-02
Reviewed by Yusuke Suzuki.

* wtf/NeverDestroyed.h:
(WTF::NeverDestroyed::NeverDestroyed):
Previously the result of makeNeverDestroyed was not always moving into
the `static NeverDestroyed` static local variable. In some cases it would
re-invoke the constructor, creating a new NeverDestroyed object. In the
case of a Vector it was causing leaks.

Adding a move constructor convinces the compiler to move the result
of makeNeverDestroyed into the NeverDestroyed static. It doesn't actually
invoke the move constructor here, which I believe means it is deciding
to perform optional copy elision optimization.
'http://en.cppreference.com/w/cpp/language/copy_elision

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@220183 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WTF/ChangeLog
Source/WTF/wtf/NeverDestroyed.h

index 27d72d71330e0a63ccbf1275c225d77602f978d8..6c07a858f8a5a75184579f57bc31ed60e93e6cfa 100644 (file)
@@ -1,3 +1,23 @@
+2017-08-02  Joseph Pecoraro  <pecoraro@apple.com>
+
+        NeverDestroyed related leaks seen on bots
+        https://bugs.webkit.org/show_bug.cgi?id=175113
+
+        Reviewed by Yusuke Suzuki.
+
+        * wtf/NeverDestroyed.h:
+        (WTF::NeverDestroyed::NeverDestroyed):
+        Previously the result of makeNeverDestroyed was not always moving into
+        the `static NeverDestroyed` static local variable. In some cases it would
+        re-invoke the constructor, creating a new NeverDestroyed object. In the
+        case of a Vector it was causing leaks.
+
+        Adding a move constructor convinces the compiler to move the result
+        of makeNeverDestroyed into the NeverDestroyed static. It doesn't actually
+        invoke the move constructor here, which I believe means it is deciding
+        to perform optional copy elision optimization.
+        'http://en.cppreference.com/w/cpp/language/copy_elision
+
 2017-08-02  Filip Pizlo  <fpizlo@apple.com>
 
         All C++ accesses to JSObject::m_butterfly should do caging
index 8784b6ed650f2775ed719fa2684c00860647ea36..c2b4842d12d256af8e488916082caf534d53031e 100644 (file)
@@ -50,6 +50,11 @@ public:
         MaybeRelax<T>(new (storagePointer()) T(std::forward<Args>(args)...));
     }
 
+    NeverDestroyed(NeverDestroyed&& other)
+    {
+        MaybeRelax<T>(new (storagePointer()) T(WTFMove(other)));
+    }
+
     operator T&() { return *storagePointer(); }
     T& get() { return *storagePointer(); }