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

AArch64: Float registers incorrectly restored in JNI call

    Details

    • Subcomponent:
    • Introduced In Version:
      9
    • Resolved In Build:
      b28
    • CPU:
      aarch64
    • OS:
      linux

      Backports

        Description

        JNI test case:

        JniStaticContextFloat.c
        #include <jni.h>
        #include <stdlib.h>

        #ifdef __cplusplus
        extern "C" {
        #endif

        JNIEXPORT jfloat JNICALL Java_JniStaticContextFloat_staticMethodFloat1(JNIEnv *env, jclass cl, jfloat j0, jfloat j1, jfloat j2, jfloat j3)
        {
            if (j0 != (float) (1) || j1 != (float) (2) || j2 != (float) (4) || j3 != (float)(8))
            {
                printf("JNI: %f %f %f %f\n", j0, j1, j2, j3);
                exit(1);
            }

            return 1;
        }

        JniStaticContextFloat.java
        public class JniStaticContextFloat {

            final static int Count = 1024;

            public static synchronized native float staticMethodFloat1(float j0, float j1, float j2, float j3);

            public static void main(String[] args) throws Exception {
                System.load("/home/yangfei/test/JNI/libJniStatic.so");

                for (int c = 0; c < Count; c++) {
                    Thread t = new Thread(new Runnable() {
                        public void run() {
                            float d = JniStaticContextFloat.staticMethodFloat1((float) (1), (float) (2), (float) (4), (float) (8));
                        }
                    });
                    t.start();
                }

                Thread.sleep(1000);

                System.out.println("PASS!");
            }

        }

        $gcc -I${JAVA_HOME}/include -I${JAVA_HOME}/include/linux -shared -fpic JniStaticContextFloat.c -o libJniStatic.so

        $javac JniStaticContextFloat.java

        $java JniStaticContextFloat

        The above testcase randomly print the following message:
        JNI: 8.000000 4.000000 2.000000 1.000000

        Patch contributed by guoge1@huawei.com:

        diff -r a25c48c0a1ab src/hotspot/cpu/aarch64/sharedRuntime_aarch64.cpp
        --- a/src/hotspot/cpu/aarch64/sharedRuntime_aarch64.cpp Mon Jul 16 15:09:19 2018 -0700
        +++ b/src/hotspot/cpu/aarch64/sharedRuntime_aarch64.cpp Thu Jul 19 15:14:08 2018 +0800
        @@ -1107,7 +1107,7 @@
             }
           }
           __ pop(x, sp);
        - for ( int i = first_arg ; i < arg_count ; i++ ) {
        + for ( int i = arg_count - 1 ; i >= first_arg ; i-- ) {
             if (args[i].first()->is_Register()) {
               ;
             } else if (args[i].first()->is_FloatRegister()) {

          Attachments

            Issue Links

              Activity

                People

                • Assignee:
                  fyang Fei Yang
                  Reporter:
                  fyang Fei Yang
                • Votes:
                  0 Vote for this issue
                  Watchers:
                  7 Start watching this issue

                  Dates

                  • Created:
                    Updated:
                    Resolved: