Path: blob/master/test/hotspot/jtreg/vmTestbase/gc/memory/LargePagesTest/LargePagesTest.java
41155 views
/*1* Copyright (c) 2013, 2020, Oracle and/or its affiliates. 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*/2223/*24* @test25* @key stress randomness26*27* @summary converted from VM Testbase gc/memory/LargePagesTest.28* VM Testbase keywords: [gc, stress, stressopt]29*30* @library /vmTestbase31* /test/lib32* @run main/othervm gc.memory.LargePagesTest.LargePagesTest noThreads=5 duration=6033*/3435package gc.memory.LargePagesTest;3637import java.io.PrintStream;38import nsk.share.test.LocalRandom;3940/*41* Allocators purpose is to create pressure on the garbage collector42* for a certain amount of time.43* Note: this test moved from the "jr", the original name is func.vm.largepages.LargePagesTest44*/454647/**48* @run main/othervm/timeout=15049* -XX:+UseLargePages50* -Xmx64m51* -Xms16m52* LargePagesTest53* noThreads=5 duration=6054* @summary heap shrink/grow test55*/56final public class LargePagesTest extends Thread {5758private static int cnt;59private static final int SMALL_OBJECT_ALLOCATER = 1;60private static final int LARGE_OBJECT_ALLOCATER = 2;61private static final int ANY_OBJECT_ALLOCATER = 3;62private static final int ANY_NO_MULTIARRAYS_ALLOCATER = 4;63private int myType;6465/** Dummy thingies to update. */66public LargePagesTest.Dummy[] d0;67/** Dummy thingies to update. */68public LargePagesTest.Dummy[] d1;69/** Dummy thingies to update. */70public LargePagesTest.Dummy[][] d2;71/** Dummy thingies to update. */72public LargePagesTest.Dummy[][] d3;73/** Dummy thingies to update. */74public LargePagesTest.Dummy[][][] d4;75/** Dummy thingies to update. */76public LargePagesTest.Dummy d5;7778/** Time to run execute(). */79private long duration;8081/** Boolean of progress should be printed. */82private boolean verbose;8384private static int noThreads = 5;8586/** Iterations. */87public long iterations = 0L;8889/** Result. */90public boolean result = false;9192private PrintStream out;9394/**95* Creates DurAllocator.96* @param name Parameter97* @param duration Parameter98* @param out Parameter99* @param verbose Parameter100*/101LargePagesTest(String name, long duration, PrintStream out, boolean verbose) {102103super(name);104this.duration = duration;105this.out = out;106this.verbose = verbose;107}108109/**110* Print status.111*/112void describe() {113out.println("DurAllocator run: ");114out.println(" test duration: " + duration / 1000 + " seconds");115out.println(" number of threads: " + noThreads + " threads");116}117118/**119* Allocates memory in a loop.120*/121public void run() {122123long startTime = System.currentTimeMillis();124125while (System.currentTimeMillis() - startTime < duration) {126try {127allocate();128} catch (Throwable t) {129out.println(getName() + " FAILED: " + t.getClass().getName() + " in iteration " + iterations + ": " + t.getMessage());130return;131}132iterations++;133if (verbose && iterations % 1000 == 0) {134out.print(".");135}136if (verbose && iterations % 60000 == 0) {137out.println(".");138}139}140if (verbose) {141out.println("");142}143144145long endTime = System.currentTimeMillis();146long runTime = endTime - startTime;147if (duration > runTime) {148out.println(getName() + " FAILED: Execution time < requested execution time.");149out.println(" execution time is " + runTime);150out.println(" requested time is " + duration);151} else if (iterations <= 0) {152out.println(getName() + " FAILED: No executions finished");153} else {154result = true;155}156}157158private void allocate() {159for (int j = 0; j < 1000; j++) {160int i = 0;161162switch (myType) {163case SMALL_OBJECT_ALLOCATER:164i = 5;165break;166case LARGE_OBJECT_ALLOCATER:167i = 1;168break;169case ANY_OBJECT_ALLOCATER:170i = LocalRandom.nextInt(100);171break;172case ANY_NO_MULTIARRAYS_ALLOCATER:173i = LocalRandom.nextInt(100);174if ((i >= 2) && (i <= 4)) {175i = 5;176}177break;178default:179break;180}181182switch (i) {183case 0:184d0 = new LargePagesTest.Dummy[10];185break;186case 1:187d1 = new LargePagesTest.Dummy[1000];188break;189case 2:190d2 = new LargePagesTest.Dummy[10][10];191break;192case 3:193d3 = new LargePagesTest.Dummy[100][100];194break;195case 4:196d4 = new LargePagesTest.Dummy[10][10][10];197break;198default:199d5 = new LargePagesTest.Dummy();200break;201}202}203}204205/**206* A Dummy class.207*/208private class Dummy {209/**210* Creates a dummy.211*/212Dummy() {213cnt++;214}215}216217/**218* @param args Input arguments219*/220public static void main(String[] args) {221222long duration = 30 * 60 * 1000;223PrintStream out = System.out;224boolean verbose = true;225226for (int i = 0; i < args.length; i++) {227String noThreadsArgName = "noThreads=";228String executionTimeArgName = "duration=";229String verboseArgName = "verbose=";230if (args[i].indexOf(noThreadsArgName) != -1) {231noThreads = Integer.parseInt(args[i].substring(noThreadsArgName.length(), args[i].length()));232} else if (args[i].indexOf(executionTimeArgName) != -1) {233duration = 1000 * Long.parseLong(args[i].substring(executionTimeArgName.length(), args[i].length()));234} else if (args[i].indexOf(verboseArgName) != -1) {235verbose = Boolean.parseBoolean(args[i].substring(verboseArgName.length(), args[i].length()));236} else {237System.out.println("ERROR: Unknown argument string: " + args[i]);238System.exit(-1);239}240}241242// Please don't...243if (noThreads <= 0) {244noThreads = 1;245}246247LargePagesTest[] runners = new LargePagesTest[noThreads];248249for (int i = 0; i < noThreads; i++) {250runners[i] = new LargePagesTest("DurAllocator " + i, duration, out, verbose);251}252253runners[0].describe();254255for (int i = 0; i < noThreads; i++) {256runners[i].start();257}258259for (int i = 0; i < noThreads; i++) {260try {261runners[i].join(duration + 10 * 60 * 1000);262} catch (InterruptedException e) {263out.println(runners[i].getName() + " FAILED: " + e.getClass().getName() + " " + e.getMessage());264System.exit(-1);265}266}267268for (int i = 0; i < noThreads; i++) {269if (!runners[i].result) {270out.println(runners[i].getName() + " FAILED: status=" + runners[i].result);271System.exit(-1);272}273}274275if (verbose) {276out.println();277}278279out.print("DurAllocator PASSED with (");280for (int i = 0; i < noThreads; i++) {281out.print("" + runners[i].iterations + (i + 1 < noThreads ? "+" : ""));282}283out.println(") iterations.");284// System.exit(90); // use to return 90 as indication of success285}286287}288289290