What is Java's -XX:+UseMembar parameter

前端 未结 4 670
隐瞒了意图╮
隐瞒了意图╮ 2021-02-13 23:12

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 expla

4条回答
  •  北荒
    北荒 (楼主)
    2021-02-13 23:43

    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) effect 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:

    • http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6546278
    • The obligatory Wikipedia link to memory barriers (fencing instructions)
    • A classic post from Raymond Chen
    • SO question on fencing

提交回复
热议问题