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

When storing MemoryAddress.ofLong(0x0000000080000000L), MemorySegment.get is not equal to MemorySegment.set because of the expanded sign

XMLWordPrintable

      ADDITIONAL SYSTEM INFORMATION :
      Debian i386 | armhf OpenJDK 19

      A DESCRIPTION OF THE PROBLEM :
      storing a MemoryAddress.ofLong(0x0000000080000000L) via MemorySegmen.set(ValueLayout.ADDRESS, offset, value) and retriving it via MemorySegmen.set(ValueLayout.ADDRESS, offset) both memory addresses are not equal because of the expanded sign in the retrieved value.
      Both memory addresses point to the same location one with 0x0000000080000000L and the other with 0xffffffff80000000L the upper 4 bytes are ignored ...

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      just run the source code provided

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      either both memory addresses have the value 0xffffffff80000000L or the upper half of the value is ignored on 32 bit pointer platforms.
      ACTUAL -
      test fails

      ---------- BEGIN SOURCE ----------
          @Test
          public void testGetAtIndex_32BitAddress() {
              try (MemorySession ms = MemorySession.openConfined()) {

                  MemorySegment pointerArray = MemorySegment.allocateNative(128, ms);
                  MemoryAddress expected = MemoryAddress.ofLong(0x0000000080000000L);

                  pointerArray.setAtIndex(ValueLayout.ADDRESS, 0, expected);

                  MemoryAddress actual = pointerArray.getAtIndex(ValueLayout.ADDRESS, 0);

                  Assertions.assertEquals(expected, actual);
              }
          }

          @Test
          public void testGet_32BitAddress() {
              try (MemorySession ms = MemorySession.openConfined()) {

                  MemorySegment pointerArray = MemorySegment.allocateNative(128, ms);
                  MemoryAddress expected = MemoryAddress.ofLong(0x0000000080000000L);

                  pointerArray.set(ValueLayout.ADDRESS, 0, expected);

                  MemoryAddress actual = pointerArray.get(ValueLayout.ADDRESS, 0);

                  Assertions.assertEquals(expected, actual);
              }
          }

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

      FREQUENCY : always


            pminborg Per-Ake Minborg
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: