@@ -281,10 +281,39 @@ protected int getSpinAttempts(int parks) {
281
281
return (1 << parks ) - 1 ;
282
282
}
283
283
284
+ // see AbstractQueuedLongSynchronizer.reacquire(Node, long)
285
+ private void reacquire (Node node , long arg ) {
286
+ try {
287
+ acquire (node , arg );
288
+ } catch (Error | RuntimeException firstEx ) {
289
+ // While we currently do not emit an JFR events in this situation, mainly
290
+ // because the conditions under which this happens are such that it
291
+ // cannot be presumed to be possible to actually allocate an event, and
292
+ // using a preconstructed one would have limited value in serviceability.
293
+ // Having said that, the following place would be the more appropriate
294
+ // place to put such logic:
295
+ // emit JFR event
296
+
297
+ for (long nanos = 1L ;;) {
298
+ U .park (false , nanos ); // must use Unsafe park to sleep
299
+ if (nanos < 1L << 30 ) { // max about 1 second
300
+ nanos <<= 1 ;
301
+ }
302
+ try {
303
+ acquire (node , arg );
304
+ } catch (Error | RuntimeException ignored ) {
305
+ continue ;
306
+ }
307
+
308
+ throw firstEx ;
309
+ }
310
+ }
311
+ }
312
+
284
313
// see AbstractQueuedLongSynchronizer.acquire(Node, long, false, false, false, 0L)
285
314
@ SuppressWarnings ("all" )
286
315
@ BasedOnJDKFile ("https://github.com/openjdk/jdk/blob/jdk-24+24/src/hotspot/share/runtime/objectMonitor.cpp#L895-L930" )
287
- final int acquire (Node node , long arg ) {
316
+ private int acquire (Node node , long arg ) {
288
317
Thread current = Thread .currentThread ();
289
318
/* Spinning logic is SVM-specific. */
290
319
int parks = 0 ;
@@ -624,7 +653,7 @@ public void await(Object obj) throws InterruptedException {
624
653
node .clearStatus ();
625
654
// waiting is done, emit wait event
626
655
JavaMonitorWaitEvent .emit (startTicks , obj , node .notifierJfrTid , 0L , false );
627
- acquire (node , savedAcquisitions );
656
+ reacquire (node , savedAcquisitions );
628
657
if (interrupted ) {
629
658
if (cancelled ) {
630
659
unlinkCancelledWaiters (node );
@@ -665,7 +694,7 @@ public boolean await(Object obj, long time, TimeUnit unit) throws InterruptedExc
665
694
node .clearStatus ();
666
695
// waiting is done, emit wait event
667
696
JavaMonitorWaitEvent .emit (startTicks , obj , node .notifierJfrTid , time , cancelled );
668
- acquire (node , savedAcquisitions );
697
+ reacquire (node , savedAcquisitions );
669
698
if (cancelled ) {
670
699
unlinkCancelledWaiters (node );
671
700
if (interrupted ) {
0 commit comments