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

Changeset 294905 in webkit


Ignore:
Timestamp:
May 26, 2022, 3:51:13 PM (4 years ago)
Author:
mark.lam@apple.com
Message:

Re-factoring clean up in allocateCell and tryAllocateCell.
​https://bugs.webkit.org/show_bug.cgi?id=240973

Reviewed by Saam Barati.

The AllocationFailureMode should be a template parameter to tryAllocateCellHelper because it's
constant. Also, tryAllocateCellHelper should take a VM& instead of taking a Heap& and then
converting it back to a VM&.

  • Source/JavaScriptCore/runtime/JSCellInlines.h:

(JSC::tryAllocateCellHelper):
(JSC::allocateCell):
(JSC::tryAllocateCell):

Canonical link: ​https://commits.webkit.org/251028@main

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/runtime/JSCellInlines.h

    r293710 r294905  
    11/*
    2  * Copyright (C) 2012-2021 Apple Inc. All rights reserved.
     2 * Copyright (C) 2012-2022 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
    … …  
    168168}
    169169
    170 template<typename T>
    171 ALWAYS_INLINE void* tryAllocateCellHelper(Heap& heap, size_t size, GCDeferralContext* deferralContext, AllocationFailureMode failureMode)
    172 {
    173     VM& vm = heap.vm();
    174     ASSERT(deferralContext || heap.isDeferred() || !DisallowGC::isInEffectOnCurrentThread());
     170template<typename T, AllocationFailureMode failureMode>
     171ALWAYS_INLINE void* tryAllocateCellHelper(VM& vm, size_t size, GCDeferralContext* deferralContext)
     172{
     173    ASSERT(deferralContext || vm.heap.isDeferred() || !DisallowGC::isInEffectOnCurrentThread());
    175174    ASSERT(size >= sizeof(T));
    176175    JSCell* result = static_cast<JSCell*>(subspaceFor<T>(vm)->allocate(vm, size, deferralContext, failureMode));
    177     if (failureMode == AllocationFailureMode::ReturnNull && !result)
    178         return nullptr;
     176    if constexpr (failureMode == AllocationFailureMode::ReturnNull) {
     177        if (!result)
     178            return nullptr;
     179    }
    179180#if ENABLE(GC_VALIDATION)
    180181    ASSERT(!vm.isInitializingObject());
    … …  
    188189void* allocateCell(VM& vm, size_t size)
    189190{
    190     return tryAllocateCellHelper<T>(vm.heap, size, nullptr, AllocationFailureMode::Assert);
     191    return tryAllocateCellHelper<T, AllocationFailureMode::Assert>(vm, size, nullptr);
    191192}
    192193
    … …  
    194195void* tryAllocateCell(VM& vm, size_t size)
    195196{
    196     return tryAllocateCellHelper<T>(vm.heap, size, nullptr, AllocationFailureMode::ReturnNull);
     197    return tryAllocateCellHelper<T, AllocationFailureMode::ReturnNull>(vm, size, nullptr);
    197198}
    198199
    … …  
    200201void* allocateCell(VM& vm, GCDeferralContext* deferralContext, size_t size)
    201202{
    202     return tryAllocateCellHelper<T>(vm.heap, size, deferralContext, AllocationFailureMode::Assert);
     203    return tryAllocateCellHelper<T, AllocationFailureMode::Assert>(vm, size, deferralContext);
    203204}
    204205
    … …  
    206207void* tryAllocateCell(VM& vm, GCDeferralContext* deferralContext, size_t size)
    207208{
    208     return tryAllocateCellHelper<T>(vm.heap, size, deferralContext, AllocationFailureMode::ReturnNull);
     209    return tryAllocateCellHelper<T, AllocationFailureMode::ReturnNull>(vm, size, deferralContext);
    209210}
    210211
Note: See TracChangeset for help on using the changeset viewer.