Path: blob/master/test/hotspot/jtreg/compiler/floatingpoint/TestFloatSyncJNIArgs.java
41149 views
/*1* Copyright (c) 2015, 2016 SAP SE. All rights reserved.2* Copyright (c) 2018 Red Hat, Inc. 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 it6* under the terms of the GNU General Public License version 2 only, as7* published by the Free Software Foundation.8*9* This code is distributed in the hope that it will be useful, but WITHOUT10* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or11* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License12* version 2 for more details (a copy is included in the LICENSE file that13* accompanied this code).14*15* You should have received a copy of the GNU General Public License version16* 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 USA20* or visit www.oracle.com if you need additional information or have any21* questions.22*/2324/* @test25* @bug 820783826* @summary Regression test for passing float args to a synchronized jni function.27*28*29* @run main/othervm/native compiler.floatingpoint.TestFloatSyncJNIArgs30*/3132package compiler.floatingpoint;3334public class TestFloatSyncJNIArgs {35static {36try {37System.loadLibrary("TestFloatSyncJNIArgs");38} catch (UnsatisfiedLinkError e) {39System.out.println("could not load native lib: " + e);40}41}4243private static final int numberOfThreads = 8;4445static volatile Error testFailed = null;4647public synchronized static native float combine15floats(48float f1, float f2, float f3, float f4,49float f5, float f6, float f7, float f8,50float f9, float f10, float f11, float f12,51float f13, float f14, float f15);5253public synchronized static native double combine15doubles(54double d1, double d2, double d3, double d4,55double d5, double d6, double d7, double d8,56double d9, double d10, double d11, double d12,57double d13, double d14, double d15);5859static void test() throws Exception {60Thread[] threads = new Thread[numberOfThreads];6162for (int i = 0; i < numberOfThreads; i++) {63threads[i] = new Thread(() -> {64for (int j = 0; j < 10000; j++) {65float f = combine15floats(1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f,669, 10, 11, 12, 13, 14, 15);67if (f != 81720.0f) {68testFailed = new Error("jni function didn't combine 15 float args properly: " + f);69throw testFailed;70}71}72});73}74for (int i = 0; i < numberOfThreads; i++) {75threads[i].start();76}77for (int i = 0; i < numberOfThreads; i++) {78threads[i].join();79}80if (testFailed != null) {81throw testFailed;82}8384for (int i = 0; i < numberOfThreads; i++) {85threads[i] = new Thread(() -> {86for (int j = 0; j < 10000; j++) {87double d = combine15doubles(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0,889, 10, 11, 12, 13, 14, 15);89if (d != 81720.0) {90testFailed = new Error("jni function didn't combine 15 double args properly: " + d);91throw testFailed;92}93}94});95}96for (int i = 0; i < numberOfThreads; i++) {97threads[i].start();98}99for (int i = 0; i < numberOfThreads; i++) {100threads[i].join();101}102if (testFailed != null) {103throw testFailed;104}105}106107public static void main(String[] args) throws Exception {108for (int i = 0; i < 200; ++i) {109test();110}111}112}113114115