Path: blob/master/test/hotspot/jtreg/gc/metaspace/InputArguments.java
40942 views
/*1* Copyright (c) 2013, 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*/2223package gc.metaspace;2425import java.lang.management.RuntimeMXBean;26import java.lang.management.ManagementFactory;27import java.util.List;2829/**30* This class provides access to the input arguments to the VM.31*/32public class InputArguments {33private static final List<String> args;3435static {36RuntimeMXBean runtimeMxBean = ManagementFactory.getRuntimeMXBean();37args = runtimeMxBean.getInputArguments();38}3940/**41* Returns true if {@code arg} is an input argument to the VM.42*43* This is useful for checking boolean flags such as -XX:+UseSerialGC or44* -XX:-UsePerfData.45*46* @param arg The name of the argument.47* @return {@code true} if the given argument is an input argument,48* otherwise {@code false}.49*/50public static boolean contains(String arg) {51return args.contains(arg);52}5354/**55* Returns true if {@code prefix} is the start of an input argument to the56* VM.57*58* This is useful for checking if flags describing a quantity, such as59* -XX:+MaxMetaspaceSize=100m, is set without having to know the quantity.60* To check if the flag -XX:MaxMetaspaceSize is set, use61* {@code InputArguments.containsPrefix("-XX:MaxMetaspaceSize")}.62*63* @param prefix The start of the argument.64* @return {@code true} if the given argument is the start of an input65* argument, otherwise {@code false}.66*/67public static boolean containsPrefix(String prefix) {68for (String arg : args) {69if (arg.startsWith(prefix)) {70return true;71}72}73return false;74}75}767778