Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/sun/management/Flag.java
38827 views
/*1* Copyright (c) 2003, 2014, 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. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package sun.management;2627import java.util.*;28import com.sun.management.VMOption;29import com.sun.management.VMOption.Origin;30import java.security.AccessController;3132/**33* Flag class is a helper class for constructing a VMOption.34* It has the static methods for getting the Flag objects, each35* corresponds to one VMOption.36*37*/38class Flag {39private String name;40private Object value;41private Origin origin;42private boolean writeable;43private boolean external;4445Flag(String name, Object value, boolean writeable,46boolean external, Origin origin) {47this.name = name;48this.value = value == null ? "" : value ;49this.origin = origin;50this.writeable = writeable;51this.external = external;52}5354Object getValue() {55return value;56}5758boolean isWriteable() {59return writeable;60}6162boolean isExternal() {63return external;64}6566VMOption getVMOption() {67return new VMOption(name, value.toString(), writeable, origin);68}6970static Flag getFlag(String name) {71String[] names = new String[1];72names[0] = name;7374List<Flag> flags = getFlags(names, 1);75if (flags.isEmpty()) {76return null;77} else {78// flags should have only one element79return flags.get(0);80}81}8283static List<Flag> getAllFlags() {84int numFlags = getInternalFlagCount();8586// Get all internal flags with names = null87return getFlags(null, numFlags);88}8990private static List<Flag> getFlags(String[] names, int numFlags) {91Flag[] flags = new Flag[numFlags];92int count = getFlags(names, flags, numFlags);9394List<Flag> result = new ArrayList<>();95for (Flag f : flags) {96if (f != null) {97result.add(f);98}99}100return result;101}102103private static native String[] getAllFlagNames();104// getFlags sets each element in the given flags array105// with a Flag object only if the name is valid and the106// type is supported. The flags array may contain null elements.107private static native int getFlags(String[] names, Flag[] flags, int count);108private static native int getInternalFlagCount();109110// These set* methods are synchronized on the class object111// to avoid multiple threads updating the same flag at the same time.112static synchronized native void setLongValue(String name, long value);113static synchronized native void setDoubleValue(String name, double value);114static synchronized native void setBooleanValue(String name, boolean value);115static synchronized native void setStringValue(String name, String value);116117static {118AccessController.doPrivileged(119new java.security.PrivilegedAction<Void>() {120public Void run() {121System.loadLibrary("management");122return null;123}124});125initialize();126}127private static native void initialize();128}129130131