src/share/vm/services/jmm.h

Fri, 14 Jan 2011 13:47:53 -0500

author
coleenp
date
Fri, 14 Jan 2011 13:47:53 -0500
changeset 2463
17c778814856
parent 2423
b1a2afa37ec4
child 2888
78542e2b5e35
permissions
-rw-r--r--

6811367: Fix code in HeapDumper::dump_heap() to avoid buffer overrun
Summary: Check buffer size before using and use dynamic buffer sizes for subsequent calls.
Reviewed-by: kamg, dholmes

duke@435 1 /*
phh@2423 2 * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
duke@435 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@435 4 *
duke@435 5 * This code is free software; you can redistribute it and/or modify it
duke@435 6 * under the terms of the GNU General Public License version 2 only, as
trims@1907 7 * published by the Free Software Foundation. Oracle designates this
duke@435 8 * particular file as subject to the "Classpath" exception as provided
trims@1907 9 * by Oracle in the LICENSE file that accompanied this code.
duke@435 10 *
duke@435 11 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@435 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@435 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@435 14 * version 2 for more details (a copy is included in the LICENSE file that
duke@435 15 * accompanied this code).
duke@435 16 *
duke@435 17 * You should have received a copy of the GNU General Public License version
duke@435 18 * 2 along with this work; if not, write to the Free Software Foundation,
duke@435 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@435 20 *
trims@1907 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@1907 22 * or visit www.oracle.com if you need additional information or have any
trims@1907 23 * questions.
duke@435 24 */
duke@435 25
duke@435 26 #ifndef _JAVA_JMM_H_
duke@435 27 #define _JAVA_JMM_H_
duke@435 28
duke@435 29 /*
duke@435 30 * This is a private interface used by JDK for JVM monitoring
duke@435 31 * and management.
duke@435 32 *
duke@435 33 * Bump the version number when either of the following happens:
duke@435 34 *
duke@435 35 * 1. There is a change in functions in JmmInterface.
duke@435 36 *
duke@435 37 * 2. There is a change in the contract between VM and Java classes.
duke@435 38 */
duke@435 39
duke@435 40 #include "jni.h"
duke@435 41
duke@435 42 #ifdef __cplusplus
duke@435 43 extern "C" {
duke@435 44 #endif
duke@435 45
duke@435 46 enum {
duke@435 47 JMM_VERSION_1 = 0x20010000,
duke@435 48 JMM_VERSION_1_0 = 0x20010000,
duke@435 49 JMM_VERSION_1_1 = 0x20010100, // JDK 6
duke@435 50 JMM_VERSION_1_2 = 0x20010200, // JDK 7
duke@435 51 JMM_VERSION = 0x20010200
duke@435 52 };
duke@435 53
duke@435 54 typedef struct {
duke@435 55 unsigned int isLowMemoryDetectionSupported : 1;
duke@435 56 unsigned int isCompilationTimeMonitoringSupported : 1;
duke@435 57 unsigned int isThreadContentionMonitoringSupported : 1;
duke@435 58 unsigned int isCurrentThreadCpuTimeSupported : 1;
duke@435 59 unsigned int isOtherThreadCpuTimeSupported : 1;
duke@435 60 unsigned int isBootClassPathSupported : 1;
duke@435 61 unsigned int isObjectMonitorUsageSupported : 1;
duke@435 62 unsigned int isSynchronizerUsageSupported : 1;
phh@2423 63 unsigned int isThreadAllocatedMemorySupported : 1;
phh@2423 64 unsigned int : 23;
duke@435 65 } jmmOptionalSupport;
duke@435 66
duke@435 67 typedef enum {
duke@435 68 JMM_CLASS_LOADED_COUNT = 1, /* Total number of loaded classes */
duke@435 69 JMM_CLASS_UNLOADED_COUNT = 2, /* Total number of unloaded classes */
duke@435 70 JMM_THREAD_TOTAL_COUNT = 3, /* Total number of threads that have been started */
duke@435 71 JMM_THREAD_LIVE_COUNT = 4, /* Current number of live threads */
duke@435 72 JMM_THREAD_PEAK_COUNT = 5, /* Peak number of live threads */
duke@435 73 JMM_THREAD_DAEMON_COUNT = 6, /* Current number of daemon threads */
duke@435 74 JMM_JVM_INIT_DONE_TIME_MS = 7, /* Time when the JVM finished initialization */
duke@435 75 JMM_COMPILE_TOTAL_TIME_MS = 8, /* Total accumulated time spent in compilation */
duke@435 76 JMM_GC_TIME_MS = 9, /* Total accumulated time spent in collection */
duke@435 77 JMM_GC_COUNT = 10, /* Total number of collections */
duke@435 78
duke@435 79 JMM_INTERNAL_ATTRIBUTE_INDEX = 100,
duke@435 80 JMM_CLASS_LOADED_BYTES = 101, /* Number of bytes loaded instance classes */
duke@435 81 JMM_CLASS_UNLOADED_BYTES = 102, /* Number of bytes unloaded instance classes */
duke@435 82 JMM_TOTAL_CLASSLOAD_TIME_MS = 103, /* Accumulated VM class loader time (TraceClassLoadingTime) */
duke@435 83 JMM_VM_GLOBAL_COUNT = 104, /* Number of VM internal flags */
duke@435 84 JMM_SAFEPOINT_COUNT = 105, /* Total number of safepoints */
duke@435 85 JMM_TOTAL_SAFEPOINTSYNC_TIME_MS = 106, /* Accumulated time spent getting to safepoints */
duke@435 86 JMM_TOTAL_STOPPED_TIME_MS = 107, /* Accumulated time spent at safepoints */
duke@435 87 JMM_TOTAL_APP_TIME_MS = 108, /* Accumulated time spent in Java application */
duke@435 88 JMM_VM_THREAD_COUNT = 109, /* Current number of VM internal threads */
duke@435 89 JMM_CLASS_INIT_TOTAL_COUNT = 110, /* Number of classes for which initializers were run */
duke@435 90 JMM_CLASS_INIT_TOTAL_TIME_MS = 111, /* Accumulated time spent in class initializers */
duke@435 91 JMM_METHOD_DATA_SIZE_BYTES = 112, /* Size of method data in memory */
duke@435 92 JMM_CLASS_VERIFY_TOTAL_TIME_MS = 113, /* Accumulated time spent in class verifier */
duke@435 93 JMM_SHARED_CLASS_LOADED_COUNT = 114, /* Number of shared classes loaded */
duke@435 94 JMM_SHARED_CLASS_UNLOADED_COUNT = 115, /* Number of shared classes unloaded */
duke@435 95 JMM_SHARED_CLASS_LOADED_BYTES = 116, /* Number of bytes loaded shared classes */
duke@435 96 JMM_SHARED_CLASS_UNLOADED_BYTES = 117, /* Number of bytes unloaded shared classes */
duke@435 97
duke@435 98 JMM_OS_ATTRIBUTE_INDEX = 200,
duke@435 99 JMM_OS_PROCESS_ID = 201, /* Process id of the JVM */
duke@435 100 JMM_OS_MEM_TOTAL_PHYSICAL_BYTES = 202, /* Physical memory size */
duke@435 101
duke@435 102 JMM_GC_EXT_ATTRIBUTE_INFO_SIZE = 401 /* the size of the GC specific attributes for a given GC memory manager */
duke@435 103 } jmmLongAttribute;
duke@435 104
duke@435 105 typedef enum {
duke@435 106 JMM_VERBOSE_GC = 21,
duke@435 107 JMM_VERBOSE_CLASS = 22,
duke@435 108 JMM_THREAD_CONTENTION_MONITORING = 23,
phh@2423 109 JMM_THREAD_CPU_TIME = 24,
phh@2423 110 JMM_THREAD_ALLOCATED_MEMORY = 25
duke@435 111 } jmmBoolAttribute;
duke@435 112
duke@435 113
duke@435 114 enum {
duke@435 115 JMM_THREAD_STATE_FLAG_SUSPENDED = 0x00100000,
duke@435 116 JMM_THREAD_STATE_FLAG_NATIVE = 0x00400000
duke@435 117 };
duke@435 118
duke@435 119 #define JMM_THREAD_STATE_FLAG_MASK 0xFFF00000
duke@435 120
duke@435 121 typedef enum {
duke@435 122 JMM_STAT_PEAK_THREAD_COUNT = 801,
duke@435 123 JMM_STAT_THREAD_CONTENTION_COUNT = 802,
duke@435 124 JMM_STAT_THREAD_CONTENTION_TIME = 803,
duke@435 125 JMM_STAT_THREAD_CONTENTION_STAT = 804,
duke@435 126 JMM_STAT_PEAK_POOL_USAGE = 805,
duke@435 127 JMM_STAT_GC_STAT = 806
duke@435 128 } jmmStatisticType;
duke@435 129
duke@435 130 typedef enum {
duke@435 131 JMM_USAGE_THRESHOLD_HIGH = 901,
duke@435 132 JMM_USAGE_THRESHOLD_LOW = 902,
duke@435 133 JMM_COLLECTION_USAGE_THRESHOLD_HIGH = 903,
duke@435 134 JMM_COLLECTION_USAGE_THRESHOLD_LOW = 904
duke@435 135 } jmmThresholdType;
duke@435 136
duke@435 137 /* Should match what is allowed in globals.hpp */
duke@435 138 typedef enum {
duke@435 139 JMM_VMGLOBAL_TYPE_UNKNOWN = 0,
duke@435 140 JMM_VMGLOBAL_TYPE_JBOOLEAN = 1,
duke@435 141 JMM_VMGLOBAL_TYPE_JSTRING = 2,
duke@435 142 JMM_VMGLOBAL_TYPE_JLONG = 3
duke@435 143 } jmmVMGlobalType;
duke@435 144
duke@435 145 typedef enum {
duke@435 146 JMM_VMGLOBAL_ORIGIN_DEFAULT = 1, /* Default value */
duke@435 147 JMM_VMGLOBAL_ORIGIN_COMMAND_LINE = 2, /* Set at command line (or JNI invocation) */
duke@435 148 JMM_VMGLOBAL_ORIGIN_MANAGEMENT = 3, /* Set via management interface */
duke@435 149 JMM_VMGLOBAL_ORIGIN_ENVIRON_VAR = 4, /* Set via environment variables */
duke@435 150 JMM_VMGLOBAL_ORIGIN_CONFIG_FILE = 5, /* Set via config file (such as .hotspotrc) */
duke@435 151 JMM_VMGLOBAL_ORIGIN_ERGONOMIC = 6, /* Set via ergonomic */
duke@435 152 JMM_VMGLOBAL_ORIGIN_OTHER = 99 /* Set via some other mechanism */
duke@435 153 } jmmVMGlobalOrigin;
duke@435 154
duke@435 155 typedef struct {
duke@435 156 jstring name;
duke@435 157 jvalue value;
duke@435 158 jmmVMGlobalType type; /* Data type */
duke@435 159 jmmVMGlobalOrigin origin; /* Default or non-default value */
duke@435 160 unsigned int writeable : 1; /* dynamically writeable */
duke@435 161 unsigned int external : 1; /* external supported interface */
duke@435 162 unsigned int reserved : 30;
duke@435 163 void *reserved1;
duke@435 164 void *reserved2;
duke@435 165 } jmmVMGlobal;
duke@435 166
duke@435 167 typedef struct {
duke@435 168 const char* name;
duke@435 169 char type;
duke@435 170 const char* description;
duke@435 171 } jmmExtAttributeInfo;
duke@435 172
duke@435 173 /* Caller has to set the following fields before calling GetLastGCStat
duke@435 174 * o usage_before_gc - array of MemoryUsage objects
duke@435 175 * o usage_after_gc - array of MemoryUsage objects
duke@435 176 * o gc_ext_attribute_values_size - size of gc_ext_atttribute_values array
duke@435 177 * o gc_ext_attribtue_values - array of jvalues
duke@435 178 */
duke@435 179 typedef struct {
duke@435 180 jlong gc_index; /* Index of the collections */
duke@435 181 jlong start_time; /* Start time of the GC */
duke@435 182 jlong end_time; /* End time of the GC */
duke@435 183 jobjectArray usage_before_gc; /* Memory usage array before GC */
duke@435 184 jobjectArray usage_after_gc; /* Memory usage array after GC */
duke@435 185 jint gc_ext_attribute_values_size; /* set by the caller of GetGCStat */
duke@435 186 jvalue* gc_ext_attribute_values; /* Array of jvalue for GC extension attributes */
duke@435 187 jint num_gc_ext_attributes; /* number of GC extension attribute values s are filled */
duke@435 188 /* -1 indicates gc_ext_attribute_values is not big enough */
duke@435 189 } jmmGCStat;
duke@435 190
duke@435 191 typedef struct jmmInterface_1_ {
duke@435 192 void* reserved1;
duke@435 193 void* reserved2;
duke@435 194
duke@435 195 jint (JNICALL *GetVersion) (JNIEnv *env);
duke@435 196
duke@435 197 jint (JNICALL *GetOptionalSupport) (JNIEnv *env,
duke@435 198 jmmOptionalSupport* support_ptr);
duke@435 199
duke@435 200 /* This is used by JDK 6 and earlier.
duke@435 201 * For JDK 7 and after, use GetInputArgumentArray.
duke@435 202 */
duke@435 203 jobject (JNICALL *GetInputArguments) (JNIEnv *env);
duke@435 204
duke@435 205 jint (JNICALL *GetThreadInfo) (JNIEnv *env,
duke@435 206 jlongArray ids,
duke@435 207 jint maxDepth,
duke@435 208 jobjectArray infoArray);
duke@435 209 jobjectArray (JNICALL *GetInputArgumentArray) (JNIEnv *env);
duke@435 210
duke@435 211 jobjectArray (JNICALL *GetMemoryPools) (JNIEnv* env, jobject mgr);
duke@435 212
duke@435 213 jobjectArray (JNICALL *GetMemoryManagers) (JNIEnv* env, jobject pool);
duke@435 214
duke@435 215 jobject (JNICALL *GetMemoryPoolUsage) (JNIEnv* env, jobject pool);
duke@435 216 jobject (JNICALL *GetPeakMemoryPoolUsage) (JNIEnv* env, jobject pool);
duke@435 217
phh@2423 218 void (JNICALL *GetThreadAllocatedMemory)
phh@2423 219 (JNIEnv *env,
phh@2423 220 jlongArray ids,
phh@2423 221 jlongArray sizeArray);
duke@435 222
duke@435 223 jobject (JNICALL *GetMemoryUsage) (JNIEnv* env, jboolean heap);
duke@435 224
duke@435 225 jlong (JNICALL *GetLongAttribute) (JNIEnv *env, jobject obj, jmmLongAttribute att);
duke@435 226 jboolean (JNICALL *GetBoolAttribute) (JNIEnv *env, jmmBoolAttribute att);
duke@435 227 jboolean (JNICALL *SetBoolAttribute) (JNIEnv *env, jmmBoolAttribute att, jboolean flag);
duke@435 228
duke@435 229 jint (JNICALL *GetLongAttributes) (JNIEnv *env,
duke@435 230 jobject obj,
duke@435 231 jmmLongAttribute* atts,
duke@435 232 jint count,
duke@435 233 jlong* result);
duke@435 234
duke@435 235 jobjectArray (JNICALL *FindCircularBlockedThreads) (JNIEnv *env);
phh@2423 236
phh@2423 237 // Not used in JDK 6 or JDK 7
duke@435 238 jlong (JNICALL *GetThreadCpuTime) (JNIEnv *env, jlong thread_id);
duke@435 239
duke@435 240 jobjectArray (JNICALL *GetVMGlobalNames) (JNIEnv *env);
duke@435 241 jint (JNICALL *GetVMGlobals) (JNIEnv *env,
duke@435 242 jobjectArray names,
duke@435 243 jmmVMGlobal *globals,
duke@435 244 jint count);
duke@435 245
duke@435 246 jint (JNICALL *GetInternalThreadTimes) (JNIEnv *env,
duke@435 247 jobjectArray names,
duke@435 248 jlongArray times);
duke@435 249
duke@435 250 jboolean (JNICALL *ResetStatistic) (JNIEnv *env,
duke@435 251 jvalue obj,
duke@435 252 jmmStatisticType type);
duke@435 253
duke@435 254 void (JNICALL *SetPoolSensor) (JNIEnv *env,
duke@435 255 jobject pool,
duke@435 256 jmmThresholdType type,
duke@435 257 jobject sensor);
duke@435 258
duke@435 259 jlong (JNICALL *SetPoolThreshold) (JNIEnv *env,
duke@435 260 jobject pool,
duke@435 261 jmmThresholdType type,
duke@435 262 jlong threshold);
duke@435 263 jobject (JNICALL *GetPoolCollectionUsage) (JNIEnv* env, jobject pool);
duke@435 264
duke@435 265 jint (JNICALL *GetGCExtAttributeInfo) (JNIEnv *env,
duke@435 266 jobject mgr,
duke@435 267 jmmExtAttributeInfo *ext_info,
duke@435 268 jint count);
duke@435 269 void (JNICALL *GetLastGCStat) (JNIEnv *env,
duke@435 270 jobject mgr,
duke@435 271 jmmGCStat *gc_stat);
phh@2423 272
phh@2423 273 jlong (JNICALL *GetThreadCpuTimeWithKind)
phh@2423 274 (JNIEnv *env,
phh@2423 275 jlong thread_id,
phh@2423 276 jboolean user_sys_cpu_time);
phh@2423 277 void (JNICALL *GetThreadCpuTimesWithKind)
phh@2423 278 (JNIEnv *env,
phh@2423 279 jlongArray ids,
phh@2423 280 jlongArray timeArray,
phh@2423 281 jboolean user_sys_cpu_time);
phh@2423 282
duke@435 283 jint (JNICALL *DumpHeap0) (JNIEnv *env,
duke@435 284 jstring outputfile,
duke@435 285 jboolean live);
phh@2423 286 jobjectArray (JNICALL *FindDeadlocks) (JNIEnv *env,
phh@2423 287 jboolean object_monitors_only);
duke@435 288 void (JNICALL *SetVMGlobal) (JNIEnv *env,
duke@435 289 jstring flag_name,
duke@435 290 jvalue new_value);
duke@435 291 void* reserved6;
duke@435 292 jobjectArray (JNICALL *DumpThreads) (JNIEnv *env,
duke@435 293 jlongArray ids,
duke@435 294 jboolean lockedMonitors,
duke@435 295 jboolean lockedSynchronizers);
duke@435 296 } JmmInterface;
duke@435 297
duke@435 298 #ifdef __cplusplus
duke@435 299 } /* extern "C" */
duke@435 300 #endif /* __cplusplus */
duke@435 301
duke@435 302 #endif /* !_JAVA_JMM_H_ */

mercurial