Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/test/gc/shenandoah/jni/TestJNICritical.java
32285 views
/*1* Copyright (c) 2016, 2017, Red Hat, Inc. All rights reserved.2*3* This code is free software; you can redistribute it and/or modify it4* under the terms of the GNU General Public License version 2 only, as5* published by the Free Software Foundation.6*7* This code is distributed in the hope that it will be useful, but WITHOUT8* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or9* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License10* version 2 for more details (a copy is included in the LICENSE file that11* accompanied this code).12*13* You should have received a copy of the GNU General Public License version14* 2 along with this work; if not, write to the Free Software Foundation,15* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.16*17* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA18* or visit www.oracle.com if you need additional information or have any19* questions.20*21*/2223import java.util.Arrays;2425public class TestJNICritical {26static {27System.loadLibrary("TestJNICritical");28}2930private static final int NUM_RUNS = 10000;31private static final int ARRAY_SIZE = 10000;32private static int[] a;33private static int[] b;3435private static native void copyAtoB(int[] a, int[] b);3637public static void main(String[] args) {38a = new int[ARRAY_SIZE];39b = new int[ARRAY_SIZE];40for (int i = 0; i < NUM_RUNS; i++) {41test();42}43}4445private static void test() {46int[] a1 = new int[ARRAY_SIZE];47int[] b1 = new int[ARRAY_SIZE];48fillArray(a);49copyAtoB(a, b);50copyAtoB(a1, b1); // Don't optimize out garbage arrays.51if (!Arrays.equals(a, b)) {52throw new RuntimeException("arrays not equal");53}54}5556private static void fillArray(int[] array) {57for (int i = 0; i < ARRAY_SIZE; i++) {58int val = (int) (Math.random() * Integer.MAX_VALUE);59array[i] = val;60}61}62}636465