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

Revisit alignment of layout constants on 32-bit platforms

XMLWordPrintable

    • Icon: CSR CSR
    • Resolution: Approved
    • Icon: P3 P3
    • 21
    • core-libs
    • None
    • behavioral
    • minimal
    • Hide
      Code assuming that byte alignment of constants such as JAVA_LONG and JAVA_DOUBLE is same on all platform might fail. That said, this should not be a problem in practice because:

      * C types on 32-bit platforms are also 32-bit aligned
      * the maximum alignment constraints for heap segments on 32-bit platforms are also tweaked accordingly.

      So, this should truly only be a problem is 32-bit code is trying to store a truly 8-byte aligned value on a heap segment.
      Show
      Code assuming that byte alignment of constants such as JAVA_LONG and JAVA_DOUBLE is same on all platform might fail. That said, this should not be a problem in practice because: * C types on 32-bit platforms are also 32-bit aligned * the maximum alignment constraints for heap segments on 32-bit platforms are also tweaked accordingly. So, this should truly only be a problem is 32-bit code is trying to store a truly 8-byte aligned value on a heap segment.
    • Java API
    • SE

      Summary

      The layout constants ValueLayout.JAVA_LONG and ValueLayout.JAVA_DOUBLE assume 8-byte alignment even on 32-bit platform, which is incorrect.

      Problem

      All layout constants in ValueLayout assume an alignment that is the same as their size. This holds for constants such as ValueLayout.JAVA_LONG and ValueLayout.JAVA_DOUBLE, which assume 8-byte alignment. This assumption is incorrect on 32-bit platform, as long[]</code> and <code class="prettyprint" >double[] arrays can only guarantee that their elements will be 4-byte aligned.

      This also creates issues when using layouts such as JAVA_LONG and JAVA_DOUBLE to interact with the Linker on 32-bit platforms: C types in such platforms are typically only 4-byte aligned, which means the linker would detect an alignment mismatch.

      Solution

      The solution is to tweak the layout constants such as JAVA_LONG and JAVA_DOUBLE so that they honestly reflect whatever alignment constraint can be provided by a particular platform. A good way to specify these constants is to define their alignment to be the same as the size of the ADDRESS constant (as that is also platform-dependent).

      Specification

      A summary of the required changes is attached to this CSR (see 8308248_v1.zip). Links are also included below:

      Javadoc: https://cr.openjdk.org/~mcimadamore/jdk/8308248/8308248/v1/javadoc/java.base/module-summary.html

      Specdiff: https://cr.openjdk.org/~mcimadamore/jdk/8308248/8308248/v1/specdiff_out/overview-summary.html

            mcimadamore Maurizio Cimadamore
            mcimadamore Maurizio Cimadamore
            Paul Sandoz
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: