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 25 * @summary test JNI critical arrays support in Shenandoah 26 * @run main/othervm/native -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:+ShenandoahVerify ShenandoahJNICritical 27 * @run main/othervm/native -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=aggressive ShenandoahJNICritical 28 */ 29 30 import java.util.Arrays; 31 32 public class ShenandoahJNICritical { 33 static { 34 System.loadLibrary("ShenandoahJNICritical"); 35 } 36 37 private static final int NUM_RUNS = 10000; 38 private static final int ARRAY_SIZE=10000; 39 private static int[] a; 40 private static int[] b; 41 private static native void copyAtoB(int[] a, int[] b); 42 43 public static void main(String[] args) { 44 a = new int[ARRAY_SIZE]; 45 b = new int[ARRAY_SIZE]; 46 for (int i = 0; i < NUM_RUNS; i++) { 47 test(); 48 } 49 } 50 51 private static void test() { 52 int[] a1 = new int[ARRAY_SIZE]; 53 int[] b1 = new int[ARRAY_SIZE]; 54 fillArray(a); 55 copyAtoB(a, b); 56 copyAtoB(a1, b1); // Don't optimize out garbage arrays. 57 if (! Arrays.equals(a, b)) { 58 throw new RuntimeException("arrays not equal"); 59 } 60 } 61 62 private static void fillArray(int[] array) { 63 for (int i = 0; i < ARRAY_SIZE; i++) { 64 int val = (int) (Math.random() * Integer.MAX_VALUE); 65 array[i] = val; 66 } 67 } 68 }