00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043 #ifndef HPROF_H
00044 #define HPROF_H
00045
00046
00047
00048 #include <stdio.h>
00049 #include <stdlib.h>
00050 #include <ctype.h>
00051 #include <string.h>
00052 #include <stddef.h>
00053 #include <stdarg.h>
00054 #include <limits.h>
00055 #include <time.h>
00056 #include <errno.h>
00057
00058
00059
00060 #include <sys/types.h>
00061 #include "jni.h"
00062 #include "jvmti.h"
00063 #include "classfile_constants.h"
00064
00065 #ifndef SKIP_NPT
00066 #include "npt.h"
00067 #endif
00068
00069
00070
00071 #define jlong_high(a) ((jint)((a)>>32))
00072 #define jlong_low(a) ((jint)(a))
00073 #define jlong_to_jint(a) ((jint)(a))
00074 #define jint_to_jlong(a) ((jlong)(a))
00075
00076 #define jlong_add(a, b) ((a) + (b))
00077
00078
00079
00080
00081 typedef unsigned SerialNumber;
00082
00083
00084
00085 #define AGENTNAME "hprof"
00086 #define XRUN "-Xrun" AGENTNAME
00087 #define AGENTLIB "-agentlib:" AGENTNAME
00088
00089
00090
00091 #define PRELUDE_FILE "jvm.hprof.txt"
00092
00093
00094
00095 #define FILE_IO_BUFFER_SIZE (1024*64)
00096
00097
00098
00099 #include "hprof_md.h"
00100
00101
00102
00103 typedef unsigned TableIndex;
00104 typedef TableIndex ClassIndex;
00105 typedef TableIndex FrameIndex;
00106 typedef TableIndex IoNameIndex;
00107 typedef TableIndex MonitorIndex;
00108 typedef TableIndex ObjectIndex;
00109 typedef TableIndex LoaderIndex;
00110 typedef TableIndex RefIndex;
00111 typedef TableIndex SiteIndex;
00112 typedef TableIndex StringIndex;
00113 typedef TableIndex TlsIndex;
00114 typedef TableIndex TraceIndex;
00115
00116
00117
00118 typedef int MethodIndex;
00119
00120
00121
00122 enum ClassStatus {
00123 CLASS_PREPARED = 0x00000001,
00124 CLASS_LOADED = 0x00000002,
00125 CLASS_UNLOADED = 0x00000004,
00126 CLASS_SPECIAL = 0x00000008,
00127 CLASS_IN_LOAD_LIST = 0x00000010,
00128 CLASS_SYSTEM = 0x00000020,
00129 CLASS_DUMPED = 0x00000040
00130 };
00131 typedef jint ClassStatus;
00132
00133
00134
00135 typedef unsigned char ObjectKind;
00136 enum {
00137 OBJECT_NORMAL = 1,
00138 OBJECT_CLASS = 2,
00139 OBJECT_SYSTEM = 3,
00140 OBJECT_HPROF = 4,
00141 OBJECT_LOADER = 5
00142 };
00143
00144
00145
00146 enum {
00147 SITE_DUMP_INCREMENTAL = 0x01,
00148 SITE_SORT_BY_ALLOC = 0x02,
00149 SITE_FORCE_GC = 0x04
00150 };
00151
00152
00153
00154 typedef struct FieldInfo {
00155 ClassIndex cnum;
00156 StringIndex name_index;
00157 StringIndex sig_index;
00158 unsigned short modifiers;
00159 unsigned char primType;
00160 unsigned char primSize;
00161 } FieldInfo;
00162
00163
00164
00165 typedef struct ConstantPoolValue {
00166 unsigned constant_pool_index;
00167 StringIndex sig_index;
00168 jvalue value;
00169 } ConstantPoolValue;
00170
00171
00172
00173 #include "hprof_error.h"
00174 #include "hprof_util.h"
00175 #include "hprof_blocks.h"
00176 #include "hprof_stack.h"
00177 #include "hprof_init.h"
00178 #include "hprof_table.h"
00179 #include "hprof_string.h"
00180 #include "hprof_class.h"
00181 #include "hprof_tracker.h"
00182 #include "hprof_frame.h"
00183 #include "hprof_monitor.h"
00184 #include "hprof_trace.h"
00185 #include "hprof_site.h"
00186 #include "hprof_event.h"
00187 #include "hprof_reference.h"
00188 #include "hprof_object.h"
00189 #include "hprof_loader.h"
00190 #include "hprof_tls.h"
00191 #include "hprof_check.h"
00192 #include "hprof_io.h"
00193 #include "hprof_listener.h"
00194 #include "hprof_cpu.h"
00195 #include "hprof_tag.h"
00196
00197
00198
00199 struct LineTable;
00200
00201 typedef struct {
00202
00203 jvmtiEnv *jvmti;
00204 JavaVM *jvm;
00205 #ifndef SKIP_NPT
00206 NptEnv *npt;
00207 #endif
00208 jint cachedJvmtiVersion;
00209
00210 char *header;
00211 jboolean segmented;
00212 jlong maxHeapSegment;
00213 jlong maxMemory;
00214
00215
00216 char * options;
00217 char * utf8_output_filename;
00218 int net_port;
00219 char * net_hostname;
00220 char output_format;
00221 int max_trace_depth;
00222 int prof_trace_depth;
00223 int sample_interval;
00224 double cutoff_point;
00225 jboolean cpu_sampling;
00226 jboolean cpu_timing;
00227 jboolean old_timing_format;
00228 jboolean heap_dump;
00229 jboolean alloc_sites;
00230 jboolean thread_in_traces;
00231 jboolean lineno_in_traces;
00232 jboolean dump_on_exit;
00233 jboolean micro_state_accounting;
00234 jboolean force_output;
00235 jboolean monitor_tracing;
00236 jboolean gc_okay;
00237
00238 unsigned logflags;
00239
00240 #define DEBUGFLAG_UNPREPARED_CLASSES 0x001
00241 unsigned debugflags;
00242
00243 jboolean coredump;
00244 jboolean errorexit;
00245 jboolean pause;
00246 jboolean debug;
00247 jboolean verbose;
00248 jboolean primfields;
00249 jboolean primarrays;
00250 jint experiment;
00251
00252 int fd;
00253 jboolean socket;
00254 jboolean bci;
00255 jboolean obj_watch;
00256
00257 int bci_counter;
00258
00259 int heap_fd;
00260 char *output_filename;
00261 char *heapfilename;
00262
00263 int check_fd;
00264 char *checkfilename;
00265
00266 volatile jboolean dump_in_process;
00267 volatile jboolean jvm_initializing;
00268 volatile jboolean jvm_initialized;
00269 volatile jboolean jvm_shut_down;
00270 jboolean vm_death_callback_active;
00271
00272
00273 Stack * object_free_stack;
00274 jrawMonitorID object_free_lock;
00275
00276
00277 jrawMonitorID debug_malloc_lock;
00278
00279
00280 jint class_count;
00281
00282
00283 jrawMonitorID callbackBlock;
00284 jrawMonitorID callbackLock;
00285 jint active_callbacks;
00286
00287
00288 jlong total_alloced_bytes;
00289 jlong total_alloced_instances;
00290 jint total_live_bytes;
00291 jint total_live_instances;
00292
00293
00294 jlong gc_start_time;
00295 jlong time_in_gc;
00296
00297
00298 jrawMonitorID data_access_lock;
00299
00300
00301 jrawMonitorID dump_lock;
00302
00303
00304 jlong micro_sec_ticks;
00305
00306
00307 ClassIndex thread_cnum;
00308
00309
00310 jboolean listener_loop_running;
00311 jrawMonitorID listener_loop_lock;
00312 jboolean cpu_loop_running;
00313 jrawMonitorID cpu_loop_lock;
00314 jrawMonitorID cpu_sample_lock;
00315 jint gc_finish;
00316 jboolean gc_finish_active;
00317 jboolean gc_finish_stop_request;
00318 jrawMonitorID gc_finish_lock;
00319
00320 jboolean pause_cpu_sampling;
00321
00322
00323 char * write_buffer;
00324 int write_buffer_index;
00325 int write_buffer_size;
00326 char * heap_buffer;
00327 int heap_buffer_index;
00328 int heap_buffer_size;
00329 jlong heap_last_tag_position;
00330 jlong heap_write_count;
00331 char * check_buffer;
00332 int check_buffer_index;
00333 int check_buffer_size;
00334
00335
00336
00337
00338 SerialNumber table_serial_number_start;
00339 SerialNumber class_serial_number_start;
00340 SerialNumber thread_serial_number_start;
00341 SerialNumber trace_serial_number_start;
00342 SerialNumber object_serial_number_start;
00343 SerialNumber frame_serial_number_start;
00344 SerialNumber gref_serial_number_start;
00345
00346 SerialNumber table_serial_number_counter;
00347 SerialNumber class_serial_number_counter;
00348 SerialNumber thread_serial_number_counter;
00349 SerialNumber trace_serial_number_counter;
00350 SerialNumber object_serial_number_counter;
00351 SerialNumber frame_serial_number_counter;
00352 SerialNumber gref_serial_number_counter;
00353
00354
00355 jmethodID object_init_method;
00356
00357
00358 volatile jint tracking_engaged;
00359 ClassIndex tracker_cnum;
00360 int tracker_method_count;
00361 struct {
00362 StringIndex name;
00363 StringIndex sig;
00364 jmethodID method;
00365 } tracker_methods[12];
00366
00367
00368 LoaderIndex system_loader;
00369 SerialNumber unknown_thread_serial_num;
00370 TraceIndex system_trace_index;
00371 SiteIndex system_object_site_index;
00372 jint system_class_size;
00373 TraceIndex hprof_trace_index;
00374 SiteIndex hprof_site_index;
00375
00376
00377 struct LookupTable * string_table;
00378 struct LookupTable * ioname_table;
00379 struct LookupTable * class_table;
00380 struct LookupTable * site_table;
00381 struct LookupTable * object_table;
00382 struct LookupTable * reference_table;
00383 struct LookupTable * frame_table;
00384 struct LookupTable * trace_table;
00385 struct LookupTable * monitor_table;
00386 struct LookupTable * tls_table;
00387 struct LookupTable * loader_table;
00388
00389
00390 void * java_crw_demo_library;
00391 void * java_crw_demo_function;
00392 void * java_crw_demo_classname_function;
00393
00394
00395 jboolean isLoaded;
00396
00397 } GlobalData;
00398
00399
00400
00401 extern GlobalData * gdata;
00402
00403 #endif
00404