Changeset 255112 in webkit


Ignore:
Timestamp:
Jan 24, 2020, 5:35:58 PM (5 years ago)
Author:
mark.lam@apple.com
Message:

IntlObject's cached strings should be immortal and safe for concurrent access.
https://bugs.webkit.org/show_bug.cgi?id=206779
<rdar://problem/58831763>

Reviewed by Yusuke Suzuki.

JSTests:

  • stress/numberingSystemsForLocale-cached-strings-should-be-immortal-and-safe-for-concurrent-access.js: Added.

Source/JavaScriptCore:

In IntlObject's numberingSystemsForLocale(), we have a never destroyed
cachedNumberingSystems which is a singleton vector of Strings which are shared
multiple VMs. Hence, the strings in this vector should be a StaticStringImpl
so that it will be immortal, and can be access concurrently from multiple VMs
on different threads without any ref/deref'ing race issues.

  • runtime/IntlObject.cpp:

(JSC::numberingSystemsForLocale):

Source/WTF:

Add a factory for creating a dynamically allocated StaticStringImpl.

Note: StaticStringImpl is guaranteed to have the same shape as StringImpl.
The only difference is that s_refCountFlagIsStaticString is set on the refCount
for StaticStringImpl. Since the client will use the StaticStringImpl as a
StringImpl, we implement the factory by using StringImpl::createInternal() for
simplicity, and set the s_refCountFlagIsStaticString flag thereafter.

  • wtf/text/StringImpl.cpp:

(WTF::StringImpl::createStaticStringImpl):

  • wtf/text/StringImpl.h:
Location:
trunk
Files:
1 added
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/JSTests/ChangeLog

    r255110 r255112  
     12020-01-24  Mark Lam  <mark.lam@apple.com>
     2
     3        IntlObject's cached strings should be immortal and safe for concurrent access.
     4        https://bugs.webkit.org/show_bug.cgi?id=206779
     5        <rdar://problem/58831763>
     6
     7        Reviewed by Yusuke Suzuki.
     8
     9        * stress/numberingSystemsForLocale-cached-strings-should-be-immortal-and-safe-for-concurrent-access.js: Added.
     10
    1112020-01-24  Yusuke Suzuki  <ysuzuki@apple.com>
    212
  • trunk/Source/JavaScriptCore/ChangeLog

    r255088 r255112  
     12020-01-24  Mark Lam  <mark.lam@apple.com>
     2
     3        IntlObject's cached strings should be immortal and safe for concurrent access.
     4        https://bugs.webkit.org/show_bug.cgi?id=206779
     5        <rdar://problem/58831763>
     6
     7        Reviewed by Yusuke Suzuki.
     8
     9        In IntlObject's numberingSystemsForLocale(), we have a never destroyed
     10        cachedNumberingSystems which is a singleton vector of Strings which are shared
     11        multiple VMs.  Hence, the strings in this vector should be a StaticStringImpl
     12        so that it will be immortal, and can be access concurrently from multiple VMs
     13        on different threads without any ref/deref'ing race issues.
     14
     15        * runtime/IntlObject.cpp:
     16        (JSC::numberingSystemsForLocale):
     17
    1182020-01-24  Caio Lima  <ticaiolima@gmail.com>
    219
  • trunk/Source/JavaScriptCore/runtime/IntlObject.cpp

    r251882 r255112  
    22 * Copyright (C) 2015 Andy VanWagoner (andy@vanwagoner.family)
    33 * Copyright (C) 2015 Sukolsak Sakshuwong (sukolsak@gmail.com)
    4  * Copyright (C) 2016-2019 Apple Inc. All rights reserved.
     4 * Copyright (C) 2016-2020 Apple Inc. All rights reserved.
    55 *
    66 * Redistribution and use in source and binary forms, with or without
     
    892892    Vector<String>& availableNumberingSystems = cachedNumberingSystems.get();
    893893
    894     if (UNLIKELY(availableNumberingSystems.isEmpty())) {
    895         static Lock cachedNumberingSystemsMutex;
    896         std::lock_guard<Lock> lock(cachedNumberingSystemsMutex);
    897         if (availableNumberingSystems.isEmpty()) {
    898             UErrorCode status = U_ZERO_ERROR;
    899             UEnumeration* numberingSystemNames = unumsys_openAvailableNames(&status);
     894    static std::once_flag initializeOnce;
     895    std::call_once(initializeOnce, [&] {
     896        ASSERT(availableNumberingSystems.isEmpty());
     897        UErrorCode status = U_ZERO_ERROR;
     898        UEnumeration* numberingSystemNames = unumsys_openAvailableNames(&status);
     899        ASSERT(U_SUCCESS(status));
     900
     901        int32_t resultLength;
     902        // Numbering system names are always ASCII, so use char[].
     903        while (const char* result = uenum_next(numberingSystemNames, &resultLength, &status)) {
    900904            ASSERT(U_SUCCESS(status));
    901 
    902             int32_t resultLength;
    903             // Numbering system names are always ASCII, so use char[].
    904             while (const char* result = uenum_next(numberingSystemNames, &resultLength, &status)) {
    905                 ASSERT(U_SUCCESS(status));
    906                 auto numsys = unumsys_openByName(result, &status);
    907                 ASSERT(U_SUCCESS(status));
    908                 // Only support algorithmic if it is the default fot the locale, handled below.
    909                 if (!unumsys_isAlgorithmic(numsys))
    910                     availableNumberingSystems.append(String(result, resultLength));
    911                 unumsys_close(numsys);
    912             }
    913             uenum_close(numberingSystemNames);
    914         }
    915     }
     905            auto numsys = unumsys_openByName(result, &status);
     906            ASSERT(U_SUCCESS(status));
     907            // Only support algorithmic if it is the default fot the locale, handled below.
     908            if (!unumsys_isAlgorithmic(numsys))
     909                availableNumberingSystems.append(String(StringImpl::createStaticStringImpl(result, resultLength)));
     910            unumsys_close(numsys);
     911        }
     912        uenum_close(numberingSystemNames);
     913    });
    916914
    917915    UErrorCode status = U_ZERO_ERROR;
  • trunk/Source/WTF/ChangeLog

    r255087 r255112  
     12020-01-24  Mark Lam  <mark.lam@apple.com>
     2
     3        IntlObject's cached strings should be immortal and safe for concurrent access.
     4        https://bugs.webkit.org/show_bug.cgi?id=206779
     5        <rdar://problem/58831763>
     6
     7        Reviewed by Yusuke Suzuki.
     8
     9        Add a factory for creating a dynamically allocated StaticStringImpl.
     10
     11        Note: StaticStringImpl is guaranteed to have the same shape as StringImpl.
     12        The only difference is that s_refCountFlagIsStaticString is set on the refCount
     13        for StaticStringImpl.  Since the client will use the StaticStringImpl as a
     14        StringImpl, we implement the factory by using StringImpl::createInternal() for
     15        simplicity, and set the s_refCountFlagIsStaticString flag thereafter.
     16
     17        * wtf/text/StringImpl.cpp:
     18        (WTF::StringImpl::createStaticStringImpl):
     19        * wtf/text/StringImpl.h:
     20
    1212020-01-24  Keith Rollin  <krollin@apple.com>
    222
  • trunk/Source/WTF/wtf/text/StringImpl.cpp

    r253987 r255112  
    33 *           (C) 1999 Antti Koivisto (koivisto@kde.org)
    44 *           (C) 2001 Dirk Mueller ( mueller@kde.org )
    5  * Copyright (C) 2003-2018 Apple Inc. All rights reserved.
     5 * Copyright (C) 2003-2020 Apple Inc. All rights reserved.
    66 * Copyright (C) 2006 Andrew Wellington (proton@wiretapped.net)
    77 *
     
    280280{
    281281    return createInternal(characters, length);
     282}
     283
     284Ref<StringImpl> StringImpl::createStaticStringImpl(const char* characters, unsigned length)
     285{
     286    ASSERT(charactersAreAllASCII<LChar>(reinterpret_cast<const LChar*>(characters), length));
     287    Ref<StringImpl> result = createInternal(reinterpret_cast<const LChar*>(characters), length);
     288    result->m_refCount |= s_refCountFlagIsStaticString;
     289    return result;
    282290}
    283291
  • trunk/Source/WTF/wtf/text/StringImpl.h

    r254881 r255112  
    11/*
    22 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
    3  * Copyright (C) 2005-2019 Apple Inc. All rights reserved.
     3 * Copyright (C) 2005-2020 Apple Inc. All rights reserved.
    44 * Copyright (C) 2009 Google Inc. All rights reserved.
    55 *
     
    255255    WTF_EXPORT_PRIVATE static Ref<StringImpl> createUninitialized(unsigned length, UChar*&);
    256256    template<typename CharacterType> static RefPtr<StringImpl> tryCreateUninitialized(unsigned length, CharacterType*&);
     257
     258    WTF_EXPORT_PRIVATE static Ref<StringImpl> createStaticStringImpl(const char*, unsigned length);
    257259
    258260    // Reallocate the StringImpl. The originalString must be only owned by the Ref,
Note: See TracChangeset for help on using the changeset viewer.