WebKit Bugzilla
Attachment 370962 Details for
Bug 198301
: IsoHeaps don't notice uncommitted VA becoming the first eligible.
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Patch
bug-198301-20190530114456.patch (text/plain), 42.94 KB, created by
Keith Miller
on 2019-05-30 11:44:57 PDT
(
hide
)
Description:
Patch
Filename:
MIME Type:
Creator:
Keith Miller
Created:
2019-05-30 11:44:57 PDT
Size:
42.94 KB
patch
obsolete
>Subversion Revision: 245818 >diff --git a/Source/bmalloc/ChangeLog b/Source/bmalloc/ChangeLog >index ddfd8067b960cf0eaf6c200b9a13ee0c85b08aa1..c6c40ed847db8d9cad87192286fa8f9d19df9bcd 100644 >--- a/Source/bmalloc/ChangeLog >+++ b/Source/bmalloc/ChangeLog >@@ -1,3 +1,36 @@ >+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 NOBODY (OOPS!). >+ >+ 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/ProcessCheck.mm: >+ (bmalloc::gigacageEnabledForProcess): >+ > 2019-05-23 Don Olmstead <don.olmstead@sony.com> > > [CMake] Use target oriented design for bmalloc >diff --git a/Source/bmalloc/bmalloc.xcodeproj/project.pbxproj b/Source/bmalloc/bmalloc.xcodeproj/project.pbxproj >index 92f85cf97c20f1b79b811f1cf90ab4dbe394861e..f7475fab5e241cd833c0972a69b35a38a182d207 100644 >--- a/Source/bmalloc/bmalloc.xcodeproj/project.pbxproj >+++ b/Source/bmalloc/bmalloc.xcodeproj/project.pbxproj >@@ -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, ); }; }; >@@ -137,7 +135,6 @@ > 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 */; }; >@@ -154,13 +151,6 @@ > /* 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 */; >@@ -177,18 +167,6 @@ > }; > /* 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>"; }; >@@ -202,8 +180,6 @@ > 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; }; >@@ -328,15 +304,6 @@ > /* 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; >@@ -356,14 +323,6 @@ > /* End PBXFrameworksBuildPhase section */ > > /* Begin PBXGroup section */ >- 0F7EB7F01F95285300F1ABCB /* test */ = { >- isa = PBXGroup; >- children = ( >- 0F7EB7F11F95285300F1ABCB /* testbmalloc.cpp */, >- ); >- path = test; >- sourceTree = "<group>"; >- }; > 0F7EB7F91F95414C00F1ABCB /* Frameworks */ = { > isa = PBXGroup; > children = ( >@@ -451,14 +410,12 @@ > 0F7EB7FB1F95416900F1ABCB /* iso */, > 145F6840179DC45F00D65598 /* Products */, > 14D9DB4F17F2868900EAAB79 /* stdlib */, >- 0F7EB7F01F95285300F1ABCB /* test */, > ); > sourceTree = "<group>"; > }; > 145F6840179DC45F00D65598 /* Products */ = { > isa = PBXGroup; > children = ( >- 0F7EB7EF1F95285300F1ABCB /* testbmalloc */, > 14F271BE18EA3963008C152F /* libbmalloc.a */, > 14CC394418EA8743004AFE34 /* libmbmalloc.dylib */, > ); >@@ -707,24 +664,6 @@ > /* 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" */; >@@ -769,10 +708,6 @@ > LastSwiftUpdateCheck = 0700; > LastUpgradeCheck = 1000; > TargetAttributes = { >- 0F7EB7EE1F95285300F1ABCB = { >- CreatedOnToolsVersion = 9.0; >- ProvisioningStyle = Manual; >- }; > 0F7EB8501F95504B00F1ABCB = { > CreatedOnToolsVersion = 9.0; > ProvisioningStyle = Automatic; >@@ -794,20 +729,11 @@ > 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; >@@ -856,11 +782,6 @@ > /* End PBXSourcesBuildPhase section */ > > /* Begin PBXTargetDependency section */ >- 0F7EB7F81F95412900F1ABCB /* PBXTargetDependency */ = { >- isa = PBXTargetDependency; >- target = 14F271BD18EA3963008C152F /* bmalloc */; >- targetProxy = 0F7EB7F71F95412900F1ABCB /* PBXContainerItemProxy */; >- }; > 0F7EB8561F95505400F1ABCB /* PBXTargetDependency */ = { > isa = PBXTargetDependency; > target = 14F271BD18EA3963008C152F /* bmalloc */; >@@ -874,30 +795,6 @@ > /* 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 = { >@@ -992,16 +889,6 @@ > /* 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 = ( >diff --git a/Source/bmalloc/bmalloc/IsoDirectory.h b/Source/bmalloc/bmalloc/IsoDirectory.h >index 30df8a6fb2b9904a04f84e239429ce2d6c8b46b9..1d824f49c76573bc377b67bdcb7cdf5138dbf297 100644 >--- a/Source/bmalloc/bmalloc/IsoDirectory.h >+++ b/Source/bmalloc/bmalloc/IsoDirectory.h >@@ -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 >diff --git a/Source/bmalloc/bmalloc/IsoDirectoryInlines.h b/Source/bmalloc/bmalloc/IsoDirectoryInlines.h >index 640d82e121dd015d97c3767974f86dff01179c58..81277f396f6ffdaf808d73c3aebf3cb177ad422a 100644 >--- a/Source/bmalloc/bmalloc/IsoDirectoryInlines.h >+++ b/Source/bmalloc/bmalloc/IsoDirectoryInlines.h >@@ -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,7 +98,7 @@ 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); >+ m_firstEligibleOrDecommitted = std::min(m_firstEligibleOrDecommitted, pageIndex); > this->m_heap.didBecomeEligible(this); > return; > case IsoPageTrigger::Empty: >@@ -122,6 +123,7 @@ 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.didDecommit(m_pages[index], IsoPageBase::pageSize); > } > >diff --git a/Source/bmalloc/bmalloc/IsoTLS.cpp b/Source/bmalloc/bmalloc/IsoTLS.cpp >index dbc0e7eba3a30ae1384f0095c0d7125f8427a173..c203213b855bdcdc9ed0796fd204ab5d948d8006 100644 >--- a/Source/bmalloc/bmalloc/IsoTLS.cpp >+++ b/Source/bmalloc/bmalloc/IsoTLS.cpp >@@ -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; >diff --git a/Source/bmalloc/bmalloc/ProcessCheck.mm b/Source/bmalloc/bmalloc/ProcessCheck.mm >index 90fdc3ba3be0d77c61dc7d90856eb80893cc9a0b..3bb63f3525429898b0994cc851793b5195f52b02 100644 >--- a/Source/bmalloc/bmalloc/ProcessCheck.mm >+++ b/Source/bmalloc/bmalloc/ProcessCheck.mm >@@ -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; > } >diff --git a/Source/bmalloc/test/testbmalloc.cpp b/Source/bmalloc/test/testbmalloc.cpp >deleted file mode 100644 >index d76bc162aef3cc5ccba8bb5f5b77f1f2b1aea51a..0000000000000000000000000000000000000000 >--- a/Source/bmalloc/test/testbmalloc.cpp >+++ /dev/null >@@ -1,348 +0,0 @@ >-/* >- * Copyright (C) 2017 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 <bmalloc/bmalloc.h> >-#include <bmalloc/Environment.h> >-#include <bmalloc/IsoHeapInlines.h> >-#include <cmath> >-#include <cstdlib> >-#include <set> >-#include <vector> >- >-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) >- >-// 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) >- >-static std::set<void*> toptrset(const std::vector<void*>& ptrs) >-{ >- std::set<void*> result; >- for (void* ptr : ptrs) { >- if (ptr) >- result.insert(ptr); >- } >- return result; >-} >- >-static void assertEmptyPointerSet(const std::set<void*>& pointers) >-{ >- if (Environment::get()->isDebugHeapEnabled()) { >- printf(" skipping checks because DebugHeap.\n"); >- return; >- } >- if (pointers.empty()) >- return; >- printf("Pointer set not empty!\n"); >- printf("Pointers:"); >- for (void* ptr : pointers) >- printf(" %p", ptr); >- printf("\n"); >- CHECK(pointers.empty()); >-} >- >-template<typename heapType> >-static void assertHasObjects(IsoHeap<heapType>& heap, std::set<void*> pointers) >-{ >- if (Environment::get()->isDebugHeapEnabled()) { >- printf(" skipping checks because DebugHeap.\n"); >- return; >- } >- auto& impl = heap.impl(); >- std::lock_guard<Mutex> locker(impl.lock); >- impl.forEachLiveObject( >- [&] (void* object) { >- pointers.erase(object); >- }); >- assertEmptyPointerSet(pointers); >-} >- >-template<typename heapType> >-static void assertHasOnlyObjects(IsoHeap<heapType>& heap, std::set<void*> pointers) >-{ >- if (Environment::get()->isDebugHeapEnabled()) { >- printf(" skipping checks because DebugHeap.\n"); >- return; >- } >- auto& impl = heap.impl(); >- std::lock_guard<Mutex> locker(impl.lock); >- impl.forEachLiveObject( >- [&] (void* object) { >- CHECK(pointers.erase(object) == 1); >- }); >- assertEmptyPointerSet(pointers); >-} >- >-template<typename heapType> >-static void assertClean(IsoHeap<heapType>& heap) >-{ >- scavengeThisThread(); >- if (!Environment::get()->isDebugHeapEnabled()) { >- auto& impl = heap.impl(); >- { >- std::lock_guard<Mutex> locker(impl.lock); >- CHECK(!impl.numLiveObjects()); >- } >- } >- heap.scavenge(); >- if (!Environment::get()->isDebugHeapEnabled()) { >- auto& impl = heap.impl(); >- std::lock_guard<Mutex> locker(impl.lock); >- CHECK(!impl.numCommittedPages()); >- } >-} >- >-static void testIsoSimple() >-{ >- static IsoHeap<double> heap; >- void* ptr1 = heap.allocate(); >- CHECK(ptr1); >- void* ptr2 = heap.allocate(); >- CHECK(ptr2); >- CHECK(ptr1 != ptr2); >- CHECK(std::abs(static_cast<char*>(ptr1) - static_cast<char*>(ptr2)) >= 8); >- assertHasObjects(heap, {ptr1, ptr2}); >- heap.deallocate(ptr1); >- heap.deallocate(ptr2); >- assertClean(heap); >-} >- >-static void testIsoSimpleScavengeBeforeDealloc() >-{ >- static IsoHeap<double> heap; >- void* ptr1 = heap.allocate(); >- CHECK(ptr1); >- void* ptr2 = heap.allocate(); >- CHECK(ptr2); >- CHECK(ptr1 != ptr2); >- CHECK(std::abs(static_cast<char*>(ptr1) - static_cast<char*>(ptr2)) >= 8); >- scavengeThisThread(); >- assertHasOnlyObjects(heap, {ptr1, ptr2}); >- heap.deallocate(ptr1); >- heap.deallocate(ptr2); >- assertClean(heap); >-} >- >-static void testIsoFlipFlopFragmentedPages() >-{ >- static IsoHeap<double> heap; >- std::vector<void*> ptrs; >- for (unsigned i = 100000; i--;) { >- void* ptr = heap.allocate(); >- CHECK(ptr); >- ptrs.push_back(ptr); >- } >- for (unsigned i = 0; i < ptrs.size(); i += 2) { >- heap.deallocate(ptrs[i]); >- ptrs[i] = nullptr; >- } >- for (unsigned i = ptrs.size() / 2; i--;) >- ptrs.push_back(heap.allocate()); >- for (void* ptr : ptrs) >- heap.deallocate(ptr); >- assertClean(heap); >-} >- >-static void testIsoFlipFlopFragmentedPagesScavengeInMiddle() >-{ >- static IsoHeap<double> heap; >- std::vector<void*> ptrs; >- for (unsigned i = 100000; i--;) { >- void* ptr = heap.allocate(); >- CHECK(ptr); >- ptrs.push_back(ptr); >- } >- CHECK(toptrset(ptrs).size() == ptrs.size()); >- for (unsigned i = 0; i < ptrs.size(); i += 2) { >- heap.deallocate(ptrs[i]); >- ptrs[i] = nullptr; >- } >- heap.scavenge(); >- unsigned numCommittedPagesBefore; >- auto& impl = heap.impl(); >- { >- std::lock_guard<Mutex> locker(impl.lock); >- numCommittedPagesBefore = impl.numCommittedPages(); >- } >- assertHasOnlyObjects(heap, toptrset(ptrs)); >- for (unsigned i = ptrs.size() / 2; i--;) >- ptrs.push_back(heap.allocate()); >- { >- std::lock_guard<Mutex> locker(impl.lock); >- CHECK(numCommittedPagesBefore == impl.numCommittedPages()); >- } >- for (void* ptr : ptrs) >- heap.deallocate(ptr); >- assertClean(heap); >-} >- >-static void testIsoFlipFlopFragmentedPagesScavengeInMiddle288() >-{ >- static IsoHeap<char[288]> heap; >- std::vector<void*> ptrs; >- for (unsigned i = 100000; i--;) { >- void* ptr = heap.allocate(); >- CHECK(ptr); >- ptrs.push_back(ptr); >- } >- CHECK(toptrset(ptrs).size() == ptrs.size()); >- for (unsigned i = 0; i < ptrs.size(); i += 2) { >- heap.deallocate(ptrs[i]); >- ptrs[i] = nullptr; >- } >- heap.scavenge(); >- unsigned numCommittedPagesBefore; >- auto& impl = heap.impl(); >- { >- std::lock_guard<Mutex> locker(impl.lock); >- numCommittedPagesBefore = impl.numCommittedPages(); >- } >- assertHasOnlyObjects(heap, toptrset(ptrs)); >- for (unsigned i = ptrs.size() / 2; i--;) >- ptrs.push_back(heap.allocate()); >- { >- std::lock_guard<Mutex> locker(impl.lock); >- CHECK(numCommittedPagesBefore == impl.numCommittedPages()); >- } >- for (void* ptr : ptrs) >- heap.deallocate(ptr); >- assertClean(heap); >-} >- >-static void testIsoMallocAndFreeFast() >-{ >- static IsoHeap<char[256]> heap; >- void* ptr = nullptr; >- for (int i = 0; i < 1e6; ++i) { >- ptr = heap.allocate(); >- heap.deallocate(ptr); >- } >- CHECK(!IsoPageBase::pageFor(ptr)->isShared()); >-} >- >-class BisoMalloced { >- MAKE_BISO_MALLOCED(BisoMalloced, BNOEXPORT); >-public: >- BisoMalloced(int x, float y) >- : x(x) >- , y(y) >- { >- } >- >- int x; >- float y; >-}; >- >-MAKE_BISO_MALLOCED_IMPL(BisoMalloced); >- >-static void testBisoMalloced() >-{ >- BisoMalloced* ptr = new BisoMalloced(4, 5); >- assertHasObjects(BisoMalloced::bisoHeap(), { ptr }); >- delete ptr; >- assertClean(BisoMalloced::bisoHeap()); >-} >- >-class BisoMallocedInline { >- MAKE_BISO_MALLOCED_INLINE(BisoMalloced); >-public: >- BisoMallocedInline(int x, float y) >- : x(x) >- , y(y) >- { >- } >- >- int x; >- float y; >-}; >- >-static void testBisoMallocedInline() >-{ >- BisoMallocedInline* ptr = new BisoMallocedInline(4, 5); >- assertHasObjects(BisoMallocedInline::bisoHeap(), { ptr }); >- delete ptr; >- assertClean(BisoMallocedInline::bisoHeap()); >-} >- >-static void run(const char* filter) >-{ >- auto shouldRun = [&] (const char* testName) -> bool { >- return !filter || !!strcasestr(testName, filter); >- }; >- >- 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; >-} >- >diff --git a/Tools/ChangeLog b/Tools/ChangeLog >index 44b0c5c7b48ffc762bcd94c9f85fa514f4def60c..57e562a6f9b9f98bf4b101438b66f7982f116876 100644 >--- a/Tools/ChangeLog >+++ b/Tools/ChangeLog >@@ -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 NOBODY (OOPS!). >+ >+ 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-28 Aakash Jain <aakash_jain@apple.com> > > [ews-build] Remove unused buildbot tabs >diff --git a/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj b/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj >index 57aa7d182e8fcf005390e22b654f306045e9c37f..d2b5d83f027b1e8987c198ec09ef9db09a647759 100644 >--- a/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj >+++ b/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj >@@ -268,6 +268,7 @@ > 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 */; }; >@@ -1697,6 +1698,7 @@ > 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>"; }; >@@ -2848,6 +2850,14 @@ > path = WebCore; > sourceTree = "<group>"; > }; >+ 53FCDE69229EFF6800598ECF /* bmalloc */ = { >+ isa = PBXGroup; >+ children = ( >+ 53FCDE6A229EFFB900598ECF /* IsoHeap.cpp */, >+ ); >+ path = bmalloc; >+ sourceTree = "<group>"; >+ }; > 7560917619259C59009EF06E /* ios */ = { > isa = PBXGroup; > children = ( >@@ -3323,6 +3333,7 @@ > BC9096461255618900083756 /* WTF */ = { > isa = PBXGroup; > children = ( >+ 53FCDE69229EFF6800598ECF /* bmalloc */, > C0991C4F143C7D68007998F2 /* cf */, > E3C21A7821B25C82003B31A3 /* cocoa */, > 7CBBA07519BB8A0900BBF025 /* darwin */, >@@ -3964,6 +3975,7 @@ > 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 */, >diff --git a/Tools/TestWebKitAPI/Tests/WTF/bmalloc/IsoHeap.cpp b/Tools/TestWebKitAPI/Tests/WTF/bmalloc/IsoHeap.cpp >new file mode 100644 >index 0000000000000000000000000000000000000000..18bcc2b1905013ed58ba81974d8c280dc09d8d8f >--- /dev/null >+++ b/Tools/TestWebKitAPI/Tests/WTF/bmalloc/IsoHeap.cpp >@@ -0,0 +1,346 @@ >+/* >+ * 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 >+ * 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. 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> >+#include <vector> >+ >+using namespace bmalloc; >+using namespace bmalloc::api; >+ >+#define RUN(test) do { \ >+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) >+ >+static std::set<void*> toptrset(const std::vector<void*>& ptrs) >+{ >+ std::set<void*> result; >+ for (void* ptr : ptrs) { >+ if (ptr) >+ result.insert(ptr); >+ } >+ return result; >+} >+ >+static void assertEmptyPointerSet(const std::set<void*>& pointers) >+{ >+ if (Environment::get()->isDebugHeapEnabled()) { >+ printf(" skipping checks because DebugHeap.\n"); >+ return; >+ } >+ if (pointers.empty()) >+ return; >+ printf("Pointer set not empty!\n"); >+ printf("Pointers:"); >+ for (void* ptr : pointers) >+ printf(" %p", ptr); >+ printf("\n"); >+ CHECK(pointers.empty()); >+} >+ >+template<typename heapType> >+static void assertHasObjects(IsoHeap<heapType>& heap, std::set<void*> pointers) >+{ >+ if (Environment::get()->isDebugHeapEnabled()) { >+ printf(" skipping checks because DebugHeap.\n"); >+ return; >+ } >+ auto& impl = heap.impl(); >+ std::lock_guard<Mutex> locker(impl.lock); >+ impl.forEachLiveObject( >+ [&] (void* object) { >+ pointers.erase(object); >+ }); >+ assertEmptyPointerSet(pointers); >+} >+ >+template<typename heapType> >+static void assertHasOnlyObjects(IsoHeap<heapType>& heap, std::set<void*> pointers) >+{ >+ if (Environment::get()->isDebugHeapEnabled()) { >+ printf(" skipping checks because DebugHeap.\n"); >+ return; >+ } >+ auto& impl = heap.impl(); >+ std::lock_guard<Mutex> locker(impl.lock); >+ impl.forEachLiveObject( >+ [&] (void* object) { >+ CHECK(pointers.erase(object) == 1); >+ }); >+ assertEmptyPointerSet(pointers); >+} >+ >+template<typename heapType> >+static void assertClean(IsoHeap<heapType>& heap) >+{ >+ scavengeThisThread(); >+ if (!Environment::get()->isDebugHeapEnabled()) { >+ auto& impl = heap.impl(); >+ { >+ std::lock_guard<Mutex> locker(impl.lock); >+ CHECK(!impl.numLiveObjects()); >+ } >+ } >+ heap.scavenge(); >+ if (!Environment::get()->isDebugHeapEnabled()) { >+ auto& impl = heap.impl(); >+ std::lock_guard<Mutex> locker(impl.lock); >+ CHECK(!impl.numCommittedPages()); >+ } >+} >+ >+TEST(bmalloc, IsoSimple) >+{ >+ static IsoHeap<double> heap; >+ void* ptr1 = heap.allocate(); >+ CHECK(ptr1); >+ void* ptr2 = heap.allocate(); >+ CHECK(ptr2); >+ CHECK(ptr1 != ptr2); >+ CHECK(std::abs(static_cast<char*>(ptr1) - static_cast<char*>(ptr2)) >= 8); >+ assertHasObjects(heap, {ptr1, ptr2}); >+ heap.deallocate(ptr1); >+ heap.deallocate(ptr2); >+ assertClean(heap); >+} >+ >+TEST(bmalloc, IsoSimpleScavengeBeforeDealloc) >+{ >+ static IsoHeap<double> heap; >+ void* ptr1 = heap.allocate(); >+ CHECK(ptr1); >+ void* ptr2 = heap.allocate(); >+ CHECK(ptr2); >+ CHECK(ptr1 != ptr2); >+ CHECK(std::abs(static_cast<char*>(ptr1) - static_cast<char*>(ptr2)) >= 8); >+ scavengeThisThread(); >+ assertHasOnlyObjects(heap, {ptr1, ptr2}); >+ heap.deallocate(ptr1); >+ heap.deallocate(ptr2); >+ assertClean(heap); >+} >+ >+TEST(bmalloc, IsoFlipFlopFragmentedPages) >+{ >+ static IsoHeap<double> heap; >+ std::vector<void*> ptrs; >+ for (unsigned i = 100000; i--;) { >+ void* ptr = heap.allocate(); >+ CHECK(ptr); >+ ptrs.push_back(ptr); >+ } >+ for (unsigned i = 0; i < ptrs.size(); i += 2) { >+ heap.deallocate(ptrs[i]); >+ ptrs[i] = nullptr; >+ } >+ for (unsigned i = ptrs.size() / 2; i--;) >+ ptrs.push_back(heap.allocate()); >+ for (void* ptr : ptrs) >+ heap.deallocate(ptr); >+ assertClean(heap); >+} >+ >+TEST(bmalloc, IsoFlipFlopFragmentedPagesScavengeInMiddle) >+{ >+ static IsoHeap<double> heap; >+ std::vector<void*> ptrs; >+ for (unsigned i = 100000; i--;) { >+ void* ptr = heap.allocate(); >+ CHECK(ptr); >+ ptrs.push_back(ptr); >+ } >+ CHECK(toptrset(ptrs).size() == ptrs.size()); >+ for (unsigned i = 0; i < ptrs.size(); i += 2) { >+ heap.deallocate(ptrs[i]); >+ ptrs[i] = nullptr; >+ } >+ heap.scavenge(); >+ unsigned numCommittedPagesBefore; >+ auto& impl = heap.impl(); >+ { >+ std::lock_guard<Mutex> locker(impl.lock); >+ numCommittedPagesBefore = impl.numCommittedPages(); >+ } >+ assertHasOnlyObjects(heap, toptrset(ptrs)); >+ for (unsigned i = ptrs.size() / 2; i--;) >+ ptrs.push_back(heap.allocate()); >+ { >+ std::lock_guard<Mutex> locker(impl.lock); >+ CHECK(numCommittedPagesBefore == impl.numCommittedPages()); >+ } >+ for (void* ptr : ptrs) >+ heap.deallocate(ptr); >+ assertClean(heap); >+} >+ >+TEST(bmalloc, IsoFlipFlopFragmentedPagesScavengeInMiddle288) >+{ >+ static IsoHeap<char[288]> heap; >+ std::vector<void*> ptrs; >+ for (unsigned i = 100000; i--;) { >+ void* ptr = heap.allocate(); >+ CHECK(ptr); >+ ptrs.push_back(ptr); >+ } >+ CHECK(toptrset(ptrs).size() == ptrs.size()); >+ for (unsigned i = 0; i < ptrs.size(); i += 2) { >+ heap.deallocate(ptrs[i]); >+ ptrs[i] = nullptr; >+ } >+ heap.scavenge(); >+ unsigned numCommittedPagesBefore; >+ auto& impl = heap.impl(); >+ { >+ std::lock_guard<Mutex> locker(impl.lock); >+ numCommittedPagesBefore = impl.numCommittedPages(); >+ } >+ assertHasOnlyObjects(heap, toptrset(ptrs)); >+ for (unsigned i = ptrs.size() / 2; i--;) >+ ptrs.push_back(heap.allocate()); >+ { >+ std::lock_guard<Mutex> locker(impl.lock); >+ CHECK(numCommittedPagesBefore == impl.numCommittedPages()); >+ } >+ for (void* ptr : ptrs) >+ heap.deallocate(ptr); >+ assertClean(heap); >+} >+ >+TEST(bmalloc, IsoMallocAndFreeFast) >+{ >+ static IsoHeap<char[256]> heap; >+ void* ptr = nullptr; >+ for (int i = 0; i < 1e6; ++i) { >+ ptr = heap.allocate(); >+ heap.deallocate(ptr); >+ } >+ CHECK(!IsoPageBase::pageFor(ptr)->isShared()); >+} >+ >+class BisoMalloced { >+ MAKE_BISO_MALLOCED(BisoMalloced, BNOEXPORT); >+public: >+ BisoMalloced(int x, float y) >+ : x(x) >+ , y(y) >+ { >+ } >+ >+ int x; >+ float y; >+}; >+ >+MAKE_BISO_MALLOCED_IMPL(BisoMalloced); >+ >+TEST(bmalloc, BisoMalloced) >+{ >+ BisoMalloced* ptr = new BisoMalloced(4, 5); >+ assertHasObjects(BisoMalloced::bisoHeap(), { ptr }); >+ delete ptr; >+ assertClean(BisoMalloced::bisoHeap()); >+} >+ >+class BisoMallocedInline { >+ MAKE_BISO_MALLOCED_INLINE(BisoMalloced); >+public: >+ BisoMallocedInline(int x, float y) >+ : x(x) >+ , y(y) >+ { >+ } >+ >+ int x; >+ float y; >+}; >+ >+TEST(bmalloc, BisoMallocedInline) >+{ >+ BisoMallocedInline* ptr = new BisoMallocedInline(4, 5); >+ assertHasObjects(BisoMallocedInline::bisoHeap(), { ptr }); >+ delete ptr; >+ assertClean(BisoMallocedInline::bisoHeap()); >+} >+ >+ >+TEST(bmalloc, ScavengedMemoryShouldBeReused) >+{ >+ 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(2); >+} >+ >+#endif
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Formatted Diff
|
Diff
Attachments on
bug 198301
:
370962
|
370963
|
370969
|
370984