Path: blob/master/test/hotspot/jtreg/gc/epsilon/TestRefArrays.java
66644 views
/*1* Copyright (c) 2017, 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*/2223package gc.epsilon;2425/**26* @test TestRefArrays27* @key randomness28* @requires vm.gc.Epsilon29* @summary Epsilon is able to allocate arrays, and does not corrupt their state30* @library /test/lib31*32* @run main/othervm -XX:+UseTLAB -Xmx256m33* -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC34* gc.epsilon.TestRefArrays35*36* @run main/othervm -XX:+UseTLAB -Xmx256m37* -Xint38* -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC39* gc.epsilon.TestRefArrays40*41* @run main/othervm -XX:+UseTLAB -Xmx256m42* -Xbatch -Xcomp -XX:TieredStopAtLevel=143* -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC44* gc.epsilon.TestRefArrays45*46* @run main/othervm -XX:+UseTLAB -Xmx256m47* -Xbatch -Xcomp -XX:-TieredCompilation48* -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC49* gc.epsilon.TestRefArrays50*51* @run main/othervm -XX:-UseTLAB -Xmx256m52* -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC53* gc.epsilon.TestRefArrays54*55* @run main/othervm -XX:-UseTLAB -Xmx256m56* -Xint57* -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC58* gc.epsilon.TestRefArrays59*60* @run main/othervm -XX:-UseTLAB -Xmx256m61* -Xbatch -Xcomp -XX:TieredStopAtLevel=162* -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC63* gc.epsilon.TestRefArrays64*65* @run main/othervm -XX:-UseTLAB -Xmx256m66* -Xbatch -Xcomp -XX:-TieredCompilation67* -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC68* gc.epsilon.TestRefArrays69*/7071import java.util.Random;72import jdk.test.lib.Utils;7374public class TestRefArrays {75static int COUNT = Integer.getInteger("count", 200); // ~100 MB allocation7677static MyObject[][] arr;7879public static void main(String[] args) throws Exception {80Random r = Utils.getRandomInstance();8182arr = new MyObject[COUNT * 100][];83for (int c = 0; c < COUNT; c++) {84arr[c] = new MyObject[c * 100];85for (int v = 0; v < c; v++) {86arr[c][v] = new MyObject(r.nextInt());87}88}8990r = new Random(Utils.SEED);91for (int c = 0; c < COUNT; c++) {92MyObject[] b = arr[c];93if (b.length != (c * 100)) {94throw new IllegalStateException("Failure: length = " + b.length + ", need = " + (c*100));95}96for (int v = 0; v < c; v++) {97int actual = b[v].id();98int expected = r.nextInt();99if (actual != expected) {100throw new IllegalStateException("Failure: expected = " + expected + ", actual = " + actual);101}102}103}104}105106public static class MyObject {107int id;108public MyObject(int id) {109this.id = id;110}111public int id() {112return id;113}114}115}116117118