319 HierarchyClosure(GrowableArray<KlassInfoEntry*> *_elements) : _elements(_elements) {}
320
321 void do_cinfo(KlassInfoEntry* cie) {
322 // ignore array classes
323 if (cie->klass()->oop_is_instance()) {
324 _elements->append(cie);
325 }
326 }
327 };
328
329 void KlassHierarchy::print_class_hierarchy(outputStream* st, bool print_interfaces,
330 bool print_subclasses, char* classname) {
331 ResourceMark rm;
332 Stack <KlassInfoEntry*, mtClass> class_stack;
333 GrowableArray<KlassInfoEntry*> elements;
334
335 // Add all classes to the KlassInfoTable, which allows for quick lookup.
336 // A KlassInfoEntry will be created for each class.
337 KlassInfoTable cit(true);
338 if (cit.allocation_failed()) {
339 st->print_cr("WARNING: Ran out of C-heap; hierarchy not generated");
340 return;
341 }
342
343 // Add all created KlassInfoEntry instances to the elements array for easy
344 // iteration, and to allow each KlassInfoEntry instance to have a unique index.
345 HierarchyClosure hc(&elements);
346 cit.iterate(&hc);
347
348 for(int i = 0; i < elements.length(); i++) {
349 KlassInfoEntry* cie = elements.at(i);
350 const InstanceKlass* k = (InstanceKlass*)cie->klass();
351 Klass* super = ((InstanceKlass*)k)->java_super();
352
353 // Set the index for the class.
354 cie->set_index(i + 1);
355
356 // Add the class to the subclass array of its superclass.
357 if (super != NULL) {
358 KlassInfoEntry* super_cie = cit.lookup(super);
359 assert(super_cie != NULL, "could not lookup superclass");
431 }
432 }
433
434 static void print_indent(outputStream* st, int indent) {
435 while (indent != 0) {
436 st->print("|");
437 indent--;
438 if (indent != 0) {
439 st->print(" ");
440 }
441 }
442 }
443
444 // Print the class name and its unique ClassLoader identifer.
445 static void print_classname(outputStream* st, Klass* klass) {
446 oop loader_oop = klass->class_loader_data()->class_loader();
447 st->print("%s/", klass->external_name());
448 if (loader_oop == NULL) {
449 st->print("null");
450 } else {
451 st->print(INTPTR_FORMAT, loader_oop->klass());
452 }
453 }
454
455 static void print_interface(outputStream* st, Klass* intf_klass, const char* intf_type, int indent) {
456 print_indent(st, indent);
457 st->print(" implements ");
458 print_classname(st, intf_klass);
459 st->print(" (%s intf)\n", intf_type);
460 }
461
462 void KlassHierarchy::print_class(outputStream* st, KlassInfoEntry* cie, bool print_interfaces) {
463 ResourceMark rm;
464 InstanceKlass* klass = (InstanceKlass*)cie->klass();
465 int indent = 0;
466
467 // Print indentation with proper indicators of superclass.
468 Klass* super = klass->super();
469 while (super != NULL) {
470 super = super->super();
471 indent++;
474 if (indent != 0) st->print("--");
475
476 // Print the class name, its unique ClassLoader identifer, and if it is an interface.
477 print_classname(st, klass);
478 if (klass->is_interface()) {
479 st->print(" (intf)");
480 }
481 st->print("\n");
482
483 // Print any interfaces the class has.
484 if (print_interfaces) {
485 Array<Klass*>* local_intfs = klass->local_interfaces();
486 Array<Klass*>* trans_intfs = klass->transitive_interfaces();
487 for (int i = 0; i < local_intfs->length(); i++) {
488 print_interface(st, local_intfs->at(i), "declared", indent);
489 }
490 for (int i = 0; i < trans_intfs->length(); i++) {
491 Klass* trans_interface = trans_intfs->at(i);
492 // Only print transitive interfaces if they are not also declared.
493 if (!local_intfs->contains(trans_interface)) {
494 print_interface(st, trans_interface, "transitive", indent);
495 }
496 }
497 }
498 }
499
500 void KlassInfoHisto::print_class_stats(outputStream* st,
501 bool csv_format, const char *columns) {
502 KlassSizeStats sz, sz_sum;
503 int i;
504 julong *col_table = (julong*)(&sz);
505 julong *colsum_table = (julong*)(&sz_sum);
506 int width_table[KlassSizeStats::_num_columns];
507 bool selected[KlassSizeStats::_num_columns];
508
509 _selected_columns = columns;
510
511 memset(&sz_sum, 0, sizeof(sz_sum));
512 for (int c=0; c<KlassSizeStats::_num_columns; c++) {
513 selected[c] = is_selected(name_table[c]);
514 }
|
319 HierarchyClosure(GrowableArray<KlassInfoEntry*> *_elements) : _elements(_elements) {}
320
321 void do_cinfo(KlassInfoEntry* cie) {
322 // ignore array classes
323 if (cie->klass()->oop_is_instance()) {
324 _elements->append(cie);
325 }
326 }
327 };
328
329 void KlassHierarchy::print_class_hierarchy(outputStream* st, bool print_interfaces,
330 bool print_subclasses, char* classname) {
331 ResourceMark rm;
332 Stack <KlassInfoEntry*, mtClass> class_stack;
333 GrowableArray<KlassInfoEntry*> elements;
334
335 // Add all classes to the KlassInfoTable, which allows for quick lookup.
336 // A KlassInfoEntry will be created for each class.
337 KlassInfoTable cit(true);
338 if (cit.allocation_failed()) {
339 st->print_cr("ERROR: Ran out of C-heap; hierarchy not generated");
340 return;
341 }
342
343 // Add all created KlassInfoEntry instances to the elements array for easy
344 // iteration, and to allow each KlassInfoEntry instance to have a unique index.
345 HierarchyClosure hc(&elements);
346 cit.iterate(&hc);
347
348 for(int i = 0; i < elements.length(); i++) {
349 KlassInfoEntry* cie = elements.at(i);
350 const InstanceKlass* k = (InstanceKlass*)cie->klass();
351 Klass* super = ((InstanceKlass*)k)->java_super();
352
353 // Set the index for the class.
354 cie->set_index(i + 1);
355
356 // Add the class to the subclass array of its superclass.
357 if (super != NULL) {
358 KlassInfoEntry* super_cie = cit.lookup(super);
359 assert(super_cie != NULL, "could not lookup superclass");
431 }
432 }
433
434 static void print_indent(outputStream* st, int indent) {
435 while (indent != 0) {
436 st->print("|");
437 indent--;
438 if (indent != 0) {
439 st->print(" ");
440 }
441 }
442 }
443
444 // Print the class name and its unique ClassLoader identifer.
445 static void print_classname(outputStream* st, Klass* klass) {
446 oop loader_oop = klass->class_loader_data()->class_loader();
447 st->print("%s/", klass->external_name());
448 if (loader_oop == NULL) {
449 st->print("null");
450 } else {
451 st->print(INTPTR_FORMAT, klass->class_loader_data());
452 }
453 }
454
455 static void print_interface(outputStream* st, Klass* intf_klass, const char* intf_type, int indent) {
456 print_indent(st, indent);
457 st->print(" implements ");
458 print_classname(st, intf_klass);
459 st->print(" (%s intf)\n", intf_type);
460 }
461
462 void KlassHierarchy::print_class(outputStream* st, KlassInfoEntry* cie, bool print_interfaces) {
463 ResourceMark rm;
464 InstanceKlass* klass = (InstanceKlass*)cie->klass();
465 int indent = 0;
466
467 // Print indentation with proper indicators of superclass.
468 Klass* super = klass->super();
469 while (super != NULL) {
470 super = super->super();
471 indent++;
474 if (indent != 0) st->print("--");
475
476 // Print the class name, its unique ClassLoader identifer, and if it is an interface.
477 print_classname(st, klass);
478 if (klass->is_interface()) {
479 st->print(" (intf)");
480 }
481 st->print("\n");
482
483 // Print any interfaces the class has.
484 if (print_interfaces) {
485 Array<Klass*>* local_intfs = klass->local_interfaces();
486 Array<Klass*>* trans_intfs = klass->transitive_interfaces();
487 for (int i = 0; i < local_intfs->length(); i++) {
488 print_interface(st, local_intfs->at(i), "declared", indent);
489 }
490 for (int i = 0; i < trans_intfs->length(); i++) {
491 Klass* trans_interface = trans_intfs->at(i);
492 // Only print transitive interfaces if they are not also declared.
493 if (!local_intfs->contains(trans_interface)) {
494 print_interface(st, trans_interface, "inherited", indent);
495 }
496 }
497 }
498 }
499
500 void KlassInfoHisto::print_class_stats(outputStream* st,
501 bool csv_format, const char *columns) {
502 KlassSizeStats sz, sz_sum;
503 int i;
504 julong *col_table = (julong*)(&sz);
505 julong *colsum_table = (julong*)(&sz_sum);
506 int width_table[KlassSizeStats::_num_columns];
507 bool selected[KlassSizeStats::_num_columns];
508
509 _selected_columns = columns;
510
511 memset(&sz_sum, 0, sizeof(sz_sum));
512 for (int c=0; c<KlassSizeStats::_num_columns; c++) {
513 selected[c] = is_selected(name_table[c]);
514 }
|