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

int8_t and int16_t return values of a method returns garbage on powerpc 32bit BE

XMLWordPrintable

      ADDITIONAL SYSTEM INFORMATION :
      >>>>>>>>>>>>>>> System properties BEGIN <<<<<<<<<<<<<<<<<<<<<<<
      java.specification.version = 23
      sun.jnu.encoding = ANSI_X3.4-1968
      java.class.path = /home/debian/mp-jnhw/de.ibapl.jnhw.libloader/target/test-classes:/home/debian/.m2/repository/org/junit/jupiter/junit-jupiter-api/5.11.4/junit-jupiter-api-5.11.4.jar:/home/debian/.m2/repository/org/opentest4j/opentest4j/1.3.0/opentest4j-1.3.0.jar:/home/debian/.m2/repository/org/junit/platform/junit-platform-commons/1.11.4/junit-platform-commons-1.11.4.jar:/home/debian/.m2/repository/org/apiguardian/apiguardian-api/1.1.2/apiguardian-api-1.1.2.jar:/home/debian/.m2/repository/org/junit/jupiter/junit-jupiter-engine/5.11.4/junit-jupiter-engine-5.11.4.jar:/home/debian/.m2/repository/org/junit/platform/junit-platform-engine/1.11.4/junit-platform-engine-1.11.4.jar:
      java.vm.vendor = Debian
      sun.arch.data.model = 32
      java.vendor.url = https://tracker.debian.org/openjdk-23
      java.vm.specification.version = 23
      os.name = Linux
      sun.java.launcher = SUN_STANDARD
      user.country = US
      sun.boot.library.path = /usr/lib/jvm/java-23-openjdk-powerpc/lib
      sun.java.command = org.apache.maven.surefire.booter.ForkedBooter /home/debian/mp-jnhw/de.ibapl.jnhw.libloader/target/surefire 2025-03-20T08-37-56_397-jvmRun1 surefire-20250320083801812_1tmp surefire_0-20250320083801812_2tmp
      jdk.debug = release
      surefire.test.class.path = /home/debian/mp-jnhw/de.ibapl.jnhw.libloader/target/test-classes:/home/debian/.m2/repository/org/junit/jupiter/junit-jupiter-api/5.11.4/junit-jupiter-api-5.11.4.jar:/home/debian/.m2/repository/org/opentest4j/opentest4j/1.3.0/opentest4j-1.3.0.jar:/home/debian/.m2/repository/org/junit/platform/junit-platform-commons/1.11.4/junit-platform-commons-1.11.4.jar:/home/debian/.m2/repository/org/apiguardian/apiguardian-api/1.1.2/apiguardian-api-1.1.2.jar:/home/debian/.m2/repository/org/junit/jupiter/junit-jupiter-engine/5.11.4/junit-jupiter-engine-5.11.4.jar:/home/debian/.m2/repository/org/junit/platform/junit-platform-engine/1.11.4/junit-platform-engine-1.11.4.jar:
      sun.cpu.endian = big
      user.home = /home/debian
      user.language = en
      java.specification.vendor = Oracle Corporation
      jdk.module.path = /home/debian/mp-jnhw/de.ibapl.jnhw.libloader/target/classes
      java.version.date = 2025-01-21
      java.home = /usr/lib/jvm/java-23-openjdk-powerpc
      file.separator = /
      basedir = /home/debian/mp-jnhw/de.ibapl.jnhw.libloader
      line.separator =

      java.vm.specification.vendor = Oracle Corporation
      java.specification.name = Java Platform API Specification
      surefire.real.class.path = /home/debian/.m2/repository/org/apache/maven/surefire/surefire-booter/3.5.2/surefire-booter-3.5.2.jar:/home/debian/.m2/repository/org/apache/maven/surefire/surefire-api/3.5.2/surefire-api-3.5.2.jar:/home/debian/.m2/repository/org/apache/maven/surefire/surefire-extensions-spi/3.5.2/surefire-extensions-spi-3.5.2.jar:/home/debian/.m2/repository/org/apache/maven/surefire/surefire-shared-utils/3.5.2/surefire-shared-utils-3.5.2.jar:/home/debian/.m2/repository/org/apache/maven/surefire/surefire-logger-api/3.5.2/surefire-logger-api-3.5.2.jar:/home/debian/mp-jnhw/de.ibapl.jnhw.libloader/target/test-classes:/home/debian/.m2/repository/org/junit/jupiter/junit-jupiter-api/5.11.4/junit-jupiter-api-5.11.4.jar:/home/debian/.m2/repository/org/opentest4j/opentest4j/1.3.0/opentest4j-1.3.0.jar:/home/debian/.m2/repository/org/junit/platform/junit-platform-commons/1.11.4/junit-platform-commons-1.11.4.jar:/home/debian/.m2/repository/org/apiguardian/apiguardian-api/1.1.2/apiguardian-api-1.1.2.jar:/home/debian/.m2/repository/org/junit/jupiter/junit-jupiter-engine/5.11.4/junit-jupiter-engine-5.11.4.jar:/home/debian/.m2/repository/org/junit/platform/junit-platform-engine/1.11.4/junit-platform-engine-1.11.4.jar:/home/debian/.m2/repository/org/apache/maven/surefire/surefire-junit-platform/3.5.2/surefire-junit-platform-3.5.2.jar:/home/debian/.m2/repository/org/apache/maven/surefire/common-java5/3.5.2/common-java5-3.5.2.jar:/home/debian/.m2/repository/org/junit/platform/junit-platform-launcher/1.11.4/junit-platform-launcher-1.11.4.jar
      java.runtime.version = 23.0.2+7-Debian-1
      user.name = debian
      stdout.encoding = ANSI_X3.4-1968
      path.separator = :
      os.version = 6.12.15-powerpc-smp
      java.runtime.name = OpenJDK Runtime Environment
      file.encoding = UTF-8
      java.vm.name = OpenJDK Zero VM
      localRepository = /home/debian/.m2/repository
      java.vendor.url.bug = https://bugs.debian.org/openjdk-23
      java.io.tmpdir = /tmp
      java.version = 23.0.2
      user.dir = /home/debian/mp-jnhw/de.ibapl.jnhw.libloader
      os.arch = ppc
      java.vm.specification.name = Java Virtual Machine Specification
      native.encoding = ANSI_X3.4-1968
      java.library.path = /usr/java/packages/lib:/usr/lib/powerpc-linux-gnu/jni:/lib/powerpc-linux-gnu:/usr/lib/powerpc-linux-gnu:/usr/lib/jni:/lib:/usr/lib
      java.vm.info = interpreted mode
      stderr.encoding = ANSI_X3.4-1968
      java.vendor = Debian
      java.vm.version = 23.0.2+7-Debian-1
      sun.io.unicode.encoding = UnicodeBig
      java.class.version = 67.0

      >>>>>>>>>>>>>>> System properties END <<<<<<<<<<<<<<<<<<<<<<<


      A DESCRIPTION OF THE PROBLEM :
      returning int8_t or int16_t returns garbage whereas int32_t and int64_t returns the expected value.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      compile native part extracted from testcase comment in a native lib and run testcases with correct native lib name on powerpc 32bit Big Endian

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      all tests pass
      ACTUAL -
      int8_t and int16_t tests fail int32_t test passes

      ---------- BEGIN SOURCE ----------
      import java.lang.foreign.Arena;
      import java.lang.foreign.FunctionDescriptor;
      import java.lang.foreign.Linker;
      import java.lang.foreign.MemorySegment;
      import java.lang.foreign.SymbolLookup;
      import java.lang.foreign.ValueLayout;
      import java.lang.invoke.MethodHandle;
      import static org.junit.jupiter.api.Assertions.assertEquals;
      import org.junit.jupiter.params.ParameterizedTest;
      import org.junit.jupiter.params.provider.ValueSource;

      /*create and compile into a lib a c file with the following content:
      #include <stdint.h>

      #define JNHW_Integer_Test( datatype ) \
      datatype jnhw_ ## datatype ## _mem; \
      void jnhw_ ## datatype ## _set( datatype value ) { jnhw_ ## datatype ## _mem = value; } \
      datatype jnhw_ ## datatype ## _get() { return jnhw_ ## datatype ## _mem; }

      JNHW_Integer_Test( uint8_t )
      JNHW_Integer_Test( int8_t )
      JNHW_Integer_Test( uint16_t )
      JNHW_Integer_Test( int16_t )
      JNHW_Integer_Test( uint32_t )
      JNHW_Integer_Test( int32_t )
      JNHW_Integer_Test( uint64_t )
      JNHW_Integer_Test( int64_t )
       */
      /**
       *
       * @author aploese
       */
      public class Test_PPC {

          //Change this path to the correct value
          private String NATIVE_TEST_LIB_PATH = "/home/debian/mp-jnhw/de.ibapl.jnhw.common/src/test/resources/lib/powerpc-linux-gnu/libjnhw-common-test.so.4";

          @ParameterizedTest
          @ValueSource(bytes = {
              (byte) 0x01,
              (byte) 0x8f,
              (byte) 0x00,
              (byte) 0xf0,
              (byte) 0xff})
          public void testInt8_t(final byte value) throws Throwable {

              final Linker linker = Linker.nativeLinker();
              try (Arena arena = Arena.ofConfined()) {
                  final SymbolLookup sb = SymbolLookup.libraryLookup(NATIVE_TEST_LIB_PATH, arena);
                  MemorySegment msSet = sb.findOrThrow("jnhw_int8_t_set");
                  MethodHandle mhSet = linker.downcallHandle(msSet, FunctionDescriptor.ofVoid(ValueLayout.JAVA_BYTE));

                  mhSet.invokeExact(value);

                  MemorySegment msMem = sb.findOrThrow("jnhw_int8_t_mem").reinterpret(ValueLayout.JAVA_BYTE.byteSize(), arena, null);

                  assertEquals(value, msMem.get(ValueLayout.JAVA_BYTE, 0));

                  MemorySegment msGet = sb.findOrThrow("jnhw_int8_t_get");
                  MethodHandle mhGet = linker.downcallHandle(msGet, FunctionDescriptor.of(ValueLayout.JAVA_BYTE));

                  assertEquals(value, (byte) mhGet.invokeExact());
              }
          }

          @ParameterizedTest
          @ValueSource(shorts = {
              (short) 0x0001,
              (short) 0x8fff,
              (short) 0x0000,
              (short) 0xf000,
              (short) 0xffff})
          public void testInt16_t(final short value) throws Throwable {

              final Linker linker = Linker.nativeLinker();
              try (Arena arena = Arena.ofConfined()) {
                  final SymbolLookup sb = SymbolLookup.libraryLookup(NATIVE_TEST_LIB_PATH, arena);
                  MemorySegment msSet = sb.findOrThrow("jnhw_int16_t_set");
                  MethodHandle mhSet = linker.downcallHandle(msSet, FunctionDescriptor.ofVoid(ValueLayout.JAVA_SHORT));

                  mhSet.invokeExact(value);

                  MemorySegment msMem = sb.findOrThrow("jnhw_int16_t_mem").reinterpret(ValueLayout.JAVA_SHORT.byteSize(), arena, null);

                  assertEquals(value, msMem.get(ValueLayout.JAVA_SHORT, 0));

                  MemorySegment msGet = sb.findOrThrow("jnhw_int16_t_get");
                  MethodHandle mhGet = linker.downcallHandle(msGet, FunctionDescriptor.of(ValueLayout.JAVA_SHORT));

                  assertEquals(value, (short) mhGet.invokeExact());
              }
          }

          @ParameterizedTest
          @ValueSource(ints = {
              0x00000001,
              0x8fffffff,
              0x00000000,
              0xf0000000,
              0xffffffff})
          public void testInt32_t(final int value) throws Throwable {

              final Linker linker = Linker.nativeLinker();
              try (Arena arena = Arena.ofConfined()) {
                  final SymbolLookup sb = SymbolLookup.libraryLookup(NATIVE_TEST_LIB_PATH, arena);
                  MemorySegment msSet = sb.findOrThrow("jnhw_int32_t_set");
                  MethodHandle mhSet = linker.downcallHandle(msSet, FunctionDescriptor.ofVoid(ValueLayout.JAVA_INT));

                  mhSet.invokeExact(value);

                  MemorySegment msMem = sb.findOrThrow("jnhw_int32_t_mem").reinterpret(ValueLayout.JAVA_INT.byteSize(), arena, null);

                  assertEquals(value, msMem.get(ValueLayout.JAVA_INT, 0));

                  MemorySegment msGet = sb.findOrThrow("jnhw_int32_t_get");
                  MethodHandle mhGet = linker.downcallHandle(msGet, FunctionDescriptor.of(ValueLayout.JAVA_INT));

                  assertEquals(value, (int) mhGet.invokeExact());
              }
          }

      }

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

        1. Main.java
          3 kB
        2. mylib.c
          0.4 kB

            Unassigned Unassigned
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: