Skip to content

Commit

Permalink
[libpas] Drop Catalina support in libpas
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=244831

Reviewed by Mark Lam.

This change drops macOS Catalina support and we always use pthread_self_is_exiting_np.

* Source/bmalloc/libpas/src/libpas/pas_darwin_spi.h: Added.
* Source/bmalloc/libpas/src/libpas/pas_thread_local_cache.c:
(destructor):
* Source/bmalloc/libpas/src/libpas/pas_thread_local_cache.h:
(pas_thread_local_cache_try_get):
(pas_thread_local_cache_can_set):

Canonical link: https://commits.webkit.org/254211@main
  • Loading branch information
Constellation committed Sep 7, 2022
1 parent e310ded commit 677b453
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 22 deletions.
1 change: 1 addition & 0 deletions Source/bmalloc/CMakeLists.txt
Expand Up @@ -407,6 +407,7 @@ set(bmalloc_PUBLIC_HEADERS
libpas/src/libpas/pas_config.h
libpas/src/libpas/pas_config_prefix.h
libpas/src/libpas/pas_create_basic_heap_page_caches_with_reserved_memory.h
libpas/src/libpas/pas_darwin_spi.h
libpas/src/libpas/pas_deallocate.h
libpas/src/libpas/pas_deallocation_mode.h
libpas/src/libpas/pas_deallocator.h
Expand Down
4 changes: 4 additions & 0 deletions Source/bmalloc/bmalloc.xcodeproj/project.pbxproj
Expand Up @@ -650,6 +650,7 @@
DE8B13B321CC5D9F00A63FCD /* BVMTags.h in Headers */ = {isa = PBXBuildFile; fileRef = DE8B13B221CC5D9F00A63FCD /* BVMTags.h */; settings = {ATTRIBUTES = (Private, ); }; };
E31E74802238CA5C005D084A /* StaticPerProcess.h in Headers */ = {isa = PBXBuildFile; fileRef = E31E747F2238CA5B005D084A /* StaticPerProcess.h */; settings = {ATTRIBUTES = (Private, ); }; };
E328D84D23CEB38900545B18 /* Packed.h in Headers */ = {isa = PBXBuildFile; fileRef = E328D84C23CEB38900545B18 /* Packed.h */; settings = {ATTRIBUTES = (Private, ); }; };
E32EBB1F28C72456009E5EB5 /* pas_darwin_spi.h in Headers */ = {isa = PBXBuildFile; fileRef = E32EBB1E28C72456009E5EB5 /* pas_darwin_spi.h */; settings = {ATTRIBUTES = (Private, ); }; };
E35B7BCA27ADB44E00C3498F /* pas_thread_suspend_lock.h in Headers */ = {isa = PBXBuildFile; fileRef = E35B7BC827ADB44E00C3498F /* pas_thread_suspend_lock.h */; settings = {ATTRIBUTES = (Private, ); }; };
E35B7BCB27ADB44E00C3498F /* pas_thread_suspend_lock.c in Sources */ = {isa = PBXBuildFile; fileRef = E35B7BC927ADB44E00C3498F /* pas_thread_suspend_lock.c */; };
E378A9DF246B68720029C2BB /* ObjectTypeTable.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E378A9DE246B686A0029C2BB /* ObjectTypeTable.cpp */; };
Expand Down Expand Up @@ -1321,6 +1322,7 @@
DE8B13B221CC5D9F00A63FCD /* BVMTags.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = BVMTags.h; path = bmalloc/BVMTags.h; sourceTree = "<group>"; };
E31E747F2238CA5B005D084A /* StaticPerProcess.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = StaticPerProcess.h; path = bmalloc/StaticPerProcess.h; sourceTree = "<group>"; };
E328D84C23CEB38900545B18 /* Packed.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Packed.h; path = bmalloc/Packed.h; sourceTree = "<group>"; };
E32EBB1E28C72456009E5EB5 /* pas_darwin_spi.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = pas_darwin_spi.h; path = libpas/src/libpas/pas_darwin_spi.h; sourceTree = "<group>"; };
E35B7BC827ADB44E00C3498F /* pas_thread_suspend_lock.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = pas_thread_suspend_lock.h; path = libpas/src/libpas/pas_thread_suspend_lock.h; sourceTree = "<group>"; };
E35B7BC927ADB44E00C3498F /* pas_thread_suspend_lock.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = pas_thread_suspend_lock.c; path = libpas/src/libpas/pas_thread_suspend_lock.c; sourceTree = "<group>"; };
E378A9DD246B686A0029C2BB /* ObjectTypeTable.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = ObjectTypeTable.h; path = bmalloc/ObjectTypeTable.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1592,6 +1594,7 @@
0FC409A82451496200876DA0 /* pas_config_prefix.h */,
0FC409A52451496200876DA0 /* pas_create_basic_heap_page_caches_with_reserved_memory.c */,
0FC4096F2451495E00876DA0 /* pas_create_basic_heap_page_caches_with_reserved_memory.h */,
E32EBB1E28C72456009E5EB5 /* pas_darwin_spi.h */,
0FC409982451496100876DA0 /* pas_deallocate.c */,
0FC4099B2451496100876DA0 /* pas_deallocate.h */,
0F5FE7DA25B6210D001859FC /* pas_deallocation_mode.h */,
Expand Down Expand Up @@ -2331,6 +2334,7 @@
0FC40A0E2451496400876DA0 /* pas_config.h in Headers */,
0FC409FE2451496400876DA0 /* pas_config_prefix.h in Headers */,
0FC409C52451496400876DA0 /* pas_create_basic_heap_page_caches_with_reserved_memory.h in Headers */,
E32EBB1F28C72456009E5EB5 /* pas_darwin_spi.h in Headers */,
0FC409F12451496400876DA0 /* pas_deallocate.h in Headers */,
0F5FE7EF25B6210D001859FC /* pas_deallocation_mode.h in Headers */,
0FC409F92451496400876DA0 /* pas_deallocator.h in Headers */,
Expand Down
4 changes: 4 additions & 0 deletions Source/bmalloc/libpas/libpas.xcodeproj/project.pbxproj
Expand Up @@ -585,6 +585,7 @@
2CB9B15B278F85EE003A8C1B /* pas_lenient_compact_ptr_inlines.h in Headers */ = {isa = PBXBuildFile; fileRef = 2CB9B157278F85EE003A8C1B /* pas_lenient_compact_ptr_inlines.h */; };
2CB9B15D278F861B003A8C1B /* LotsOfHeapsAndThreads.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2CB9B15C278F861B003A8C1B /* LotsOfHeapsAndThreads.cpp */; };
2CE2AE35275A953E00D02BBC /* BitfitTests.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2CE2AE34275A953E00D02BBC /* BitfitTests.cpp */; };
E3AA9B8328C724D8005DF9D6 /* pas_darwin_spi.h in Headers */ = {isa = PBXBuildFile; fileRef = E3AA9B8228C724D8005DF9D6 /* pas_darwin_spi.h */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -1291,6 +1292,7 @@
2CB9B157278F85EE003A8C1B /* pas_lenient_compact_ptr_inlines.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = pas_lenient_compact_ptr_inlines.h; sourceTree = "<group>"; };
2CB9B15C278F861B003A8C1B /* LotsOfHeapsAndThreads.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = LotsOfHeapsAndThreads.cpp; sourceTree = "<group>"; };
2CE2AE34275A953E00D02BBC /* BitfitTests.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = BitfitTests.cpp; sourceTree = "<group>"; };
E3AA9B8228C724D8005DF9D6 /* pas_darwin_spi.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = pas_darwin_spi.h; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -1586,6 +1588,7 @@
0F85EFD522E2BEC7003A362B /* pas_config_prefix.h */,
0F329A2623F1D63500A133C4 /* pas_create_basic_heap_page_caches_with_reserved_memory.c */,
0F329A2523F1D63500A133C4 /* pas_create_basic_heap_page_caches_with_reserved_memory.h */,
E3AA9B8228C724D8005DF9D6 /* pas_darwin_spi.h */,
0FE7EE5F229E14FA004F4166 /* pas_deallocate.c */,
0FE7EE5E229E14FA004F4166 /* pas_deallocate.h */,
0FFFD514256B0FBC001EB94C /* pas_deallocation_mode.h */,
Expand Down Expand Up @@ -2145,6 +2148,7 @@
0FE7EE0A22960142004F4166 /* pas_config.h in Headers */,
0F85EFDA22E2BEC7003A362B /* pas_config_prefix.h in Headers */,
0F329A2B23F1D63600A133C4 /* pas_create_basic_heap_page_caches_with_reserved_memory.h in Headers */,
E3AA9B8328C724D8005DF9D6 /* pas_darwin_spi.h in Headers */,
0FE7EE66229E14FA004F4166 /* pas_deallocate.h in Headers */,
0FFFD515256B0FBD001EB94C /* pas_deallocation_mode.h in Headers */,
0FE7EE0B22960142004F4166 /* pas_deallocator.h in Headers */,
Expand Down
46 changes: 46 additions & 0 deletions Source/bmalloc/libpas/src/libpas/pas_darwin_spi.h
@@ -0,0 +1,46 @@
/*
* Copyright (c) 2022 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.
*/

#ifndef PAS_DARWIN_SPI_H
#define PAS_DARWIN_SPI_H

#include "pas_utils.h"
#include <pthread.h>

#if PAS_OS(DARWIN)
#if defined(__has_include) && __has_include(<pthread/private.h>)
PAS_BEGIN_EXTERN_C;
#include <pthread/private.h>
PAS_END_EXTERN_C;
#define PAS_HAVE_PTHREAD_PRIVATE 1
#else
PAS_BEGIN_EXTERN_C;
int pthread_self_is_exiting_np(void);
PAS_END_EXTERN_C;
#define PAS_HAVE_PTHREAD_PRIVATE 0
#endif
#endif

#endif /* PAS_DARWIN_SPI_H */
2 changes: 1 addition & 1 deletion Source/bmalloc/libpas/src/libpas/pas_thread_local_cache.c
Expand Up @@ -141,7 +141,7 @@ static void destructor(void* arg)
if (verbose)
pas_log("[%d] Destructor call for TLS %p\n", getpid(), thread_local_cache);

#ifndef PAS_THREAD_LOCAL_CACHE_CAN_DETECT_THREAD_EXIT
#if !PAS_OS(DARWIN)
/* If pthread_self_is_exiting_np does not exist, we set PAS_THREAD_LOCAL_CACHE_DESTROYED in the TLS so that
subsequent calls of pas_thread_local_cache_try_get() can detect whether TLS is destroyed. Since
PAS_THREAD_LOCAL_CACHE_DESTROYED is a non-null value, pthread will call this destructor again (up to
Expand Down
24 changes: 3 additions & 21 deletions Source/bmalloc/libpas/src/libpas/pas_thread_local_cache.h
Expand Up @@ -28,6 +28,7 @@

#include "pas_allocator_index.h"
#include "pas_allocator_scavenge_action.h"
#include "pas_darwin_spi.h"
#include "pas_deallocator_scavenge_action.h"
#include "pas_decommit_exclusion_range.h"
#include "pas_fast_tls.h"
Expand All @@ -38,27 +39,8 @@
#include "pas_utils.h"
#include <pthread.h>

#if defined(__has_include) && __has_include(<pthread/private.h>)
PAS_BEGIN_EXTERN_C;
#include <pthread/private.h>
PAS_END_EXTERN_C;
#define PAS_HAVE_PTHREAD_PRIVATE 1
#else
#define PAS_HAVE_PTHREAD_PRIVATE 0
#endif

#define PAS_THREAD_LOCAL_CACHE_DESTROYED 1

#if PAS_HAVE_PTHREAD_PRIVATE
#if (PAS_PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 110000) \
|| (PAS_PLATFORM(MACCATALYST) && __IPHONE_OS_VERSION_MIN_REQUIRED >= 140000) \
|| (PAS_PLATFORM(IOS) && PAS_PLATFORM(IOS_FAMILY_SIMULATOR) && __IPHONE_OS_VERSION_MIN_REQUIRED >= 140000) \
|| (PAS_PLATFORM(WATCHOS) && PAS_PLATFORM(IOS_FAMILY_SIMULATOR) && __WATCH_OS_VERSION_MIN_REQUIRED >= 70000) \
|| (PAS_PLATFORM(APPLETV) && PAS_PLATFORM(IOS_FAMILY_SIMULATOR) && __TV_OS_VERSION_MIN_REQUIRED >= 140000)
#define PAS_THREAD_LOCAL_CACHE_CAN_DETECT_THREAD_EXIT 1
#endif
#endif

PAS_BEGIN_EXTERN_C;

struct pas_magazine;
Expand Down Expand Up @@ -114,7 +96,7 @@ static PAS_ALWAYS_INLINE pas_thread_local_cache* pas_thread_local_cache_try_get_
static inline pas_thread_local_cache* pas_thread_local_cache_try_get(void)
{
pas_thread_local_cache* cache = pas_thread_local_cache_try_get_impl();
#ifndef PAS_THREAD_LOCAL_CACHE_CAN_DETECT_THREAD_EXIT
#if !PAS_OS(DARWIN)
if (((uintptr_t)cache) == PAS_THREAD_LOCAL_CACHE_DESTROYED)
return NULL;
#endif
Expand All @@ -123,7 +105,7 @@ static inline pas_thread_local_cache* pas_thread_local_cache_try_get(void)

static inline bool pas_thread_local_cache_can_set(void)
{
#ifdef PAS_THREAD_LOCAL_CACHE_CAN_DETECT_THREAD_EXIT
#if PAS_OS(DARWIN)
return !pthread_self_is_exiting_np();
#else
return ((uintptr_t)pas_thread_local_cache_try_get_impl()) != PAS_THREAD_LOCAL_CACHE_DESTROYED;
Expand Down

0 comments on commit 677b453

Please sign in to comment.