Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/com/sun/management/VMOption.java
38831 views
/*1* Copyright (c) 2005, 2013, 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 com.sun.management;2627import sun.management.VMOptionCompositeData;28import javax.management.openmbean.CompositeData;2930/**31* Information about a VM option including its value and32* where the value came from which is referred as its33* {@link VMOption.Origin <i>origin</i>}.34* <p>35* Each VM option has a default value. A VM option can36* be set at VM creation time typically as a command line37* argument to the launcher or an argument passed to the38* VM created using the JNI invocation interface.39* In addition, a VM option may be set via an environment40* variable or a configuration file. A VM option can also41* be set dynamically via a management interface after42* the VM was started.43*44* A <tt>VMOption</tt> contains the value of a VM option45* and the origin of that value at the time this <tt>VMOption</tt>46* object was constructed. The value of the VM option47* may be changed after the <tt>VMOption</tt> object was constructed,48*49* @see <a href="{@docRoot}/../../../../technotes/guides/vm/index.html">50* Java Virtual Machine</a>51* @author Mandy Chung52* @since 1.653*/54@jdk.Exported55public class VMOption {56private String name;57private String value;58private boolean writeable;59private Origin origin;6061/**62* Origin of the value of a VM option. It tells where the63* value of a VM option came from.64*65* @since 1.666*/67@jdk.Exported68public enum Origin {69/**70* The VM option has not been set and its value71* is the default value.72*/73DEFAULT,74/**75* The VM option was set at VM creation time typically76* as a command line argument to the launcher or77* an argument passed to the VM created using the78* JNI invocation interface.79*/80VM_CREATION,81/**82* The VM option was set via an environment variable.83*/84ENVIRON_VAR,85/**86* The VM option was set via a configuration file.87*/88CONFIG_FILE,89/**90* The VM option was set via the management interface after the VM91* was started.92*/93MANAGEMENT,94/**95* The VM option was set via the VM ergonomic support.96*/97ERGONOMIC,98/**99* The VM option was set via some other mechanism.100*/101OTHER102}103104/**105* Constructs a <tt>VMOption</tt>.106*107* @param name Name of a VM option.108* @param value Value of a VM option.109* @param writeable <tt>true</tt> if a VM option can be set dynamically,110* or <tt>false</tt> otherwise.111* @param origin where the value of a VM option came from.112*113* @throws NullPointerException if the name or value is <tt>null</tt>114*/115public VMOption(String name, String value, boolean writeable, Origin origin) {116this.name = name;117this.value = value;118this.writeable = writeable;119this.origin = origin;120}121122/**123* Constructs a <tt>VMOption</tt> object from a124* {@link CompositeData CompositeData}.125*/126private VMOption(CompositeData cd) {127// validate the input composite data128VMOptionCompositeData.validateCompositeData(cd);129130this.name = VMOptionCompositeData.getName(cd);131this.value = VMOptionCompositeData.getValue(cd);132this.writeable = VMOptionCompositeData.isWriteable(cd);133this.origin = VMOptionCompositeData.getOrigin(cd);134}135136/**137* Returns the name of this VM option.138*139* @return the name of this VM option.140*/141public String getName() {142return name;143}144145/**146* Returns the value of this VM option at the time when147* this <tt>VMOption</tt> was created. The value could have been changed.148*149* @return the value of the VM option at the time when150* this <tt>VMOption</tt> was created.151*/152public String getValue() {153return value;154}155156/**157* Returns the origin of the value of this VM option. That is,158* where the value of this VM option came from.159*160* @return where the value of this VM option came from.161*/162public Origin getOrigin() {163return origin;164}165166/**167* Tests if this VM option is writeable. If this VM option is writeable,168* it can be set by the {@link HotSpotDiagnosticMXBean#setVMOption169* HotSpotDiagnosticMXBean.setVMOption} method.170*171* @return <tt>true</tt> if this VM option is writeable; <tt>false</tt>172* otherwise.173*/174public boolean isWriteable() {175return writeable;176}177178public String toString() {179return "VM option: " + getName() +180" value: " + value + " " +181" origin: " + origin + " " +182(writeable ? "(read-write)" : "(read-only)");183}184185/**186* Returns a <tt>VMOption</tt> object represented by the187* given <tt>CompositeData</tt>. The given <tt>CompositeData</tt>188* must contain the following attributes:189* <p>190* <blockquote>191* <table border>192* <tr>193* <th align=left>Attribute Name</th>194* <th align=left>Type</th>195* </tr>196* <tr>197* <td>name</td>198* <td><tt>java.lang.String</tt></td>199* </tr>200* <tr>201* <td>value</td>202* <td><tt>java.lang.String</tt></td>203* </tr>204* <tr>205* <td>origin</td>206* <td><tt>java.lang.String</tt></td>207* </tr>208* <tr>209* <td>writeable</td>210* <td><tt>java.lang.Boolean</tt></td>211* </tr>212* </table>213* </blockquote>214*215* @param cd <tt>CompositeData</tt> representing a <tt>VMOption</tt>216*217* @throws IllegalArgumentException if <tt>cd</tt> does not218* represent a <tt>VMOption</tt> with the attributes described219* above.220*221* @return a <tt>VMOption</tt> object represented by <tt>cd</tt>222* if <tt>cd</tt> is not <tt>null</tt>;223* <tt>null</tt> otherwise.224*/225public static VMOption from(CompositeData cd) {226if (cd == null) {227return null;228}229230if (cd instanceof VMOptionCompositeData) {231return ((VMOptionCompositeData) cd).getVMOption();232} else {233return new VMOption(cd);234}235236}237238239}240241242