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

Initializing volatile fields to default values should be optimized

    XMLWordPrintable

    Details

      Description

      This is a compiler-side follow-up for JDK-6736490.

      class A {
          volatile int x;
      }

      class B {
          volatile int x = 0;
      }

      These two classes appear different, but they have the same semantics in both single-threaded and multi-threaded cases:
       http://cs.oswego.edu/pipermail/concurrency-interest/2015-December/014767.html

      However, class B would be much slower to initialize, because the volatile field init would be present in constructor generated code. We may want to elide that volatile store to improve performance for all existing code.

      Benchmark, performance data, and generated code:
       http://cr.openjdk.java.net/~shade/8145948/InitStores.java
       http://cr.openjdk.java.net/~shade/8145948/benchmarks.jar

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              Unassigned Unassigned
              Reporter:
              shade Aleksey Shipilev
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Dates

                Created:
                Updated: