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

acessing an int64_t in an struct which is aligned at 4

XMLWordPrintable

      ADDITIONAL SYSTEM INFORMATION :
      Debian i386

      A DESCRIPTION OF THE PROBLEM :
      having this structure:
      struct s_i8_i64 {
          int8_t _0_i8;
          int16_t _1_i16;
          int8_t _2_i8;
          int32_t _3_i32;
          int8_t _4_i8;
          int64_t _5_i64;
          int8_t _6_i8;
          int64_t _7_i64;
          int8_t _8_i8;
          int32_t _9_i32;
          int8_t _10_i8;
          int16_t _11_i16;
          int8_t _12_i8;
      };

      the starting offset is 28 on i386, so it is aligned at the 4 boundary.

      So accessing this field in memory I got:
      java.lang.IllegalArgumentException: Misaligned access at address: 1683619964
      at java.base/java.lang.invoke.VarHandleSegmentViewBase.newIllegalArgumentExceptionForMisalignedAccess(VarHandleSegmentViewBase.java:57)
      at java.base/java.lang.invoke.VarHandleSegmentAsLongs.offsetNoVMAlignCheck(VarHandleSegmentAsLongs.java:100)
      at java.base/java.lang.invoke.VarHandleSegmentAsLongs.set(VarHandleSegmentAsLongs.java:121)
      at java.base/java.lang.foreign.MemorySegment.set(MemorySegment.java:1383)



      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      access a memory address as JAVA_LONG with the alignment 4.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      No IllegalArgumentException thrown
      ACTUAL -
      IllegalArgumentException

      ---------- BEGIN SOURCE ----------
          @Test
          public void testInt64_tAt4() {
              MemorySegment mem = MemorySegment.allocateNative(16, 4, MemorySession.openImplicit());
              assertEquals(16, mem.byteSize());
              byte b = mem.get(ValueLayout.JAVA_BYTE, 0);
              System.out.println("b: " + b);
              long l = mem.get(ValueLayout.JAVA_LONG, 4);
              System.out.println("l: " + l);
          }

      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      none that I know of.

      FREQUENCY : always


            mchung Mandy Chung (Inactive)
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: