jdk/src/share/classes/sun/management/VMManagementImpl.java
author fparain
Mon, 16 May 2011 17:28:18 +0200
changeset 9698 8b66cd6c5ebc
parent 8001 192adf3627b7
child 17954 885a02686acb
permissions -rw-r--r--
7036199: Adding a notification to the implementation of GarbageCollectorMXBeans Summary: Add a JMX notification to GarbageCollectorMXBeans Reviewed-by: acorn, mchung
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
8001
192adf3627b7 6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents: 5506
diff changeset
     2
 * Copyright (c) 2003, 2011, 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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import sun.misc.Perf;
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
import sun.security.action.GetPropertyAction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * Implementation of VMManagement interface that accesses the management
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * attributes and operations locally within the same Java virtual
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * machine.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
class VMManagementImpl implements VMManagement {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    private static String version;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    private static boolean compTimeMonitoringSupport;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    private static boolean threadContentionMonitoringSupport;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    private static boolean currentThreadCpuTimeSupport;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    private static boolean otherThreadCpuTimeSupport;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    private static boolean bootClassPathSupport;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    private static boolean objectMonitorUsageSupport;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    private static boolean synchronizerUsageSupport;
8001
192adf3627b7 6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents: 5506
diff changeset
    58
    private static boolean threadAllocatedMemorySupport;
9698
8b66cd6c5ebc 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents: 8001
diff changeset
    59
    private static boolean gcNotificationSupport;
8b66cd6c5ebc 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents: 8001
diff changeset
    60
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        version = getVersion0();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        if (version == null) {
401
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
    65
            throw new AssertionError("Invalid Management Version");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        initOptionalSupportFields();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    private native static String getVersion0();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    private native static void initOptionalSupportFields();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    // Optional supports
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    public boolean isCompilationTimeMonitoringSupported() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        return compTimeMonitoringSupport;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    public boolean isThreadContentionMonitoringSupported() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        return threadContentionMonitoringSupport;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    public boolean isCurrentThreadCpuTimeSupported() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        return currentThreadCpuTimeSupport;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    public boolean isOtherThreadCpuTimeSupported() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        return otherThreadCpuTimeSupport;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    public boolean isBootClassPathSupported() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        return bootClassPathSupport;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    public boolean isObjectMonitorUsageSupported() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        return objectMonitorUsageSupport;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    public boolean isSynchronizerUsageSupported() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        return synchronizerUsageSupport;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
8001
192adf3627b7 6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents: 5506
diff changeset
   101
    public boolean isThreadAllocatedMemorySupported() {
192adf3627b7 6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents: 5506
diff changeset
   102
        return threadAllocatedMemorySupport;
192adf3627b7 6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents: 5506
diff changeset
   103
    }
192adf3627b7 6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents: 5506
diff changeset
   104
9698
8b66cd6c5ebc 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents: 8001
diff changeset
   105
    public boolean isGcNotificationSupported() {
8b66cd6c5ebc 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents: 8001
diff changeset
   106
        return gcNotificationSupport;
8b66cd6c5ebc 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents: 8001
diff changeset
   107
    }
8b66cd6c5ebc 7036199: Adding a notification to the implementation of GarbageCollectorMXBeans
fparain
parents: 8001
diff changeset
   108
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    public native boolean isThreadContentionMonitoringEnabled();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    public native boolean isThreadCpuTimeEnabled();
8001
192adf3627b7 6173675: M&M: approximate memory allocation rate/amount per thread
phh
parents: 5506
diff changeset
   111
    public native boolean isThreadAllocatedMemoryEnabled();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    // Class Loading Subsystem
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    public int    getLoadedClassCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        long count = getTotalClassCount() - getUnloadedClassCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        return (int) count;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    public native long getTotalClassCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    public native long getUnloadedClassCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    public native boolean getVerboseClass();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    // Memory Subsystem
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    public native boolean getVerboseGC();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    // Runtime Subsystem
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    public String   getManagementVersion() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        return version;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    public String getVmId() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        int pid = getProcessId();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        String hostname = "localhost";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
            hostname = InetAddress.getLocalHost().getHostName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        } catch (UnknownHostException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
            // ignore
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        return pid + "@" + hostname;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    private native int getProcessId();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    public String   getVmName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        return System.getProperty("java.vm.name");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    public String   getVmVendor() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        return System.getProperty("java.vm.vendor");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    public String   getVmVersion() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        return System.getProperty("java.vm.version");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    public String   getVmSpecName()  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        return System.getProperty("java.vm.specification.name");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    public String   getVmSpecVendor() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        return System.getProperty("java.vm.specification.vendor");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    public String   getVmSpecVersion() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        return System.getProperty("java.vm.specification.version");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    public String   getClassPath() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        return System.getProperty("java.class.path");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    public String   getLibraryPath()  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        return System.getProperty("java.library.path");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    public String   getBootClassPath( ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        PrivilegedAction<String> pa
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
            = new GetPropertyAction("sun.boot.class.path");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        String result =  AccessController.doPrivileged(pa);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    private List<String> vmArgs = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    public synchronized List<String> getVmArguments() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        if (vmArgs == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
            String[] args = getVmArguments0();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
            List<String> l = ((args != null && args.length != 0) ? Arrays.asList(args) :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
                                        Collections.<String>emptyList());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
            vmArgs = Collections.unmodifiableList(l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        return vmArgs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    public native String[] getVmArguments0();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    public native long getStartupTime();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    public native int getAvailableProcessors();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    // Compilation Subsystem
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    public String   getCompilerName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        String name =  AccessController.doPrivileged(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
            new PrivilegedAction<String>() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
                public String run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
                    return System.getProperty("sun.management.compiler");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
            });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        return name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    public native long getTotalCompileTime();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    // Thread Subsystem
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    public native long getTotalThreadCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    public native int  getLiveThreadCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    public native int  getPeakThreadCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    public native int  getDaemonThreadCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    // Operating System
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    public String getOsName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        return System.getProperty("os.name");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    public String getOsArch() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        return System.getProperty("os.arch");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    public String getOsVersion() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        return System.getProperty("os.version");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    // Hotspot-specific runtime support
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    public native long getSafepointCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    public native long getTotalSafepointTime();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    public native long getSafepointSyncTime();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    public native long getTotalApplicationNonStoppedTime();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    public native long getLoadedClassSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
    public native long getUnloadedClassSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    public native long getClassLoadingTime();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    public native long getMethodDataSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    public native long getInitializedClassCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    public native long getClassInitializationTime();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    public native long getClassVerificationTime();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    // Performance Counter Support
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    private PerfInstrumentation perfInstr = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    private boolean noPerfData = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    private synchronized PerfInstrumentation getPerfInstrumentation() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        if (noPerfData || perfInstr != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
             return perfInstr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        // construct PerfInstrumentation object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        Perf perf =  AccessController.doPrivileged(new Perf.GetPerfAction());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
            ByteBuffer bb = perf.attach(0, "r");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
            if (bb.capacity() == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
                noPerfData = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
            perfInstr = new PerfInstrumentation(bb);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        } catch (IllegalArgumentException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
            // If the shared memory doesn't exist e.g. if -XX:-UsePerfData
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
            // was set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
            noPerfData = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        } catch (IOException e) {
401
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   258
            throw new AssertionError(e);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        return perfInstr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
    public List<Counter> getInternalCounters(String pattern) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        PerfInstrumentation perf = getPerfInstrumentation();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        if (perf != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
            return perf.findByPattern(pattern);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
            return Collections.emptyList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
}