1 /*
2  * Copyright (c) 2015, 2016 SAP SE. All rights reserved.
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * This code is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License version 2 only, as
7  * published by the Free Software Foundation.
8  *
9  * This code is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12  * version 2 for more details (a copy is included in the LICENSE file that
13  * accompanied this code).
14  *
15  * You should have received a copy of the GNU General Public License version
16  * 2 along with this work; if not, write to the Free Software Foundation,
17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18  *
19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20  * or visit www.oracle.com if you need additional information or have any
21  * questions.
22  */
23 
24 /* @test
25  * @bug 8139258 8165673
26  * @summary Regression test for passing float args to a jni function.
27  *
28  *
29  * @run main/othervm/native -Xint compiler.floatingpoint.TestFloatJNIArgs
30  * @run main/othervm/native -XX:+TieredCompilation -Xcomp compiler.floatingpoint.TestFloatJNIArgs
31  * @run main/othervm/native -XX:-TieredCompilation -Xcomp compiler.floatingpoint.TestFloatJNIArgs
32  */
33 
34 package compiler.floatingpoint;
35 
36 public class TestFloatJNIArgs {
37     static {
38         try {
39             System.loadLibrary("TestFloatJNIArgs");
40         } catch (UnsatisfiedLinkError e) {
41             System.out.println("could not load native lib: " + e);
42         }
43     }
44 
add15floats( float f1, float f2, float f3, float f4, float f5, float f6, float f7, float f8, float f9, float f10, float f11, float f12, float f13, float f14, float f15)45     public static native float add15floats(
46         float f1, float f2, float f3, float f4,
47         float f5, float f6, float f7, float f8,
48         float f9, float f10, float f11, float f12,
49         float f13, float f14, float f15);
50 
add10floats( float f1, float f2, float f3, float f4, float f5, float f6, float f7, float f8, float f9, float f10)51     public static native float add10floats(
52         float f1, float f2, float f3, float f4,
53         float f5, float f6, float f7, float f8,
54         float f9, float f10);
55 
addFloatsInts( float f1, float f2, float f3, float f4, float f5, float f6, float f7, float f8, float f9, float f10, float f11, float f12, float f13, float f14, float f15, int a16, int a17)56     public static native float addFloatsInts(
57         float f1, float f2, float f3, float f4,
58         float f5, float f6, float f7, float f8,
59         float f9, float f10, float f11, float f12,
60         float f13, float f14, float f15, int a16, int a17);
61 
add15doubles( double d1, double d2, double d3, double d4, double d5, double d6, double d7, double d8, double d9, double d10, double d11, double d12, double d13, double d14, double d15)62     public static native double add15doubles(
63         double d1, double d2, double d3, double d4,
64         double d5, double d6, double d7, double d8,
65         double d9, double d10, double d11, double d12,
66         double d13, double d14, double d15);
67 
test()68     static void test() throws Exception {
69         float sum = TestFloatJNIArgs.add15floats(1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f,
70                                                  1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f);
71         if (sum != 15.0f) {
72             throw new Error("Passed 15 times 1.0f to jni function which didn't add them properly: " + sum);
73         }
74 
75         float sum1 = TestFloatJNIArgs.add10floats(1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f);
76         if (sum1 != 10.0f) {
77             throw new Error("Passed 10 times 1.0f to jni function which didn't add them properly: " + sum1);
78         }
79 
80         float sum2 = TestFloatJNIArgs.addFloatsInts(1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f,
81                                                    1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1, 1);
82         if (sum2 != 17.0f) {
83             throw new Error("Passed 17 times 1 to jni function which didn't add them properly: " + sum2);
84         }
85 
86         double dsum = TestFloatJNIArgs.add15doubles(1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0,
87                                                       1.0, 1.0, 1.0, 1.0, 1.0, 1.0);
88         if (dsum != 15.0) {
89             throw new Error("Passed 15 times 1.0 to jni function which didn't add them properly: " + dsum);
90         }
91     }
92 
main(String[] args)93     public static void main(String[] args) throws Exception {
94         for (int i = 0; i < 200; ++i) {
95             test();
96         }
97     }
98 }
99