views:

1130

answers:

2

I see this parameter in all kinds of places (forums, etc.) and the common answer it help highly concurrent servers. Still, I cannot find an official documentation from sun explaining what it does. Also, was it added in Java 6 or did it exist in Java 5?

(BTW, a good place for many hotspot VM parameters is this page)

Update: Java 5 does not boot with this parameter.

+5  A: 

In order to optimise performance, the JVM uses a "pseudo memory barrier" in code to act as a fencing instruction when synchronizing across multiple processors. It is possible to revert back to a "true" memory barrier instruction, but this can have a noticeable (and bad) affect upon performance.

The use of -XX:+UseMembar causes the VM to revert back to true memory barrier instructions. This parameter was originally intended to exist temporarily as a verification mechanism of the new pseudo-barrier logic, but it turned out that the new pseudo-memory barrier code introduced some synchronization issues. I believe these are now fixed, but until they were, the acceptable way to get around these issues was to use the reinstated flag.

The bug was introduced in 1.5, and I believe the flag exists in 1.5 and 1.6.

I've google-fu'ed this from a variety of mailing lists and JVM bugs:

butterchicken
What I don't know (and would love to) is how the pseudo barrier code works...
butterchicken
Also see http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6822370 : on newer cpus and VMs with this bug you may have very odd synchronization issues (fixed in 6u18)
ankon
A: 

I don't agree with answer from butterchicken. This page http://www.md.pp.ru/~eu/jdk6options.html says that this flag causes memory barriers to be issued then thread changes it's state (from RUNNABLE to WAITING or to BLOCKED, for example).

kmatveev
I guess we need on the JVM developers from Sun o respond ...
David Rabinowitz