test/mips64/11080/TestFloatSyncJNIArgs.java

changeset 9758
122547cfa3c8
     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 +}

mercurial