Disable IsoHeaps when Gigacage is off
authormsaboff@apple.com <msaboff@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 5 Jul 2018 23:12:04 +0000 (23:12 +0000)
committermsaboff@apple.com <msaboff@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 5 Jul 2018 23:12:04 +0000 (23:12 +0000)
https://bugs.webkit.org/show_bug.cgi?id=187160

Reviewed by Saam Barati.

Updated determineMallocFallbackState to base enabling of Iso Heaps on Gigacage
being enabled.  We do this because if Gigacage is disabled, it may be due to lack
of address space.

To work around a compiler issue uncovered by the change above, I added explicit
instantiation of PerThread's static variables.  Defined the same explicit
instantiated static variables with export scope in the new file PerThread.cpp
to eliminate separate variables allocations in each linked framework / library.

* CMakeLists.txt:
* bmalloc.xcodeproj/project.pbxproj:
* bmalloc/IsoTLS.cpp:
(bmalloc::IsoTLS::determineMallocFallbackState):
* bmalloc/PerThread.cpp: Added.
* bmalloc/PerThread.h:

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

Source/bmalloc/CMakeLists.txt
Source/bmalloc/ChangeLog
Source/bmalloc/bmalloc.xcodeproj/project.pbxproj
Source/bmalloc/bmalloc/IsoTLS.cpp
Source/bmalloc/bmalloc/PerThread.cpp [new file with mode: 0644]
Source/bmalloc/bmalloc/PerThread.h

index 2fef48c..aeead58 100644 (file)
@@ -27,6 +27,7 @@ set(bmalloc_SOURCES
     bmalloc/Mutex.cpp
     bmalloc/ObjectType.cpp
     bmalloc/PerProcess.cpp
+    bmalloc/PerThread.cpp
     bmalloc/Scavenger.cpp
     bmalloc/VMHeap.cpp
     bmalloc/bmalloc.cpp
index 0fedc77..75126e4 100644 (file)
@@ -1,3 +1,26 @@
+2018-07-05  Michael Saboff  <msaboff@apple.com>
+
+        Disable IsoHeaps when Gigacage is off
+        https://bugs.webkit.org/show_bug.cgi?id=187160
+
+        Reviewed by Saam Barati.
+
+        Updated determineMallocFallbackState to base enabling of Iso Heaps on Gigacage 
+        being enabled.  We do this because if Gigacage is disabled, it may be due to lack
+        of address space.
+
+        To work around a compiler issue uncovered by the change above, I added explicit
+        instantiation of PerThread's static variables.  Defined the same explicit
+        instantiated static variables with export scope in the new file PerThread.cpp
+        to eliminate separate variables allocations in each linked framework / library.
+
+        * CMakeLists.txt:
+        * bmalloc.xcodeproj/project.pbxproj:
+        * bmalloc/IsoTLS.cpp:
+        (bmalloc::IsoTLS::determineMallocFallbackState):
+        * bmalloc/PerThread.cpp: Added.
+        * bmalloc/PerThread.h:
+
 2018-07-04  Tim Horton  <timothy_horton@apple.com>
 
         Introduce PLATFORM(IOSMAC)
index ee6de66..7d18ef5 100644 (file)
                4426E2801C838EE0008EB042 /* Logging.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4426E27E1C838EE0008EB042 /* Logging.cpp */; };
                4426E2811C838EE0008EB042 /* Logging.h in Headers */ = {isa = PBXBuildFile; fileRef = 4426E27F1C838EE0008EB042 /* Logging.h */; settings = {ATTRIBUTES = (Private, ); }; };
                4426E2831C839547008EB042 /* BSoftLinking.h in Headers */ = {isa = PBXBuildFile; fileRef = 4426E2821C839547008EB042 /* BSoftLinking.h */; };
+               6543DDB420EEAEF3003B23D8 /* PerThread.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6543DDB320EEAEF3003B23D8 /* PerThread.cpp */; };
                6599C5CC1EC3F15900A2F7BB /* AvailableMemory.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6599C5CA1EC3F15900A2F7BB /* AvailableMemory.cpp */; };
                6599C5CD1EC3F15900A2F7BB /* AvailableMemory.h in Headers */ = {isa = PBXBuildFile; fileRef = 6599C5CB1EC3F15900A2F7BB /* AvailableMemory.h */; settings = {ATTRIBUTES = (Private, ); }; };
                7939885B2076EEB60074A2E7 /* BulkDecommit.h in Headers */ = {isa = PBXBuildFile; fileRef = 7939885A2076EEB50074A2E7 /* BulkDecommit.h */; settings = {ATTRIBUTES = (Private, ); }; };
                4426E27E1C838EE0008EB042 /* Logging.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = Logging.cpp; path = bmalloc/Logging.cpp; sourceTree = "<group>"; };
                4426E27F1C838EE0008EB042 /* Logging.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Logging.h; path = bmalloc/Logging.h; sourceTree = "<group>"; };
                4426E2821C839547008EB042 /* BSoftLinking.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = BSoftLinking.h; path = bmalloc/darwin/BSoftLinking.h; sourceTree = "<group>"; };
+               6543DDB320EEAEF3003B23D8 /* PerThread.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; name = PerThread.cpp; path = bmalloc/PerThread.cpp; sourceTree = "<group>"; };
                6599C5CA1EC3F15900A2F7BB /* AvailableMemory.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = AvailableMemory.cpp; path = bmalloc/AvailableMemory.cpp; sourceTree = "<group>"; };
                6599C5CB1EC3F15900A2F7BB /* AvailableMemory.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = AvailableMemory.h; path = bmalloc/AvailableMemory.h; sourceTree = "<group>"; };
                7939885A2076EEB50074A2E7 /* BulkDecommit.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = BulkDecommit.h; path = bmalloc/BulkDecommit.h; sourceTree = "<group>"; };
                                0F26A7A42054830D0090A141 /* PerProcess.cpp */,
                                14446A0717A61FA400F9EA1D /* PerProcess.h */,
                                144469FD17A61F1F00F9EA1D /* PerThread.h */,
+                               6543DDB320EEAEF3003B23D8 /* PerThread.cpp */,
                                145F6878179E3A4400D65598 /* Range.h */,
                                148EFAE61D6B953B008E721E /* ScopeExit.h */,
                                1417F64F18B7280C0076FA3F /* Syscall.h */,
                                0F5BF14F1F22DEAF0029D91D /* Gigacage.cpp in Sources */,
                                14F271C718EA3990008C152F /* Heap.cpp in Sources */,
                                0FD557331F7EDB7B00B1F0A3 /* HeapKind.cpp in Sources */,
+                               6543DDB420EEAEF3003B23D8 /* PerThread.cpp in Sources */,
                                0F7EB83B1F9541B000F1ABCB /* IsoHeapImpl.cpp in Sources */,
                                0F5549EF1FB54704007FF75A /* IsoPage.cpp in Sources */,
                                0F7EB8361F9541B000F1ABCB /* IsoTLS.cpp in Sources */,
index aca5bf0..feb83ff 100644 (file)
@@ -27,6 +27,7 @@
 
 #include "DebugHeap.h"
 #include "Environment.h"
+#include "Gigacage.h"
 #include "IsoTLSEntryInlines.h"
 #include "IsoTLSInlines.h"
 #include "IsoTLSLayout.h"
@@ -201,12 +202,20 @@ void IsoTLS::determineMallocFallbackState()
         [] {
             if (s_mallocFallbackState != MallocFallbackState::Undecided)
                 return;
-            
+
+#if GIGACAGE_ENABLED
+            if (!Gigacage::shouldBeEnabled()) {
+                s_mallocFallbackState = MallocFallbackState::FallBackToMalloc;
+                return;
+            }
             const char* env = getenv("bmalloc_IsoHeap");
             if (env && (!strcasecmp(env, "false") || !strcasecmp(env, "no") || !strcmp(env, "0")))
                 s_mallocFallbackState = MallocFallbackState::FallBackToMalloc;
             else
                 s_mallocFallbackState = MallocFallbackState::DoNotFallBack;
+#else
+            s_mallocFallbackState = MallocFallbackState::FallBackToMalloc;
+#endif
         });
 }
 
diff --git a/Source/bmalloc/bmalloc/PerThread.cpp b/Source/bmalloc/bmalloc/PerThread.cpp
new file mode 100644 (file)
index 0000000..9514456
--- /dev/null
@@ -0,0 +1,40 @@
+/*
+ * Copyright (C) 2018 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "PerThread.h"
+
+#include "BExport.h"
+
+namespace bmalloc {
+    
+template<> BEXPORT bool PerThreadStorage<PerHeapKind<Cache>>::s_didInitialize = false;
+template<> BEXPORT pthread_key_t PerThreadStorage<PerHeapKind<Cache>>::s_key = 0;
+template<> BEXPORT std::once_flag PerThreadStorage<PerHeapKind<Cache>>::s_onceFlag = { };
+
+template<> BEXPORT bool PerThreadStorage<PerHeapKind<Heap>>::s_didInitialize = false;
+template<> BEXPORT pthread_key_t PerThreadStorage<PerHeapKind<Heap>>::s_key = 0;
+template<> BEXPORT std::once_flag PerThreadStorage<PerHeapKind<Heap>>::s_onceFlag = { };
+
+} // namespace bmalloc
index b848f82..eda7420 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2014-2017 Apple Inc. All rights reserved.
+ * Copyright (C) 2014-2018 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -108,9 +108,16 @@ template<typename T> struct PerThreadStorage {
     }
 };
 
-template<typename T> bool PerThreadStorage<T>::s_didInitialize;
-template<typename T> pthread_key_t PerThreadStorage<T>::s_key;
-template<typename T> std::once_flag PerThreadStorage<T>::s_onceFlag;
+class Cache;
+class Heap;
+    
+template<> bool PerThreadStorage<PerHeapKind<Cache>>::s_didInitialize;
+template<> pthread_key_t PerThreadStorage<PerHeapKind<Cache>>::s_key;
+template<> std::once_flag PerThreadStorage<PerHeapKind<Cache>>::s_onceFlag;
+
+template<> bool PerThreadStorage<PerHeapKind<Heap>>::s_didInitialize;
+template<> pthread_key_t PerThreadStorage<PerHeapKind<Heap>>::s_key;
+template<> std::once_flag PerThreadStorage<PerHeapKind<Heap>>::s_onceFlag;
 
 #endif