1 /*
2  * Copyright (c) 2003, 2013, 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 sun.management;
27 
28 import java.lang.management.RuntimeMXBean;
29 import java.lang.management.ManagementFactory;
30 
31 import java.util.List;
32 import java.util.HashMap;
33 import java.util.Map;
34 import java.util.Set;
35 import java.util.Properties;
36 import javax.management.ObjectName;
37 
38 /**
39  * Implementation class for the runtime subsystem.
40  * Standard and committed hotspot-specific metrics if any.
41  *
42  * ManagementFactory.getRuntimeMXBean() returns an instance
43  * of this class.
44  */
45 class RuntimeImpl implements RuntimeMXBean {
46 
47     private final VMManagement jvm;
48     private final long vmStartupTime;
49 
50     /**
51      * Constructor of RuntimeImpl class.
52      */
RuntimeImpl(VMManagement vm)53     RuntimeImpl(VMManagement vm) {
54         this.jvm = vm;
55         this.vmStartupTime = jvm.getStartupTime();
56     }
57 
getName()58     public String getName() {
59         return jvm.getVmId();
60     }
61 
getManagementSpecVersion()62     public String getManagementSpecVersion() {
63         return jvm.getManagementVersion();
64     }
65 
getVmName()66     public String getVmName() {
67         return jvm.getVmName();
68     }
69 
getVmVendor()70     public String getVmVendor() {
71         return jvm.getVmVendor();
72     }
73 
getVmVersion()74     public String getVmVersion() {
75         return jvm.getVmVersion();
76     }
77 
getSpecName()78     public String getSpecName() {
79         return jvm.getVmSpecName();
80     }
81 
getSpecVendor()82     public String getSpecVendor() {
83         return jvm.getVmSpecVendor();
84     }
85 
getSpecVersion()86     public String getSpecVersion() {
87         return jvm.getVmSpecVersion();
88     }
89 
getClassPath()90     public String getClassPath() {
91         return jvm.getClassPath();
92     }
93 
getLibraryPath()94     public String getLibraryPath() {
95         return jvm.getLibraryPath();
96     }
97 
getBootClassPath()98     public String getBootClassPath() {
99         throw new UnsupportedOperationException(
100             "Boot class path mechanism is not supported");
101     }
102 
getInputArguments()103     public List<String> getInputArguments() {
104         Util.checkMonitorAccess();
105         return jvm.getVmArguments();
106     }
107 
getUptime()108     public long getUptime() {
109         return jvm.getUptime();
110     }
111 
getStartTime()112     public long getStartTime() {
113         return vmStartupTime;
114     }
115 
isBootClassPathSupported()116     public boolean isBootClassPathSupported() {
117         return false;
118     }
119 
getSystemProperties()120     public Map<String,String> getSystemProperties() {
121         Properties sysProps = System.getProperties();
122         Map<String,String> map = new HashMap<>();
123 
124         // Properties.entrySet() does not include the entries in
125         // the default properties.  So use Properties.stringPropertyNames()
126         // to get the list of property keys including the default ones.
127         Set<String> keys = sysProps.stringPropertyNames();
128         for (String k : keys) {
129             String value = sysProps.getProperty(k);
130             map.put(k, value);
131         }
132 
133         return map;
134     }
135 
getObjectName()136     public ObjectName getObjectName() {
137         return Util.newObjectName(ManagementFactory.RUNTIME_MXBEAN_NAME);
138     }
139 
140 }
141