Commit ea2a517
perf(core): Lazily allocate AutoClosableReentrantLock (JAVA-588) (#5643)
* perf(core): Lazily allocate AutoClosableReentrantLock (JAVA-588)
AutoClosableReentrantLock extended ReentrantLock, so every SDK object
holding one allocated a ReentrantLock (and its AbstractQueuedSynchronizer)
eagerly in its field initializer. A customer Perfetto trace showed ~81 such
allocations on the main thread during SentryAndroid.init, many for locks
that are never acquired during init.
Hold the ReentrantLock internally and create it lazily on first acquire(),
using an AtomicReferenceFieldUpdater CAS so creation stays atomic and
Loom-friendly (no synchronized, preserving #3715). Every call site uses
acquire() only, so dropping the ReentrantLock superclass touches no caller.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
* changelog
* perf(core): Harden lazy lock init and mark AutoClosableReentrantLock internal (JAVA-588)
Replace the unreachable candidate fallback after a failed CAS with an
explicit non-null check, so a broken invariant fails loudly instead of
handing two threads different locks. Mark the class @ApiStatus.Internal
and make the lazy-allocation test assert the lock field directly.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
* perf(core): Return the lock itself as the lifecycle token (JAVA-588)
Every acquire() allocated a fresh lifecycle token, which is per-use
garbage on every lock acquisition forever, not just at init. The token
was stateless apart from its lock reference, so AutoClosableReentrantLock
now implements ISentryLifecycleToken itself and acquire() returns this,
making the steady-state acquire/close path allocation-free. Semantics
are unchanged: try-with-resources closes once per acquire, so reentrant
acquires stay balanced, and unlocking without holding the lock still
throws IllegalMonitorStateException.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>1 parent 4414d9f commit ea2a517
4 files changed
Lines changed: 116 additions & 15 deletions
File tree
- sentry
- api
- src
- main/java/io/sentry/util
- test/java/io/sentry/util
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
| 24 | + | |
24 | 25 | | |
25 | 26 | | |
26 | 27 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7589 | 7589 | | |
7590 | 7590 | | |
7591 | 7591 | | |
7592 | | - | |
| 7592 | + | |
7593 | 7593 | | |
7594 | 7594 | | |
| 7595 | + | |
7595 | 7596 | | |
7596 | 7597 | | |
7597 | 7598 | | |
| |||
Lines changed: 55 additions & 14 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
| 4 | + | |
4 | 5 | | |
| 6 | + | |
5 | 7 | | |
| 8 | + | |
| 9 | + | |
6 | 10 | | |
7 | | - | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
8 | 27 | | |
9 | | - | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
10 | 33 | | |
11 | | - | |
12 | | - | |
13 | | - | |
14 | | - | |
| 34 | + | |
15 | 35 | | |
16 | | - | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
17 | 40 | | |
18 | | - | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
19 | 45 | | |
20 | | - | |
21 | | - | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
22 | 50 | | |
23 | | - | |
24 | | - | |
25 | | - | |
26 | | - | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
27 | 54 | | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
28 | 69 | | |
29 | 70 | | |
Lines changed: 58 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
3 | 6 | | |
| 7 | + | |
4 | 8 | | |
| 9 | + | |
5 | 10 | | |
6 | 11 | | |
7 | 12 | | |
| |||
11 | 16 | | |
12 | 17 | | |
13 | 18 | | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
14 | 72 | | |
0 commit comments