-
-
Notifications
You must be signed in to change notification settings - Fork 40
fix: serialize extended-class allocate/register to prevent duplicate class names #421
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+131
−22
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| #ifndef UnfairLock_h | ||
| #define UnfairLock_h | ||
|
|
||
| #include <os/lock.h> | ||
|
|
||
| /** | ||
| BasicLockable wrapper over os_unfair_lock — the fastest blocking lock on | ||
| Darwin. Drive it with std::lock_guard<UnfairMutex>. | ||
|
|
||
| Prefer this over SpinLock for any critical section that can block (syscalls, | ||
| objc runtime calls, allocation) or that can see bursty contention: waiters | ||
| sleep in the kernel and donate their priority to the holder, while SpinLock | ||
| busy-waits in userspace, invisible to the scheduler. Benchmarked on an | ||
| M-series host: under an 8-thread burst on a short section os_unfair_lock is | ||
| ~30x faster than SpinLock at ~33x less CPU, and against a holder that sleeps | ||
| mid-section waiters cost ~100x less CPU. SpinLock stays marginally faster | ||
| (~0.2 ns/op) only for uncontended nanosecond-scale sections — its documented | ||
| niche (selector caching). | ||
|
|
||
| NATIVESCRIPT_UNFAIR_LOCK_ADAPTIVE_SPIN opts lock() into | ||
| os_unfair_lock_lock_with_options() with kernel-informed adaptive spinning — | ||
| the approach Firefox adopted for its nanosecond-hot allocator locks: | ||
| https://hacks.mozilla.org/2022/10/improving-firefox-responsiveness-on-macos/ | ||
|
|
||
| Experiments only, never ship it: | ||
| - PRIVATE API (os/lock_private.h); App Review flags the symbol. | ||
| - It only wins for nanosecond-scale sections at low contention with the | ||
| holder on-core (measured ~2x over plain os_unfair_lock at 2 threads). | ||
| Under bursty contention it degenerates to spinlock behavior (~30x slower, | ||
| ~30x more CPU at 8 threads), it is the worst option under QoS inversion, | ||
| and it changes nothing when the holder sleeps. | ||
| */ | ||
|
|
||
| #ifdef NATIVESCRIPT_UNFAIR_LOCK_ADAPTIVE_SPIN | ||
| extern "C" void os_unfair_lock_lock_with_options(os_unfair_lock_t lock, | ||
| uint32_t options); | ||
| // Values from os/lock_private.h (ADAPTIVE_SPIN requires iOS 13+). | ||
| #define NATIVESCRIPT_OS_UNFAIR_LOCK_DATA_SYNCHRONIZATION 0x00010000u | ||
| #define NATIVESCRIPT_OS_UNFAIR_LOCK_ADAPTIVE_SPIN 0x00040000u | ||
| #endif | ||
|
|
||
| struct UnfairMutex { | ||
| os_unfair_lock lock_ = OS_UNFAIR_LOCK_INIT; | ||
|
|
||
| inline void lock() noexcept { | ||
| #ifdef NATIVESCRIPT_UNFAIR_LOCK_ADAPTIVE_SPIN | ||
| os_unfair_lock_lock_with_options( | ||
| &lock_, NATIVESCRIPT_OS_UNFAIR_LOCK_DATA_SYNCHRONIZATION | | ||
| NATIVESCRIPT_OS_UNFAIR_LOCK_ADAPTIVE_SPIN); | ||
| #else | ||
| os_unfair_lock_lock(&lock_); | ||
| #endif | ||
| } | ||
|
|
||
| inline bool try_lock() noexcept { return os_unfair_lock_trylock(&lock_); } | ||
|
|
||
| inline void unlock() noexcept { os_unfair_lock_unlock(&lock_); } | ||
| }; | ||
|
|
||
| #endif /* UnfairLock_h */ |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🩺 Stability & Availability | 🟠 Major | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
Repository: NativeScript/ios
Length of output: 1521
🏁 Script executed:
Repository: NativeScript/ios
Length of output: 21637
🏁 Script executed:
Repository: NativeScript/ios
Length of output: 16303
🏁 Script executed:
Repository: NativeScript/ios
Length of output: 14908
Guard against
NullptrExceptioninGetExtendedClassbefore assertingextendedClass.The two assertions prevent a nil class when allocation fails, but
GetExtendedClasscan also throwNullptrException(isolate)directly; callers ofExtendCallbackneed to ensure that exception is handled before this guard is evaluated so the failure does not fall through to later allocation work.🤖 Prompt for AI Agents