Biased locking in java

后端 未结 4 2059
遥遥无期
遥遥无期 2020-12-13 09:34

I keep reading about how biased locking, using the flag -XX:+UseBiasedLocking, can improve the performance of un-contended synchronization. I couldn\'t find a r

4条回答
  •  余生分开走
    2020-12-13 09:37

    I've been wondering about biased locks myself.

    However it seems that java's biased locks are slower on intel's nehalem processors than normal locks, and presumably on the two generations of processors since nehalem. See http://mechanical-sympathy.blogspot.com/2011/11/java-lock-implementations.html and here http://www.azulsystems.com/blog/cliff/2011-11-16-a-short-conversation-on-biased-locking

    Also more information here https://blogs.oracle.com/dave/entry/biased_locking_in_hotspot

    I've been hoping that there is some relatively cheap way to revoke a biased lock on intel, but I'm beginning to believe that isn't possible. The articles I've seen on how it's done rely on either:

    1. using the os to stop the thread
    2. sending a signal, ie running code in the other thread
    3. having safe points that are guaranteed to run fairly often in the other thread and waiting for one to be executed (which is what java does).
    4. having similar safe points that are a call to a return - and the other thread MODIFIES THE CODE to a breakpoint...

提交回复
热议问题