Path: blob/master/test/hotspot/jtreg/gc/shenandoah/TestArrayCopyStress.java
40942 views
/*1* Copyright (c) 2018, Red Hat, Inc. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 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 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324import java.util.Random;25import jdk.test.lib.Utils;2627/*28* @test TestArrayCopyStress29* @key randomness30* @requires vm.gc.Shenandoah31* @library /test/lib32*33* @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:TieredStopAtLevel=0 -Xmx16m TestArrayCopyStress34*/35public class TestArrayCopyStress {3637private static final int ARRAY_SIZE = 1000;38private static final int ITERATIONS = 10000;3940static class Foo {41int num;4243Foo(int num) {44this.num = num;45}46}4748static class Bar {}4950public static void main(String[] args) throws Exception {51for (int i = 0; i < ITERATIONS; i++) {52testConjoint();53}54}5556private static void testConjoint() {57Foo[] array = new Foo[ARRAY_SIZE];58for (int i = 0; i < ARRAY_SIZE; i++) {59array[i] = new Foo(i);60}61Random rng = Utils.getRandomInstance();62int src_idx = rng.nextInt(ARRAY_SIZE);63int dst_idx = rng.nextInt(ARRAY_SIZE);64int len = rng.nextInt(Math.min(ARRAY_SIZE - src_idx, ARRAY_SIZE - dst_idx));65System.arraycopy(array, src_idx, array, dst_idx, len);6667for (int i = 0; i < ARRAY_SIZE; i++) {68if (i >= dst_idx && i < dst_idx + len) {69assertEquals(array[i].num, i - (dst_idx - src_idx));70} else {71assertEquals(array[i].num, i);72}73}74}7576private static void assertEquals(int a, int b) {77if (a != b) throw new RuntimeException("assert failed");78}7980}818283