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
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056 #include "hprof.h"
00057
00058 typedef struct SiteKey {
00059 ClassIndex cnum;
00060 TraceIndex trace_index;
00061 } SiteKey;
00062
00063 typedef struct SiteInfo {
00064 int changed;
00065 unsigned n_alloced_instances;
00066 unsigned n_alloced_bytes;
00067 unsigned n_live_instances;
00068 unsigned n_live_bytes;
00069 } SiteInfo;
00070
00071 typedef struct IterateInfo {
00072 SiteIndex * site_nums;
00073 int count;
00074 int changed_only;
00075 } IterateInfo;
00076
00077
00078
00079 static SiteKey*
00080 get_pkey(SiteIndex index)
00081 {
00082 void *key_ptr;
00083 int key_len;
00084
00085 table_get_key(gdata->site_table, index, &key_ptr, &key_len);
00086 HPROF_ASSERT(key_len==sizeof(SiteKey));
00087 HPROF_ASSERT(key_ptr!=NULL);
00088 return (SiteKey*)key_ptr;
00089 }
00090
00091 ClassIndex
00092 site_get_class_index(SiteIndex index)
00093 {
00094 SiteKey *pkey;
00095
00096 pkey = get_pkey(index);
00097 return pkey->cnum;
00098 }
00099
00100 TraceIndex
00101 site_get_trace_index(SiteIndex index)
00102 {
00103 SiteKey *pkey;
00104
00105 pkey = get_pkey(index);
00106 return pkey->trace_index;
00107 }
00108
00109 static SiteInfo *
00110 get_info(SiteIndex index)
00111 {
00112 SiteInfo *info;
00113
00114 info = (SiteInfo*)table_get_info(gdata->site_table, index);
00115 return info;
00116 }
00117
00118 static void
00119 list_item(TableIndex i, void *key_ptr, int key_len, void *info_ptr, void *arg)
00120 {
00121 SiteKey *pkey;
00122 jlong n_alloced_instances;
00123 jlong n_alloced_bytes;
00124 jlong n_live_instances;
00125 jlong n_live_bytes;
00126
00127 HPROF_ASSERT(key_ptr!=NULL);
00128 HPROF_ASSERT(key_len==sizeof(SiteKey));
00129 pkey = (SiteKey*)key_ptr;
00130
00131 if ( info_ptr != NULL ) {
00132 SiteInfo *info;
00133
00134 info = (SiteInfo *)info_ptr;
00135 n_alloced_instances = info->n_alloced_instances;
00136 n_alloced_bytes = info->n_alloced_bytes;
00137 n_live_instances = info->n_live_instances;
00138 n_live_bytes = info->n_live_bytes;
00139 } else {
00140 n_alloced_instances = 0;
00141 n_alloced_bytes = 0;
00142 n_live_instances = 0;
00143 n_live_bytes = 0;
00144 }
00145
00146 debug_message( "Site 0x%08x: class=0x%08x, trace=0x%08x, "
00147 "Ninst=(%d,%d), Nbytes=(%d,%d), "
00148 "Nlive=(%d,%d), NliveBytes=(%d,%d)\n",
00149 i,
00150 pkey->cnum,
00151 pkey->trace_index,
00152 jlong_high(n_alloced_instances), jlong_low(n_alloced_instances),
00153 jlong_high(n_alloced_bytes), jlong_low(n_alloced_bytes),
00154 jlong_high(n_live_instances), jlong_low(n_live_instances),
00155 jlong_high(n_live_bytes), jlong_low(n_live_bytes));
00156 }
00157
00158 static void
00159 collect_iterator(TableIndex i, void *key_ptr, int key_len, void *info_ptr, void *arg)
00160 {
00161 IterateInfo *iterate;
00162
00163 HPROF_ASSERT(key_ptr!=NULL);
00164 HPROF_ASSERT(key_len==sizeof(SiteKey));
00165 HPROF_ASSERT(arg!=NULL);
00166 iterate = (IterateInfo *)arg;
00167
00168 if ( iterate->changed_only ) {
00169 SiteInfo *info;
00170
00171 info = (SiteInfo *)info_ptr;
00172 if ( info==NULL || !info->changed ) {
00173 return;
00174 }
00175 }
00176 iterate->site_nums[iterate->count++] = i;
00177 }
00178
00179 static void
00180 mark_unchanged_iterator(TableIndex i, void *key_ptr, int key_len, void *info_ptr, void *arg)
00181 {
00182 SiteInfo *info;
00183
00184 HPROF_ASSERT(key_ptr!=NULL);
00185 HPROF_ASSERT(key_len==sizeof(SiteKey));
00186
00187 info = (SiteInfo *)info_ptr;
00188 if ( info != NULL ) {
00189 info->changed = 0;
00190 }
00191 }
00192
00193 static int
00194 qsort_compare_allocated_bytes(const void *p_site1, const void *p_site2)
00195 {
00196 SiteIndex site1;
00197 SiteIndex site2;
00198 SiteInfo *info1;
00199 SiteInfo *info2;
00200
00201 HPROF_ASSERT(p_site1!=NULL);
00202 HPROF_ASSERT(p_site2!=NULL);
00203 site1 = *(SiteIndex *)p_site1;
00204 site2 = *(SiteIndex *)p_site2;
00205 info1 = get_info(site1);
00206 info2 = get_info(site2);
00207 return info2->n_alloced_bytes - info1->n_alloced_bytes;
00208 }
00209
00210 static int
00211 qsort_compare_live_bytes(const void *p_site1, const void *p_site2)
00212 {
00213 SiteIndex site1;
00214 SiteIndex site2;
00215 SiteInfo *info1;
00216 SiteInfo *info2;
00217
00218 HPROF_ASSERT(p_site1!=NULL);
00219 HPROF_ASSERT(p_site2!=NULL);
00220 site1 = *(SiteIndex *)p_site1;
00221 site2 = *(SiteIndex *)p_site2;
00222 info1 = get_info(site1);
00223 info2 = get_info(site2);
00224 return info2->n_live_bytes - info1->n_live_bytes;
00225 }
00226
00227 static ClassIndex
00228 find_cnum(jlong class_tag)
00229 {
00230 ClassIndex cnum;
00231 ObjectIndex class_object_index;
00232 SiteIndex class_site_index;
00233 SiteKey *pkey;
00234
00235 HPROF_ASSERT(class_tag!=(jlong)0);
00236 class_object_index = tag_extract(class_tag);
00237 class_site_index = object_get_site(class_object_index);
00238 pkey = get_pkey(class_site_index);
00239 cnum = pkey->cnum;
00240 return cnum;
00241 }
00242
00243
00244 static jlong
00245 make_new_tag(jlong class_tag, jlong size, TraceIndex trace_index,
00246 SerialNumber thread_serial_num,
00247 ObjectIndex *pindex, SiteIndex *psite)
00248 {
00249 ObjectIndex object_index;
00250 SiteIndex object_site_index;
00251
00252 HPROF_ASSERT(class_tag!=(jlong)0);
00253 object_site_index = site_find_or_create(find_cnum(class_tag), trace_index);
00254 object_index = object_new(object_site_index, (jint)size,
00255 OBJECT_SYSTEM, thread_serial_num);
00256 if ( pindex != NULL ) {
00257 *pindex = object_index;
00258 }
00259 if ( psite != NULL ) {
00260 *psite = object_site_index;
00261 }
00262 return tag_create(object_index);
00263 }
00264
00265
00266 static void
00267 setup_tag_on_root(jlong *tag_ptr, jlong class_tag, jlong size,
00268 SerialNumber thread_serial_num,
00269 ObjectIndex *pindex, SiteIndex *psite)
00270 {
00271 HPROF_ASSERT(class_tag!=(jlong)0);
00272 if ( (*tag_ptr) != (jlong)0 ) {
00273 if ( pindex != NULL ) {
00274 *pindex = tag_extract(*tag_ptr);
00275 }
00276 if ( psite != NULL ) {
00277 *psite = object_get_site(tag_extract(*tag_ptr));
00278 }
00279 } else {
00280
00281 *tag_ptr = make_new_tag(class_tag, size, gdata->system_trace_index,
00282 thread_serial_num, pindex, psite);
00283 }
00284 }
00285
00286
00287
00288 SiteIndex
00289 site_find_or_create(ClassIndex cnum, TraceIndex trace_index)
00290 {
00291 SiteIndex index;
00292 static SiteKey empty_key;
00293 SiteKey key;
00294
00295 key = empty_key;
00296 HPROF_ASSERT(cnum!=0);
00297 HPROF_ASSERT(trace_index!=0);
00298 key.cnum = cnum;
00299 key.trace_index = trace_index;
00300 index = table_find_or_create_entry(gdata->site_table,
00301 &key, (int)sizeof(key), NULL, NULL);
00302 return index;
00303 }
00304
00305 void
00306 site_init(void)
00307 {
00308 HPROF_ASSERT(gdata->site_table==NULL);
00309 gdata->site_table = table_initialize("Site",
00310 1024, 1024, 511, (int)sizeof(SiteInfo));
00311 }
00312
00313 void
00314 site_list(void)
00315 {
00316 debug_message(
00317 "--------------------- Site Table ------------------------\n");
00318 table_walk_items(gdata->site_table, &list_item, NULL);
00319 debug_message(
00320 "----------------------------------------------------------\n");
00321 }
00322
00323 void
00324 site_cleanup(void)
00325 {
00326 table_cleanup(gdata->site_table, NULL, NULL);
00327 gdata->site_table = NULL;
00328 }
00329
00330 void
00331 site_update_stats(SiteIndex index, jint size, jint hits)
00332 {
00333 SiteInfo *info;
00334
00335 table_lock_enter(gdata->site_table); {
00336 info = get_info(index);
00337
00338 info->n_live_instances += hits;
00339 info->n_live_bytes += size;
00340 info->changed = 1;
00341
00342 gdata->total_live_bytes += size;
00343 gdata->total_live_instances += hits;
00344
00345 if ( size > 0 ) {
00346 info->n_alloced_instances += hits;
00347 info->n_alloced_bytes += size;
00348 gdata->total_alloced_bytes =
00349 jlong_add(gdata->total_alloced_bytes, jint_to_jlong(size));
00350 gdata->total_alloced_instances =
00351 jlong_add(gdata->total_alloced_instances, jint_to_jlong(hits));
00352 }
00353 } table_lock_exit(gdata->site_table);
00354 }
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364
00365 void
00366 site_write(JNIEnv *env, int flags, double cutoff)
00367 {
00368 HPROF_ASSERT(gdata->site_table!=NULL);
00369 LOG3("site_write", "flags", flags);
00370
00371 if (flags & SITE_FORCE_GC) {
00372 runGC();
00373 }
00374
00375 HPROF_ASSERT(gdata->total_live_bytes!=0);
00376
00377 rawMonitorEnter(gdata->data_access_lock); {
00378
00379 IterateInfo iterate;
00380 int site_table_size;
00381 double accum_percent;
00382 void * comment_str;
00383 int i;
00384 int cutoff_count;
00385 int nbytes;
00386
00387 accum_percent = 0;
00388 site_table_size = table_element_count(gdata->site_table);
00389
00390 (void)memset(&iterate, 0, sizeof(iterate));
00391 nbytes = site_table_size * (int)sizeof(SiteIndex);
00392 if ( nbytes > 0 ) {
00393 iterate.site_nums = HPROF_MALLOC(nbytes);
00394 (void)memset(iterate.site_nums, 0, nbytes);
00395 }
00396 iterate.count = 0;
00397 iterate.changed_only = flags & SITE_DUMP_INCREMENTAL;
00398 table_walk_items(gdata->site_table, &collect_iterator, &iterate);
00399
00400 site_table_size = iterate.count;
00401
00402 if (flags & SITE_SORT_BY_ALLOC) {
00403 comment_str = "allocated bytes";
00404 qsort(iterate.site_nums, site_table_size, sizeof(SiteIndex),
00405 &qsort_compare_allocated_bytes);
00406 } else {
00407 comment_str = "live bytes";
00408 qsort(iterate.site_nums, site_table_size, sizeof(SiteIndex),
00409 &qsort_compare_live_bytes);
00410 }
00411
00412 trace_output_unmarked(env);
00413
00414 cutoff_count = 0;
00415 for (i = 0; i < site_table_size; i++) {
00416 SiteInfo *info;
00417 SiteIndex index;
00418 double ratio;
00419
00420 index= iterate.site_nums[i];
00421 HPROF_ASSERT(index!=0);
00422 info = get_info(index);
00423 ratio = (double)info->n_live_bytes / (double)gdata->total_live_bytes;
00424 if (ratio < cutoff) {
00425 break;
00426 }
00427 cutoff_count++;
00428 }
00429
00430 io_write_sites_header( comment_str,
00431 flags,
00432 cutoff,
00433 gdata->total_live_bytes,
00434 gdata->total_live_instances,
00435 gdata->total_alloced_bytes,
00436 gdata->total_alloced_instances,
00437 cutoff_count);
00438
00439 for (i = 0; i < cutoff_count; i++) {
00440 SiteInfo *info;
00441 SiteKey *pkey;
00442 SiteIndex index;
00443 char *class_signature;
00444 double ratio;
00445
00446 index = iterate.site_nums[i];
00447 pkey = get_pkey(index);
00448 info = get_info(index);
00449
00450 ratio = (double)info->n_live_bytes / (double)gdata->total_live_bytes;
00451 accum_percent += ratio;
00452
00453 class_signature = string_get(class_get_signature(pkey->cnum));
00454
00455 io_write_sites_elem(i + 1,
00456 ratio,
00457 accum_percent,
00458 class_signature,
00459 class_get_serial_number(pkey->cnum),
00460 trace_get_serial_number(pkey->trace_index),
00461 info->n_live_bytes,
00462 info->n_live_instances,
00463 info->n_alloced_bytes,
00464 info->n_alloced_instances);
00465 }
00466
00467 io_write_sites_footer();
00468
00469 table_walk_items(gdata->site_table, &mark_unchanged_iterator, NULL);
00470
00471 if ( iterate.site_nums != NULL ) {
00472 HPROF_FREE(iterate.site_nums);
00473 }
00474
00475 } rawMonitorExit(gdata->data_access_lock);
00476 }
00477
00478
00479 static jint JNICALL
00480 cbPrimArrayData(jlong class_tag, jlong size, jlong* tag_ptr,
00481 jint element_count, jvmtiPrimitiveType element_type,
00482 const void* elements, void* user_data)
00483 {
00484 ObjectIndex object_index;
00485 RefIndex ref_index;
00486 RefIndex prev_ref_index;
00487
00488 HPROF_ASSERT(tag_ptr!=NULL);
00489 HPROF_ASSERT(class_tag!=(jlong)0);
00490 HPROF_ASSERT((*tag_ptr)!=(jlong)0);
00491 if ( class_tag == (jlong)0 || (*tag_ptr) == (jlong)0 ) {
00492
00493 return JVMTI_VISIT_OBJECTS;
00494 }
00495
00496
00497 object_index = tag_extract((*tag_ptr));
00498
00499
00500 prev_ref_index = object_get_references(object_index);
00501 ref_index = reference_prim_array(prev_ref_index,
00502 element_type, elements, element_count);
00503 object_set_references(object_index, ref_index);
00504
00505 return JVMTI_VISIT_OBJECTS;
00506 }
00507
00508
00509 static jint JNICALL
00510 cbPrimFieldData(jvmtiHeapReferenceKind reference_kind,
00511 const jvmtiHeapReferenceInfo* reference_info, jlong class_tag,
00512 jlong* tag_ptr, jvalue value, jvmtiPrimitiveType value_type,
00513 void* user_data)
00514 {
00515 ObjectIndex object_index;
00516 jint field_index;
00517 RefIndex ref_index;
00518 RefIndex prev_ref_index;
00519
00520 HPROF_ASSERT(tag_ptr!=NULL);
00521 HPROF_ASSERT(class_tag!=(jlong)0);
00522 HPROF_ASSERT((*tag_ptr)!=(jlong)0);
00523 if ( class_tag == (jlong)0 || (*tag_ptr) == (jlong)0 ) {
00524
00525 return JVMTI_VISIT_OBJECTS;
00526 }
00527
00528
00529 if ( value.j == (jlong)0 ) {
00530 return JVMTI_VISIT_OBJECTS;
00531 }
00532
00533
00534 field_index = reference_info->field.index;
00535
00536
00537 object_index = tag_extract((*tag_ptr));
00538
00539
00540 prev_ref_index = object_get_references(object_index);
00541 ref_index = reference_prim_field(prev_ref_index, reference_kind,
00542 value_type, value, field_index);
00543 object_set_references(object_index, ref_index);
00544
00545 return JVMTI_VISIT_OBJECTS;
00546 }
00547
00548 static SerialNumber
00549 checkThreadSerialNumber(SerialNumber thread_serial_num)
00550 {
00551 TlsIndex tls_index;
00552
00553 if ( thread_serial_num == gdata->unknown_thread_serial_num ) {
00554 return thread_serial_num;
00555 }
00556 tls_index = tls_find(thread_serial_num);
00557 if ( tls_index != 0 && tls_get_in_heap_dump(tls_index) != 0 ) {
00558 return thread_serial_num;
00559 }
00560 return gdata->unknown_thread_serial_num;
00561 }
00562
00563
00564 static void
00565 localReference(jlong *tag_ptr, jlong class_tag, jlong thread_tag,
00566 jlong size, ObjectIndex *pobject_index, SerialNumber *pthread_serial_num)
00567 {
00568 ObjectIndex object_index;
00569 SerialNumber thread_serial_num;
00570
00571 HPROF_ASSERT(pobject_index!=NULL);
00572 HPROF_ASSERT(pthread_serial_num!=NULL);
00573 HPROF_ASSERT(tag_ptr!=NULL);
00574 HPROF_ASSERT(class_tag!=(jlong)0);
00575
00576 if ( (*tag_ptr) != (jlong)0 ) {
00577 object_index = tag_extract(*tag_ptr);
00578 thread_serial_num = object_get_thread_serial_number(object_index);
00579 thread_serial_num = checkThreadSerialNumber(thread_serial_num);
00580 } else {
00581 if ( thread_tag != (jlong)0 ) {
00582 ObjectIndex thread_object_index;
00583
00584 thread_object_index = tag_extract(thread_tag);
00585 thread_serial_num =
00586 object_get_thread_serial_number(thread_object_index);
00587 thread_serial_num = checkThreadSerialNumber(thread_serial_num);
00588 } else {
00589 thread_serial_num = gdata->unknown_thread_serial_num;
00590 }
00591
00592 *tag_ptr = make_new_tag(class_tag, size, gdata->system_trace_index,
00593 thread_serial_num, &object_index, NULL);
00594 }
00595
00596 HPROF_ASSERT(thread_serial_num!=0);
00597 HPROF_ASSERT(object_index!=0);
00598 *pobject_index = object_index;
00599 *pthread_serial_num = thread_serial_num;
00600 }
00601
00602
00603 static jint
00604 objectReference(jvmtiHeapReferenceKind reference_kind,
00605 const jvmtiHeapReferenceInfo* reference_info,
00606 jlong class_tag, jlong size, jlong* tag_ptr,
00607 jlong* referrer_tag_ptr, jint length)
00608 {
00609 ObjectIndex object_index;
00610 jint reference_index;
00611 RefIndex ref_index;
00612 RefIndex prev_ref_index;
00613 ObjectIndex referrer_object_index;
00614 jlong object_tag;
00615
00616 HPROF_ASSERT(tag_ptr!=NULL);
00617 HPROF_ASSERT(class_tag!=(jlong)0);
00618 HPROF_ASSERT(referrer_tag_ptr!=NULL);
00619 HPROF_ASSERT((*referrer_tag_ptr)!=(jlong)0);
00620 if ( class_tag == (jlong)0 || (*referrer_tag_ptr) == (jlong)0 ) {
00621
00622 return JVMTI_VISIT_OBJECTS;
00623 }
00624
00625 switch ( reference_kind ) {
00626 case JVMTI_HEAP_REFERENCE_CLASS_LOADER:
00627 case JVMTI_HEAP_REFERENCE_INTERFACE:
00628 default:
00629
00630 return JVMTI_VISIT_OBJECTS;
00631 case JVMTI_HEAP_REFERENCE_FIELD:
00632 case JVMTI_HEAP_REFERENCE_STATIC_FIELD:
00633 reference_index = reference_info->field.index;
00634 break;
00635 case JVMTI_HEAP_REFERENCE_ARRAY_ELEMENT:
00636 reference_index = reference_info->array.index;
00637 break;
00638 case JVMTI_HEAP_REFERENCE_CONSTANT_POOL:
00639 reference_index = reference_info->constant_pool.index;
00640 break;
00641 case JVMTI_HEAP_REFERENCE_SIGNERS:
00642 case JVMTI_HEAP_REFERENCE_PROTECTION_DOMAIN:
00643 reference_index = 0;
00644 break;
00645 }
00646
00647
00648 referrer_object_index = tag_extract((*referrer_tag_ptr));
00649
00650
00651 object_tag = *tag_ptr;
00652 if ( object_tag != (jlong)0 ) {
00653 object_index = tag_extract(object_tag);
00654 } else {
00655
00656 object_tag = make_new_tag(class_tag, size, gdata->system_trace_index,
00657 gdata->unknown_thread_serial_num,
00658 &object_index, NULL);
00659 *tag_ptr = object_tag;
00660 }
00661 HPROF_ASSERT(object_index!=0);
00662
00663
00664 prev_ref_index = object_get_references(referrer_object_index);
00665 ref_index = reference_obj(prev_ref_index, reference_kind,
00666 object_index, reference_index, length);
00667 object_set_references(referrer_object_index, ref_index);
00668
00669 return JVMTI_VISIT_OBJECTS;
00670 }
00671
00672
00673 static jint JNICALL
00674 cbReference(jvmtiHeapReferenceKind reference_kind,
00675 const jvmtiHeapReferenceInfo* reference_info,
00676 jlong class_tag, jlong referrer_class_tag,
00677 jlong size, jlong* tag_ptr,
00678 jlong* referrer_tag_ptr, jint length, void* user_data)
00679 {
00680 ObjectIndex object_index;
00681
00682
00683
00684
00685
00686 HPROF_ASSERT(tag_ptr!=NULL);
00687 HPROF_ASSERT(class_tag!=(jlong)0);
00688 if ( class_tag == (jlong)0 ) {
00689
00690 return JVMTI_VISIT_OBJECTS;
00691 }
00692
00693 switch ( reference_kind ) {
00694
00695 case JVMTI_HEAP_REFERENCE_FIELD:
00696 case JVMTI_HEAP_REFERENCE_ARRAY_ELEMENT:
00697 case JVMTI_HEAP_REFERENCE_CLASS_LOADER:
00698 case JVMTI_HEAP_REFERENCE_SIGNERS:
00699 case JVMTI_HEAP_REFERENCE_PROTECTION_DOMAIN:
00700 case JVMTI_HEAP_REFERENCE_INTERFACE:
00701 case JVMTI_HEAP_REFERENCE_STATIC_FIELD:
00702 case JVMTI_HEAP_REFERENCE_CONSTANT_POOL:
00703 return objectReference(reference_kind, reference_info,
00704 class_tag, size, tag_ptr, referrer_tag_ptr, length);
00705
00706 case JVMTI_HEAP_REFERENCE_JNI_GLOBAL: {
00707 SerialNumber trace_serial_num;
00708 SerialNumber gref_serial_num;
00709 TraceIndex trace_index;
00710 SiteIndex object_site_index;
00711
00712 setup_tag_on_root(tag_ptr, class_tag, size,
00713 gdata->unknown_thread_serial_num,
00714 &object_index, &object_site_index);
00715 if ( object_site_index != 0 ) {
00716 SiteKey *pkey;
00717
00718 pkey = get_pkey(object_site_index);
00719 trace_index = pkey->trace_index;
00720 } else {
00721 trace_index = gdata->system_trace_index;
00722 }
00723 trace_serial_num = trace_get_serial_number(trace_index);
00724 gref_serial_num = gdata->gref_serial_number_counter++;
00725 io_heap_root_jni_global(object_index, gref_serial_num,
00726 trace_serial_num);
00727 }
00728 break;
00729
00730 case JVMTI_HEAP_REFERENCE_SYSTEM_CLASS: {
00731 char *sig;
00732 SerialNumber class_serial_num;
00733 SiteIndex object_site_index;
00734
00735 setup_tag_on_root(tag_ptr, class_tag, size,
00736 gdata->unknown_thread_serial_num,
00737 &object_index, &object_site_index);
00738 sig = "Unknown";
00739 class_serial_num = 0;
00740 if ( object_site_index != 0 ) {
00741 SiteKey *pkey;
00742
00743 pkey = get_pkey(object_site_index);
00744 sig = string_get(class_get_signature(pkey->cnum));
00745 class_serial_num = class_get_serial_number(pkey->cnum);
00746 }
00747 io_heap_root_system_class(object_index, sig, class_serial_num);
00748 }
00749 break;
00750
00751 case JVMTI_HEAP_REFERENCE_MONITOR:
00752 setup_tag_on_root(tag_ptr, class_tag, size,
00753 gdata->unknown_thread_serial_num,
00754 &object_index, NULL);
00755 io_heap_root_monitor(object_index);
00756 break;
00757
00758 case JVMTI_HEAP_REFERENCE_STACK_LOCAL: {
00759 SerialNumber thread_serial_num;
00760 jlong thread_tag;
00761
00762 thread_tag = reference_info->stack_local.thread_tag;
00763 localReference(tag_ptr, class_tag, thread_tag, size,
00764 &object_index, &thread_serial_num);
00765 io_heap_root_java_frame(object_index, thread_serial_num,
00766 reference_info->stack_local.depth);
00767 }
00768 break;
00769
00770 case JVMTI_HEAP_REFERENCE_JNI_LOCAL: {
00771 SerialNumber thread_serial_num;
00772 jlong thread_tag;
00773
00774 thread_tag = reference_info->jni_local.thread_tag;
00775 localReference(tag_ptr, class_tag, thread_tag, size,
00776 &object_index, &thread_serial_num);
00777 io_heap_root_jni_local(object_index, thread_serial_num,
00778 reference_info->jni_local.depth);
00779 }
00780 break;
00781
00782 case JVMTI_HEAP_REFERENCE_THREAD: {
00783 SerialNumber thread_serial_num;
00784 SerialNumber trace_serial_num;
00785 TraceIndex trace_index;
00786 SiteIndex object_site_index;
00787 TlsIndex tls_index;
00788
00789
00790
00791
00792 if ( (*tag_ptr) != (jlong)0 ) {
00793 setup_tag_on_root(tag_ptr, class_tag, size, 0,
00794 &object_index, &object_site_index);
00795 trace_index = site_get_trace_index(object_site_index);
00796
00797
00798
00799 thread_serial_num = object_get_thread_serial_number(object_index);
00800 } else {
00801
00802
00803
00804
00805
00806
00807 thread_serial_num = gdata->thread_serial_number_counter++;
00808 setup_tag_on_root(tag_ptr, class_tag, size,
00809 thread_serial_num,
00810 &object_index, &object_site_index);
00811 trace_index = gdata->system_trace_index;
00812 }
00813
00814 tls_index = tls_find(thread_serial_num);
00815 if ( tls_index != 0 ) {
00816 tls_set_in_heap_dump(tls_index, 1);
00817 }
00818 trace_serial_num = trace_get_serial_number(trace_index);
00819
00820 io_heap_root_thread_object(object_index,
00821 thread_serial_num, trace_serial_num);
00822
00823 io_heap_root_thread(object_index, thread_serial_num);
00824 }
00825 break;
00826
00827 case JVMTI_HEAP_REFERENCE_OTHER:
00828 setup_tag_on_root(tag_ptr, class_tag, size,
00829 gdata->unknown_thread_serial_num,
00830 &object_index, NULL);
00831 io_heap_root_unknown(object_index);
00832 break;
00833
00834 default:
00835
00836 break;
00837
00838 }
00839
00840 return JVMTI_VISIT_OBJECTS;
00841 }
00842
00843 void
00844 site_heapdump(JNIEnv *env)
00845 {
00846
00847 rawMonitorEnter(gdata->data_access_lock); {
00848
00849 jvmtiHeapCallbacks heapCallbacks;
00850
00851
00852 class_all_status_remove(CLASS_DUMPED);
00853
00854
00855 tls_clear_in_heap_dump();
00856
00857
00858 tls_dump_traces(env);
00859
00860
00861 io_heap_header(gdata->total_live_instances, gdata->total_live_bytes);
00862
00863
00864 reference_init();
00865
00866
00867 gdata->gref_serial_number_counter = gdata->gref_serial_number_start;
00868
00869
00870
00871
00872
00873 io_heap_root_thread_object(0, gdata->unknown_thread_serial_num,
00874 trace_get_serial_number(gdata->system_trace_index));
00875
00876
00877 (void)memset(&heapCallbacks, 0, sizeof(heapCallbacks));
00878
00879
00880 heapCallbacks.heap_reference_callback = &cbReference;
00881 if ( gdata->primfields == JNI_TRUE ) {
00882 heapCallbacks.primitive_field_callback = &cbPrimFieldData;
00883 }
00884 if ( gdata->primarrays == JNI_TRUE ) {
00885 heapCallbacks.array_primitive_value_callback = &cbPrimArrayData;
00886 }
00887 followReferences(&heapCallbacks, (void*)NULL);
00888
00889
00890 object_reference_dump(env);
00891 object_clear_references();
00892 reference_cleanup();
00893
00894
00895 tls_dump_traces(env);
00896
00897
00898 io_heap_footer();
00899
00900 } rawMonitorExit(gdata->data_access_lock);
00901 }
00902