Path: blob/master/test/hotspot/jtreg/vmTestbase/jit/graph/CGT.java
40948 views
/*1* Copyright (c) 1998, 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*/2223package jit.graph;2425import jdk.test.lib.Utils;26import jtreg.SkippedException;27import nsk.share.TestFailure;28import nsk.share.test.StressOptions;2930import java.lang.reflect.InvocationTargetException;31import java.util.Vector;3233public class CGT {34private static StressOptions stressOptions = new StressOptions();35private static String ClistPath = "";36private static long finishTime;3738private final Vector summation = new Vector(100000);39private final Vector idList = new Vector(100000);4041public CGT(String[] args) {42parse(args);43Globals.initialize(ClistPath);44outputStats(args);45}4647public static void main(String[] args) {48stressOptions.parseCommandLine(args);49new CGT(args).run();50}5152public void outputStats(String[] args) {53System.out.println("CGT command line options:");54for (String arg : args) {55System.out.println("# " + arg);56}5758System.out.println();5960System.out.println("CGT parameters");61System.out.println("Seed: " + Utils.SEED);62System.out.println("Number of Random Loop iterations: " + Globals.RANDOM_LOOP);63System.out.println("Number of Static Loop iterations: " + Globals.STATIC_LOOP);64System.out.println("Max number of Methods in the Graph: " + Globals.NUM_TEST_CLASSES);65System.out.println("Verbose function calls: " + Globals.VERBOSE);6667System.out.println();68}6970public void run() {71finishTime = System.currentTimeMillis() + stressOptions.getTime() * 1000;72Long numFcalls = Globals.RANDOM_LOOP - 1;73Integer staticFcalls = Globals.STATIC_LOOP;74MethodData methodCallStr = Globals.nextRandomMethod();75Globals.addFunctionIDToVector(methodCallStr.id, idList);76Throwable invocationExcept;7778try {79methodCallStr.nextMethod.invoke(methodCallStr.instance, summation, idList, numFcalls, staticFcalls);80} catch (IllegalAccessException e) {81throw new TestFailure("Illegal Access Exception", e);82} catch (InvocationTargetException e) {83System.out.println("Invocation Target Exception");84invocationExcept = e.getTargetException();85System.out.println(invocationExcept);86if (invocationExcept.getClass() == e.getClass()) {87System.out.println("Processing Exception Invocation Target Exception");88while (invocationExcept.getClass() == e.getClass()) {89invocationExcept = ((InvocationTargetException) invocationExcept).getTargetException();90}91System.out.println(invocationExcept);92}93if (invocationExcept instanceof StackOverflowError) {94throw new SkippedException("stack overflow: skipping verification.", invocationExcept);95} else if (invocationExcept instanceof OutOfMemoryError) {96throw new SkippedException("test devoured heap ;), skipping verification.", invocationExcept);97} else {98throw new TestFailure(invocationExcept);99}100}101102verify();103}104105private void verify() {106long oldsum = 0;107long newsum;108System.out.println("begin call stack validation");109if (summation.size() != idList.size()) {110throw new TestFailure("Vector Length's Do Not Match, VERIFY ERROR : Summation Element Count = " + summation.size() + " ID Element Count = " + idList.size());111}112long vectorSize = summation.size();113114while (!summation.isEmpty()) {115if (CGT.shouldFinish()) {116throw new SkippedException("skipping verification due to timeout");117}118119newsum = (Long) summation.firstElement();120summation.removeElementAt(0);121122int functionID = (Integer) idList.firstElement();123idList.removeElementAt(0);124125if ((newsum - oldsum) != (functionID)) {126throw new TestFailure("Function Call structure invalid, VERIFY ERROR. Expected = " + (newsum - oldsum) + " Actual = " + functionID);127}128oldsum = newsum;129}130131System.out.println("function call structure validated successfully (" + vectorSize + " calls validated)");132}133134public static boolean shouldFinish() {135return System.currentTimeMillis() >= finishTime;136}137138public void parse(String args[]) {139for (int i = 0; i < args.length; i++) {140String arg = args[i].toLowerCase();141switch (arg) {142case "-help":143case "-h":144case "-?": {145usage();146System.exit(1);147break;148}149case "-staticloop": {150int argIndex = i + 1;151if (argIndex < args.length) {152try {153Globals.STATIC_LOOP = Math.abs(Integer.parseInt(args[argIndex])) * stressOptions.getIterationsFactor();154} catch (NumberFormatException e) {155usage();156throw new Error("TESTBUG: Improper Argument: " + args[i] + " " + args[argIndex], e);157}158i++;159} else {160usage();161throw new Error("TESTBUG: Improper Argument: " + args[i]);162}163break;164}165case "-randomloop": {166int argIndex = i + 1;167if (argIndex < args.length) {168try {169Globals.RANDOM_LOOP = Math.abs(Long.parseLong(args[argIndex])) * stressOptions.getIterationsFactor();170} catch (NumberFormatException e) {171usage();172throw new Error("TESTBUG: Improper Argument: " + args[i] + " " + args[argIndex], e);173}174i++;175} else {176usage();177throw new Error("TESTBUG: Improper Argument: " + args[i]);178179}180break;181}182case "-numtestclass": {183int argIndex = i + 1;184if (argIndex < args.length) {185try {186Globals.NUM_TEST_CLASSES = Math.abs(Integer.parseInt(args[argIndex]));187} catch (NumberFormatException e) {188usage();189throw new Error("TESTBUG: Improper Argument: " + args[i] + " " + args[argIndex], e);190}191i++;192} else {193usage();194throw new Error("TESTBUG: Improper Argument: " + args[i]);195}196break;197}198case "-verbose":199case "-v": {200Globals.VERBOSE = true;201break;202}203case "-path": {204int argIndex = i + 1;205if (argIndex < args.length) {206ClistPath = args[argIndex];207i++;208} else {209usage();210throw new Error("TESTBUG: Improper Argument: " + args[i]);211}212break;213}214default: {215if (!arg.startsWith("-stress")) {216usage();217throw new Error("TESTBUG: Invalid Argument: " + args[i]);218}219}220}221}222223if ("".equals(ClistPath)) {224usage();225throw new Error("TESTBUG: class list path not defined");226}227}228229public void usage() {230System.out.println("usage: java CGT [options]");231System.out.println(" -help prints out this message");232System.out.println(" -numTestClass # limits the number of \"Test Methods\" to #");233System.out.println(" -randomcLoop # # of random function calls");234System.out.println(" -staticLoop # # of non-random static function calls");235System.out.println(" -v -verbose turn on verbose mode");236System.out.println(" -path <path to classlist> required, argument so program can find classes");237}238}239240241