Does any JVM provide queuing blocking?

In Java Concurrency, in practice, authors write:

When blocked, it is considered that the loss stream (s) should be blocked. The JVM can implement a lock either by waiting in a queue (repeatedly trying to obtain a lock until it succeeds) or suspend a blocked thread through the operating system. more efficient depends on the relationship between the context switch overhead and time until a lock is available; Delayed waiting is preferred for short expectations, and suspension is preferred for long expectations. Some JVMs choose between two adaptive ones based on profiling data from past wait times, but most simply pause threads waiting for locks.

When I read this, I was very surprised. Are there any known JVMs that implement locking, either always waiting for rotation or waiting for rotation due to profiling results? It’s hard to believe yet.

+4
source share
2 answers

Here is the proof that JRockit can use spinlocks - http://forums.oracle.com/forums/thread.jspa?threadID=816625&tstart=494

And if you are looking for β€œrotation” in the JVM parameters listed here , you will see evidence of usage / support for spin-lock in Hotspot JVMs.

+4
source

What the authors wrote correctly makes sense. This is also true for Linux. The rationale for why spin locks are used is that most resources are protected for a fraction of a millisecond. Thus, to pause, pull the entire contents of the registers onto the stack and abandon the processor, this is too much overhead and not worth it. Thus, although it just rotates in a narrow set of instructions, sometimes just wasting time, it is still more efficient than replacing.

Given that with VM profiling, this ideally makes your processing more efficient. So is there a special case that you always want to pause? Or maybe always spin-wait?

+2
source

All Articles