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

Changeset 279028 in webkit


Ignore:
Timestamp:
Jun 17, 2021, 6:44:42 PM (5 years ago)
Author:
mark.lam@apple.com
Message:

Define MacroAssemblerARM64E::numberOfPACBits based on OS_CONSTANT(EFFECTIVE_ADDRESS_WIDTH).
​https://bugs.webkit.org/show_bug.cgi?id=227147
rdar://78785309

Reviewed by Saam Barati.

Source/bmalloc:

For OS(DARWIN), define BOS_EFFECTIVE_ADDRESS_WIDTH in terms of MACH_VM_MAX_ADDRESS,
which is provided by the SDK. This ensures that it is correct for each target
OS(DARWIN) platform.

  • bmalloc/Algorithm.h:

(bmalloc::clzConstexpr):
(bmalloc::getMSBSetConstexpr):

  • bmalloc/BPlatform.h:
  • bmalloc/Gigacage.h:
  • bmalloc/ObjectTypeTable.h:
  • bmalloc/Packed.h:

Source/JavaScriptCore:

  • assembler/MacroAssemblerARM64E.h:
  • bytecode/CodeOrigin.h:
  • runtime/JSString.h:
  • runtime/OptionsList.h:

Source/WTF:

For OS(DARWIN), define OS_CONSTANT(EFFECTIVE_ADDRESS_WIDTH) in terms of
MACH_VM_MAX_ADDRESS, which is provided by the SDK. This ensures that it is
correct for each target OS(DARWIN) platform.

Also update an assertion in WTFAssertions.cpp to verify that address bits are
less than 48. The purpose of this assertion is to ensure that our 64-bit NaN
boxing encoding for JSValues will work. Hence, we should use the encoding limit
for pointers of 48 bits. It no longer makes sense to assert based on
OS_CONSTANT(EFFECTIVE_ADDRESS_WIDTH), because OS_CONSTANT(EFFECTIVE_ADDRESS_WIDTH)
is defined in terms of MACH_VM_MAX_ADDRESS.

  • wtf/CagedPtr.h:
  • wtf/CompactPointerTuple.h:
  • wtf/PlatformOS.h:
  • wtf/WTFAssertions.cpp:
  • wtf/threads/Signals.cpp:

Tools:

  • TestWebKitAPI/Tests/WTF/Packed.cpp:
Location:
trunk
Files:
20 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r279008 r279028  
     12021-06-17  Mark Lam  <mark.lam@apple.com>
     2
     3        Define MacroAssemblerARM64E::numberOfPACBits based on OS_CONSTANT(EFFECTIVE_ADDRESS_WIDTH).
     4        https://bugs.webkit.org/show_bug.cgi?id=227147
     5        rdar://78785309
     6
     7        Reviewed by Saam Barati.
     8
     9        * assembler/MacroAssemblerARM64E.h:
     10        * bytecode/CodeOrigin.h:
     11        * runtime/JSString.h:
     12        * runtime/OptionsList.h:
     13
    1142021-06-17  Fujii Hironori  <Hironori.Fujii@sony.com>
    215
  • trunk/Source/JavaScriptCore/assembler/MacroAssemblerARM64E.h

    r278656 r279028  
    11/*
    2  * Copyright (C) 2018-2020 Apple Inc. All rights reserved.
     2 * Copyright (C) 2018-2021 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
    … …  
    2929
    3030#include "DisallowMacroScratchRegisterUsage.h"
     31#include <wtf/MathExtras.h>
    3132
    3233// We need to include this before MacroAssemblerARM64.h because MacroAssemblerARM64
    … …  
    3940#endif
    4041
     42#if OS(DARWIN)
     43#include <mach/vm_param.h>
     44#endif
     45
    4146namespace JSC {
    4247
    … …  
    4550class MacroAssemblerARM64E : public MacroAssemblerARM64 {
    4651public:
    47     static constexpr unsigned numberOfPACBits = 25;
    48     static constexpr uintptr_t nonPACBitsMask = (1ull << (64 - numberOfPACBits)) - 1;
     52    static constexpr unsigned numberOfPointerBits = sizeof(void*) * CHAR_BIT;
     53    static constexpr unsigned numberOfPACBits = numberOfPointerBits - OS_CONSTANT(EFFECTIVE_ADDRESS_WIDTH);
     54    static constexpr uintptr_t nonPACBitsMask = (1ull << (numberOfPointerBits - numberOfPACBits)) - 1;
    4955
    5056    ALWAYS_INLINE void tagReturnAddress()
  • trunk/Source/JavaScriptCore/bytecode/CodeOrigin.h

    r264488 r279028  
    3030#include <limits.h>
    3131#include <wtf/HashMap.h>
     32#include <wtf/MathExtras.h>
    3233#include <wtf/PrintStream.h>
    3334#include <wtf/StdLibExtras.h>
    3435#include <wtf/Vector.h>
     36
     37#if OS(DARWIN)
     38#include <mach/vm_param.h>
     39#endif
    3540
    3641namespace JSC {
  • trunk/Source/JavaScriptCore/runtime/JSString.h

    r278338 r279028  
    3535#include <wtf/CheckedArithmetic.h>
    3636#include <wtf/ForbidHeapAllocation.h>
     37#include <wtf/MathExtras.h>
    3738#include <wtf/text/StringView.h>
     39
     40#if OS(DARWIN)
     41#include <mach/vm_param.h>
     42#endif
    3843
    3944namespace JSC {
  • trunk/Source/JavaScriptCore/runtime/OptionsList.h

    r278699 r279028  
    2727
    2828#include "GCLogging.h"
     29#include <wtf/MathExtras.h>
     30
     31#if OS(DARWIN)
     32#include <mach/vm_param.h>
     33#endif
    2934
    3035using WTF::PrintStream;
  • trunk/Source/WTF/ChangeLog

    r279027 r279028  
     12021-06-17  Mark Lam  <mark.lam@apple.com>
     2
     3        Define MacroAssemblerARM64E::numberOfPACBits based on OS_CONSTANT(EFFECTIVE_ADDRESS_WIDTH).
     4        https://bugs.webkit.org/show_bug.cgi?id=227147
     5        rdar://78785309
     6
     7        Reviewed by Saam Barati.
     8
     9        For OS(DARWIN), define OS_CONSTANT(EFFECTIVE_ADDRESS_WIDTH) in terms of
     10        MACH_VM_MAX_ADDRESS, which is provided by the SDK.  This ensures that it is
     11        correct for each target OS(DARWIN) platform.
     12
     13        Also update an assertion in WTFAssertions.cpp to verify that address bits are
     14        less than 48.  The purpose of this assertion is to ensure that our 64-bit NaN
     15        boxing encoding for JSValues will work.  Hence, we should use the encoding limit
     16        for pointers of 48 bits.  It no longer makes sense to assert based on
     17        OS_CONSTANT(EFFECTIVE_ADDRESS_WIDTH), because OS_CONSTANT(EFFECTIVE_ADDRESS_WIDTH)
     18        is defined in terms of MACH_VM_MAX_ADDRESS.
     19
     20        * wtf/CagedPtr.h:
     21        * wtf/CompactPointerTuple.h:
     22        * wtf/PlatformOS.h:
     23        * wtf/WTFAssertions.cpp:
     24        * wtf/threads/Signals.cpp:
     25
    1262021-06-17  Fujii Hironori  <Hironori.Fujii@sony.com>
    227
  • trunk/Source/WTF/wtf/CagedPtr.h

    r275597 r279028  
    11/*
    2  * Copyright (C) 2017 Apple Inc. All rights reserved.
     2 * Copyright (C) 2017-2021 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
    … …  
    2727
    2828#include <wtf/Gigacage.h>
     29#include <wtf/MathExtras.h>
    2930#include <wtf/PtrTag.h>
    3031#include <wtf/RawPtrTraits.h>
    3132
    3233#include <climits>
     34
     35#if OS(DARWIN)
     36#include <mach/vm_param.h>
     37#endif
    3338
    3439namespace WTF {
    … …  
    4045public:
    4146    static constexpr Gigacage::Kind kind = passedKind;
    42     static constexpr unsigned numberOfPACBits = 25;
    43     static constexpr uintptr_t nonPACBitsMask = (1ull << ((sizeof(T*) * CHAR_BIT) - numberOfPACBits)) - 1;
     47    static constexpr unsigned numberOfPointerBits = sizeof(T*) * CHAR_BIT;
     48    static constexpr unsigned numberOfPACBits = numberOfPointerBits - OS_CONSTANT(EFFECTIVE_ADDRESS_WIDTH);
     49    static constexpr uintptr_t nonPACBitsMask = (1ull << (numberOfPointerBits - numberOfPACBits)) - 1;
    4450
    4551    CagedPtr() : CagedPtr(nullptr) { }
  • trunk/Source/WTF/wtf/CompactPointerTuple.h

    r266713 r279028  
    2929#include <type_traits>
    3030#include <wtf/FastMalloc.h>
     31#include <wtf/MathExtras.h>
    3132#include <wtf/StdLibExtras.h>
     33
     34#if OS(DARWIN)
     35#include <mach/vm_param.h>
     36#endif
    3237
    3338namespace WTF {
  • trunk/Source/WTF/wtf/Packed.h

    r278878 r279028  
    3434#include <wtf/UnalignedAccess.h>
    3535
     36#if OS(DARWIN)
     37#include <mach/vm_param.h>
     38#endif
     39
    3640namespace WTF {
    3741
  • trunk/Source/WTF/wtf/PlatformOS.h

    r262223 r279028  
    11/*
    2  * Copyright (C) 2006-2019 Apple Inc. All rights reserved.
     2 * Copyright (C) 2006-2021 Apple Inc. All rights reserved.
    33 * Copyright (C) 2007-2009 Torch Mobile, Inc.
    44 * Copyright (C) 2010, 2011 Research In Motion Limited. All rights reserved.
    … …  
    3838#include <TargetConditionals.h>
    3939#endif
    40 
    4140
    4241/* OS() - underlying operating system; only to be used for mandated low-level services like
    … …  
    138137
    139138#if CPU(ADDRESS64)
    140 #if (OS(IOS) || OS(TVOS) || OS(WATCHOS)) && CPU(ARM64)
    141 #define WTF_OS_CONSTANT_EFFECTIVE_ADDRESS_WIDTH 36
     139#if OS(DARWIN)
     140#define WTF_OS_CONSTANT_EFFECTIVE_ADDRESS_WIDTH (WTF::getMSBSetConstexpr(MACH_VM_MAX_ADDRESS) + 1)
    142141#else
    143142/* We strongly assume that effective address width is <= 48 in 64bit architectures (e.g. NaN boxing). */
  • trunk/Source/WTF/wtf/WTFAssertions.cpp

    r254843 r279028  
    11/*
    2  * Copyright (C) 2017-2019 Apple Inc. All rights reserved.
     2 * Copyright (C) 2017-2021 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
    … …  
    5151
    5252#if OS(DARWIN) && CPU(ADDRESS64)
    53 static_assert(MACH_VM_MAX_ADDRESS <= ((1ULL << OS_CONSTANT(EFFECTIVE_ADDRESS_WIDTH)) - 1));
     53// NaN boxing encoding relies on this.
     54static_assert(MACH_VM_MAX_ADDRESS <= (1ull << 48));
    5455#endif
    5556
  • trunk/Source/WTF/wtf/threads/Signals.cpp

    r277900 r279028  
    4545#endif
    4646
     47#if OS(DARWIN)
     48#include <mach/vm_param.h>
     49#endif
     50
    4751#include <wtf/Atomics.h>
    4852#include <wtf/DataLog.h>
     53#include <wtf/MathExtras.h>
    4954#include <wtf/NeverDestroyed.h>
    5055#include <wtf/PlatformRegisters.h>
  • trunk/Source/bmalloc/ChangeLog

    r278447 r279028  
     12021-06-17  Mark Lam  <mark.lam@apple.com>
     2
     3        Define MacroAssemblerARM64E::numberOfPACBits based on OS_CONSTANT(EFFECTIVE_ADDRESS_WIDTH).
     4        https://bugs.webkit.org/show_bug.cgi?id=227147
     5        rdar://78785309
     6
     7        Reviewed by Saam Barati.
     8
     9        For OS(DARWIN), define BOS_EFFECTIVE_ADDRESS_WIDTH in terms of MACH_VM_MAX_ADDRESS,
     10        which is provided by the SDK.  This ensures that it is correct for each target
     11        OS(DARWIN) platform.
     12
     13        * bmalloc/Algorithm.h:
     14        (bmalloc::clzConstexpr):
     15        (bmalloc::getMSBSetConstexpr):
     16        * bmalloc/BPlatform.h:
     17        * bmalloc/Gigacage.h:
     18        * bmalloc/ObjectTypeTable.h:
     19        * bmalloc/Packed.h:
     20
    1212021-06-03  Michael Saboff  <msaboff@apple.com>
    222
  • trunk/Source/bmalloc/bmalloc/Algorithm.h

    r261827 r279028  
    11/*
    2  * Copyright (C) 2014-2020 Apple Inc. All rights reserved.
     2 * Copyright (C) 2014-2021 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
    … …  
    170170#endif
    171171
     172template <typename T>
     173constexpr unsigned clzConstexpr(T value)
     174{
     175    constexpr unsigned bitSize = sizeof(T) * CHAR_BIT;
     176
     177    using UT = typename std::make_unsigned<T>::type;
     178    UT uValue = value;
     179
     180    unsigned zeroCount = 0;
     181    for (int i = bitSize - 1; i >= 0; i--) {
     182        if (uValue >> i)
     183            break;
     184        zeroCount++;
     185    }
     186    return zeroCount;
     187}
     188
    172189constexpr unsigned long log2(unsigned long value)
    173190{
    … …  
    263280}
    264281
     282template<typename T>
     283constexpr unsigned getMSBSetConstexpr(T t)
     284{
     285    constexpr unsigned bitSize = sizeof(T) * CHAR_BIT;
     286    return bitSize - 1 - clzConstexpr(t);
     287}
     288
    265289// From http://graphics.stanford.edu/~seander/bithacks.html#RoundUpPowerOf2
    266290constexpr uint32_t roundUpToPowerOfTwo(uint32_t v)
  • trunk/Source/bmalloc/bmalloc/BPlatform.h

    r278447 r279028  
    11/*
    2  * Copyright (C) 2014-2020 Apple Inc. All rights reserved.
     2 * Copyright (C) 2014-2021 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
    … …  
    275275
    276276#if BCPU(ADDRESS64)
    277 #if (BOS(IOS) || BOS(TVOS) || BOS(WATCHOS)) && BCPU(ARM64)
    278 #define BOS_EFFECTIVE_ADDRESS_WIDTH 36
     277#if BOS(DARWIN)
     278#define BOS_EFFECTIVE_ADDRESS_WIDTH (bmalloc::getMSBSetConstexpr(MACH_VM_MAX_ADDRESS) + 1)
    279279#else
    280280/* We strongly assume that effective address width is <= 48 in 64bit architectures (e.g. NaN boxing). */
  • trunk/Source/bmalloc/bmalloc/Gigacage.h

    r263316 r279028  
    11/*
    2  * Copyright (C) 2017-2020 Apple Inc. All rights reserved.
     2 * Copyright (C) 2017-2021 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
    … …  
    2626#pragma once
    2727
     28#include "Algorithm.h"
    2829#include "BAssert.h"
    2930#include "BExport.h"
    … …  
    3536#include <cstddef>
    3637#include <inttypes.h>
     38
     39#if BOS(DARWIN)
     40#include <mach/vm_param.h>
     41#endif
    3742
    3843#if ((BOS(DARWIN) || BOS(LINUX)) && \
    … …  
    6267#if GIGACAGE_ENABLED
    6368
    64 #if BOS_EFFECTIVE_ADDRESS_WIDTH < 48
    65 constexpr size_t primitiveGigacageSize = 2 * bmalloc::Sizes::GB;
    66 constexpr size_t jsValueGigacageSize = 2 * bmalloc::Sizes::GB;
    67 constexpr size_t maximumCageSizeReductionForSlide = bmalloc::Sizes::GB / 4;
    68 #else
    69 constexpr size_t primitiveGigacageSize = 32 * bmalloc::Sizes::GB;
    70 constexpr size_t jsValueGigacageSize = 16 * bmalloc::Sizes::GB;
    71 constexpr size_t maximumCageSizeReductionForSlide = 4 * bmalloc::Sizes::GB;
    72 #endif
     69constexpr bool useLargeGigacage = BOS_EFFECTIVE_ADDRESS_WIDTH > 36;
     70constexpr size_t primitiveGigacageSize = (useLargeGigacage ? 32 : 2) * bmalloc::Sizes::GB;
     71constexpr size_t jsValueGigacageSize = (useLargeGigacage ? 16 : 2) * bmalloc::Sizes::GB;
     72constexpr size_t maximumCageSizeReductionForSlide = useLargeGigacage ? 4 * bmalloc::Sizes::GB : bmalloc::Sizes::GB / 4;
     73
    7374
    7475// In Linux, if `vm.overcommit_memory = 2` is specified, mmap with large size can fail if it exceeds the size of RAM.
  • trunk/Source/bmalloc/bmalloc/ObjectTypeTable.h

    r261667 r279028  
    11/*
    2  * Copyright (C) 2020 Apple Inc. All rights reserved.
     2 * Copyright (C) 2020-2021 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
    … …  
    2626#pragma once
    2727
     28#include "Algorithm.h"
    2829#include "Mutex.h"
    2930#include "ObjectType.h"
    3031#include "Sizes.h"
     32
     33#if BOS(DARWIN)
     34#include <mach/vm_param.h>
     35#endif
    3136
    3237namespace bmalloc {
  • trunk/Source/bmalloc/bmalloc/Packed.h

    r257301 r279028  
    11/*
    2  * Copyright (C) 2019-2020 Apple Inc. All rights reserved.
     2 * Copyright (C) 2019-2021 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
    … …  
    3030#include <array>
    3131
     32#if BOS(DARWIN)
     33#include <mach/vm_param.h>
     34#endif
     35
    3236namespace bmalloc {
    3337
  • trunk/Tools/ChangeLog

    r279027 r279028  
     12021-06-17  Mark Lam  <mark.lam@apple.com>
     2
     3        Define MacroAssemblerARM64E::numberOfPACBits based on OS_CONSTANT(EFFECTIVE_ADDRESS_WIDTH).
     4        https://bugs.webkit.org/show_bug.cgi?id=227147
     5        rdar://78785309
     6
     7        Reviewed by Saam Barati.
     8
     9        * TestWebKitAPI/Tests/WTF/Packed.cpp:
     10
    1112021-06-17  Fujii Hironori  <Hironori.Fujii@sony.com>
    212
  • trunk/Tools/TestWebKitAPI/Tests/WTF/Packed.cpp

    r264718 r279028  
    11/*
    2  * Copyright (C) 2019 Apple Inc. All rights reserved.
     2 * Copyright (C) 2019-2021 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
    … …  
    2828#include <wtf/Packed.h>
    2929#include <wtf/HashMap.h>
     30#include <wtf/MathExtras.h>
    3031#include <wtf/Vector.h>
     32
     33#if OS(DARWIN)
     34#include <mach/vm_param.h>
     35#endif
    3136
    3237namespace TestWebKitAPI {
Note: See TracChangeset for help on using the changeset viewer.