Path: blob/master/test/hotspot/jtreg/runtime/InvocationTests/shared/Utils.java
40948 views
/*1* Copyright (c) 2009, 2019, 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*22*/2324package shared;2526import java.util.List;2728/**29* Just a set of constants30*/31public class Utils {32public static final String TARGET_METHOD_NAME = "m";33public static int version = 50;3435public static boolean isACC_SUPER = false;3637public static void init(List<String> args) {38for (String param : args) {39String name = "classfile_version";40String pattern = "--"+name+"=";41if (param.startsWith(pattern)) {42String value = param.substring(pattern.length());43int majorVersion = 50;44int minorVersion = 0;4546try {47String[] versions = value.split(":");48if (versions.length > 2) {49throw new RuntimeException(String.format("Unknown %s value: %s", name, value));50}5152try {53majorVersion = Integer.parseInt(versions[0]);54if (versions.length > 1) {55minorVersion = Integer.parseInt(versions[1]);56}57} catch(Exception e) {58throw new RuntimeException(String.format("Can't parse %s value: '%s'", name, value));59}60} catch (Exception e) {61System.out.println("ERROR: "+e.getMessage());62}6364version = majorVersion + (minorVersion << 16);6566System.out.printf("INFO: Class file version: major: %d; minor: %d\n", majorVersion, minorVersion);6768if (majorVersion < 49 && !args.contains("--no_acc_super")) {69isACC_SUPER = true;70System.out.printf("INFO: Enabling ACC_SUPER flag for major: %d\nTo disable it, specify --no_acc_super option.\n", majorVersion, minorVersion);71}72} else if (param.equals("--no_acc_super")){73System.out.println("INFO: ACC_SUPER flag is disabled");74isACC_SUPER = false;75} else if (param.equals("--acc_super")){76isACC_SUPER = true;77} else {78System.out.println("ERROR: Unknown option: "+param);79printHelp();80System.exit(1);81}82}83}8485public static void printHelp() {86System.out.println(87"Supported parameters:\n"88+ "\t--classfile_version=major_version[:minor_version]\n"89+ "\t\t- specify class file version for generated classes\n"90+ "\t--no_acc_super\n"91+ "\t\t- don't add ACC_SUPER flag into generated classes\n"92+ "\t--acc_super\n"93+ "\t\t- force ACC_SUPER flag in generated classes\n"94+ "\t--dump\n"95+ "\t\t- dump generated classes\n"96+ "\t--noexecute\n"97+ "\t\t- print only expected results, don't execute tests\n"98);99}100101/*******************************************************************/102public static String getInternalName(String s) {103return s.replaceAll("\\.", "/");104}105106}107108109