IsoHeaps don't notice uncommitted VA becoming the first eligible.
authorkeith_miller@apple.com <keith_miller@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 30 May 2019 23:07:27 +0000 (23:07 +0000)
committerkeith_miller@apple.com <keith_miller@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 30 May 2019 23:07:27 +0000 (23:07 +0000)
https://bugs.webkit.org/show_bug.cgi?id=198301

Reviewed by Yusuke Suzuki.

Source/bmalloc:

IsoDirectory has a firstEligible member that is used as an
optimization to help find the first fit. However if the scavenger
decommitted a page before firstEligible then we wouldn't move
firstEligible. Thus, if no space is ever freed below firstEligible
we will never reused the decommitted memory (e.g. if the VA page
is decommitted). The fix is to make IsoDirectory::didDecommit move
the firstEligible page back if the decommitted page is smaller
than the current firstEligible. As such, this patch renames
firstEligible to firstEligibleOrDecommitted.

Also, this patch changes gigacageEnabledForProcess to check if the
process starts with Test rather than just test as TestWTF does.

Lastly, unbeknownst to me IsoHeaps are dependent on gigacage, so
by removing gigacage from arm64 I accidentally disabled
IsoHeaps...

* bmalloc.xcodeproj/project.pbxproj:
* bmalloc/IsoDirectory.h:
* bmalloc/IsoDirectoryInlines.h:
(bmalloc::passedNumPages>::takeFirstEligible):
(bmalloc::passedNumPages>::didBecome):
(bmalloc::passedNumPages>::didDecommit):
* bmalloc/IsoHeapImpl.h:
* bmalloc/IsoHeapImplInlines.h:
(bmalloc::IsoHeapImpl<Config>::takeFirstEligible):
(bmalloc::IsoHeapImpl<Config>::didBecomeEligibleOrDecommited):
(bmalloc::IsoHeapImpl<Config>::didCommit):
(bmalloc::IsoHeapImpl<Config>::didBecomeEligible): Deleted.
* bmalloc/IsoTLS.cpp:
(bmalloc::IsoTLS::determineMallocFallbackState):
* bmalloc/ProcessCheck.mm:
(bmalloc::gigacageEnabledForProcess):

Tools:

Move testbmalloc.cpp to TestWTF so it runs in automation.

* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* TestWebKitAPI/Tests/WTF/bmalloc/IsoHeap.cpp: Renamed from Source/bmalloc/test/testbmalloc.cpp.
(TEST):

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

Source/bmalloc/ChangeLog
Source/bmalloc/bmalloc.xcodeproj/project.pbxproj
Source/bmalloc/bmalloc/IsoDirectory.h
Source/bmalloc/bmalloc/IsoDirectoryInlines.h
Source/bmalloc/bmalloc/IsoHeapImpl.h
Source/bmalloc/bmalloc/IsoHeapImplInlines.h
Source/bmalloc/bmalloc/IsoTLS.cpp
Source/bmalloc/bmalloc/ProcessCheck.mm
Tools/ChangeLog
Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj
Tools/TestWebKitAPI/Tests/WTF/bmalloc/IsoHeap.cpp [moved from Source/bmalloc/test/testbmalloc.cpp with 71% similarity]

index ddfd806..ba9dbf0 100644 (file)
@@ -1,3 +1,44 @@
+2019-05-30  Keith Miller  <keith_miller@apple.com>
+
+        IsoHeaps don't notice uncommitted VA becoming the first eligible.
+        https://bugs.webkit.org/show_bug.cgi?id=198301
+
+        Reviewed by Yusuke Suzuki.
+
+        IsoDirectory has a firstEligible member that is used as an
+        optimization to help find the first fit. However if the scavenger
+        decommitted a page before firstEligible then we wouldn't move
+        firstEligible. Thus, if no space is ever freed below firstEligible
+        we will never reused the decommitted memory (e.g. if the VA page
+        is decommitted). The fix is to make IsoDirectory::didDecommit move
+        the firstEligible page back if the decommitted page is smaller
+        than the current firstEligible. As such, this patch renames
+        firstEligible to firstEligibleOrDecommitted.
+
+        Also, this patch changes gigacageEnabledForProcess to check if the
+        process starts with Test rather than just test as TestWTF does.
+
+        Lastly, unbeknownst to me IsoHeaps are dependent on gigacage, so
+        by removing gigacage from arm64 I accidentally disabled
+        IsoHeaps...
+
+        * bmalloc.xcodeproj/project.pbxproj:
+        * bmalloc/IsoDirectory.h:
+        * bmalloc/IsoDirectoryInlines.h:
+        (bmalloc::passedNumPages>::takeFirstEligible):
+        (bmalloc::passedNumPages>::didBecome):
+        (bmalloc::passedNumPages>::didDecommit):
+        * bmalloc/IsoHeapImpl.h:
+        * bmalloc/IsoHeapImplInlines.h:
+        (bmalloc::IsoHeapImpl<Config>::takeFirstEligible):
+        (bmalloc::IsoHeapImpl<Config>::didBecomeEligibleOrDecommited):
+        (bmalloc::IsoHeapImpl<Config>::didCommit):
+        (bmalloc::IsoHeapImpl<Config>::didBecomeEligible): Deleted.
+        * bmalloc/IsoTLS.cpp:
+        (bmalloc::IsoTLS::determineMallocFallbackState):
+        * bmalloc/ProcessCheck.mm:
+        (bmalloc::gigacageEnabledForProcess):
+
 2019-05-23  Don Olmstead  <don.olmstead@sony.com>
 
         [CMake] Use target oriented design for bmalloc
index 92f85cf..f7475fa 100644 (file)
@@ -33,8 +33,6 @@
                0F5BF1731F23C5710029D91D /* BExport.h in Headers */ = {isa = PBXBuildFile; fileRef = 0F5BF1721F23C5710029D91D /* BExport.h */; settings = {ATTRIBUTES = (Private, ); }; };
                0F74B93E1F89713E00B935D3 /* CryptoRandom.h in Headers */ = {isa = PBXBuildFile; fileRef = 0F74B93C1F89713E00B935D3 /* CryptoRandom.h */; settings = {ATTRIBUTES = (Private, ); }; };
                0F74B93F1F89713E00B935D3 /* CryptoRandom.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0F74B93D1F89713E00B935D3 /* CryptoRandom.cpp */; };
-               0F7EB7F21F95285300F1ABCB /* testbmalloc.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0F7EB7F11F95285300F1ABCB /* testbmalloc.cpp */; };
-               0F7EB7FA1F95414C00F1ABCB /* libbmalloc.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 14F271BE18EA3963008C152F /* libbmalloc.a */; };
                0F7EB8231F9541B000F1ABCB /* EligibilityResult.h in Headers */ = {isa = PBXBuildFile; fileRef = 0F7EB7FC1F9541AD00F1ABCB /* EligibilityResult.h */; settings = {ATTRIBUTES = (Private, ); }; };
                0F7EB8241F9541B000F1ABCB /* IsoHeapImplInlines.h in Headers */ = {isa = PBXBuildFile; fileRef = 0F7EB7FD1F9541AD00F1ABCB /* IsoHeapImplInlines.h */; settings = {ATTRIBUTES = (Private, ); }; };
                0F7EB8251F9541B000F1ABCB /* DeferredTriggerInlines.h in Headers */ = {isa = PBXBuildFile; fileRef = 0F7EB7FE1F9541AD00F1ABCB /* DeferredTriggerInlines.h */; settings = {ATTRIBUTES = (Private, ); }; };
                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, ); }; };
                795AB3C7206E0D340074FE76 /* PhysicalPageMap.h in Headers */ = {isa = PBXBuildFile; fileRef = 795AB3C6206E0D250074FE76 /* PhysicalPageMap.h */; settings = {ATTRIBUTES = (Private, ); }; };
-               7C571EFF22388B080077A3C7 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 142FC6212096409E00A99362 /* Foundation.framework */; };
                7C571F0122388B840077A3C7 /* StdLibExtras.h in Headers */ = {isa = PBXBuildFile; fileRef = 7C571F0022388B840077A3C7 /* StdLibExtras.h */; settings = {ATTRIBUTES = (Private, ); }; };
                AD0934331FCF406D00E85EB5 /* BCompiler.h in Headers */ = {isa = PBXBuildFile; fileRef = AD0934321FCF405000E85EB5 /* BCompiler.h */; settings = {ATTRIBUTES = (Private, ); }; };
                AD14AD29202529C400890E3B /* ProcessCheck.h in Headers */ = {isa = PBXBuildFile; fileRef = AD14AD27202529A600890E3B /* ProcessCheck.h */; };
 /* End PBXBuildFile section */
 
 /* Begin PBXContainerItemProxy section */
-               0F7EB7F71F95412900F1ABCB /* PBXContainerItemProxy */ = {
-                       isa = PBXContainerItemProxy;
-                       containerPortal = 145F6837179DC45F00D65598 /* Project object */;
-                       proxyType = 1;
-                       remoteGlobalIDString = 14F271BD18EA3963008C152F;
-                       remoteInfo = bmalloc;
-               };
                0F7EB8551F95505400F1ABCB /* PBXContainerItemProxy */ = {
                        isa = PBXContainerItemProxy;
                        containerPortal = 145F6837179DC45F00D65598 /* Project object */;
                };
 /* End PBXContainerItemProxy section */
 
-/* Begin PBXCopyFilesBuildPhase section */
-               0F7EB7ED1F95285300F1ABCB /* CopyFiles */ = {
-                       isa = PBXCopyFilesBuildPhase;
-                       buildActionMask = 2147483647;
-                       dstPath = /usr/share/man/man1/;
-                       dstSubfolderSpec = 0;
-                       files = (
-                       );
-                       runOnlyForDeploymentPostprocessing = 1;
-               };
-/* End PBXCopyFilesBuildPhase section */
-
 /* Begin PBXFileReference section */
                0F26A7A42054830D0090A141 /* PerProcess.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = PerProcess.cpp; path = bmalloc/PerProcess.cpp; sourceTree = "<group>"; };
                0F5167731FAD6852008236A8 /* bmalloc.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = bmalloc.cpp; path = bmalloc/bmalloc.cpp; sourceTree = "<group>"; };
                0F5BF1721F23C5710029D91D /* BExport.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = BExport.h; path = bmalloc/BExport.h; sourceTree = "<group>"; };
                0F74B93C1F89713E00B935D3 /* CryptoRandom.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CryptoRandom.h; path = bmalloc/CryptoRandom.h; sourceTree = "<group>"; };
                0F74B93D1F89713E00B935D3 /* CryptoRandom.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CryptoRandom.cpp; path = bmalloc/CryptoRandom.cpp; sourceTree = "<group>"; };
-               0F7EB7EF1F95285300F1ABCB /* testbmalloc */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = testbmalloc; sourceTree = BUILT_PRODUCTS_DIR; };
-               0F7EB7F11F95285300F1ABCB /* testbmalloc.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = testbmalloc.cpp; sourceTree = "<group>"; };
                0F7EB7FC1F9541AD00F1ABCB /* EligibilityResult.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = EligibilityResult.h; path = bmalloc/EligibilityResult.h; sourceTree = SOURCE_ROOT; };
                0F7EB7FD1F9541AD00F1ABCB /* IsoHeapImplInlines.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = IsoHeapImplInlines.h; path = bmalloc/IsoHeapImplInlines.h; sourceTree = SOURCE_ROOT; };
                0F7EB7FE1F9541AD00F1ABCB /* DeferredTriggerInlines.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = DeferredTriggerInlines.h; path = bmalloc/DeferredTriggerInlines.h; sourceTree = SOURCE_ROOT; };
 /* End PBXFileReference section */
 
 /* Begin PBXFrameworksBuildPhase section */
-               0F7EB7EC1F95285300F1ABCB /* Frameworks */ = {
-                       isa = PBXFrameworksBuildPhase;
-                       buildActionMask = 2147483647;
-                       files = (
-                               7C571EFF22388B080077A3C7 /* Foundation.framework in Frameworks */,
-                               0F7EB7FA1F95414C00F1ABCB /* libbmalloc.a in Frameworks */,
-                       );
-                       runOnlyForDeploymentPostprocessing = 0;
-               };
                14CC394118EA8743004AFE34 /* Frameworks */ = {
                        isa = PBXFrameworksBuildPhase;
                        buildActionMask = 2147483647;
 /* End PBXFrameworksBuildPhase section */
 
 /* Begin PBXGroup section */
-               0F7EB7F01F95285300F1ABCB /* test */ = {
-                       isa = PBXGroup;
-                       children = (
-                               0F7EB7F11F95285300F1ABCB /* testbmalloc.cpp */,
-                       );
-                       path = test;
-                       sourceTree = "<group>";
-               };
                0F7EB7F91F95414C00F1ABCB /* Frameworks */ = {
                        isa = PBXGroup;
                        children = (
                                0F7EB7FB1F95416900F1ABCB /* iso */,
                                145F6840179DC45F00D65598 /* Products */,
                                14D9DB4F17F2868900EAAB79 /* stdlib */,
-                               0F7EB7F01F95285300F1ABCB /* test */,
                        );
                        sourceTree = "<group>";
                };
                145F6840179DC45F00D65598 /* Products */ = {
                        isa = PBXGroup;
                        children = (
-                               0F7EB7EF1F95285300F1ABCB /* testbmalloc */,
                                14F271BE18EA3963008C152F /* libbmalloc.a */,
                                14CC394418EA8743004AFE34 /* libmbmalloc.dylib */,
                        );
 /* End PBXHeadersBuildPhase section */
 
 /* Begin PBXNativeTarget section */
-               0F7EB7EE1F95285300F1ABCB /* testbmalloc */ = {
-                       isa = PBXNativeTarget;
-                       buildConfigurationList = 0F7EB7F61F95285300F1ABCB /* Build configuration list for PBXNativeTarget "testbmalloc" */;
-                       buildPhases = (
-                               0F7EB7EB1F95285300F1ABCB /* Sources */,
-                               0F7EB7EC1F95285300F1ABCB /* Frameworks */,
-                               0F7EB7ED1F95285300F1ABCB /* CopyFiles */,
-                       );
-                       buildRules = (
-                       );
-                       dependencies = (
-                               0F7EB7F81F95412900F1ABCB /* PBXTargetDependency */,
-                       );
-                       name = testbmalloc;
-                       productName = testbmalloc;
-                       productReference = 0F7EB7EF1F95285300F1ABCB /* testbmalloc */;
-                       productType = "com.apple.product-type.tool";
-               };
                14CC394318EA8743004AFE34 /* mbmalloc */ = {
                        isa = PBXNativeTarget;
                        buildConfigurationList = 14CC394518EA8743004AFE34 /* Build configuration list for PBXNativeTarget "mbmalloc" */;
                                LastSwiftUpdateCheck = 0700;
                                LastUpgradeCheck = 1000;
                                TargetAttributes = {
-                                       0F7EB7EE1F95285300F1ABCB = {
-                                               CreatedOnToolsVersion = 9.0;
-                                               ProvisioningStyle = Manual;
-                                       };
                                        0F7EB8501F95504B00F1ABCB = {
                                                CreatedOnToolsVersion = 9.0;
                                                ProvisioningStyle = Automatic;
                                0F7EB8501F95504B00F1ABCB /* All */,
                                14F271BD18EA3963008C152F /* bmalloc */,
                                14CC394318EA8743004AFE34 /* mbmalloc */,
-                               0F7EB7EE1F95285300F1ABCB /* testbmalloc */,
                        );
                };
 /* End PBXProject section */
 
 /* Begin PBXSourcesBuildPhase section */
-               0F7EB7EB1F95285300F1ABCB /* Sources */ = {
-                       isa = PBXSourcesBuildPhase;
-                       buildActionMask = 2147483647;
-                       files = (
-                               0F7EB7F21F95285300F1ABCB /* testbmalloc.cpp in Sources */,
-                       );
-                       runOnlyForDeploymentPostprocessing = 0;
-               };
                14CC394018EA8743004AFE34 /* Sources */ = {
                        isa = PBXSourcesBuildPhase;
                        buildActionMask = 2147483647;
 /* End PBXSourcesBuildPhase section */
 
 /* Begin PBXTargetDependency section */
-               0F7EB7F81F95412900F1ABCB /* PBXTargetDependency */ = {
-                       isa = PBXTargetDependency;
-                       target = 14F271BD18EA3963008C152F /* bmalloc */;
-                       targetProxy = 0F7EB7F71F95412900F1ABCB /* PBXContainerItemProxy */;
-               };
                0F7EB8561F95505400F1ABCB /* PBXTargetDependency */ = {
                        isa = PBXTargetDependency;
                        target = 14F271BD18EA3963008C152F /* bmalloc */;
 /* End PBXTargetDependency section */
 
 /* Begin XCBuildConfiguration section */
-               0F7EB7F31F95285300F1ABCB /* Debug */ = {
-                       isa = XCBuildConfiguration;
-                       baseConfigurationReference = 14B650C718F39F4800751968 /* DebugRelease.xcconfig */;
-                       buildSettings = {
-                               PRODUCT_NAME = "$(TARGET_NAME)";
-                       };
-                       name = Debug;
-               };
-               0F7EB7F41F95285300F1ABCB /* Release */ = {
-                       isa = XCBuildConfiguration;
-                       baseConfigurationReference = 14B650C718F39F4800751968 /* DebugRelease.xcconfig */;
-                       buildSettings = {
-                               PRODUCT_NAME = "$(TARGET_NAME)";
-                       };
-                       name = Release;
-               };
-               0F7EB7F51F95285300F1ABCB /* Production */ = {
-                       isa = XCBuildConfiguration;
-                       baseConfigurationReference = 14B650C518F39F4800751968 /* Base.xcconfig */;
-                       buildSettings = {
-                               PRODUCT_NAME = "$(TARGET_NAME)";
-                       };
-                       name = Production;
-               };
                0F7EB8521F95504B00F1ABCB /* Debug */ = {
                        isa = XCBuildConfiguration;
                        buildSettings = {
 /* End XCBuildConfiguration section */
 
 /* Begin XCConfigurationList section */
-               0F7EB7F61F95285300F1ABCB /* Build configuration list for PBXNativeTarget "testbmalloc" */ = {
-                       isa = XCConfigurationList;
-                       buildConfigurations = (
-                               0F7EB7F31F95285300F1ABCB /* Debug */,
-                               0F7EB7F41F95285300F1ABCB /* Release */,
-                               0F7EB7F51F95285300F1ABCB /* Production */,
-                       );
-                       defaultConfigurationIsVisible = 0;
-                       defaultConfigurationName = Production;
-               };
                0F7EB8511F95504B00F1ABCB /* Build configuration list for PBXAggregateTarget "All" */ = {
                        isa = XCConfigurationList;
                        buildConfigurations = (
index 30df8a6..1d824f4 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2017-2018 Apple Inc. All rights reserved.
+ * Copyright (C) 2017-2019 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -88,7 +88,7 @@ private:
     Bits<numPages> m_empty;
     Bits<numPages> m_committed;
     std::array<IsoPage<Config>*, numPages> m_pages;
-    unsigned m_firstEligible { 0 };
+    unsigned m_firstEligibleOrDecommitted { 0 };
 };
 
 } // namespace bmalloc
index 640d82e..cc0e6a7 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2017-2018 Apple Inc. All rights reserved.
+ * Copyright (C) 2017-2019 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -46,8 +46,9 @@ IsoDirectory<Config, passedNumPages>::IsoDirectory(IsoHeapImpl<Config>& heap)
 template<typename Config, unsigned passedNumPages>
 EligibilityResult<Config> IsoDirectory<Config, passedNumPages>::takeFirstEligible()
 {
-    unsigned pageIndex = (m_eligible | ~m_committed).findBit(m_firstEligible, true);
-    m_firstEligible = pageIndex;
+    unsigned pageIndex = (m_eligible | ~m_committed).findBit(m_firstEligibleOrDecommitted, true);
+    m_firstEligibleOrDecommitted = pageIndex;
+    BASSERT((m_eligible | ~m_committed).findBit(0, true) == pageIndex);
     if (pageIndex >= numPages)
         return EligibilityKind::Full;
 
@@ -97,8 +98,8 @@ void IsoDirectory<Config, passedNumPages>::didBecome(IsoPage<Config>* page, IsoP
         if (verbose)
             fprintf(stderr, "%p: %p did become eligible.\n", this, page);
         m_eligible[pageIndex] = true;
-        m_firstEligible = std::min(m_firstEligible, pageIndex);
-        this->m_heap.didBecomeEligible(this);
+        m_firstEligibleOrDecommitted = std::min(m_firstEligibleOrDecommitted, pageIndex);
+        this->m_heap.didBecomeEligibleOrDecommited(this);
         return;
     case IsoPageTrigger::Empty:
         if (verbose)
@@ -122,6 +123,8 @@ void IsoDirectory<Config, passedNumPages>::didDecommit(unsigned index)
     BASSERT(!!m_committed[index]);
     this->m_heap.isNoLongerFreeable(m_pages[index], IsoPageBase::pageSize);
     m_committed[index] = false;
+    m_firstEligibleOrDecommitted = std::min(m_firstEligibleOrDecommitted, index);
+    this->m_heap.didBecomeEligibleOrDecommited(this);
     this->m_heap.didDecommit(m_pages[index], IsoPageBase::pageSize);
 }
 
index 9ed3cc5..228fa54 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2017-2018 Apple Inc. All rights reserved.
+ * Copyright (C) 2017-2019 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -80,8 +80,8 @@ public:
     EligibilityResult<Config> takeFirstEligible();
     
     // Callbacks from directory.
-    void didBecomeEligible(IsoDirectory<Config, numPagesInInlineDirectory>*);
-    void didBecomeEligible(IsoDirectory<Config, IsoDirectoryPage<Config>::numPages>*);
+    void didBecomeEligibleOrDecommited(IsoDirectory<Config, numPagesInInlineDirectory>*);
+    void didBecomeEligibleOrDecommited(IsoDirectory<Config, IsoDirectoryPage<Config>::numPages>*);
     
     void scavenge(Vector<DeferredDecommit>&) override;
 
@@ -134,8 +134,8 @@ private:
     unsigned m_nextDirectoryPageIndex { 1 }; // We start at 1 so that the high water mark being zero means we've only allocated in the inline directory since the last scavenge.
     unsigned m_directoryHighWatermark { 0 };
     
-    bool m_isInlineDirectoryEligible { true };
-    IsoDirectoryPage<Config>* m_firstEligibleDirectory { nullptr };
+    bool m_isInlineDirectoryEligibleOrDecommitted { true };
+    IsoDirectoryPage<Config>* m_firstEligibleOrDecommitedDirectory { nullptr };
     
     IsoTLSAllocatorEntry<Config> m_allocator;
 };
index ba41093..27ba93e 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2017-2018 Apple Inc. All rights reserved.
+ * Copyright (C) 2017-2019 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -44,26 +44,26 @@ IsoHeapImpl<Config>::IsoHeapImpl()
 template<typename Config>
 EligibilityResult<Config> IsoHeapImpl<Config>::takeFirstEligible()
 {
-    if (m_isInlineDirectoryEligible) {
+    if (m_isInlineDirectoryEligibleOrDecommitted) {
         EligibilityResult<Config> result = m_inlineDirectory.takeFirstEligible();
         if (result.kind == EligibilityKind::Full)
-            m_isInlineDirectoryEligible = false;
+            m_isInlineDirectoryEligibleOrDecommitted = false;
         else
             return result;
     }
     
-    if (!m_firstEligibleDirectory) {
+    if (!m_firstEligibleOrDecommitedDirectory) {
         // If nothing is eligible, it can only be because we have no directories. It wouldn't be the end
-        // of the world if we broke this invariant. It would only mean that didBecomeEligible() would need
+        // of the world if we broke this invariant. It would only mean that didBecomeEligibleOrDecommited() would need
         // a null check.
         RELEASE_BASSERT(!m_headDirectory);
         RELEASE_BASSERT(!m_tailDirectory);
     }
     
-    for (; m_firstEligibleDirectory; m_firstEligibleDirectory = m_firstEligibleDirectory->next) {
-        EligibilityResult<Config> result = m_firstEligibleDirectory->payload.takeFirstEligible();
+    for (; m_firstEligibleOrDecommitedDirectory; m_firstEligibleOrDecommitedDirectory = m_firstEligibleOrDecommitedDirectory->next) {
+        EligibilityResult<Config> result = m_firstEligibleOrDecommitedDirectory->payload.takeFirstEligible();
         if (result.kind != EligibilityKind::Full) {
-            m_directoryHighWatermark = std::max(m_directoryHighWatermark, m_firstEligibleDirectory->index());
+            m_directoryHighWatermark = std::max(m_directoryHighWatermark, m_firstEligibleOrDecommitedDirectory->index());
             return result;
         }
     }
@@ -78,26 +78,26 @@ EligibilityResult<Config> IsoHeapImpl<Config>::takeFirstEligible()
         m_tailDirectory = newDirectory;
     }
     m_directoryHighWatermark = newDirectory->index();
-    m_firstEligibleDirectory = newDirectory;
+    m_firstEligibleOrDecommitedDirectory = newDirectory;
     EligibilityResult<Config> result = newDirectory->payload.takeFirstEligible();
     RELEASE_BASSERT(result.kind != EligibilityKind::Full);
     return result;
 }
 
 template<typename Config>
-void IsoHeapImpl<Config>::didBecomeEligible(IsoDirectory<Config, numPagesInInlineDirectory>* directory)
+void IsoHeapImpl<Config>::didBecomeEligibleOrDecommited(IsoDirectory<Config, numPagesInInlineDirectory>* directory)
 {
     RELEASE_BASSERT(directory == &m_inlineDirectory);
-    m_isInlineDirectoryEligible = true;
+    m_isInlineDirectoryEligibleOrDecommitted = true;
 }
 
 template<typename Config>
-void IsoHeapImpl<Config>::didBecomeEligible(IsoDirectory<Config, IsoDirectoryPage<Config>::numPages>* directory)
+void IsoHeapImpl<Config>::didBecomeEligibleOrDecommited(IsoDirectory<Config, IsoDirectoryPage<Config>::numPages>* directory)
 {
-    RELEASE_BASSERT(m_firstEligibleDirectory);
+    RELEASE_BASSERT(m_firstEligibleOrDecommitedDirectory);
     auto* directoryPage = IsoDirectoryPage<Config>::pageFor(directory);
-    if (directoryPage->index() < m_firstEligibleDirectory->index())
-        m_firstEligibleDirectory = directoryPage;
+    if (directoryPage->index() < m_firstEligibleOrDecommitedDirectory->index())
+        m_firstEligibleOrDecommitedDirectory = directoryPage;
 }
 
 template<typename Config>
index dbc0e7e..c203213 100644 (file)
@@ -183,11 +183,13 @@ void IsoTLS::determineMallocFallbackState()
             if (s_mallocFallbackState != MallocFallbackState::Undecided)
                 return;
 
-#if GIGACAGE_ENABLED
+#if GIGACAGE_ENABLED || BCPU(ARM64)
+#if !BCPU(ARM64)
             if (!Gigacage::shouldBeEnabled()) {
                 s_mallocFallbackState = MallocFallbackState::FallBackToMalloc;
                 return;
             }
+#endif
             const char* env = getenv("bmalloc_IsoHeap");
             if (env && (!strcasecmp(env, "false") || !strcasecmp(env, "no") || !strcmp(env, "0")))
                 s_mallocFallbackState = MallocFallbackState::FallBackToMalloc;
index 90fdc3b..3bb63f3 100644 (file)
@@ -46,7 +46,8 @@ bool gigacageEnabledForProcess()
     bool isOptInBinary = [processName isEqualToString:@"jsc"]
         || [processName isEqualToString:@"DumpRenderTree"]
         || [processName isEqualToString:@"wasm"]
-        || [processName hasPrefix:@"test"];
+        || [processName hasPrefix:@"test"]
+        || [processName hasPrefix:@"Test"];
 
     return isOptInBinary;
 }
index 7f549ad..5fb6173 100644 (file)
@@ -1,3 +1,16 @@
+2019-05-30  Keith Miller  <keith_miller@apple.com>
+
+        IsoHeaps don't notice uncommitted VA becoming the first eligible.
+        https://bugs.webkit.org/show_bug.cgi?id=198301
+
+        Reviewed by Yusuke Suzuki.
+
+        Move testbmalloc.cpp to TestWTF so it runs in automation.
+
+        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+        * TestWebKitAPI/Tests/WTF/bmalloc/IsoHeap.cpp: Renamed from Source/bmalloc/test/testbmalloc.cpp.
+        (TEST):
+
 2019-05-30  Wenson Hsieh  <wenson_hsieh@apple.com>
 
         DragAndDropTests.DataTransferExposePlainTextWithFileURLAsFile API test is failing
index 60801c0..93c1967 100644 (file)
                536770341CC8022800D425B1 /* WebScriptObjectDescription.mm in Sources */ = {isa = PBXBuildFile; fileRef = 536770331CC8022800D425B1 /* WebScriptObjectDescription.mm */; };
                536770361CC81B6100D425B1 /* WebScriptObjectDescription.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 536770351CC812F900D425B1 /* WebScriptObjectDescription.html */; };
                53EC25411E96FD87000831B9 /* PriorityQueue.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 53EC253F1E96BC80000831B9 /* PriorityQueue.cpp */; };
+               53FCDE6B229EFFB900598ECF /* IsoHeap.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 53FCDE6A229EFFB900598ECF /* IsoHeap.cpp */; };
                55226A2F1EBA44B900C36AD0 /* large-red-square-image.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 55226A2E1EB969B600C36AD0 /* large-red-square-image.html */; };
                5597F8361D9596C80066BC21 /* SynchronizedFixedQueue.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5597F8341D9596C80066BC21 /* SynchronizedFixedQueue.cpp */; };
                55A817FC218100E00004A39A /* AdditionalSupportedImageTypes.mm in Sources */ = {isa = PBXBuildFile; fileRef = 55A817FB218100E00004A39A /* AdditionalSupportedImageTypes.mm */; };
                536770331CC8022800D425B1 /* WebScriptObjectDescription.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebScriptObjectDescription.mm; sourceTree = "<group>"; };
                536770351CC812F900D425B1 /* WebScriptObjectDescription.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = WebScriptObjectDescription.html; sourceTree = "<group>"; };
                53EC253F1E96BC80000831B9 /* PriorityQueue.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PriorityQueue.cpp; sourceTree = "<group>"; };
+               53FCDE6A229EFFB900598ECF /* IsoHeap.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = IsoHeap.cpp; sourceTree = "<group>"; };
                55226A2E1EB969B600C36AD0 /* large-red-square-image.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "large-red-square-image.html"; sourceTree = "<group>"; };
                5597F8341D9596C80066BC21 /* SynchronizedFixedQueue.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SynchronizedFixedQueue.cpp; sourceTree = "<group>"; };
                55A817FB218100E00004A39A /* AdditionalSupportedImageTypes.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = AdditionalSupportedImageTypes.mm; sourceTree = "<group>"; };
                        path = WebCore;
                        sourceTree = "<group>";
                };
+               53FCDE69229EFF6800598ECF /* bmalloc */ = {
+                       isa = PBXGroup;
+                       children = (
+                               53FCDE6A229EFFB900598ECF /* IsoHeap.cpp */,
+                       );
+                       path = bmalloc;
+                       sourceTree = "<group>";
+               };
                7560917619259C59009EF06E /* ios */ = {
                        isa = PBXGroup;
                        children = (
                BC9096461255618900083756 /* WTF */ = {
                        isa = PBXGroup;
                        children = (
+                               53FCDE69229EFF6800598ECF /* bmalloc */,
                                C0991C4F143C7D68007998F2 /* cf */,
                                E3C21A7821B25C82003B31A3 /* cocoa */,
                                7CBBA07519BB8A0900BBF025 /* darwin */,
                                7C83DED21D0A590C00FEBCF3 /* HashMap.cpp in Sources */,
                                7C83DED41D0A590C00FEBCF3 /* HashSet.cpp in Sources */,
                                7C83DEE01D0A590C00FEBCF3 /* IntegerToStringConversion.cpp in Sources */,
+                               53FCDE6B229EFFB900598ECF /* IsoHeap.cpp in Sources */,
                                7CEB62AB223609DE0069CBB0 /* IteratorRange.cpp in Sources */,
                                7A0509411FB9F06400B33FB8 /* JSONValue.cpp in Sources */,
                                531C1D8E1DF8EF72006E979F /* LEBDecoder.cpp in Sources */,
similarity index 71%
rename from Source/bmalloc/test/testbmalloc.cpp
rename to Tools/TestWebKitAPI/Tests/WTF/bmalloc/IsoHeap.cpp
index d76bc16..8b2aca7 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2017 Apple Inc. All rights reserved.
+ * Copyright (C) 2017-2019 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  *    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. 
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``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 ITS 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 "config.h"
+
+#if !USE(SYSTEM_MALLOC)
+
 #include <bmalloc/bmalloc.h>
 #include <bmalloc/Environment.h>
 #include <bmalloc/IsoHeapInlines.h>
+
 #include <cmath>
 #include <cstdlib>
 #include <set>
 using namespace bmalloc;
 using namespace bmalloc::api;
 
-// We don't have a NO_RETURN_DUE_TO_EXIT, nor should we. That's ridiculous.
-static bool hiddenTruthBecauseNoReturnIsStupid() { return true; }
-
-static void usage()
-{
-    puts("Usage: testb3 [<filter>]");
-    if (hiddenTruthBecauseNoReturnIsStupid())
-        exit(1);
-}
-
 #define RUN(test) do {                          \
-        if (!shouldRun(#test))                  \
-            break;                              \
-        puts(#test "...");                      \
-        test;                                   \
-        puts(#test ": OK!");                    \
-    } while (false)
+if (!shouldRun(#test))                  \
+break;                              \
+puts(#test "...");                      \
+test;                                   \
+puts(#test ": OK!");                    \
+} while (false)
 
 // Nothing fancy for now; we just use the existing WTF assertion machinery.
 #define CHECK(x) do {                                                   \
-        if (!!(x))                                                      \
-            break;                                                      \
-        fprintf(stderr, "%s:%d: in %s: assertion %s failed.\n",         \
-            __FILE__, __LINE__, __PRETTY_FUNCTION__, #x);               \
-        abort();                                                        \
-    } while (false)
+if (!!(x))                                                      \
+break;                                                      \
+fprintf(stderr, "%s:%d: in %s: assertion %s failed.\n",         \
+__FILE__, __LINE__, __PRETTY_FUNCTION__, #x);               \
+abort();                                                        \
+} while (false)
 
 static std::set<void*> toptrset(const std::vector<void*>& ptrs)
 {
@@ -138,7 +133,7 @@ static void assertClean(IsoHeap<heapType>& heap)
     }
 }
 
-static void testIsoSimple()
+TEST(bmalloc, IsoSimple)
 {
     static IsoHeap<double> heap;
     void* ptr1 = heap.allocate();
@@ -153,7 +148,7 @@ static void testIsoSimple()
     assertClean(heap);
 }
 
-static void testIsoSimpleScavengeBeforeDealloc()
+TEST(bmalloc, IsoSimpleScavengeBeforeDealloc)
 {
     static IsoHeap<double> heap;
     void* ptr1 = heap.allocate();
@@ -169,7 +164,7 @@ static void testIsoSimpleScavengeBeforeDealloc()
     assertClean(heap);
 }
 
-static void testIsoFlipFlopFragmentedPages()
+TEST(bmalloc, IsoFlipFlopFragmentedPages)
 {
     static IsoHeap<double> heap;
     std::vector<void*> ptrs;
@@ -189,7 +184,7 @@ static void testIsoFlipFlopFragmentedPages()
     assertClean(heap);
 }
 
-static void testIsoFlipFlopFragmentedPagesScavengeInMiddle()
+TEST(bmalloc, IsoFlipFlopFragmentedPagesScavengeInMiddle)
 {
     static IsoHeap<double> heap;
     std::vector<void*> ptrs;
@@ -222,7 +217,7 @@ static void testIsoFlipFlopFragmentedPagesScavengeInMiddle()
     assertClean(heap);
 }
 
-static void testIsoFlipFlopFragmentedPagesScavengeInMiddle288()
+TEST(bmalloc, IsoFlipFlopFragmentedPagesScavengeInMiddle288)
 {
     static IsoHeap<char[288]> heap;
     std::vector<void*> ptrs;
@@ -255,7 +250,7 @@ static void testIsoFlipFlopFragmentedPagesScavengeInMiddle288()
     assertClean(heap);
 }
 
-static void testIsoMallocAndFreeFast()
+TEST(bmalloc, IsoMallocAndFreeFast)
 {
     static IsoHeap<char[256]> heap;
     void* ptr = nullptr;
@@ -274,14 +269,14 @@ public:
         , y(y)
     {
     }
-    
+
     int x;
     float y;
 };
 
 MAKE_BISO_MALLOCED_IMPL(BisoMalloced);
 
-static void testBisoMalloced()
+TEST(bmalloc, BisoMalloced)
 {
     BisoMalloced* ptr = new BisoMalloced(4, 5);
     assertHasObjects(BisoMalloced::bisoHeap(), { ptr });
@@ -297,12 +292,12 @@ public:
         , y(y)
     {
     }
-    
+
     int x;
     float y;
 };
 
-static void testBisoMallocedInline()
+TEST(bmalloc, BisoMallocedInline)
 {
     BisoMallocedInline* ptr = new BisoMallocedInline(4, 5);
     assertHasObjects(BisoMallocedInline::bisoHeap(), { ptr });
@@ -310,39 +305,42 @@ static void testBisoMallocedInline()
     assertClean(BisoMallocedInline::bisoHeap());
 }
 
-static void run(const char* filter)
+
+TEST(bmalloc, ScavengedMemoryShouldBeReused)
 {
-    auto shouldRun = [&] (const char* testName) -> bool {
-        return !filter || !!strcasestr(testName, filter);
+    static IsoHeap<double> heap;
+
+    auto run = [] (unsigned numPagesToCommit) {
+        auto* ptr1 = heap.allocate();
+
+        std::vector<void*> ptrs;
+
+        for (unsigned i = 0; ;i++) {
+            void* ptr = heap.allocate();
+            CHECK(ptr);
+            ptrs.push_back(ptr);
+            if (heap.impl().numCommittedPages() == numPagesToCommit)
+                break;
+        }
+
+        std::set<void*> uniquedPtrs = toptrset(ptrs);
+
+        heap.deallocate(ptr1);
+        for (unsigned i = 0; i < IsoPage<decltype(heap)::Config>::numObjects - 1; i++) {
+            heap.deallocate(ptrs[i]);
+            uniquedPtrs.erase(ptrs[i]);
+        }
+
+        scavenge();
+        assertHasOnlyObjects(heap, uniquedPtrs);
+
+        // FIXME: This only seems to pass when lldb is attached but the scavenger thread isn't running...
+        // see: https://bugs.webkit.org/show_bug.cgi?id=198384
+        // auto* ptr2 = heap.allocate();
+        // CHECK(ptr1 == ptr2);
     };
-    
-    RUN(testIsoSimple());
-    RUN(testIsoSimpleScavengeBeforeDealloc());
-    RUN(testIsoFlipFlopFragmentedPages());
-    RUN(testIsoFlipFlopFragmentedPagesScavengeInMiddle());
-    RUN(testIsoFlipFlopFragmentedPagesScavengeInMiddle288());
-    RUN(testIsoMallocAndFreeFast());
-    RUN(testBisoMalloced());
-    RUN(testBisoMallocedInline());
-    
-    puts("Success!");
-}
 
-int main(int argc, char** argv)
-{
-    const char* filter = nullptr;
-    switch (argc) {
-    case 1:
-        break;
-    case 2:
-        filter = argv[1];
-        break;
-    default:
-        usage();
-        break;
-    }
-    
-    run(filter);
-    return 0;
+    run(2);
 }
 
+#endif