Biased locking benchmark

classic Classic list List threaded Threaded
14 messages Options
Reply | Threaded
Open this post in threaded view
|

Biased locking benchmark

Dmitry Zaslavsky
HI, 
  I was trying to reproduce the benchmarks from the following article http://mechanical-sympathy.blogspot.com/2011/11/biased-locking-osr-and-benchmarking-fun.html 

On my current setup (haswell i7 laptop and idk 8) I see no difference between biased locking and no-biased locking.
In a single threaded case j.u.c. lock is always faster by about 20%

I am going to investigate more, but would some one know if JVM 8 disabled biased locking feature?
 

_______________________________________________
Concurrency-interest mailing list
[hidden email]
http://cs.oswego.edu/mailman/listinfo/concurrency-interest
Reply | Threaded
Open this post in threaded view
|

Re: Biased locking benchmark

David Holmes-6

Hi,

 

Generally biased-locking is enabled by default in 7, 8 and 9, but there can be architecture specific differences. Eg any platform only using the C++ interpreter doesn’t have biased-locking; aarch64 disables it by default.

 

David

 

From: [hidden email] [mailto:[hidden email]] On Behalf Of Dmitry Zaslavsky
Sent: Tuesday, November 17, 2015 11:44 AM
To: concurrency-interest
Subject: [concurrency-interest] Biased locking benchmark

 

HI, 

  I was trying to reproduce the benchmarks from the following article http://mechanical-sympathy.blogspot.com/2011/11/biased-locking-osr-and-benchmarking-fun.html 

 

On my current setup (haswell i7 laptop and idk 8) I see no difference between biased locking and no-biased locking.

In a single threaded case j.u.c. lock is always faster by about 20%

 

I am going to investigate more, but would some one know if JVM 8 disabled biased locking feature?

 


_______________________________________________
Concurrency-interest mailing list
[hidden email]
http://cs.oswego.edu/mailman/listinfo/concurrency-interest
Reply | Threaded
Open this post in threaded view
|

Re: Biased locking benchmark

Andrew Haley
In reply to this post by Dmitry Zaslavsky
Hi,

On 17/11/15 01:44, Dmitry Zaslavsky wrote:

>   I was trying to reproduce the benchmarks from the following
> article
> http://mechanical-sympathy.blogspot.com/2011/11/biased-locking-osr-and-benchmarking-fun.html
> <http://mechanical-sympathy.blogspot.com/2011/11/biased-locking-osr-and-benchmarking-fun.html>
>
> On my current setup (haswell i7 laptop and idk 8) I see no
> difference between biased locking and no-biased locking.
> In a single threaded case j.u.c. lock is always faster by about 20%

I'm not surprised.  It's true that biased locking doesn't necessarily
make sense on modern CPUs: it was invented in order to mitigate the
local latency of CAS, and CAS has been improved.

Andrew.
_______________________________________________
Concurrency-interest mailing list
[hidden email]
http://cs.oswego.edu/mailman/listinfo/concurrency-interest
Reply | Threaded
Open this post in threaded view
|

Re: Biased locking benchmark

Vitaly Davidovich

Whoops, replied just to Andrew mistakenly.

sent from my phone

On Nov 17, 2015 7:05 AM, "Vitaly Davidovich" <[hidden email]> wrote:

I'd say the only remaining valid use case for biased locking is when using synchronization heavy APIs that can be confined to a single thread.  Otherwise, turn it off unless one likes global safepoints :).

sent from my phone

On Nov 17, 2015 4:54 AM, "Andrew Haley" <[hidden email]> wrote:
Hi,

On 17/11/15 01:44, Dmitry Zaslavsky wrote:

>   I was trying to reproduce the benchmarks from the following
> article
> http://mechanical-sympathy.blogspot.com/2011/11/biased-locking-osr-and-benchmarking-fun.html
> <http://mechanical-sympathy.blogspot.com/2011/11/biased-locking-osr-and-benchmarking-fun.html>
>
> On my current setup (haswell i7 laptop and idk 8) I see no
> difference between biased locking and no-biased locking.
> In a single threaded case j.u.c. lock is always faster by about 20%

I'm not surprised.  It's true that biased locking doesn't necessarily
make sense on modern CPUs: it was invented in order to mitigate the
local latency of CAS, and CAS has been improved.

Andrew.
_______________________________________________
Concurrency-interest mailing list
[hidden email]
http://cs.oswego.edu/mailman/listinfo/concurrency-interest

_______________________________________________
Concurrency-interest mailing list
[hidden email]
http://cs.oswego.edu/mailman/listinfo/concurrency-interest
Reply | Threaded
Open this post in threaded view
|

Re: Biased locking benchmark

Dmitry Zaslavsky
In reply to this post by David Holmes-6
Thanks

Tried few more JVMs. Makes no diff.
Basically on haswell it seem like biased locks are off.
On SB they are on.


On Nov 16, 2015, at 9:06 PM, David Holmes <[hidden email]> wrote:

Hi,
 
Generally biased-locking is enabled by default in 7, 8 and 9, but there can be architecture specific differences. Eg any platform only using the C++ interpreter doesn’t have biased-locking; aarch64 disables it by default.
 
David
 
From: [hidden email] [[hidden email]] On Behalf Of Dmitry Zaslavsky
Sent: Tuesday, November 17, 2015 11:44 AM
To: concurrency-interest
Subject: [concurrency-interest] Biased locking benchmark
 
HI, 
  I was trying to reproduce the benchmarks from the following article http://mechanical-sympathy.blogspot.com/2011/11/biased-locking-osr-and-benchmarking-fun.html 
 
On my current setup (haswell i7 laptop and idk 8) I see no difference between biased locking and no-biased locking.
In a single threaded case j.u.c. lock is always faster by about 20%
 
I am going to investigate more, but would some one know if JVM 8 disabled biased locking feature?


_______________________________________________
Concurrency-interest mailing list
[hidden email]
http://cs.oswego.edu/mailman/listinfo/concurrency-interest
Reply | Threaded
Open this post in threaded view
|

Re: Biased locking benchmark

Vitaly Davidovich
Hotspot turns off biased locking if UseRTM is used (which haswell supports), but that option is disabled by default (AFAIK).  What does "java -XX:+PrintFlagsFinal -version | grep UseBiasedLocking" show on haswell?

On Tue, Nov 17, 2015 at 1:23 PM, Dmitry Zaslavsky <[hidden email]> wrote:
Thanks

Tried few more JVMs. Makes no diff.
Basically on haswell it seem like biased locks are off.
On SB they are on.


On Nov 16, 2015, at 9:06 PM, David Holmes <[hidden email]> wrote:

Hi,
 
Generally biased-locking is enabled by default in 7, 8 and 9, but there can be architecture specific differences. Eg any platform only using the C++ interpreter doesn’t have biased-locking; aarch64 disables it by default.
 
David
 
From: [hidden email] [[hidden email]] On Behalf Of Dmitry Zaslavsky
Sent: Tuesday, November 17, 2015 11:44 AM
To: concurrency-interest
Subject: [concurrency-interest] Biased locking benchmark
 
HI, 
  I was trying to reproduce the benchmarks from the following article http://mechanical-sympathy.blogspot.com/2011/11/biased-locking-osr-and-benchmarking-fun.html 
 
On my current setup (haswell i7 laptop and idk 8) I see no difference between biased locking and no-biased locking.
In a single threaded case j.u.c. lock is always faster by about 20%
 
I am going to investigate more, but would some one know if JVM 8 disabled biased locking feature?


_______________________________________________
Concurrency-interest mailing list
[hidden email]
http://cs.oswego.edu/mailman/listinfo/concurrency-interest



_______________________________________________
Concurrency-interest mailing list
[hidden email]
http://cs.oswego.edu/mailman/listinfo/concurrency-interest
Reply | Threaded
Open this post in threaded view
|

Re: Biased locking benchmark

Dmitry Zaslavsky
 intx BiasedLockingBulkRebiasThreshold          = 20                                  {product}
 intx BiasedLockingBulkRevokeThreshold          = 40                                  {product}
 intx BiasedLockingDecayTime                    = 25000                               {product}
 intx BiasedLockingStartupDelay                := 0               

java version "1.8.0_40"
Java(TM) SE Runtime Environment (build 1.8.0_40-b27)
Java HotSpot(TM) 64-Bit Server VM (build 25.40-b25, mixed mode)

On Nov 17, 2015, at 2:01 PM, Vitaly Davidovich <[hidden email]> wrote:

Hotspot turns off biased locking if UseRTM is used (which haswell supports), but that option is disabled by default (AFAIK).  What does "java -XX:+PrintFlagsFinal -version | grep UseBiasedLocking" show on haswell?

On Tue, Nov 17, 2015 at 1:23 PM, Dmitry Zaslavsky <[hidden email]> wrote:
Thanks

Tried few more JVMs. Makes no diff.
Basically on haswell it seem like biased locks are off.
On SB they are on.


On Nov 16, 2015, at 9:06 PM, David Holmes <[hidden email]> wrote:

Hi,
 
Generally biased-locking is enabled by default in 7, 8 and 9, but there can be architecture specific differences. Eg any platform only using the C++ interpreter doesn’t have biased-locking; aarch64 disables it by default.
 
David
 
From: [hidden email] [[hidden email]] On Behalf Of Dmitry Zaslavsky
Sent: Tuesday, November 17, 2015 11:44 AM
To: concurrency-interest
Subject: [concurrency-interest] Biased locking benchmark
 
HI, 
  I was trying to reproduce the benchmarks from the following article http://mechanical-sympathy.blogspot.com/2011/11/biased-locking-osr-and-benchmarking-fun.html 
 
On my current setup (haswell i7 laptop and idk 8) I see no difference between biased locking and no-biased locking.
In a single threaded case j.u.c. lock is always faster by about 20%
 
I am going to investigate more, but would some one know if JVM 8 disabled biased locking feature?


_______________________________________________
Concurrency-interest mailing list
[hidden email]
http://cs.oswego.edu/mailman/listinfo/concurrency-interest




_______________________________________________
Concurrency-interest mailing list
[hidden email]
http://cs.oswego.edu/mailman/listinfo/concurrency-interest
Reply | Threaded
Open this post in threaded view
|

Re: Biased locking benchmark

Vitaly Davidovich

Where's the main UseBiasedLocking flag?

sent from my phone

On Nov 17, 2015 2:23 PM, "Dmitry Zaslavsky" <[hidden email]> wrote:
 intx BiasedLockingBulkRebiasThreshold          = 20                                  {product}
 intx BiasedLockingBulkRevokeThreshold          = 40                                  {product}
 intx BiasedLockingDecayTime                    = 25000                               {product}
 intx BiasedLockingStartupDelay                := 0               

java version "1.8.0_40"
Java(TM) SE Runtime Environment (build 1.8.0_40-b27)
Java HotSpot(TM) 64-Bit Server VM (build 25.40-b25, mixed mode)

On Nov 17, 2015, at 2:01 PM, Vitaly Davidovich <[hidden email]> wrote:

Hotspot turns off biased locking if UseRTM is used (which haswell supports), but that option is disabled by default (AFAIK).  What does "java -XX:+PrintFlagsFinal -version | grep UseBiasedLocking" show on haswell?

On Tue, Nov 17, 2015 at 1:23 PM, Dmitry Zaslavsky <[hidden email]> wrote:
Thanks

Tried few more JVMs. Makes no diff.
Basically on haswell it seem like biased locks are off.
On SB they are on.


On Nov 16, 2015, at 9:06 PM, David Holmes <[hidden email]> wrote:

Hi,
 
Generally biased-locking is enabled by default in 7, 8 and 9, but there can be architecture specific differences. Eg any platform only using the C++ interpreter doesn’t have biased-locking; aarch64 disables it by default.
 
David
 
From: [hidden email] [[hidden email]] On Behalf Of Dmitry Zaslavsky
Sent: Tuesday, November 17, 2015 11:44 AM
To: concurrency-interest
Subject: [concurrency-interest] Biased locking benchmark
 
HI, 
  I was trying to reproduce the benchmarks from the following article http://mechanical-sympathy.blogspot.com/2011/11/biased-locking-osr-and-benchmarking-fun.html 
 
On my current setup (haswell i7 laptop and idk 8) I see no difference between biased locking and no-biased locking.
In a single threaded case j.u.c. lock is always faster by about 20%
 
I am going to investigate more, but would some one know if JVM 8 disabled biased locking feature?


_______________________________________________
Concurrency-interest mailing list
[hidden email]
http://cs.oswego.edu/mailman/listinfo/concurrency-interest




_______________________________________________
Concurrency-interest mailing list
[hidden email]
http://cs.oswego.edu/mailman/listinfo/concurrency-interest
Reply | Threaded
Open this post in threaded view
|

Re: Biased locking benchmark

Dmitry Zaslavsky
bool UseBiasedLocking                         := true

On Nov 17, 2015, at 2:25 PM, Vitaly Davidovich <[hidden email]> wrote:

UseBiasedLocking


_______________________________________________
Concurrency-interest mailing list
[hidden email]
http://cs.oswego.edu/mailman/listinfo/concurrency-interest
Reply | Threaded
Open this post in threaded view
|

Re: Biased locking benchmark

Vitaly Davidovich
Then it should be on.  Are you running the exact same benchmark as that blog post?

On Tue, Nov 17, 2015 at 3:32 PM, Dmitry Zaslavsky <[hidden email]> wrote:
bool UseBiasedLocking                         := true

On Nov 17, 2015, at 2:25 PM, Vitaly Davidovich <[hidden email]> wrote:

UseBiasedLocking



_______________________________________________
Concurrency-interest mailing list
[hidden email]
http://cs.oswego.edu/mailman/listinfo/concurrency-interest
Reply | Threaded
Open this post in threaded view
|

Re: Biased locking benchmark

Chris Vest
In reply to this post by Vitaly Davidovich
Only the most recent Haswell Xeon models support RTM, and its support is turned off by default in HotSpot, locked behind an experimental flag. 

Chris

On 17. nov. 2015, at 20.01, Vitaly Davidovich <[hidden email]> wrote:

Hotspot turns off biased locking if UseRTM is used (which haswell supports), but that option is disabled by default (AFAIK).  What does "java -XX:+PrintFlagsFinal -version | grep UseBiasedLocking" show on haswell?

On Tue, Nov 17, 2015 at 1:23 PM, Dmitry Zaslavsky <[hidden email]> wrote:
Thanks

Tried few more JVMs. Makes no diff.
Basically on haswell it seem like biased locks are off.
On SB they are on.


On Nov 16, 2015, at 9:06 PM, David Holmes <[hidden email]> wrote:

Hi,
 
Generally biased-locking is enabled by default in 7, 8 and 9, but there can be architecture specific differences. Eg any platform only using the C++ interpreter doesn’t have biased-locking; aarch64 disables it by default.
 
David
 
From: [hidden email] [[hidden email]] On Behalf Of Dmitry Zaslavsky
Sent: Tuesday, November 17, 2015 11:44 AM
To: concurrency-interest
Subject: [concurrency-interest] Biased locking benchmark
 
HI, 
  I was trying to reproduce the benchmarks from the following article http://mechanical-sympathy.blogspot.com/2011/11/biased-locking-osr-and-benchmarking-fun.html 
 
On my current setup (haswell i7 laptop and idk 8) I see no difference between biased locking and no-biased locking.
In a single threaded case j.u.c. lock is always faster by about 20%
 
I am going to investigate more, but would some one know if JVM 8 disabled biased locking feature?


_______________________________________________
Concurrency-interest mailing list
[hidden email]
http://cs.oswego.edu/mailman/listinfo/concurrency-interest


_______________________________________________
Concurrency-interest mailing list
[hidden email]
http://cs.oswego.edu/mailman/listinfo/concurrency-interest

_______________________________________________
Concurrency-interest mailing list
[hidden email]
http://cs.oswego.edu/mailman/listinfo/concurrency-interest
Reply | Threaded
Open this post in threaded view
|

Re: Biased locking benchmark

Dmitry Zaslavsky
In reply to this post by Vitaly Davidovich
Yes and I can repro the rough timings on my other machine 

Also I was just thinking I can't repro under Mac OS. Maybe that's the key. I'll try later on Haskell with Linux 

Sent from mobile device

On Nov 17, 2015, at 3:55 PM, Vitaly Davidovich <[hidden email]> wrote:

Then it should be on.  Are you running the exact same benchmark as that blog post?

On Tue, Nov 17, 2015 at 3:32 PM, Dmitry Zaslavsky <[hidden email]> wrote:
bool UseBiasedLocking                         := true

On Nov 17, 2015, at 2:25 PM, Vitaly Davidovich <[hidden email]> wrote:

UseBiasedLocking



_______________________________________________
Concurrency-interest mailing list
[hidden email]
http://cs.oswego.edu/mailman/listinfo/concurrency-interest
Reply | Threaded
Open this post in threaded view
|

Re: Biased locking benchmark

Aleksey Shipilev-2
In reply to this post by Dmitry Zaslavsky
On 11/17/2015 04:44 AM, Dmitry Zaslavsky wrote:
>   I was trying to reproduce the benchmarks from the following
> article http://mechanical-sympathy.blogspot.com/2011/11/biased-locking-osr-and-benchmarking-fun.html 
>
> On my current setup (haswell i7 laptop and idk 8) I see no difference
> between biased locking and no-biased locking.
> In a single threaded case j.u.c. lock is always faster by about 20%
>
> I am going to investigate more, but would some one know if JVM 8
> disabled biased locking feature?

Oracle/OpenJDK 8 has biased locking enabled on by default.

These benchmarking "deja vu"-s are coming strong, see e.g. two months
ago on this list (BTW, that result is the counter-example to the myth
that local CAS latency is so low these days that biased locking is not
needed anymore):
 http://cs.oswego.edu/pipermail/concurrency-interest/2015-September/014452.html

Aside: it is much more productive to get into the habit of quickly
analyzing the benchmarks, instead of speculating about what could and/or
could not happen in them. JMH's -prof perfasm was designed to aid this
kind of research, use it.

Thanks,
-Aleksey


_______________________________________________
Concurrency-interest mailing list
[hidden email]
http://cs.oswego.edu/mailman/listinfo/concurrency-interest

signature.asc (836 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Biased locking benchmark

Dmitry Zaslavsky
OK, I got to the bottom of this.
Slightly faulty test :) (Thanks to Aleksey for suggesting that) 
Thanks to Vitaly for suggesting dump of flags and my discovery of TraceBiasedLocking 

The bottom line is that this test warms up by running test few times before.
Each time creating a “new” Thread()…. On windows / linux the real thread gets re-used.
So the object which is static final never gets re-biased.
On Mac for whatever reason the new Thread doesn’t reuse previous os thread (or id used for biasing is computed differently) and this “lock” gets re-biased.
I modified the code to create a new “lock” object and can now repro the experiment.

So just to confirm what you guys already said, based locking is on by default and can easily make 10x difference.


On Nov 18, 2015, at 7:04 AM, Aleksey Shipilev <[hidden email]> wrote:

On 11/17/2015 04:44 AM, Dmitry Zaslavsky wrote:
 I was trying to reproduce the benchmarks from the following
article http://mechanical-sympathy.blogspot.com/2011/11/biased-locking-osr-and-benchmarking-fun.html

On my current setup (haswell i7 laptop and idk 8) I see no difference
between biased locking and no-biased locking.
In a single threaded case j.u.c. lock is always faster by about 20%

I am going to investigate more, but would some one know if JVM 8
disabled biased locking feature?

Oracle/OpenJDK 8 has biased locking enabled on by default.

These benchmarking "deja vu"-s are coming strong, see e.g. two months
ago on this list (BTW, that result is the counter-example to the myth
that local CAS latency is so low these days that biased locking is not
needed anymore):
http://cs.oswego.edu/pipermail/concurrency-interest/2015-September/014452.html

Aside: it is much more productive to get into the habit of quickly
analyzing the benchmarks, instead of speculating about what could and/or
could not happen in them. JMH's -prof perfasm was designed to aid this
kind of research, use it.

Thanks,
-Aleksey



_______________________________________________
Concurrency-interest mailing list
[hidden email]
http://cs.oswego.edu/mailman/listinfo/concurrency-interest