1 /*
2  * Copyright (c) 2003, 2017, Oracle and/or its affiliates. All rights reserved.
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * This code is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License version 2 only, as
7  * published by the Free Software Foundation.  Oracle designates this
8  * particular file as subject to the "Classpath" exception as provided
9  * by Oracle in the LICENSE file that accompanied this code.
10  *
11  * This code is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14  * version 2 for more details (a copy is included in the LICENSE file that
15  * accompanied this code).
16  *
17  * You should have received a copy of the GNU General Public License version
18  * 2 along with this work; if not, write to the Free Software Foundation,
19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20  *
21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22  * or visit www.oracle.com if you need additional information or have any
23  * questions.
24  */

25
26 package java.lang.management;
27
28 import java.security.AccessController;
29 import java.security.PrivilegedAction;
30
31 /**
32  * The management interface for the runtime system of
33  * the Java virtual machine.
34  *
35  * <p> A Java virtual machine has a single instance of the implementation
36  * class of this interface.  This instance implementing this interface is
37  * an <a href="ManagementFactory.html#MXBean">MXBean</a>
38  * that can be obtained by calling
39  * the {@link ManagementFactory#getRuntimeMXBean} method or
40  * from the {@link ManagementFactory#getPlatformMBeanServer
41  * platform MBeanServer} method.
42  *
43  * <p>The {@code ObjectName} for uniquely identifying the MXBean for
44  * the runtime system within an MBeanServer is:
45  * <blockquote>
46  *    {@link ManagementFactory#RUNTIME_MXBEAN_NAME
47  *           java.lang:type=Runtime}
48  * </blockquote>
49  *
50  * It can be obtained by calling the
51  * {@link PlatformManagedObject#getObjectName} method.
52  *
53  * <p> This interface defines several convenient methods for accessing
54  * system properties about the Java virtual machine.
55  *
56  * @see ManagementFactory#getPlatformMXBeans(Class)
57  * @see <a href="../../../javax/management/package-summary.html">
58  *      JMX Specification.</a>
59  * @see <a href="package-summary.html#examples">
60  *      Ways to Access MXBeans</a>
61  *
62  * @author  Mandy Chung
63  * @since   1.5
64  */

65 public interface RuntimeMXBean extends PlatformManagedObject {
66     /**
67      * Returns the {@linkplain ProcessHandle#pid process ID} representing
68      * the running Java virtual machine.
69      *
70      * @implSpec The default implementation returns {@link ProcessHandle#pid process ID}
71      * of the {@linkplain ProcessHandle#current current process}.
72      *
73      * @return the process ID representing the running Java virtual machine.
74      *
75      * @since 10
76      */

77     public default long getPid() {
78         return AccessController.doPrivileged((PrivilegedAction<Long>)
79                 () -> ProcessHandle.current().pid());
80     }
81
82     /**
83      * Returns the name representing the running Java virtual machine.
84      * The returned name string can be any arbitrary string and
85      * a Java virtual machine implementation can choose
86      * to embed platform-specific useful information in the
87      * returned name string.  Each running virtual machine could have
88      * a different name.
89      *
90      * @return the name representing the running Java virtual machine.
91      */

92     public String getName();
93
94     /**
95      * Returns the Java virtual machine implementation name.
96      * This method is equivalent to {@link System#getProperty
97      * System.getProperty("java.vm.name")}.
98      *
99      * @return the Java virtual machine implementation name.
100      *
101      * @throws  java.lang.SecurityException
102      *     if a security manager exists and its
103      *     {@code checkPropertiesAccess} method doesn't allow access
104      *     to this system property.
105      * @see java.lang.SecurityManager#checkPropertyAccess(java.lang.String)
106      * @see java.lang.System#getProperty
107      */

108     public String getVmName();
109
110     /**
111      * Returns the Java virtual machine implementation vendor.
112      * This method is equivalent to {@link System#getProperty
113      * System.getProperty("java.vm.vendor")}.
114      *
115      * @return the Java virtual machine implementation vendor.
116      *
117      * @throws  java.lang.SecurityException
118      *     if a security manager exists and its
119      *     {@code checkPropertiesAccess} method doesn't allow access
120      *     to this system property.
121      * @see java.lang.SecurityManager#checkPropertyAccess(java.lang.String)
122      * @see java.lang.System#getProperty
123      */

124     public String getVmVendor();
125
126     /**
127      * Returns the Java virtual machine implementation version.
128      * This method is equivalent to {@link System#getProperty
129      * System.getProperty("java.vm.version")}.
130      *
131      * @return the Java virtual machine implementation version.
132      *
133      * @throws  java.lang.SecurityException
134      *     if a security manager exists and its
135      *     {@code checkPropertiesAccess} method doesn't allow access
136      *     to this system property.
137      * @see java.lang.SecurityManager#checkPropertyAccess(java.lang.String)
138      * @see java.lang.System#getProperty
139      */

140     public String getVmVersion();
141
142     /**
143      * Returns the Java virtual machine specification name.
144      * This method is equivalent to {@link System#getProperty
145      * System.getProperty("java.vm.specification.name")}.
146      *
147      * @return the Java virtual machine specification name.
148      *
149      * @throws  java.lang.SecurityException
150      *     if a security manager exists and its
151      *     {@code checkPropertiesAccess} method doesn't allow access
152      *     to this system property.
153      * @see java.lang.SecurityManager#checkPropertyAccess(java.lang.String)
154      * @see java.lang.System#getProperty
155      */

156     public String getSpecName();
157
158     /**
159      * Returns the Java virtual machine specification vendor.
160      * This method is equivalent to {@link System#getProperty
161      * System.getProperty("java.vm.specification.vendor")}.
162      *
163      * @return the Java virtual machine specification vendor.
164      *
165      * @throws  java.lang.SecurityException
166      *     if a security manager exists and its
167      *     {@code checkPropertiesAccess} method doesn't allow access
168      *     to this system property.
169      * @see java.lang.SecurityManager#checkPropertyAccess(java.lang.String)
170      * @see java.lang.System#getProperty
171      */

172     public String getSpecVendor();
173
174     /**
175      * Returns the Java virtual machine specification version.
176      * This method is equivalent to {@link System#getProperty
177      * System.getProperty("java.vm.specification.version")}.
178      *
179      * @return the Java virtual machine specification version.
180      *
181      * @throws  java.lang.SecurityException
182      *     if a security manager exists and its
183      *     {@code checkPropertiesAccess} method doesn't allow access
184      *     to this system property.
185      * @see java.lang.SecurityManager#checkPropertyAccess(java.lang.String)
186      * @see java.lang.System#getProperty
187      */

188     public String getSpecVersion();
189
190
191     /**
192      * Returns the version of the specification for the management interface
193      * implemented by the running Java virtual machine.
194      *
195      * @return the version of the specification for the management interface
196      * implemented by the running Java virtual machine.
197      */

198     public String getManagementSpecVersion();
199
200     /**
201      * Returns the Java class path that is used by the system class loader
202      * to search for class files.
203      * This method is equivalent to {@link System#getProperty
204      * System.getProperty("java.class.path")}.
205      *
206      * <p> Multiple paths in the Java class path are separated by the
207      * path separator character of the platform of the Java virtual machine
208      * being monitored.
209      *
210      * @return the Java class path.
211      *
212      * @throws  java.lang.SecurityException
213      *     if a security manager exists and its
214      *     {@code checkPropertiesAccess} method doesn't allow access
215      *     to this system property.
216      * @see java.lang.SecurityManager#checkPropertyAccess(java.lang.String)
217      * @see java.lang.System#getProperty
218      */

219     public String getClassPath();
220
221     /**
222      * Returns the Java library path.
223      * This method is equivalent to {@link System#getProperty
224      * System.getProperty("java.library.path")}.
225      *
226      * <p> Multiple paths in the Java library path are separated by the
227      * path separator character of the platform of the Java virtual machine
228      * being monitored.
229      *
230      * @return the Java library path.
231      *
232      * @throws  java.lang.SecurityException
233      *     if a security manager exists and its
234      *     {@code checkPropertiesAccess} method doesn't allow access
235      *     to this system property.
236      * @see java.lang.SecurityManager#checkPropertyAccess(java.lang.String)
237      * @see java.lang.System#getProperty
238      */

239     public String getLibraryPath();
240
241     /**
242      * Tests if the Java virtual machine supports the boot class path
243      * mechanism used by the bootstrap class loader to search for class
244      * files.
245      *
246      * @return {@code trueif the Java virtual machine supports the
247      * class path mechanism; {@code false} otherwise.
248      */

249     public boolean isBootClassPathSupported();
250
251     /**
252      * Returns the boot class path that is used by the bootstrap class loader
253      * to search for class files.
254      *
255      * <p> Multiple paths in the boot class path are separated by the
256      * path separator character of the platform on which the Java
257      * virtual machine is running.
258      *
259      * <p>A Java virtual machine implementation may not support
260      * the boot class path mechanism for the bootstrap class loader
261      * to search for class files.
262      * The {@link #isBootClassPathSupported} method can be used
263      * to determine if the Java virtual machine supports this method.
264      *
265      * @return the boot class path.
266      *
267      * @throws java.lang.UnsupportedOperationException
268      *     if the Java virtual machine does not support this operation.
269      *
270      * @throws  java.lang.SecurityException
271      *     if a security manager exists and the caller does not have
272      *     ManagementPermission("monitor").
273      */

274     public String getBootClassPath();
275
276     /**
277      * Returns the input arguments passed to the Java virtual machine
278      * which does not include the arguments to the {@code main} method.
279      * This method returns an empty list if there is no input argument
280      * to the Java virtual machine.
281      * <p>
282      * Some Java virtual machine implementations may take input arguments
283      * from multiple different sources: for examples, arguments passed from
284      * the application that launches the Java virtual machine such as
285      * the 'java' command, environment variables, configuration files, etc.
286      * <p>
287      * Typically, not all command-line options to the 'java' command
288      * are passed to the Java virtual machine.
289      * Thus, the returned input arguments may not
290      * 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 element
297      * is an argument passed to the Java virtual machine.
298      *
299      * @throws  java.lang.SecurityException
300      *     if a security manager exists and the caller does not have
301      *     ManagementPermission("monitor").
302      */

303     public java.util.List<String> getInputArguments();
304
305     /**
306      * Returns the uptime of the Java virtual machine in milliseconds.
307      *
308      * @return uptime of the Java virtual machine in milliseconds.
309      */

310     public long getUptime();
311
312     /**
313      * Returns the start time of the Java virtual machine in milliseconds.
314      * This method returns the approximate time when the Java virtual
315      * machine started.
316      *
317      * @return start time of the Java virtual machine in milliseconds.
318      *
319      */

320     public long getStartTime();
321
322     /**
323      * Returns a map of names and values of all system properties.
324      * This method calls {@link System#getProperties} to get all
325      * system properties.  Properties whose name or value is not
326      * a {@code String} are omitted.
327      *
328      * <p>
329      * <b>MBeanServer access</b>:<br>
330      * The mapped type of {@code Map<String,String>} is
331      * {@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.SecurityException
356      *     if a security manager exists and its
357      *     {@code checkPropertiesAccess} method doesn't allow access
358      *     to the system properties.
359      */

360     public java.util.Map<String, String> getSystemProperties();
361 }
362