2 * @(#)jvmpi.h 1.28 03/12/19
\r
4 * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
\r
5 * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
\r
8 #ifndef _JAVASOFT_JVMPI_H_
\r
9 #define _JAVASOFT_JVMPI_H_
\r
13 #define JVMPI_VERSION_1 ((jint)0x10000001) /* implied 0 for minor version */
\r
14 #define JVMPI_VERSION_1_1 ((jint)0x10000002)
\r
15 #define JVMPI_VERSION_1_2 ((jint)0x10000003)
\r
20 typedef void (*jvmpi_void_function_of_void)(void *);
\r
25 /****************************************************************
\r
26 * Profiler interface data structures.
\r
27 ****************************************************************/
\r
28 /* identifier types. */
\r
30 typedef struct _jobjectID * jobjectID; /* type of object ids */
\r
33 struct _JVMPI_RawMonitor;
\r
34 typedef struct _JVMPI_RawMonitor * JVMPI_RawMonitor;
\r
38 jint lineno; /* line number in the source file */
\r
39 jmethodID method_id; /* method executed in this frame */
\r
44 JNIEnv *env_id; /* Env where trace was recorded */
\r
45 jint num_frames; /* number of frames in this trace */
\r
46 JVMPI_CallFrame *frames; /* frames */
\r
51 char *method_name; /* name of method */
\r
52 char *method_signature; /* signature of method */
\r
53 jint start_lineno; /* -1 if native, abstract .. */
\r
54 jint end_lineno; /* -1 if native, abstract .. */
\r
55 jmethodID method_id; /* id assigned to this method */
\r
60 char *field_name; /* name of field */
\r
61 char *field_signature; /* signature of field */
\r
64 /* line number info for a compiled method */
\r
66 jint offset; /* offset from beginning of method */
\r
67 jint lineno; /* lineno from beginning of src file */
\r
72 jint event_type; /* event_type */
\r
73 JNIEnv *env_id; /* env where this event occured */
\r
77 const char *class_name; /* class name */
\r
78 char *source_name; /* name of source file */
\r
79 jint num_interfaces; /* number of interfaces implemented */
\r
80 jint num_methods; /* number of methods in the class */
\r
81 JVMPI_Method *methods; /* methods */
\r
82 jint num_static_fields; /* number of static fields */
\r
83 JVMPI_Field *statics; /* static fields */
\r
84 jint num_instance_fields; /* number of instance fields */
\r
85 JVMPI_Field *instances; /* instance fields */
\r
86 jobjectID class_id; /* id of the class object */
\r
90 jobjectID class_id; /* id of the class object */
\r
94 unsigned char *class_data; /* content of class file */
\r
95 jint class_data_len; /* class file length */
\r
96 unsigned char *new_class_data; /* instrumented class file */
\r
97 jint new_class_data_len; /* new class file length */
\r
98 void * (*malloc_f)(unsigned int); /* memory allocation function */
\r
103 jobjectID class_id; /* id of object class */
\r
104 jint is_array; /* JVMPI_NORMAL_OBJECT, ... */
\r
105 jint size; /* size in number of bytes */
\r
106 jobjectID obj_id; /* id assigned to this object */
\r
110 jobjectID obj_id; /* id of the object */
\r
114 jint arena_id; /* cur arena id */
\r
115 jobjectID obj_id; /* cur object id */
\r
116 jint new_arena_id; /* new arena id */
\r
117 jobjectID new_obj_id; /* new object id */
\r
121 jint arena_id; /* id of arena */
\r
122 const char *arena_name; /* name of arena */
\r
126 jint arena_id; /* id of arena */
\r
130 char *thread_name; /* name of thread */
\r
131 char *group_name; /* name of group */
\r
132 char *parent_name; /* name of parent */
\r
133 jobjectID thread_id; /* id of the thread object */
\r
134 JNIEnv *thread_env_id;
\r
138 int dump_level; /* level of the heap dump info */
\r
139 char *begin; /* where all the root records begin,
\r
140 please see the heap dump buffer
\r
141 format described below */
\r
142 char *end; /* where the object records end. */
\r
143 jint num_traces; /* number of thread traces,
\r
144 0 if dump level = JVMPI_DUMP_LEVEL_0 */
\r
145 JVMPI_CallTrace *traces; /* thread traces collected during
\r
150 jobjectID obj_id; /* object id */
\r
151 jobject ref_id; /* id assigned to the globalref */
\r
152 } jni_globalref_alloc;
\r
155 jobject ref_id; /* id of the global ref */
\r
156 } jni_globalref_free;
\r
159 jmethodID method_id; /* method */
\r
163 jmethodID method_id; /* id of method */
\r
164 jobjectID obj_id; /* id of target object */
\r
168 jmethodID method_id; /* id of compiled method */
\r
169 void *code_addr; /* code start addr. in memory */
\r
170 jint code_size; /* code size */
\r
171 jint lineno_table_size; /* size of lineno table */
\r
172 JVMPI_Lineno *lineno_table; /* lineno info */
\r
173 } compiled_method_load;
\r
176 jmethodID method_id; /* id of unloaded compiled method */
\r
177 } compiled_method_unload;
\r
180 jmethodID method_id; /* id of the method the instruction belongs to */
\r
181 jint offset; /* instruction offset in the method's bytecode */
\r
184 jboolean is_true; /* whether true or false branch is taken */
\r
187 jint key; /* top stack value used as an index */
\r
188 jint low; /* min value of the index */
\r
189 jint hi; /* max value of the index */
\r
190 } tableswitch_info;
\r
192 jint chosen_pair_index; /* actually chosen pair index (0-based)
\r
193 * if chosen_pair_index == pairs_total then
\r
194 * the 'default' branch is taken
\r
196 jint pairs_total; /* total number of lookupswitch pairs */
\r
197 } lookupswitch_info;
\r
202 char *begin; /* beginning of dump buffer,
\r
203 see below for format */
\r
204 char *end; /* end of dump buffer */
\r
205 jint num_traces; /* number of traces */
\r
206 JVMPI_CallTrace *traces; /* traces of all threads */
\r
207 jint *threads_status; /* status of all threads */
\r
211 const char *name; /* name of raw monitor */
\r
212 JVMPI_RawMonitor id; /* id */
\r
216 jobjectID object; /* Java object */
\r
220 jobjectID object; /* Java object */
\r
221 jlong timeout; /* timeout period */
\r
225 jlong used_objects;
\r
226 jlong used_object_space;
\r
227 jlong total_object_space;
\r
237 /* interface functions */
\r
239 jint version; /* JVMPI version */
\r
241 /* ------interface implemented by the profiler------ */
\r
244 * Function called by the JVM to notify an event.
\r
246 void (*NotifyEvent)(JVMPI_Event *event);
\r
248 /* ------interface implemented by the JVM------ */
\r
251 * Function called by the profiler to enable/disable/send notification
\r
252 * for a particular event type.
\r
254 * event_type - event_type
\r
255 * arg - event specific arg
\r
257 * return JVMPI_NOT_AVAILABLE, JVMPI_SUCCESS or JVMPI_FAIL
\r
259 jint (*EnableEvent)(jint event_type, void *arg);
\r
260 jint (*DisableEvent)(jint event_type, void *arg);
\r
261 jint (*RequestEvent)(jint event_type, void *arg);
\r
264 * Function called by the profiler to get a stack
\r
265 * trace from the JVM.
\r
267 * trace - trace data structure to be filled
\r
268 * depth - maximum depth of the trace.
\r
270 void (*GetCallTrace)(JVMPI_CallTrace *trace, jint depth);
\r
273 * Function called by profiler when it wants to exit/stop.
\r
275 void (*ProfilerExit)(jint);
\r
278 * Utility functions provided by the JVM.
\r
280 JVMPI_RawMonitor (*RawMonitorCreate)(char *lock_name);
\r
281 void (*RawMonitorEnter)(JVMPI_RawMonitor lock_id);
\r
282 void (*RawMonitorExit)(JVMPI_RawMonitor lock_id);
\r
283 void (*RawMonitorWait)(JVMPI_RawMonitor lock_id, jlong ms);
\r
284 void (*RawMonitorNotifyAll)(JVMPI_RawMonitor lock_id);
\r
285 void (*RawMonitorDestroy)(JVMPI_RawMonitor lock_id);
\r
288 * Function called by the profiler to get the current thread's CPU time.
\r
290 * return time in nanoseconds;
\r
292 jlong (*GetCurrentThreadCpuTime)(void);
\r
294 void (*SuspendThread)(JNIEnv *env);
\r
295 void (*ResumeThread)(JNIEnv *env);
\r
296 jint (*GetThreadStatus)(JNIEnv *env);
\r
297 jboolean (*ThreadHasRun)(JNIEnv *env);
\r
299 /* This function can be called safely only after JVMPI_EVENT_VM_INIT_DONE
\r
300 notification by the JVM. */
\r
301 jint (*CreateSystemThread)(char *name, jint priority, void (*f)(void *));
\r
303 /* thread local storage access functions to avoid locking in time
\r
304 critical functions */
\r
305 void (*SetThreadLocalStorage)(JNIEnv *env_id, void *ptr);
\r
306 void * (*GetThreadLocalStorage)(JNIEnv *env_id);
\r
309 void (*DisableGC)(void);
\r
310 void (*EnableGC)(void);
\r
311 void (*RunGC)(void);
\r
313 jobjectID (*GetThreadObject)(JNIEnv *env);
\r
314 jobjectID (*GetMethodClass)(jmethodID mid);
\r
316 /* JNI <-> jobject conversions */
\r
317 jobject (*jobjectID2jobject)(jobjectID jid);
\r
318 jobjectID (*jobject2jobjectID)(jobject jobj);
\r
320 void (*SuspendThreadList)
\r
321 (jint reqCount, JNIEnv **reqList, jint *results);
\r
322 void (*ResumeThreadList)
\r
323 (jint reqCount, JNIEnv **reqList, jint *results);
\r
326 /* type of argument passed to RequestEvent for heap dumps */
\r
328 jint heap_dump_level;
\r
329 } JVMPI_HeapDumpArg;
\r
331 /**********************************************************************
\r
332 * Constants and formats used in JVM Profiler Interface.
\r
333 **********************************************************************/
\r
335 * Event type constants.
\r
337 #define JVMPI_EVENT_METHOD_ENTRY ((jint)1)
\r
338 #define JVMPI_EVENT_METHOD_ENTRY2 ((jint)2)
\r
339 #define JVMPI_EVENT_METHOD_EXIT ((jint)3)
\r
341 #define JVMPI_EVENT_OBJECT_ALLOC ((jint)4)
\r
342 #define JVMPI_EVENT_OBJECT_FREE ((jint)5)
\r
343 #define JVMPI_EVENT_OBJECT_MOVE ((jint)6)
\r
345 #define JVMPI_EVENT_COMPILED_METHOD_LOAD ((jint)7)
\r
346 #define JVMPI_EVENT_COMPILED_METHOD_UNLOAD ((jint)8)
\r
348 #define JVMPI_EVENT_INSTRUCTION_START ((jint)9)
\r
350 #define JVMPI_EVENT_THREAD_START ((jint)33)
\r
351 #define JVMPI_EVENT_THREAD_END ((jint)34)
\r
353 #define JVMPI_EVENT_CLASS_LOAD_HOOK ((jint)35)
\r
355 #define JVMPI_EVENT_HEAP_DUMP ((jint)37)
\r
356 #define JVMPI_EVENT_JNI_GLOBALREF_ALLOC ((jint)38)
\r
357 #define JVMPI_EVENT_JNI_GLOBALREF_FREE ((jint)39)
\r
358 #define JVMPI_EVENT_JNI_WEAK_GLOBALREF_ALLOC ((jint)40)
\r
359 #define JVMPI_EVENT_JNI_WEAK_GLOBALREF_FREE ((jint)41)
\r
360 #define JVMPI_EVENT_CLASS_LOAD ((jint)42)
\r
361 #define JVMPI_EVENT_CLASS_UNLOAD ((jint)43)
\r
362 #define JVMPI_EVENT_DATA_DUMP_REQUEST ((jint)44)
\r
363 #define JVMPI_EVENT_DATA_RESET_REQUEST ((jint)45)
\r
365 #define JVMPI_EVENT_JVM_INIT_DONE ((jint)46)
\r
366 #define JVMPI_EVENT_JVM_SHUT_DOWN ((jint)47)
\r
368 #define JVMPI_EVENT_ARENA_NEW ((jint)48)
\r
369 #define JVMPI_EVENT_ARENA_DELETE ((jint)49)
\r
371 #define JVMPI_EVENT_OBJECT_DUMP ((jint)50)
\r
373 #define JVMPI_EVENT_RAW_MONITOR_CONTENDED_ENTER ((jint)51)
\r
374 #define JVMPI_EVENT_RAW_MONITOR_CONTENDED_ENTERED ((jint)52)
\r
375 #define JVMPI_EVENT_RAW_MONITOR_CONTENDED_EXIT ((jint)53)
\r
376 #define JVMPI_EVENT_MONITOR_CONTENDED_ENTER ((jint)54)
\r
377 #define JVMPI_EVENT_MONITOR_CONTENDED_ENTERED ((jint)55)
\r
378 #define JVMPI_EVENT_MONITOR_CONTENDED_EXIT ((jint)56)
\r
379 #define JVMPI_EVENT_MONITOR_WAIT ((jint)57)
\r
380 #define JVMPI_EVENT_MONITOR_WAITED ((jint)58)
\r
381 #define JVMPI_EVENT_MONITOR_DUMP ((jint)59)
\r
383 #define JVMPI_EVENT_GC_START ((jint)60)
\r
384 #define JVMPI_EVENT_GC_FINISH ((jint)61)
\r
386 #define JVMPI_MAX_EVENT_TYPE_VAL ((jint)61)
\r
388 /* old definitions, to be removed */
\r
389 #define JVMPI_EVENT_LOAD_COMPILED_METHOD ((jint)7)
\r
390 #define JVMPI_EVENT_UNLOAD_COMPILED_METHOD ((jint)8)
\r
391 #define JVMPI_EVENT_NEW_ARENA ((jint)48)
\r
392 #define JVMPI_EVENT_DELETE_ARENA ((jint)49)
\r
393 #define JVMPI_EVENT_DUMP_DATA_REQUEST ((jint)44)
\r
394 #define JVMPI_EVENT_RESET_DATA_REQUEST ((jint)45)
\r
395 #define JVMPI_EVENT_OBJ_ALLOC ((jint)4)
\r
396 #define JVMPI_EVENT_OBJ_FREE ((jint)5)
\r
397 #define JVMPI_EVENT_OBJ_MOVE ((jint)6)
\r
399 #define JVMPI_REQUESTED_EVENT ((jint)0x10000000)
\r
404 * enabling/disabling event notification.
\r
407 #define JVMPI_SUCCESS ((jint)0)
\r
408 #define JVMPI_NOT_AVAILABLE ((jint)1)
\r
409 #define JVMPI_FAIL ((jint)-1)
\r
415 JVMPI_THREAD_RUNNABLE = 1,
\r
416 JVMPI_THREAD_MONITOR_WAIT,
\r
417 JVMPI_THREAD_CONDVAR_WAIT
\r
420 #define JVMPI_THREAD_SUSPENDED 0x8000
\r
421 #define JVMPI_THREAD_INTERRUPTED 0x4000
\r
426 #define JVMPI_MINIMUM_PRIORITY 1
\r
427 #define JVMPI_MAXIMUM_PRIORITY 10
\r
428 #define JVMPI_NORMAL_PRIORITY 5
\r
431 * Object type constants.
\r
433 #define JVMPI_NORMAL_OBJECT ((jint)0)
\r
434 #define JVMPI_CLASS ((jint)2)
\r
435 #define JVMPI_BOOLEAN ((jint)4)
\r
436 #define JVMPI_CHAR ((jint)5)
\r
437 #define JVMPI_FLOAT ((jint)6)
\r
438 #define JVMPI_DOUBLE ((jint)7)
\r
439 #define JVMPI_BYTE ((jint)8)
\r
440 #define JVMPI_SHORT ((jint)9)
\r
441 #define JVMPI_INT ((jint)10)
\r
442 #define JVMPI_LONG ((jint)11)
\r
445 * Monitor dump constants.
\r
448 #define JVMPI_MONITOR_JAVA 0x01
\r
449 #define JVMPI_MONITOR_RAW 0x02
\r
452 * Heap dump constants.
\r
454 #define JVMPI_GC_ROOT_UNKNOWN 0xff
\r
455 #define JVMPI_GC_ROOT_JNI_GLOBAL 0x01
\r
456 #define JVMPI_GC_ROOT_JNI_LOCAL 0x02
\r
457 #define JVMPI_GC_ROOT_JAVA_FRAME 0x03
\r
458 #define JVMPI_GC_ROOT_NATIVE_STACK 0x04
\r
459 #define JVMPI_GC_ROOT_STICKY_CLASS 0x05
\r
460 #define JVMPI_GC_ROOT_THREAD_BLOCK 0x06
\r
461 #define JVMPI_GC_ROOT_MONITOR_USED 0x07
\r
462 #define JVMPI_GC_ROOT_THREAD_OBJ 0x08
\r
464 #define JVMPI_GC_CLASS_DUMP 0x20
\r
465 #define JVMPI_GC_INSTANCE_DUMP 0x21
\r
466 #define JVMPI_GC_OBJ_ARRAY_DUMP 0x22
\r
467 #define JVMPI_GC_PRIM_ARRAY_DUMP 0x23
\r
472 #define JVMPI_DUMP_LEVEL_0 ((jint)0)
\r
473 #define JVMPI_DUMP_LEVEL_1 ((jint)1)
\r
474 #define JVMPI_DUMP_LEVEL_2 ((jint)2)
\r
476 /* Types used in dumps -
\r
484 * JVMPI_CLASS: object
\r
485 * JVMPI_BOOLEAN: boolean
\r
487 * JVMPI_FLOAT: float
\r
488 * JVMPI_DOUBLE: double
\r
490 * JVMPI_SHORT: short
\r
494 * vl: values, exact type depends on the type of the value:
\r
495 * JVMPI_BOOLEAN & JVMPI_BYTE: u1
\r
496 * JVMPI_SHORT & JVMPI_CHAR: u2
\r
497 * JVMPI_INT & JVMPI_FLOAT: u4
\r
498 * JVMPI_LONG & JVMPI_DOUBLE: u8
\r
499 * JVMPI_CLASS: jobjectID
\r
502 /* Format of the monitor dump buffer:
\r
506 * JVMPI_MONITOR_JAVA Java monitor
\r
509 * JNIEnv * owner thread
\r
511 * u4 # of threads waiting to enter
\r
512 * [JNIEnv *]* threads waiting to enter
\r
513 * u4 # of threads waiting to be notified
\r
514 * [JNIEnv *]* threads waiting to be notified
\r
516 * JVMPI_MONITOR_RAW raw monitor
\r
519 * JVMPI_RawMonitor raw monitor
\r
520 * JNIEnv * owner thread
\r
522 * u4 # of threads waiting to enter
\r
523 * [JNIEnv *]* threads waiting to enter
\r
524 * u4 # of threads waiting to be notified
\r
525 * [JNIEnv *]* threads waiting to be notified
\r
528 /* Format of the heap dump buffer depends on the dump level
\r
529 * specified in the JVMPI_HeapDumpArg passed to RequestEvent as arg.
\r
530 * The default is JVMPI_DUMP_LEVEL_2.
\r
532 * JVMPI_DUMP_LEVEL_0:
\r
534 * u1 object type (JVMPI_CLASS ...)
\r
537 * JVMPI_DUMP_LEVEL_1 and JVMPI_DUMP_LEVEL_2 use the following format:
\r
538 * In the case of JVMPI_DUMP_LEVEL_1 the values of primitive fields in object
\r
539 * instance dumps , the values of primitive statics in class dumps and the
\r
540 * values of primitive arrays are excluded. JVMPI_DUMP_LEVEL_2 includes the
\r
541 * primitive values.
\r
545 * JVMPI_GC_ROOT_UNKNOWN unknown root
\r
549 * JVMPI_GC_ROOT_JNI_GLOBAL JNI global ref root
\r
552 * jobject JNI global reference
\r
554 * JVMPI_GC_ROOT_JNI_LOCAL JNI local ref
\r
558 * u4 frame # in stack trace (-1 for empty)
\r
560 * JVMPI_GC_ROOT_JAVA_FRAME Java stack frame
\r
564 * u4 frame # in stack trace (-1 for empty)
\r
566 * JVMPI_GC_ROOT_NATIVE_STACK Native stack
\r
571 * JVMPI_GC_ROOT_STICKY_CLASS System class
\r
573 * jobjectID class object
\r
575 * JVMPI_GC_ROOT_THREAD_BLOCK Reference from thread block
\r
577 * jobjectID thread object
\r
580 * JVMPI_GC_ROOT_MONITOR_USED Busy monitor
\r
584 * JVMPI_GC_CLASS_DUMP dump of a class object
\r
588 * jobjectID class loader
\r
589 * jobjectID signers
\r
590 * jobjectID protection domain
\r
591 * jobjectID class name
\r
594 * u4 instance size (in bytes)
\r
596 * [jobjectID]* interfaces
\r
598 * u2 size of constant pool
\r
599 * [u2, constant pool index,
\r
603 * [vl]* static field values
\r
605 * JVMPI_GC_INSTANCE_DUMP dump of a normal object
\r
609 * u4 number of bytes that follow
\r
610 * [vl]* instance field values (class, followed
\r
611 * by super, super's super ...)
\r
613 * JVMPI_GC_OBJ_ARRAY_DUMP dump of an object array
\r
615 * jobjectID array object
\r
616 * u4 number of elements
\r
617 * jobjectID element class
\r
618 * [jobjectID]* elements
\r
620 * JVMPI_GC_PRIM_ARRAY_DUMP dump of a primitive array
\r
622 * jobjectID array object
\r
623 * u4 number of elements
\r
629 /* Format of the dump received in JVMPI_EVENT_OBJECT_DUMP:
\r
630 * All the records have JVMPI_DUMP_LEVEL_2 information.
\r
636 * JVMPI_GC_CLASS_DUMP,
\r
637 * JVMPI_GC_INSTANCE_DUMP,
\r
638 * JVMPI_GC_OBJ_ARRAY_DUMP, or
\r
639 * JVMPI_GC_PRIM_ARRAY_DUMP record.
\r
642 #endif /* !_JAVASOFT_JVMPI_H_ */
\r