#11080 Backport testcase of JDK-8207838 compiler/floatingpoint/TestFloatSyncJNIArgs.java

Mon, 25 Nov 2019 15:36:48 +0800

author
huangjia
date
Mon, 25 Nov 2019 15:36:48 +0800
changeset 9758
122547cfa3c8
parent 9757
a9a6cc2af3e8
child 9759
8c71022cf5f3

#11080 Backport testcase of JDK-8207838 compiler/floatingpoint/TestFloatSyncJNIArgs.java
Reviewed-by: aoqi
Contributed-by: guoge1@huawei.com, huangjia

test/mips64/11080/TestFloatSyncJNIArgs.java file | annotate | diff | comparison | revisions
test/mips64/11080/libTestFloatSyncJNIArgs.c file | annotate | diff | comparison | revisions
test/mips64/11080/test.sh file | annotate | diff | comparison | revisions
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/test/mips64/11080/TestFloatSyncJNIArgs.java	Mon Nov 25 15:36:48 2019 +0800
     1.3 @@ -0,0 +1,103 @@
     1.4 +/*
     1.5 + * Copyright (c) 2015, 2019, SAP SE. All rights reserved.
     1.6 + * Copyright (c) 2018, 2019, Red Hat, Inc. All rights reserved.
     1.7 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.8 + *
     1.9 + * This code is free software; you can redistribute it and/or modify it
    1.10 + * under the terms of the GNU General Public License version 2 only, as
    1.11 + * published by the Free Software Foundation.
    1.12 + *
    1.13 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.14 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.15 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.16 + * version 2 for more details (a copy is included in the LICENSE file that
    1.17 + * accompanied this code).
    1.18 + *
    1.19 + * You should have received a copy of the GNU General Public License version
    1.20 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.21 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.22 + *
    1.23 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.24 + * or visit www.oracle.com if you need additional information or have any
    1.25 + * questions.
    1.26 + */
    1.27 +
    1.28 +public class TestFloatSyncJNIArgs {
    1.29 +    static {
    1.30 +        try {
    1.31 +            System.loadLibrary("TestFloatSyncJNIArgs");
    1.32 +        } catch (UnsatisfiedLinkError e) {
    1.33 +            System.out.println("could not load native lib: " + e);
    1.34 +        }
    1.35 +    }
    1.36 +
    1.37 +    private static final int numberOfThreads = 8;
    1.38 +
    1.39 +    static volatile Error testFailed = null;
    1.40 +
    1.41 +    public synchronized static native float combine15floats(
    1.42 +        float f1, float f2, float f3, float f4,
    1.43 +        float f5, float f6, float f7, float f8,
    1.44 +        float f9, float f10, float f11, float f12,
    1.45 +        float f13, float f14, float f15);
    1.46 +
    1.47 +    public synchronized static native double combine15doubles(
    1.48 +        double d1, double d2, double d3, double d4,
    1.49 +        double d5, double d6, double d7, double d8,
    1.50 +        double d9, double d10, double d11, double d12,
    1.51 +        double d13, double d14, double d15);
    1.52 +
    1.53 +    static void test() throws Exception {
    1.54 +        Thread[] threads = new Thread[numberOfThreads];
    1.55 +
    1.56 +        for (int i = 0; i < numberOfThreads; i++) {
    1.57 +            threads[i] = new Thread(() -> {
    1.58 +                for (int j = 0; j < 10000; j++) {
    1.59 +                    float f = combine15floats(1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f,
    1.60 +                                              9, 10, 11, 12, 13, 14, 15);
    1.61 +                    if (f != 81720.0f) {
    1.62 +                        testFailed = new Error("jni function didn't combine 15 float args properly: " + f);
    1.63 +                        throw testFailed;
    1.64 +                    }
    1.65 +                }
    1.66 +            });
    1.67 +        }
    1.68 +        for (int i = 0; i < numberOfThreads; i++) {
    1.69 +            threads[i].start();
    1.70 +        }
    1.71 +        for (int i = 0; i < numberOfThreads; i++) {
    1.72 +            threads[i].join();
    1.73 +        }
    1.74 +        if (testFailed != null) {
    1.75 +            throw testFailed;
    1.76 +        }
    1.77 +
    1.78 +        for (int i = 0; i < numberOfThreads; i++) {
    1.79 +            threads[i] = new Thread(() -> {
    1.80 +                for (int j = 0; j < 10000; j++) {
    1.81 +                    double d = combine15doubles(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0,
    1.82 +                                                9, 10, 11, 12, 13, 14, 15);
    1.83 +                    if (d != 81720.0) {
    1.84 +                        testFailed = new Error("jni function didn't combine 15 double args properly: " + d);
    1.85 +                        throw testFailed;
    1.86 +                    }
    1.87 +                }
    1.88 +            });
    1.89 +        }
    1.90 +        for (int i = 0; i < numberOfThreads; i++) {
    1.91 +            threads[i].start();
    1.92 +        }
    1.93 +        for (int i = 0; i < numberOfThreads; i++) {
    1.94 +            threads[i].join();
    1.95 +        }
    1.96 +        if (testFailed != null) {
    1.97 +            throw testFailed;
    1.98 +        }
    1.99 +    }
   1.100 +
   1.101 +    public static void main(String[] args) throws Exception {
   1.102 +        for (int i = 0; i < 200; ++i) {
   1.103 +            test();
   1.104 +        }
   1.105 +    }
   1.106 +}
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/test/mips64/11080/libTestFloatSyncJNIArgs.c	Mon Nov 25 15:36:48 2019 +0800
     2.3 @@ -0,0 +1,86 @@
     2.4 +/*
     2.5 + * Copyright (c) 2018, 2019, Red Hat, Inc. All rights reserved.
     2.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     2.7 + *
     2.8 + * This code is free software; you can redistribute it and/or modify it
     2.9 + * under the terms of the GNU General Public License version 2 only, as
    2.10 + * published by the Free Software Foundation.
    2.11 + *
    2.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    2.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    2.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    2.15 + * version 2 for more details (a copy is included in the LICENSE file that
    2.16 + * accompanied this code).
    2.17 + *
    2.18 + * You should have received a copy of the GNU General Public License version
    2.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    2.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    2.21 + *
    2.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    2.23 + * or visit www.oracle.com if you need additional information or have any
    2.24 + * questions.
    2.25 + */
    2.26 +
    2.27 +#include <jni.h>
    2.28 +
    2.29 +#ifdef __cplusplus
    2.30 +extern "C" {
    2.31 +#endif
    2.32 +
    2.33 +/* Fletcher checksum. This is a nonlinear function which detects both */
    2.34 +/* missing or otherwise incorrect arguments and arguments in the wrong */
    2.35 +/* order. */
    2.36 +static jfloat fcombine(jfloat f[], int len) {
    2.37 +  int i;
    2.38 +  jfloat sum = 0, sum_of_sums = 0;
    2.39 +  for (i = 0; i < len; i++) {
    2.40 +    sum += f[i];
    2.41 +    sum_of_sums += sum;
    2.42 +  }
    2.43 +  return sum + sum_of_sums * sum;
    2.44 +}
    2.45 +
    2.46 +static jdouble combine(jdouble f[], int len) {
    2.47 +  int i;
    2.48 +  double sum = 0, sum_of_sums = 0;
    2.49 +  for (i = 0; i < len; i++) {
    2.50 +    sum += f[i];
    2.51 +    sum_of_sums += sum;
    2.52 +  }
    2.53 +  return sum + sum_of_sums * sum;
    2.54 +}
    2.55 +
    2.56 +JNIEXPORT jfloat JNICALL Java_TestFloatSyncJNIArgs_combine15floats
    2.57 +  (JNIEnv *env, jclass cls,
    2.58 +   jfloat  f1, jfloat  f2, jfloat  f3, jfloat  f4,
    2.59 +   jfloat  f5, jfloat  f6, jfloat  f7, jfloat  f8,
    2.60 +   jfloat  f9, jfloat f10, jfloat f11, jfloat f12,
    2.61 +   jfloat f13, jfloat f14, jfloat f15) {
    2.62 +
    2.63 +  jfloat f[15];
    2.64 +  f[0] = f1; f[1] = f2; f[2] = f3; f[3] = f4; f[4] = f5;
    2.65 +  f[5] = f6; f[6] = f7; f[7] = f8; f[8] = f9; f[9] = f10;
    2.66 +  f[10] = f11; f[11] = f12; f[12] = f13; f[13] = f14; f[14] = f15;
    2.67 +
    2.68 +  return fcombine(f, sizeof f / sizeof f[0]);
    2.69 +}
    2.70 +
    2.71 +JNIEXPORT jdouble JNICALL Java_TestFloatSyncJNIArgs_combine15doubles
    2.72 +  (JNIEnv *env, jclass cls,
    2.73 +   jdouble  f1, jdouble  f2, jdouble  f3, jdouble  f4,
    2.74 +   jdouble  f5, jdouble  f6, jdouble  f7, jdouble  f8,
    2.75 +   jdouble  f9, jdouble f10, jdouble f11, jdouble f12,
    2.76 +   jdouble f13, jdouble f14, jdouble f15) {
    2.77 +
    2.78 +  jdouble f[15];
    2.79 +  f[0] = f1; f[1] = f2; f[2] = f3; f[3] = f4; f[4] = f5;
    2.80 +  f[5] = f6; f[6] = f7; f[7] = f8; f[8] = f9; f[9] = f10;
    2.81 +  f[10] = f11; f[11] = f12; f[12] = f13; f[13] = f14; f[14] = f15;
    2.82 +
    2.83 +  return combine(f, sizeof f / sizeof f[0]);
    2.84 +}
    2.85 +
    2.86 +
    2.87 +#ifdef __cplusplus
    2.88 +}
    2.89 +#endif
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/test/mips64/11080/test.sh	Mon Nov 25 15:36:48 2019 +0800
     3.3 @@ -0,0 +1,74 @@
     3.4 +#!/bin/bash
     3.5 +
     3.6 +#
     3.7 +#  Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved.
     3.8 +#  Copyright (c) 2019, Loongson Technology. All rights reserved.
     3.9 +#  DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    3.10 +#
    3.11 +#  This code is free software; you can redistribute it and/or modify it
    3.12 +#  under the terms of the GNU General Public License version 2 only, as
    3.13 +#  published by the Free Software Foundation.
    3.14 +#
    3.15 +#  This code is distributed in the hope that it will be useful, but WITHOUT
    3.16 +#  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    3.17 +#  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    3.18 +#  version 2 for more details (a copy is included in the LICENSE file that
    3.19 +#  accompanied this code).
    3.20 +#
    3.21 +#  You should have received a copy of the GNU General Public License version
    3.22 +#  2 along with this work; if not, write to the Free Software Foundation,
    3.23 +#  Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    3.24 +#
    3.25 +#  Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    3.26 +#  or visit www.oracle.com if you need additional information or have any
    3.27 +#  questions.
    3.28 +#
    3.29 +
    3.30 +##
    3.31 +## @test test.sh
    3.32 +## @bug 8207838
    3.33 +## @summary Regression test for passing float args to a synchronized jni function.
    3.34 +## @run shell test.sh
    3.35 +##
    3.36 +
    3.37 +if [ "${TESTSRC}" = "" ]
    3.38 +then
    3.39 +  TESTSRC=${PWD}
    3.40 +  echo "TESTSRC not set.  Using "${TESTSRC}" as default"
    3.41 +fi
    3.42 +echo "TESTSRC=${TESTSRC}"
    3.43 +## Adding common setup Variables for running shell tests.
    3.44 +. ${TESTSRC}/../../test_env.sh
    3.45 +
    3.46 +# set platform-dependent variables
    3.47 +OS=`uname -s`
    3.48 +echo "Testing on " $OS
    3.49 +case "$OS" in
    3.50 +  Linux)
    3.51 +    cc_cmd=`which gcc`
    3.52 +    if [ "x$cc_cmd" == "x" ]; then
    3.53 +        echo "WARNING: gcc not found. Cannot execute test." 2>&1
    3.54 +        exit 0;
    3.55 +    fi
    3.56 +    ;;
    3.57 +  *)
    3.58 +    echo "Test passed; only valid for Linux"
    3.59 +    exit 0;
    3.60 +    ;;
    3.61 +esac
    3.62 +
    3.63 +THIS_DIR=.
    3.64 +
    3.65 +cp ${TESTSRC}${FS}TestFloatSyncJNIArgs.java ${THIS_DIR}
    3.66 +${TESTJAVA}${FS}bin${FS}javac TestFloatSyncJNIArgs.java
    3.67 +
    3.68 +$cc_cmd -fPIC -shared \
    3.69 +   -o libTestFloatSyncJNIArgs.so \
    3.70 +   -I${TESTJAVA}${FS}include \
    3.71 +   -I${TESTJAVA}${FS}include${FS}linux \
    3.72 +   ${TESTSRC}${FS}libTestFloatSyncJNIArgs.c
    3.73 +
    3.74 +${TESTJAVA}${FS}bin${FS}java \
    3.75 +   -Djava.library.path=${THIS_DIR} TestFloatSyncJNIArgs
    3.76 +
    3.77 +exit $?

mercurial