src/java.management/share/classes/sun/management/VMManagementImpl.java
author erikj
Tue, 12 Sep 2017 19:03:39 +0200
changeset 47216 71c04702a3d5
parent 42102 jdk/src/java.management/share/classes/sun/management/VMManagementImpl.java@3e0a2861efe1
permissions -rw-r--r--
8187443: Forest Consolidation: Move files to unified layout Reviewed-by: darcy, ihse
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
42102
3e0a2861efe1 8151099: java.lang.management.ManagementFactory.getPlatformMXBeans() should work even if jdk.management is not present.
vtewari
parents: 36511
diff changeset
     2
 * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package sun.management;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
34953
67245e3259bf 8146736: Move sun.misc performance counters to jdk.internal.perf
chegar
parents: 25859
diff changeset
    28
import jdk.internal.perf.Perf;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import sun.management.counter.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import sun.management.counter.perf.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.nio.ByteBuffer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.net.InetAddress;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.net.UnknownHostException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.util.List;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.util.Arrays;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.util.Collections;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.security.AccessController;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.security.PrivilegedAction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * Implementation of VMManagement interface that accesses the management
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * attributes and operations locally within the same Java virtual
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * machine.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
class VMManagementImpl implements VMManagement {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    private static String version;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    private static boolean compTimeMonitoringSupport;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    private static boolean threadContentionMonitoringSupport;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    private static boolean currentThreadCpuTimeSupport;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    private static boolean otherThreadCpuTimeSupport;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    private static boolean objectMonitorUsageSupport;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    private static boolean synchronizerUsageSupport;
8001
192adf3627b7 6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents: 5506
diff changeset
    56
    private static boolean threadAllocatedMemorySupport;
9698
8b66cd6c5ebc 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents: 8001
diff changeset
    57
    private static boolean gcNotificationSupport;
17954
885a02686acb 7150256: Add back Diagnostic Command JMX API
fparain
parents: 9698
diff changeset
    58
    private static boolean remoteDiagnosticCommandsSupport;
9698
8b66cd6c5ebc 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents: 8001
diff changeset
    59
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        version = getVersion0();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        if (version == null) {
401
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
    64
            throw new AssertionError("Invalid Management Version");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        initOptionalSupportFields();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    private native static String getVersion0();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    private native static void initOptionalSupportFields();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    // Optional supports
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    public boolean isCompilationTimeMonitoringSupported() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        return compTimeMonitoringSupport;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    public boolean isThreadContentionMonitoringSupported() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        return threadContentionMonitoringSupport;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    public boolean isCurrentThreadCpuTimeSupported() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        return currentThreadCpuTimeSupport;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    public boolean isOtherThreadCpuTimeSupported() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        return otherThreadCpuTimeSupport;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    public boolean isBootClassPathSupported() {
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 34953
diff changeset
    89
        return false;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    public boolean isObjectMonitorUsageSupported() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        return objectMonitorUsageSupport;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    public boolean isSynchronizerUsageSupported() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        return synchronizerUsageSupport;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
8001
192adf3627b7 6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents: 5506
diff changeset
   100
    public boolean isThreadAllocatedMemorySupported() {
192adf3627b7 6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents: 5506
diff changeset
   101
        return threadAllocatedMemorySupport;
192adf3627b7 6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents: 5506
diff changeset
   102
    }
192adf3627b7 6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents: 5506
diff changeset
   103
9698
8b66cd6c5ebc 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents: 8001
diff changeset
   104
    public boolean isGcNotificationSupported() {
42102
3e0a2861efe1 8151099: java.lang.management.ManagementFactory.getPlatformMXBeans() should work even if jdk.management is not present.
vtewari
parents: 36511
diff changeset
   105
        boolean isSupported = true;
3e0a2861efe1 8151099: java.lang.management.ManagementFactory.getPlatformMXBeans() should work even if jdk.management is not present.
vtewari
parents: 36511
diff changeset
   106
        try {
3e0a2861efe1 8151099: java.lang.management.ManagementFactory.getPlatformMXBeans() should work even if jdk.management is not present.
vtewari
parents: 36511
diff changeset
   107
            Class.forName("com.sun.management.GarbageCollectorMXBean");
3e0a2861efe1 8151099: java.lang.management.ManagementFactory.getPlatformMXBeans() should work even if jdk.management is not present.
vtewari
parents: 36511
diff changeset
   108
        } catch (ClassNotFoundException x) {
3e0a2861efe1 8151099: java.lang.management.ManagementFactory.getPlatformMXBeans() should work even if jdk.management is not present.
vtewari
parents: 36511
diff changeset
   109
            isSupported = false;
3e0a2861efe1 8151099: java.lang.management.ManagementFactory.getPlatformMXBeans() should work even if jdk.management is not present.
vtewari
parents: 36511
diff changeset
   110
        }
3e0a2861efe1 8151099: java.lang.management.ManagementFactory.getPlatformMXBeans() should work even if jdk.management is not present.
vtewari
parents: 36511
diff changeset
   111
        return isSupported;
9698
8b66cd6c5ebc 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents: 8001
diff changeset
   112
    }
8b66cd6c5ebc 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents: 8001
diff changeset
   113
17954
885a02686acb 7150256: Add back Diagnostic Command JMX API
fparain
parents: 9698
diff changeset
   114
    public boolean isRemoteDiagnosticCommandsSupported() {
885a02686acb 7150256: Add back Diagnostic Command JMX API
fparain
parents: 9698
diff changeset
   115
        return remoteDiagnosticCommandsSupport;
885a02686acb 7150256: Add back Diagnostic Command JMX API
fparain
parents: 9698
diff changeset
   116
    }
885a02686acb 7150256: Add back Diagnostic Command JMX API
fparain
parents: 9698
diff changeset
   117
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    public native boolean isThreadContentionMonitoringEnabled();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    public native boolean isThreadCpuTimeEnabled();
8001
192adf3627b7 6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents: 5506
diff changeset
   120
    public native boolean isThreadAllocatedMemoryEnabled();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    // Class Loading Subsystem
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    public int    getLoadedClassCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        long count = getTotalClassCount() - getUnloadedClassCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        return (int) count;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    public native long getTotalClassCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    public native long getUnloadedClassCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    public native boolean getVerboseClass();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    // Memory Subsystem
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    public native boolean getVerboseGC();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    // Runtime Subsystem
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    public String   getManagementVersion() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        return version;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    public String getVmId() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        int pid = getProcessId();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        String hostname = "localhost";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
            hostname = InetAddress.getLocalHost().getHostName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        } catch (UnknownHostException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
            // ignore
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        return pid + "@" + hostname;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    private native int getProcessId();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    public String   getVmName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        return System.getProperty("java.vm.name");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    public String   getVmVendor() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        return System.getProperty("java.vm.vendor");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    public String   getVmVersion() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        return System.getProperty("java.vm.version");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    public String   getVmSpecName()  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        return System.getProperty("java.vm.specification.name");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    public String   getVmSpecVendor() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        return System.getProperty("java.vm.specification.vendor");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    public String   getVmSpecVersion() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        return System.getProperty("java.vm.specification.version");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    public String   getClassPath() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        return System.getProperty("java.class.path");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    public String   getLibraryPath()  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        return System.getProperty("java.library.path");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    public String   getBootClassPath( ) {
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 34953
diff changeset
   180
        throw new UnsupportedOperationException(
9d0388c6b336 8142968: Module System implementation
alanb
parents: 34953
diff changeset
   181
            "Boot class path mechanism is not supported");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
21640
6bbdcc430310 6523160: RuntimeMXBean.getUptime() returns negative values
jbachorik
parents: 17954
diff changeset
   184
    public long getUptime() {
6bbdcc430310 6523160: RuntimeMXBean.getUptime() returns negative values
jbachorik
parents: 17954
diff changeset
   185
        return getUptime0();
6bbdcc430310 6523160: RuntimeMXBean.getUptime() returns negative values
jbachorik
parents: 17954
diff changeset
   186
    }
6bbdcc430310 6523160: RuntimeMXBean.getUptime() returns negative values
jbachorik
parents: 17954
diff changeset
   187
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    private List<String> vmArgs = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    public synchronized List<String> getVmArguments() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        if (vmArgs == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
            String[] args = getVmArguments0();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
            List<String> l = ((args != null && args.length != 0) ? Arrays.asList(args) :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
                                        Collections.<String>emptyList());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
            vmArgs = Collections.unmodifiableList(l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        return vmArgs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    public native String[] getVmArguments0();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    public native long getStartupTime();
21640
6bbdcc430310 6523160: RuntimeMXBean.getUptime() returns negative values
jbachorik
parents: 17954
diff changeset
   201
    private native long getUptime0();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    public native int getAvailableProcessors();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    // Compilation Subsystem
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    public String   getCompilerName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        String name =  AccessController.doPrivileged(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
            new PrivilegedAction<String>() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
                public String run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
                    return System.getProperty("sun.management.compiler");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
            });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        return name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    public native long getTotalCompileTime();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    // Thread Subsystem
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    public native long getTotalThreadCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    public native int  getLiveThreadCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
    public native int  getPeakThreadCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    public native int  getDaemonThreadCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    // Operating System
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    public String getOsName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        return System.getProperty("os.name");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
    public String getOsArch() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        return System.getProperty("os.arch");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    public String getOsVersion() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        return System.getProperty("os.version");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    // Hotspot-specific runtime support
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    public native long getSafepointCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    public native long getTotalSafepointTime();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    public native long getSafepointSyncTime();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    public native long getTotalApplicationNonStoppedTime();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    public native long getLoadedClassSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    public native long getUnloadedClassSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
    public native long getClassLoadingTime();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    public native long getMethodDataSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
    public native long getInitializedClassCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    public native long getClassInitializationTime();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
    public native long getClassVerificationTime();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    // Performance Counter Support
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
    private PerfInstrumentation perfInstr = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
    private boolean noPerfData = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
    private synchronized PerfInstrumentation getPerfInstrumentation() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        if (noPerfData || perfInstr != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
             return perfInstr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        // construct PerfInstrumentation object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        Perf perf =  AccessController.doPrivileged(new Perf.GetPerfAction());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
            ByteBuffer bb = perf.attach(0, "r");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
            if (bb.capacity() == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
                noPerfData = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
            perfInstr = new PerfInstrumentation(bb);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        } catch (IllegalArgumentException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
            // If the shared memory doesn't exist e.g. if -XX:-UsePerfData
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
            // was set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
            noPerfData = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        } catch (IOException e) {
401
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   270
            throw new AssertionError(e);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        return perfInstr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    public List<Counter> getInternalCounters(String pattern) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        PerfInstrumentation perf = getPerfInstrumentation();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
        if (perf != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
            return perf.findByPattern(pattern);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
            return Collections.emptyList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
}