Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8057737

Avoid G1 write barriers on newly allocated objects


    • Type: Enhancement
    • Status: Resolved
    • Priority: P3
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 9
    • Component/s: hotspot
    • Subcomponent:
    • Resolved In Build:



        G1 requires pre and post barriers when writing references. They can under different circumstances be filtered to be avoided and the compiler is able to remove some of them and others are dynamically filtered during runtime to avoid doing the actual barrier.

        For newly allocated objects it should be possible to avoid the barrier if it can be proven the reference write is the first write to the object and no safe point exists between the allocation and the write itself.

        This pattern can for example be found in some objects where a reference is written to the object as part of the constructor, please look at the Node class in HashMap for a specific example.

        A small microbenchmark trying to mimic the Node class allocation and write shows that it is possible to prove the barrier is not required in this case and performance gets closer to what the parallel GC is able to achieve in this case. See attached images for a graphical comparison, the 3 fields version is most similar to the Node class which has three fields being written.


            Issue Links



                • Assignee:
                  sfriberg Staffan Friberg (Inactive)
                  sfriberg Staffan Friberg (Inactive)
                • Votes:
                  0 Vote for this issue
                  3 Start watching this issue


                  • Created: