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