Path: blob/master/test/hotspot/jtreg/gc/epsilon/TestRefArrays.java
40948 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 -Xmx1g -XX:+UseTLAB -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC gc.epsilon.TestRefArrays33* @run main/othervm -Xmx1g -Xint -XX:+UseTLAB -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC gc.epsilon.TestRefArrays34* @run main/othervm -Xmx1g -Xbatch -Xcomp -XX:+UseTLAB -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC gc.epsilon.TestRefArrays35* @run main/othervm -Xmx1g -Xbatch -Xcomp -XX:TieredStopAtLevel=1 -XX:+UseTLAB -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC gc.epsilon.TestRefArrays36* @run main/othervm -Xmx1g -Xbatch -Xcomp -XX:-TieredCompilation -XX:+UseTLAB -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC gc.epsilon.TestRefArrays37*38* @run main/othervm -Xmx1g -XX:-UseTLAB -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC gc.epsilon.TestRefArrays39* @run main/othervm -Xmx1g -Xint -XX:-UseTLAB -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC gc.epsilon.TestRefArrays40* @run main/othervm -Xmx1g -Xbatch -Xcomp -XX:-UseTLAB -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC gc.epsilon.TestRefArrays41* @run main/othervm -Xmx1g -Xbatch -Xcomp -XX:TieredStopAtLevel=1 -XX:-UseTLAB -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC gc.epsilon.TestRefArrays42* @run main/othervm -Xmx1g -Xbatch -Xcomp -XX:-TieredCompilation -XX:-UseTLAB -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC gc.epsilon.TestRefArrays43*/4445import java.util.Random;46import jdk.test.lib.Utils;4748public class TestRefArrays {49static int COUNT = Integer.getInteger("count", 1000); // ~500 MB allocation5051static MyObject[][] arr;5253public static void main(String[] args) throws Exception {54Random r = Utils.getRandomInstance();5556arr = new MyObject[COUNT * 100][];57for (int c = 0; c < COUNT; c++) {58arr[c] = new MyObject[c * 100];59for (int v = 0; v < c; v++) {60arr[c][v] = new MyObject(r.nextInt());61}62}6364r = new Random(Utils.SEED);65for (int c = 0; c < COUNT; c++) {66MyObject[] b = arr[c];67if (b.length != (c * 100)) {68throw new IllegalStateException("Failure: length = " + b.length + ", need = " + (c*100));69}70for (int v = 0; v < c; v++) {71int actual = b[v].id();72int expected = r.nextInt();73if (actual != expected) {74throw new IllegalStateException("Failure: expected = " + expected + ", actual = " + actual);75}76}77}78}7980public static class MyObject {81int id;82public MyObject(int id) {83this.id = id;84}85public int id() {86return id;87}88}89}909192