⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 246421 in webkit


Ignore:
Timestamp:
Jun 13, 2019, 7:30:48 PM (7 years ago)
Author:
Kocsen Chung
Message:

Apply patch. rdar://problem/51656608

Location:
branches/safari-607-branch
Files:
1 added
10 edited
1 moved

Legend:

Unmodified
Added
Removed
  • branches/safari-607-branch/Source/bmalloc/ChangeLog

    r240392 r246421  
     12019-06-13  Kocsen Chung  <kocsen_chung@apple.com>
     2
     3        Apply patch. rdar://problem/51656608
     4
     5    2019-06-13  Keith Miller  <keith_miller@apple.com>
     6
     7            IsoHeaps don't notice uncommitted VA becoming the first eligible.
     8            https://bugs.webkit.org/show_bug.cgi?id=198301
     9
     10            Reviewed by Yusuke Suzuki.
     11
     12            IsoDirectory has a firstEligible member that is used as an
     13            optimization to help find the first fit. However if the scavenger
     14            decommitted a page before firstEligible then we wouldn't move
     15            firstEligible. Thus, if no space is ever freed below firstEligible
     16            we will never reused the decommitted memory (e.g. if the VA page
     17            is decommitted). The fix is to make IsoDirectory::didDecommit move
     18            the firstEligible page back if the decommitted page is smaller
     19            than the current firstEligible. As such, this patch renames
     20            firstEligible to firstEligibleOrDecommitted.
     21
     22            Also, this patch changes gigacageEnabledForProcess to check if the
     23            process starts with Test rather than just test as TestWTF does.
     24
     25            Lastly, unbeknownst to me IsoHeaps are dependent on gigacage, so
     26            by removing gigacage from arm64 I accidentally disabled
     27            IsoHeaps...
     28
     29            * bmalloc.xcodeproj/project.pbxproj:
     30            * bmalloc/IsoDirectory.h:
     31            * bmalloc/IsoDirectoryInlines.h:
     32            (bmalloc::passedNumPages>::takeFirstEligible):
     33            (bmalloc::passedNumPages>::didBecome):
     34            (bmalloc::passedNumPages>::didDecommit):
     35            * bmalloc/IsoHeapImpl.h:
     36            * bmalloc/IsoHeapImplInlines.h:
     37            (bmalloc::IsoHeapImpl<Config>::takeFirstEligible):
     38            (bmalloc::IsoHeapImpl<Config>::didBecomeEligibleOrDecommited):
     39            (bmalloc::IsoHeapImpl<Config>::didCommit):
     40            (bmalloc::IsoHeapImpl<Config>::didBecomeEligible): Deleted.
     41            * bmalloc/IsoTLS.cpp:
     42            (bmalloc::IsoTLS::determineMallocFallbackState):
     43            * bmalloc/ProcessCheck.mm:
     44            (bmalloc::gigacageEnabledForProcess):
     45
    1462019-01-23  Alan Coon  <alancoon@apple.com>
    247
  • branches/safari-607-branch/Source/bmalloc/bmalloc.xcodeproj/project.pbxproj

    r236805 r246421  
    3434                0F74B93E1F89713E00B935D3 /* CryptoRandom.h in Headers */ = {isa = PBXBuildFile; fileRef = 0F74B93C1F89713E00B935D3 /* CryptoRandom.h */; settings = {ATTRIBUTES = (Private, ); }; };
    3535                0F74B93F1F89713E00B935D3 /* CryptoRandom.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0F74B93D1F89713E00B935D3 /* CryptoRandom.cpp */; };
    36                 0F7EB7F21F95285300F1ABCB /* testbmalloc.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0F7EB7F11F95285300F1ABCB /* testbmalloc.cpp */; };
    37                 0F7EB7FA1F95414C00F1ABCB /* libbmalloc.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 14F271BE18EA3963008C152F /* libbmalloc.a */; };
    3836                0F7EB8231F9541B000F1ABCB /* EligibilityResult.h in Headers */ = {isa = PBXBuildFile; fileRef = 0F7EB7FC1F9541AD00F1ABCB /* EligibilityResult.h */; settings = {ATTRIBUTES = (Private, ); }; };
    3937                0F7EB8241F9541B000F1ABCB /* IsoHeapImplInlines.h in Headers */ = {isa = PBXBuildFile; fileRef = 0F7EB7FD1F9541AD00F1ABCB /* IsoHeapImplInlines.h */; settings = {ATTRIBUTES = (Private, ); }; };
     
    144142
    145143/* Begin PBXContainerItemProxy section */
    146                 0F7EB7F71F95412900F1ABCB /* PBXContainerItemProxy */ = {
    147                         isa = PBXContainerItemProxy;
    148                         containerPortal = 145F6837179DC45F00D65598 /* Project object */;
    149                         proxyType = 1;
    150                         remoteGlobalIDString = 14F271BD18EA3963008C152F;
    151                         remoteInfo = bmalloc;
    152                 };
    153144                0F7EB8551F95505400F1ABCB /* PBXContainerItemProxy */ = {
    154145                        isa = PBXContainerItemProxy;
     
    166157                };
    167158/* End PBXContainerItemProxy section */
    168 
    169 /* Begin PBXCopyFilesBuildPhase section */
    170                 0F7EB7ED1F95285300F1ABCB /* CopyFiles */ = {
    171                         isa = PBXCopyFilesBuildPhase;
    172                         buildActionMask = 2147483647;
    173                         dstPath = /usr/share/man/man1/;
    174                         dstSubfolderSpec = 0;
    175                         files = (
    176                         );
    177                         runOnlyForDeploymentPostprocessing = 1;
    178                 };
    179 /* End PBXCopyFilesBuildPhase section */
    180159
    181160/* Begin PBXFileReference section */
     
    192171                0F74B93C1F89713E00B935D3 /* CryptoRandom.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CryptoRandom.h; path = bmalloc/CryptoRandom.h; sourceTree = "<group>"; };
    193172                0F74B93D1F89713E00B935D3 /* CryptoRandom.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CryptoRandom.cpp; path = bmalloc/CryptoRandom.cpp; sourceTree = "<group>"; };
    194                 0F7EB7EF1F95285300F1ABCB /* testbmalloc */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = testbmalloc; sourceTree = BUILT_PRODUCTS_DIR; };
    195                 0F7EB7F11F95285300F1ABCB /* testbmalloc.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = testbmalloc.cpp; sourceTree = "<group>"; };
    196173                0F7EB7FC1F9541AD00F1ABCB /* EligibilityResult.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = EligibilityResult.h; path = bmalloc/EligibilityResult.h; sourceTree = SOURCE_ROOT; };
    197174                0F7EB7FD1F9541AD00F1ABCB /* IsoHeapImplInlines.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = IsoHeapImplInlines.h; path = bmalloc/IsoHeapImplInlines.h; sourceTree = SOURCE_ROOT; };
     
    307284
    308285/* Begin PBXFrameworksBuildPhase section */
    309                 0F7EB7EC1F95285300F1ABCB /* Frameworks */ = {
    310                         isa = PBXFrameworksBuildPhase;
    311                         buildActionMask = 2147483647;
    312                         files = (
    313                                 0F7EB7FA1F95414C00F1ABCB /* libbmalloc.a in Frameworks */,
    314                         );
    315                         runOnlyForDeploymentPostprocessing = 0;
    316                 };
    317286                14CC394118EA8743004AFE34 /* Frameworks */ = {
    318287                        isa = PBXFrameworksBuildPhase;
     
    334303
    335304/* Begin PBXGroup section */
    336                 0F7EB7F01F95285300F1ABCB /* test */ = {
    337                         isa = PBXGroup;
    338                         children = (
    339                                 0F7EB7F11F95285300F1ABCB /* testbmalloc.cpp */,
    340                         );
    341                         path = test;
    342                         sourceTree = "<group>";
    343                 };
    344305                0F7EB7F91F95414C00F1ABCB /* Frameworks */ = {
    345306                        isa = PBXGroup;
     
    422383                                145F6840179DC45F00D65598 /* Products */,
    423384                                14D9DB4F17F2868900EAAB79 /* stdlib */,
    424                                 0F7EB7F01F95285300F1ABCB /* test */,
    425385                        );
    426386                        sourceTree = "<group>";
     
    429389                        isa = PBXGroup;
    430390                        children = (
    431                                 0F7EB7EF1F95285300F1ABCB /* testbmalloc */,
    432391                                14F271BE18EA3963008C152F /* libbmalloc.a */,
    433392                                14CC394418EA8743004AFE34 /* libmbmalloc.dylib */,
     
    666625
    667626/* Begin PBXNativeTarget section */
    668                 0F7EB7EE1F95285300F1ABCB /* testbmalloc */ = {
    669                         isa = PBXNativeTarget;
    670                         buildConfigurationList = 0F7EB7F61F95285300F1ABCB /* Build configuration list for PBXNativeTarget "testbmalloc" */;
    671                         buildPhases = (
    672                                 0F7EB7EB1F95285300F1ABCB /* Sources */,
    673                                 0F7EB7EC1F95285300F1ABCB /* Frameworks */,
    674                                 0F7EB7ED1F95285300F1ABCB /* CopyFiles */,
    675                         );
    676                         buildRules = (
    677                         );
    678                         dependencies = (
    679                                 0F7EB7F81F95412900F1ABCB /* PBXTargetDependency */,
    680                         );
    681                         name = testbmalloc;
    682                         productName = testbmalloc;
    683                         productReference = 0F7EB7EF1F95285300F1ABCB /* testbmalloc */;
    684                         productType = "com.apple.product-type.tool";
    685                 };
    686627                14CC394318EA8743004AFE34 /* mbmalloc */ = {
    687628                        isa = PBXNativeTarget;
     
    728669                                LastUpgradeCheck = 1000;
    729670                                TargetAttributes = {
    730                                         0F7EB7EE1F95285300F1ABCB = {
    731                                                 CreatedOnToolsVersion = 9.0;
    732                                                 ProvisioningStyle = Manual;
    733                                         };
    734671                                        0F7EB8501F95504B00F1ABCB = {
    735672                                                CreatedOnToolsVersion = 9.0;
     
    753690                                14F271BD18EA3963008C152F /* bmalloc */,
    754691                                14CC394318EA8743004AFE34 /* mbmalloc */,
    755                                 0F7EB7EE1F95285300F1ABCB /* testbmalloc */,
    756692                        );
    757693                };
     
    759695
    760696/* Begin PBXSourcesBuildPhase section */
    761                 0F7EB7EB1F95285300F1ABCB /* Sources */ = {
    762                         isa = PBXSourcesBuildPhase;
    763                         buildActionMask = 2147483647;
    764                         files = (
    765                                 0F7EB7F21F95285300F1ABCB /* testbmalloc.cpp in Sources */,
    766                         );
    767                         runOnlyForDeploymentPostprocessing = 0;
    768                 };
    769697                14CC394018EA8743004AFE34 /* Sources */ = {
    770698                        isa = PBXSourcesBuildPhase;
     
    813741
    814742/* Begin PBXTargetDependency section */
    815                 0F7EB7F81F95412900F1ABCB /* PBXTargetDependency */ = {
    816                         isa = PBXTargetDependency;
    817                         target = 14F271BD18EA3963008C152F /* bmalloc */;
    818                         targetProxy = 0F7EB7F71F95412900F1ABCB /* PBXContainerItemProxy */;
    819                 };
    820743                0F7EB8561F95505400F1ABCB /* PBXTargetDependency */ = {
    821744                        isa = PBXTargetDependency;
     
    831754
    832755/* Begin XCBuildConfiguration section */
    833                 0F7EB7F31F95285300F1ABCB /* Debug */ = {
    834                         isa = XCBuildConfiguration;
    835                         baseConfigurationReference = 14B650C718F39F4800751968 /* DebugRelease.xcconfig */;
    836                         buildSettings = {
    837                                 PRODUCT_NAME = "$(TARGET_NAME)";
    838                         };
    839                         name = Debug;
    840                 };
    841                 0F7EB7F41F95285300F1ABCB /* Release */ = {
    842                         isa = XCBuildConfiguration;
    843                         baseConfigurationReference = 14B650C718F39F4800751968 /* DebugRelease.xcconfig */;
    844                         buildSettings = {
    845                                 PRODUCT_NAME = "$(TARGET_NAME)";
    846                         };
    847                         name = Release;
    848                 };
    849                 0F7EB7F51F95285300F1ABCB /* Production */ = {
    850                         isa = XCBuildConfiguration;
    851                         baseConfigurationReference = 14B650C518F39F4800751968 /* Base.xcconfig */;
    852                         buildSettings = {
    853                                 PRODUCT_NAME = "$(TARGET_NAME)";
    854                         };
    855                         name = Production;
    856                 };
    857756                0F7EB8521F95504B00F1ABCB /* Debug */ = {
    858757                        isa = XCBuildConfiguration;
     
    949848
    950849/* Begin XCConfigurationList section */
    951                 0F7EB7F61F95285300F1ABCB /* Build configuration list for PBXNativeTarget "testbmalloc" */ = {
    952                         isa = XCConfigurationList;
    953                         buildConfigurations = (
    954                                 0F7EB7F31F95285300F1ABCB /* Debug */,
    955                                 0F7EB7F41F95285300F1ABCB /* Release */,
    956                                 0F7EB7F51F95285300F1ABCB /* Production */,
    957                         );
    958                         defaultConfigurationIsVisible = 0;
    959                         defaultConfigurationName = Production;
    960                 };
    961850                0F7EB8511F95504B00F1ABCB /* Build configuration list for PBXAggregateTarget "All" */ = {
    962851                        isa = XCConfigurationList;
  • branches/safari-607-branch/Source/bmalloc/bmalloc/IsoDirectory.h

    r230501 r246421  
    11/*
    2  * Copyright (C) 2017-2018 Apple Inc. All rights reserved.
     2 * Copyright (C) 2017-2019 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    9090    Bits<numPages> m_committed;
    9191    std::array<IsoPage<Config>*, numPages> m_pages;
    92     unsigned m_firstEligible { 0 };
     92    unsigned m_firstEligibleOrDecommitted { 0 };
    9393    unsigned m_highWatermark { 0 };
    9494};
  • branches/safari-607-branch/Source/bmalloc/bmalloc/IsoDirectoryInlines.h

    r230501 r246421  
    11/*
    2  * Copyright (C) 2017-2018 Apple Inc. All rights reserved.
     2 * Copyright (C) 2017-2019 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    4747EligibilityResult<Config> IsoDirectory<Config, passedNumPages>::takeFirstEligible()
    4848{
    49     unsigned pageIndex = (m_eligible | ~m_committed).findBit(m_firstEligible, true);
    50     m_firstEligible = pageIndex;
     49    unsigned pageIndex = (m_eligible | ~m_committed).findBit(m_firstEligibleOrDecommitted, true);
     50    m_firstEligibleOrDecommitted = pageIndex;
     51    BASSERT((m_eligible | ~m_committed).findBit(0, true) == pageIndex);
    5152    if (pageIndex >= numPages)
    5253        return EligibilityKind::Full;
     
    100101            fprintf(stderr, "%p: %p did become eligible.\n", this, page);
    101102        m_eligible[pageIndex] = true;
    102         m_firstEligible = std::min(m_firstEligible, pageIndex);
    103         this->m_heap.didBecomeEligible(this);
     103        m_firstEligibleOrDecommitted = std::min(m_firstEligibleOrDecommitted, pageIndex);
     104        this->m_heap.didBecomeEligibleOrDecommited(this);
    104105        return;
    105106    case IsoPageTrigger::Empty:
     
    125126    this->m_heap.isNoLongerFreeable(m_pages[index], IsoPageBase::pageSize);
    126127    m_committed[index] = false;
     128    m_firstEligibleOrDecommitted = std::min(m_firstEligibleOrDecommitted, index);
     129    this->m_heap.didBecomeEligibleOrDecommited(this);
    127130    this->m_heap.didDecommit(m_pages[index], IsoPageBase::pageSize);
    128131}
  • branches/safari-607-branch/Source/bmalloc/bmalloc/IsoHeapImpl.h

    r230501 r246421  
    11/*
    2  * Copyright (C) 2017-2018 Apple Inc. All rights reserved.
     2 * Copyright (C) 2017-2019 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    6969   
    7070    // Callbacks from directory.
    71     void didBecomeEligible(IsoDirectory<Config, numPagesInInlineDirectory>*);
    72     void didBecomeEligible(IsoDirectory<Config, IsoDirectoryPage<Config>::numPages>*);
     71    void didBecomeEligibleOrDecommited(IsoDirectory<Config, numPagesInInlineDirectory>*);
     72    void didBecomeEligibleOrDecommited(IsoDirectory<Config, IsoDirectoryPage<Config>::numPages>*);
    7373   
    7474    void scavenge(Vector<DeferredDecommit>&) override;
     
    121121    unsigned m_directoryHighWatermark { 0 };
    122122   
    123     bool m_isInlineDirectoryEligible { true };
    124     IsoDirectoryPage<Config>* m_firstEligibleDirectory { nullptr };
     123    bool m_isInlineDirectoryEligibleOrDecommitted { true };
     124    IsoDirectoryPage<Config>* m_firstEligibleOrDecommitedDirectory { nullptr };
    125125   
    126126    IsoTLSAllocatorEntry<Config> m_allocator;
  • branches/safari-607-branch/Source/bmalloc/bmalloc/IsoHeapImplInlines.h

    r230515 r246421  
    11/*
    2  * Copyright (C) 2017-2018 Apple Inc. All rights reserved.
     2 * Copyright (C) 2017-2019 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    4343EligibilityResult<Config> IsoHeapImpl<Config>::takeFirstEligible()
    4444{
    45     if (m_isInlineDirectoryEligible) {
     45    if (m_isInlineDirectoryEligibleOrDecommitted) {
    4646        EligibilityResult<Config> result = m_inlineDirectory.takeFirstEligible();
    4747        if (result.kind == EligibilityKind::Full)
    48             m_isInlineDirectoryEligible = false;
     48            m_isInlineDirectoryEligibleOrDecommitted = false;
    4949        else
    5050            return result;
    5151    }
    5252   
    53     if (!m_firstEligibleDirectory) {
     53    if (!m_firstEligibleOrDecommitedDirectory) {
    5454        // If nothing is eligible, it can only be because we have no directories. It wouldn't be the end
    55         // of the world if we broke this invariant. It would only mean that didBecomeEligible() would need
     55        // of the world if we broke this invariant. It would only mean that didBecomeEligibleOrDecommited() would need
    5656        // a null check.
    5757        RELEASE_BASSERT(!m_headDirectory);
     
    5959    }
    6060   
    61     for (; m_firstEligibleDirectory; m_firstEligibleDirectory = m_firstEligibleDirectory->next) {
    62         EligibilityResult<Config> result = m_firstEligibleDirectory->payload.takeFirstEligible();
     61    for (; m_firstEligibleOrDecommitedDirectory; m_firstEligibleOrDecommitedDirectory = m_firstEligibleOrDecommitedDirectory->next) {
     62        EligibilityResult<Config> result = m_firstEligibleOrDecommitedDirectory->payload.takeFirstEligible();
    6363        if (result.kind != EligibilityKind::Full) {
    64             m_directoryHighWatermark = std::max(m_directoryHighWatermark, m_firstEligibleDirectory->index());
     64            m_directoryHighWatermark = std::max(m_directoryHighWatermark, m_firstEligibleOrDecommitedDirectory->index());
    6565            return result;
    6666        }
     
    7777    }
    7878    m_directoryHighWatermark = newDirectory->index();
    79     m_firstEligibleDirectory = newDirectory;
     79    m_firstEligibleOrDecommitedDirectory = newDirectory;
    8080    EligibilityResult<Config> result = newDirectory->payload.takeFirstEligible();
    8181    RELEASE_BASSERT(result.kind != EligibilityKind::Full);
     
    8484
    8585template<typename Config>
    86 void IsoHeapImpl<Config>::didBecomeEligible(IsoDirectory<Config, numPagesInInlineDirectory>* directory)
     86void IsoHeapImpl<Config>::didBecomeEligibleOrDecommited(IsoDirectory<Config, numPagesInInlineDirectory>* directory)
    8787{
    8888    RELEASE_BASSERT(directory == &m_inlineDirectory);
    89     m_isInlineDirectoryEligible = true;
    90 }
    91 
    92 template<typename Config>
    93 void IsoHeapImpl<Config>::didBecomeEligible(IsoDirectory<Config, IsoDirectoryPage<Config>::numPages>* directory)
    94 {
    95     RELEASE_BASSERT(m_firstEligibleDirectory);
     89    m_isInlineDirectoryEligibleOrDecommitted = true;
     90}
     91
     92template<typename Config>
     93void IsoHeapImpl<Config>::didBecomeEligibleOrDecommited(IsoDirectory<Config, IsoDirectoryPage<Config>::numPages>* directory)
     94{
     95    RELEASE_BASSERT(m_firstEligibleOrDecommitedDirectory);
    9696    auto* directoryPage = IsoDirectoryPage<Config>::pageFor(directory);
    97     if (directoryPage->index() < m_firstEligibleDirectory->index())
    98         m_firstEligibleDirectory = directoryPage;
     97    if (directoryPage->index() < m_firstEligibleOrDecommitedDirectory->index())
     98        m_firstEligibleOrDecommitedDirectory = directoryPage;
    9999}
    100100
  • branches/safari-607-branch/Source/bmalloc/bmalloc/IsoTLS.cpp

    r234913 r246421  
    206206                return;
    207207
    208 #if GIGACAGE_ENABLED
     208#if GIGACAGE_ENABLED || BCPU(ARM64)
     209#if !BCPU(ARM64)
    209210            if (!Gigacage::shouldBeEnabled()) {
    210211                s_mallocFallbackState = MallocFallbackState::FallBackToMalloc;
    211212                return;
    212213            }
     214#endif
    213215            const char* env = getenv("bmalloc_IsoHeap");
    214216            if (env && (!strcasecmp(env, "false") || !strcasecmp(env, "no") || !strcmp(env, "0")))
  • branches/safari-607-branch/Source/bmalloc/bmalloc/ProcessCheck.mm

    r236474 r246421  
    4747        || [processName isEqualToString:@"DumpRenderTree"]
    4848        || [processName isEqualToString:@"wasm"]
    49         || [processName hasPrefix:@"test"];
     49        || [processName hasPrefix:@"test"]
     50        || [processName hasPrefix:@"Test"];
    5051
    5152    return isOptInBinary;
  • branches/safari-607-branch/Tools/ChangeLog

    r246376 r246421  
     12019-06-13  Kocsen Chung  <kocsen_chung@apple.com>
     2
     3        Apply patch. rdar://problem/51656608
     4
     5    2019-06-13  Keith Miller  <keith_miller@apple.com>
     6
     7            IsoHeaps don't notice uncommitted VA becoming the first eligible.
     8            https://bugs.webkit.org/show_bug.cgi?id=198301
     9
     10            Reviewed by Yusuke Suzuki.
     11
     12            Move testbmalloc.cpp to TestWTF so it runs in automation.
     13
     14            * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
     15            * TestWebKitAPI/Tests/WTF/bmalloc/IsoHeap.cpp: Renamed from Source/bmalloc/test/testbmalloc.cpp.
     16            (TEST):
     17
    1182019-06-12  Null  <null@apple.com>
    219
  • branches/safari-607-branch/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj

    r246376 r246421  
    259259                536770361CC81B6100D425B1 /* WebScriptObjectDescription.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 536770351CC812F900D425B1 /* WebScriptObjectDescription.html */; };
    260260                53EC25411E96FD87000831B9 /* PriorityQueue.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 53EC253F1E96BC80000831B9 /* PriorityQueue.cpp */; };
     261                53FCDE6B229EFFB900598ECF /* IsoHeap.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 53FCDE6A229EFFB900598ECF /* IsoHeap.cpp */; };
    261262                55226A2F1EBA44B900C36AD0 /* large-red-square-image.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 55226A2E1EB969B600C36AD0 /* large-red-square-image.html */; };
    262263                5597F8361D9596C80066BC21 /* SynchronizedFixedQueue.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5597F8341D9596C80066BC21 /* SynchronizedFixedQueue.cpp */; };
     
    16401641                536770351CC812F900D425B1 /* WebScriptObjectDescription.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = WebScriptObjectDescription.html; sourceTree = "<group>"; };
    16411642                53EC253F1E96BC80000831B9 /* PriorityQueue.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PriorityQueue.cpp; sourceTree = "<group>"; };
     1643                53FCDE6A229EFFB900598ECF /* IsoHeap.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = IsoHeap.cpp; sourceTree = "<group>"; };
    16421644                55226A2E1EB969B600C36AD0 /* large-red-square-image.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "large-red-square-image.html"; sourceTree = "<group>"; };
    16431645                5597F8341D9596C80066BC21 /* SynchronizedFixedQueue.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SynchronizedFixedQueue.cpp; sourceTree = "<group>"; };
     
    27422744                        sourceTree = "<group>";
    27432745                };
     2746                53FCDE69229EFF6800598ECF /* bmalloc */ = {
     2747                        isa = PBXGroup;
     2748                        children = (
     2749                                53FCDE6A229EFFB900598ECF /* IsoHeap.cpp */,
     2750                        );
     2751                        path = bmalloc;
     2752                        sourceTree = "<group>";
     2753                };
    27442754                7560917619259C59009EF06E /* ios */ = {
    27452755                        isa = PBXGroup;
     
    31983208                        isa = PBXGroup;
    31993209                        children = (
     3210                                53FCDE69229EFF6800598ECF /* bmalloc */,
    32003211                                C0991C4F143C7D68007998F2 /* cf */,
    32013212                                E3C21A7821B25C82003B31A3 /* cocoa */,
     
    38333844                                7C83DED41D0A590C00FEBCF3 /* HashSet.cpp in Sources */,
    38343845                                7C83DEE01D0A590C00FEBCF3 /* IntegerToStringConversion.cpp in Sources */,
     3846                                53FCDE6B229EFFB900598ECF /* IsoHeap.cpp in Sources */,
    38353847                                7A0509411FB9F06400B33FB8 /* JSONValue.cpp in Sources */,
    38363848                                531C1D8E1DF8EF72006E979F /* LEBDecoder.cpp in Sources */,
  • branches/safari-607-branch/Tools/TestWebKitAPI/Tests/WTF/bmalloc/IsoHeap.cpp

    r246420 r246421  
    11/*
    2  * Copyright (C) 2017 Apple Inc. All rights reserved.
     2 * Copyright (C) 2017-2019 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    1111 *    documentation and/or other materials provided with the distribution.
    1212 *
    13  * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
    14  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    15  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
    16  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
    17  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
    18  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
    19  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
    20  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
    21  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    22  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
    23  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
     14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
     15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
     17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
     23 * THE POSSIBILITY OF SUCH DAMAGE.
    2424 */
     25
     26#include "config.h"
     27
     28#if !USE(SYSTEM_MALLOC)
    2529
    2630#include <bmalloc/bmalloc.h>
    2731#include <bmalloc/Environment.h>
    2832#include <bmalloc/IsoHeapInlines.h>
     33
    2934#include <cmath>
    3035#include <cstdlib>
     
    3540using namespace bmalloc::api;
    3641
    37 // We don't have a NO_RETURN_DUE_TO_EXIT, nor should we. That's ridiculous.
    38 static bool hiddenTruthBecauseNoReturnIsStupid() { return true; }
    39 
    40 static void usage()
    41 {
    42     puts("Usage: testb3 [<filter>]");
    43     if (hiddenTruthBecauseNoReturnIsStupid())
    44         exit(1);
    45 }
    46 
    4742#define RUN(test) do {                          \
    48         if (!shouldRun(#test))                  \
    49             break;                              \
    50         puts(#test "...");                      \
    51         test;                                   \
    52         puts(#test ": OK!");                    \
    53     } while (false)
     43if (!shouldRun(#test))                  \
     44break;                              \
     45puts(#test "...");                      \
     46test;                                   \
     47puts(#test ": OK!");                    \
     48} while (false)
    5449
    5550// Nothing fancy for now; we just use the existing WTF assertion machinery.
    5651#define CHECK(x) do {                                                   \
    57         if (!!(x))                                                      \
    58             break;                                                      \
    59         fprintf(stderr, "%s:%d: in %s: assertion %s failed.\n",         \
    60             __FILE__, __LINE__, __PRETTY_FUNCTION__, #x);               \
    61         abort();                                                        \
    62     } while (false)
     52if (!!(x))                                                      \
     53break;                                                      \
     54fprintf(stderr, "%s:%d: in %s: assertion %s failed.\n",         \
     55__FILE__, __LINE__, __PRETTY_FUNCTION__, #x);               \
     56abort();                                                        \
     57} while (false)
    6358
    6459static std::set<void*> toptrset(const std::vector<void*>& ptrs)
     
    139134}
    140135
    141 static void testIsoSimple()
     136TEST(bmalloc, IsoSimple)
    142137{
    143138    static IsoHeap<double> heap;
     
    154149}
    155150
    156 static void testIsoSimpleScavengeBeforeDealloc()
     151TEST(bmalloc, IsoSimpleScavengeBeforeDealloc)
    157152{
    158153    static IsoHeap<double> heap;
     
    170165}
    171166
    172 static void testIsoFlipFlopFragmentedPages()
     167TEST(bmalloc, IsoFlipFlopFragmentedPages)
    173168{
    174169    static IsoHeap<double> heap;
     
    190185}
    191186
    192 static void testIsoFlipFlopFragmentedPagesScavengeInMiddle()
     187TEST(bmalloc, IsoFlipFlopFragmentedPagesScavengeInMiddle)
    193188{
    194189    static IsoHeap<double> heap;
     
    223218}
    224219
    225 static void testIsoFlipFlopFragmentedPagesScavengeInMiddle288()
     220TEST(bmalloc, IsoFlipFlopFragmentedPagesScavengeInMiddle288)
    226221{
    227222    static IsoHeap<char[288]> heap;
     
    264259    {
    265260    }
    266    
     261
    267262    int x;
    268263    float y;
     
    271266MAKE_BISO_MALLOCED_IMPL(BisoMalloced);
    272267
    273 static void testBisoMalloced()
     268TEST(bmalloc, BisoMalloced)
    274269{
    275270    BisoMalloced* ptr = new BisoMalloced(4, 5);
     
    287282    {
    288283    }
    289    
     284
    290285    int x;
    291286    float y;
    292287};
    293288
    294 static void testBisoMallocedInline()
     289TEST(bmalloc, BisoMallocedInline)
    295290{
    296291    BisoMallocedInline* ptr = new BisoMallocedInline(4, 5);
     
    300295}
    301296
    302 static void run(const char* filter)
    303 {
    304     auto shouldRun = [&] (const char* testName) -> bool {
    305         return !filter || !!strcasestr(testName, filter);
     297
     298TEST(bmalloc, ScavengedMemoryShouldBeReused)
     299{
     300    static IsoHeap<double> heap;
     301
     302    auto run = [] (unsigned numPagesToCommit) {
     303        auto* ptr1 = heap.allocate();
     304
     305        std::vector<void*> ptrs;
     306
     307        for (unsigned i = 0; ;i++) {
     308            void* ptr = heap.allocate();
     309            CHECK(ptr);
     310            ptrs.push_back(ptr);
     311            if (heap.impl().numCommittedPages() == numPagesToCommit)
     312                break;
     313        }
     314
     315        std::set<void*> uniquedPtrs = toptrset(ptrs);
     316
     317        heap.deallocate(ptr1);
     318        for (unsigned i = 0; i < IsoPage<decltype(heap)::Config>::numObjects - 1; i++) {
     319            heap.deallocate(ptrs[i]);
     320            uniquedPtrs.erase(ptrs[i]);
     321        }
     322
     323        scavenge();
     324        assertHasOnlyObjects(heap, uniquedPtrs);
     325
     326        // FIXME: This only seems to pass when lldb is attached but the scavenger thread isn't running...
     327        // see: https://bugs.webkit.org/show_bug.cgi?id=198384
     328        // auto* ptr2 = heap.allocate();
     329        // CHECK(ptr1 == ptr2);
    306330    };
    307    
    308     RUN(testIsoSimple());
    309     RUN(testIsoSimpleScavengeBeforeDealloc());
    310     RUN(testIsoFlipFlopFragmentedPages());
    311     RUN(testIsoFlipFlopFragmentedPagesScavengeInMiddle());
    312     RUN(testIsoFlipFlopFragmentedPagesScavengeInMiddle288());
    313     RUN(testBisoMalloced());
    314     RUN(testBisoMallocedInline());
    315    
    316     puts("Success!");
    317 }
    318 
    319 int main(int argc, char** argv)
    320 {
    321     const char* filter = nullptr;
    322     switch (argc) {
    323     case 1:
    324         break;
    325     case 2:
    326         filter = argv[1];
    327         break;
    328     default:
    329         usage();
    330         break;
    331     }
    332    
    333     run(filter);
    334     return 0;
    335 }
    336 
     331
     332    run(2);
     333}
     334
     335#endif
Note: See TracChangeset for help on using the changeset viewer.