1 /* 2 * Copyright (c) 2016, 2018, Red Hat, Inc. All rights reserved. 3 * 4 * This code is free software; you can redistribute it and/or modify it 5 * under the terms of the GNU General Public License version 2 only, as 6 * published by the Free Software Foundation. 7 * 8 * This code is distributed in the hope that it will be useful, but WITHOUT 9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 11 * version 2 for more details (a copy is included in the LICENSE file that 12 * accompanied this code). 13 * 14 * You should have received a copy of the GNU General Public License version 15 * 2 along with this work; if not, write to the Free Software Foundation, 16 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 17 * 18 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 19 * or visit www.oracle.com if you need additional information or have any 20 * questions. 21 * 22 */ 23 24 /* @test TestJNICritical 25 * @summary test JNI critical arrays support in Shenandoah 26 * @key gc 27 * @requires vm.gc.Shenandoah 28 * 29 * @run main/othervm/native -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:+ShenandoahVerify TestJNICritical 30 * @run main/othervm/native -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=aggressive TestJNICritical 31 */ 32 33 import java.util.Arrays; 34 35 public class TestJNICritical { 36 static { 37 System.loadLibrary("TestJNICritical"); 38 } 39 40 private static final int NUM_RUNS = 10000; 41 private static final int ARRAY_SIZE = 10000; 42 private static int[] a; 43 private static int[] b; 44 45 private static native void copyAtoB(int[] a, int[] b); 46 47 public static void main(String[] args) { 48 a = new int[ARRAY_SIZE]; 49 b = new int[ARRAY_SIZE]; 50 for (int i = 0; i < NUM_RUNS; i++) { 51 test(); 52 } 53 } 54 55 private static void test() { 56 int[] a1 = new int[ARRAY_SIZE]; 57 int[] b1 = new int[ARRAY_SIZE]; 58 fillArray(a); 59 copyAtoB(a, b); 60 copyAtoB(a1, b1); // Don't optimize out garbage arrays. 61 if (!Arrays.equals(a, b)) { 62 throw new RuntimeException("arrays not equal"); 63 } 64 } 65 66 private static void fillArray(int[] array) { 67 for (int i = 0; i < ARRAY_SIZE; i++) { 68 int val = (int) (Math.random() * Integer.MAX_VALUE); 69 array[i] = val; 70 } 71 } 72 }