Path: blob/master/src/java.management/share/classes/java/lang/management/RuntimeMXBean.java
41159 views
/*1* Copyright (c) 2003, 2021, 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 java.lang.management;2627import java.security.AccessController;28import java.security.PrivilegedAction;2930/**31* The management interface for the runtime system of32* the Java virtual machine.33*34* <p> A Java virtual machine has a single instance of the implementation35* class of this interface. This instance implementing this interface is36* an <a href="ManagementFactory.html#MXBean">MXBean</a>37* that can be obtained by calling38* the {@link ManagementFactory#getRuntimeMXBean} method or39* from the {@link ManagementFactory#getPlatformMBeanServer40* platform MBeanServer} method.41*42* <p>The {@code ObjectName} for uniquely identifying the MXBean for43* the runtime system within an MBeanServer is:44* <blockquote>45* {@link ManagementFactory#RUNTIME_MXBEAN_NAME46* java.lang:type=Runtime}47* </blockquote>48*49* It can be obtained by calling the50* {@link PlatformManagedObject#getObjectName} method.51*52* <p> This interface defines several convenient methods for accessing53* system properties about the Java virtual machine.54*55* @see ManagementFactory#getPlatformMXBeans(Class)56* @see <a href="../../../javax/management/package-summary.html">57* JMX Specification.</a>58* @see <a href="package-summary.html#examples">59* Ways to Access MXBeans</a>60*61* @author Mandy Chung62* @since 1.563*/64public interface RuntimeMXBean extends PlatformManagedObject {65/**66* Returns the {@linkplain ProcessHandle#pid process ID} representing67* the running Java virtual machine.68*69* @implSpec The default implementation returns {@link ProcessHandle#pid process ID}70* of the {@linkplain ProcessHandle#current current process}.71*72* @return the process ID representing the running Java virtual machine.73*74* @since 1075*/76@SuppressWarnings("removal")77public default long getPid() {78return AccessController.doPrivileged((PrivilegedAction<Long>)79() -> ProcessHandle.current().pid());80}8182/**83* Returns the name representing the running Java virtual machine.84* The returned name string can be any arbitrary string and85* a Java virtual machine implementation can choose86* to embed platform-specific useful information in the87* returned name string. Each running virtual machine could have88* a different name.89*90* @return the name representing the running Java virtual machine.91*/92public String getName();9394/**95* Returns the Java virtual machine implementation name.96* This method is equivalent to {@link System#getProperty97* System.getProperty("java.vm.name")}.98*99* @return the Java virtual machine implementation name.100*101* @throws java.lang.SecurityException102* if a security manager exists and its103* {@code checkPropertiesAccess} method doesn't allow access104* to this system property.105* @see java.lang.SecurityManager#checkPropertyAccess(java.lang.String)106* @see java.lang.System#getProperty107*/108public String getVmName();109110/**111* Returns the Java virtual machine implementation vendor.112* This method is equivalent to {@link System#getProperty113* System.getProperty("java.vm.vendor")}.114*115* @return the Java virtual machine implementation vendor.116*117* @throws java.lang.SecurityException118* if a security manager exists and its119* {@code checkPropertiesAccess} method doesn't allow access120* to this system property.121* @see java.lang.SecurityManager#checkPropertyAccess(java.lang.String)122* @see java.lang.System#getProperty123*/124public String getVmVendor();125126/**127* Returns the Java virtual machine implementation version.128* This method is equivalent to {@link System#getProperty129* System.getProperty("java.vm.version")}.130*131* @return the Java virtual machine implementation version.132*133* @throws java.lang.SecurityException134* if a security manager exists and its135* {@code checkPropertiesAccess} method doesn't allow access136* to this system property.137* @see java.lang.SecurityManager#checkPropertyAccess(java.lang.String)138* @see java.lang.System#getProperty139*/140public String getVmVersion();141142/**143* Returns the Java virtual machine specification name.144* This method is equivalent to {@link System#getProperty145* System.getProperty("java.vm.specification.name")}.146*147* @return the Java virtual machine specification name.148*149* @throws java.lang.SecurityException150* if a security manager exists and its151* {@code checkPropertiesAccess} method doesn't allow access152* to this system property.153* @see java.lang.SecurityManager#checkPropertyAccess(java.lang.String)154* @see java.lang.System#getProperty155*/156public String getSpecName();157158/**159* Returns the Java virtual machine specification vendor.160* This method is equivalent to {@link System#getProperty161* System.getProperty("java.vm.specification.vendor")}.162*163* @return the Java virtual machine specification vendor.164*165* @throws java.lang.SecurityException166* if a security manager exists and its167* {@code checkPropertiesAccess} method doesn't allow access168* to this system property.169* @see java.lang.SecurityManager#checkPropertyAccess(java.lang.String)170* @see java.lang.System#getProperty171*/172public String getSpecVendor();173174/**175* Returns the Java virtual machine specification version.176* This method is equivalent to {@link System#getProperty177* System.getProperty("java.vm.specification.version")}.178*179* @return the Java virtual machine specification version.180*181* @throws java.lang.SecurityException182* if a security manager exists and its183* {@code checkPropertiesAccess} method doesn't allow access184* to this system property.185* @see java.lang.SecurityManager#checkPropertyAccess(java.lang.String)186* @see java.lang.System#getProperty187*/188public String getSpecVersion();189190191/**192* Returns the version of the specification for the management interface193* implemented by the running Java virtual machine.194*195* @return the version of the specification for the management interface196* implemented by the running Java virtual machine.197*/198public String getManagementSpecVersion();199200/**201* Returns the Java class path that is used by the system class loader202* to search for class files.203* This method is equivalent to {@link System#getProperty204* System.getProperty("java.class.path")}.205*206* <p> Multiple paths in the Java class path are separated by the207* path separator character of the platform of the Java virtual machine208* being monitored.209*210* @return the Java class path.211*212* @throws java.lang.SecurityException213* if a security manager exists and its214* {@code checkPropertiesAccess} method doesn't allow access215* to this system property.216* @see java.lang.SecurityManager#checkPropertyAccess(java.lang.String)217* @see java.lang.System#getProperty218*/219public String getClassPath();220221/**222* Returns the Java library path.223* This method is equivalent to {@link System#getProperty224* System.getProperty("java.library.path")}.225*226* <p> Multiple paths in the Java library path are separated by the227* path separator character of the platform of the Java virtual machine228* being monitored.229*230* @return the Java library path.231*232* @throws java.lang.SecurityException233* if a security manager exists and its234* {@code checkPropertiesAccess} method doesn't allow access235* to this system property.236* @see java.lang.SecurityManager#checkPropertyAccess(java.lang.String)237* @see java.lang.System#getProperty238*/239public String getLibraryPath();240241/**242* Tests if the Java virtual machine supports the boot class path243* mechanism used by the bootstrap class loader to search for class244* files.245*246* @return {@code true} if the Java virtual machine supports the247* class path mechanism; {@code false} otherwise.248*/249public boolean isBootClassPathSupported();250251/**252* Returns the boot class path that is used by the bootstrap class loader253* to search for class files.254*255* <p> Multiple paths in the boot class path are separated by the256* path separator character of the platform on which the Java257* virtual machine is running.258*259* <p>A Java virtual machine implementation may not support260* the boot class path mechanism for the bootstrap class loader261* to search for class files.262* The {@link #isBootClassPathSupported} method can be used263* to determine if the Java virtual machine supports this method.264*265* @return the boot class path.266*267* @throws java.lang.UnsupportedOperationException268* if the Java virtual machine does not support this operation.269*270* @throws java.lang.SecurityException271* if a security manager exists and the caller does not have272* ManagementPermission("monitor").273*/274public String getBootClassPath();275276/**277* Returns the input arguments passed to the Java virtual machine278* which does not include the arguments to the {@code main} method.279* This method returns an empty list if there is no input argument280* to the Java virtual machine.281* <p>282* Some Java virtual machine implementations may take input arguments283* from multiple different sources: for examples, arguments passed from284* the application that launches the Java virtual machine such as285* the 'java' command, environment variables, configuration files, etc.286* <p>287* Typically, not all command-line options to the 'java' command288* are passed to the Java virtual machine.289* Thus, the returned input arguments may not290* include all command-line options.291*292* <p>293* <b>MBeanServer access</b>:<br>294* The mapped type of {@code List<String>} is {@code String[]}.295*296* @return a list of {@code String} objects; each element297* is an argument passed to the Java virtual machine.298*299* @throws java.lang.SecurityException300* if a security manager exists and the caller does not have301* ManagementPermission("monitor").302*/303public java.util.List<String> getInputArguments();304305/**306* Returns the uptime of the Java virtual machine in milliseconds.307*308* @return uptime of the Java virtual machine in milliseconds.309*/310public long getUptime();311312/**313* Returns the start time of the Java virtual machine in milliseconds.314* This method returns the approximate time when the Java virtual315* machine started.316*317* @return start time of the Java virtual machine in milliseconds.318*319*/320public long getStartTime();321322/**323* Returns a map of names and values of all system properties.324* This method calls {@link System#getProperties} to get all325* system properties. Properties whose name or value is not326* a {@code String} are omitted.327*328* <p>329* <b>MBeanServer access</b>:<br>330* The mapped type of {@code Map<String,String>} is331* {@link javax.management.openmbean.TabularData TabularData}332* with two items in each row as follows:333* <table class="striped" style="margin-left:2em">334* <caption style="display:none">Name and Type for each item</caption>335* <thead>336* <tr>337* <th scope="col">Item Name</th>338* <th scope="col">Item Type</th>339* </tr>340* </thead>341* <tbody>342* <tr style="text-align:left">343* <th scope="row">{@code key}</th>344* <td>{@code String}</td>345* </tr>346* <tr>347* <th scope="row">{@code value}</th>348* <td>{@code String}</td>349* </tr>350* </tbody>351* </table>352*353* @return a map of names and values of all system properties.354*355* @throws java.lang.SecurityException356* if a security manager exists and its357* {@code checkPropertiesAccess} method doesn't allow access358* to the system properties.359*/360public java.util.Map<String, String> getSystemProperties();361}362363364