< prev index next >

src/hotspot/share/classfile/classLoaderHierarchyDCmd.cpp

Print this page




 112     Mark(BranchTracker& tr, bool has_branch_here)
 113       : _tr(tr)  { _tr.push(has_branch_here); }
 114     ~Mark() { _tr.pop(); }
 115   };
 116 
 117 }; // end: BranchTracker
 118 
 119 struct LoadedClassInfo : public ResourceObj {
 120 public:
 121   LoadedClassInfo* _next;
 122   Klass* const _klass;
 123   const ClassLoaderData* const _cld;
 124 
 125   LoadedClassInfo(Klass* klass, const ClassLoaderData* cld)
 126     : _klass(klass), _cld(cld) {}
 127 
 128 };
 129 
 130 class LoaderTreeNode : public ResourceObj {
 131 
 132   // We walk the CLDG and, for each CLD which is non-unsafe_anonymous, add
 133   // a tree node.
 134   // To add a node we need its parent node; if the parent node does not yet
 135   // exist - because we have not yet encountered the CLD for the parent loader -
 136   // we add a preliminary empty LoaderTreeNode for it. This preliminary node
 137   // just contains the loader oop and nothing else. Once we encounter the CLD of
 138   // this parent loader, we fill in all the other details.
 139 
 140   const oop _loader_oop;
 141   const ClassLoaderData* _cld;
 142 
 143   LoaderTreeNode* _child;
 144   LoaderTreeNode* _next;
 145 
 146   LoadedClassInfo* _classes;
 147   int _num_classes;
 148 
 149   LoadedClassInfo* _anon_classes;
 150   int _num_anon_classes;
 151 
 152   // In default view, similar tree nodes (same loader class, same name or no name)


 203       st->cr();
 204 
 205       const int indentation = 18;
 206 
 207       if (verbose) {
 208         branchtracker.print(st);
 209         st->print_cr("%*s " PTR_FORMAT, indentation, "Loader Oop:", p2i(_loader_oop));
 210         branchtracker.print(st);
 211         st->print_cr("%*s " PTR_FORMAT, indentation, "Loader Data:", p2i(_cld));
 212         branchtracker.print(st);
 213         st->print_cr("%*s " PTR_FORMAT, indentation, "Loader Klass:", p2i(loader_klass));
 214 
 215         // Empty line
 216         branchtracker.print(st);
 217         st->cr();
 218       }
 219 
 220       if (print_classes) {
 221         if (_classes != NULL) {
 222           for (LoadedClassInfo* lci = _classes; lci; lci = lci->_next) {
 223             // Non-unsafe anonymous classes should live in the primary CLD of its loader
 224             assert(lci->_cld == _cld, "must be");
 225 
 226             branchtracker.print(st);
 227             if (lci == _classes) { // first iteration
 228               st->print("%*s ", indentation, "Classes:");
 229             } else {
 230               st->print("%*s ", indentation, "");
 231             }
 232             st->print("%s", lci->_klass->external_name());
 233 
 234             // Special treatment for generated core reflection accessor classes: print invocation target.
 235             if (ReflectionAccessorImplKlassHelper::is_generated_accessor(lci->_klass)) {
 236               st->print(" (invokes: ");
 237               ReflectionAccessorImplKlassHelper::print_invocation_target(st, lci->_klass);
 238               st->print(")");
 239             }
 240 
 241             st->cr();
 242           }
 243           branchtracker.print(st);
 244           st->print("%*s ", indentation, "");
 245           st->print_cr("(%u class%s)", _num_classes, (_num_classes == 1) ? "" : "es");
 246 
 247           // Empty line
 248           branchtracker.print(st);
 249           st->cr();
 250         }
 251 
 252         if (_anon_classes != NULL) {
 253           for (LoadedClassInfo* lci = _anon_classes; lci; lci = lci->_next) {
 254             branchtracker.print(st);
 255             if (lci == _anon_classes) { // first iteration
 256               st->print("%*s ", indentation, "Unsafe Anonymous Classes:");
 257             } else {
 258               st->print("%*s ", indentation, "");
 259             }
 260             st->print("%s", lci->_klass->external_name());
 261             // For unsafe anonymous classes, also print CLD if verbose. Should be a different one than the primary CLD.
 262             assert(lci->_cld != _cld, "must be");
 263             if (verbose) {
 264               st->print("  (Loader Data: " PTR_FORMAT ")", p2i(lci->_cld));
 265             }
 266             st->cr();
 267           }
 268           branchtracker.print(st);
 269           st->print("%*s ", indentation, "");
 270           st->print_cr("(%u unsafe anonymous class%s)", _num_anon_classes, (_num_anon_classes == 1) ? "" : "es");
 271 
 272           // Empty line
 273           branchtracker.print(st);
 274           st->cr();
 275         }
 276 
 277       } // end: print_classes
 278 
 279     } // Pop branchtracker mark
 280 
 281     // Print children, recursively


 302     : _loader_oop(loader_oop), _cld(NULL), _child(NULL), _next(NULL),
 303       _classes(NULL), _num_classes(0), _anon_classes(NULL), _num_anon_classes(0),
 304       _num_folded(0)
 305     {}
 306 
 307   void set_cld(const ClassLoaderData* cld) {
 308     _cld = cld;
 309   }
 310 
 311   void add_child(LoaderTreeNode* info) {
 312     info->_next = _child;
 313     _child = info;
 314   }
 315 
 316   void add_sibling(LoaderTreeNode* info) {
 317     assert(info->_next == NULL, "must be");
 318     info->_next = _next;
 319     _next = info;
 320   }
 321 
 322   void add_classes(LoadedClassInfo* first_class, int num_classes, bool is_unsafe_anonymous) {
 323     LoadedClassInfo** p_list_to_add_to = is_unsafe_anonymous ? &_anon_classes : &_classes;
 324     // Search tail.
 325     while ((*p_list_to_add_to) != NULL) {
 326       p_list_to_add_to = &(*p_list_to_add_to)->_next;
 327     }
 328     *p_list_to_add_to = first_class;
 329     if (is_unsafe_anonymous) {
 330       _num_anon_classes += num_classes;
 331     } else {
 332       _num_classes += num_classes;
 333     }
 334   }
 335 
 336   const ClassLoaderData* cld() const {
 337     return _cld;
 338   }
 339 
 340   const oop loader_oop() const {
 341     return _loader_oop;
 342   }
 343 
 344   LoaderTreeNode* find(const oop loader_oop) {
 345     LoaderTreeNode* result = NULL;
 346     if (_loader_oop == loader_oop) {
 347       result = this;
 348     } else {
 349       LoaderTreeNode* c = _child;


 404     : _list(NULL), _cld(cld), _num_classes(0) {}
 405   void do_klass(Klass* k) {
 406     LoadedClassInfo* lki = new LoadedClassInfo(k, _cld);
 407     lki->_next = _list;
 408     _list = lki;
 409     _num_classes ++;
 410   }
 411 };
 412 
 413 class LoaderInfoScanClosure : public CLDClosure {
 414 
 415   const bool _print_classes;
 416   const bool _verbose;
 417   LoaderTreeNode* _root;
 418 
 419   static void fill_in_classes(LoaderTreeNode* info, const ClassLoaderData* cld) {
 420     assert(info != NULL && cld != NULL, "must be");
 421     LoadedClassCollectClosure lccc(cld);
 422     const_cast<ClassLoaderData*>(cld)->classes_do(&lccc);
 423     if (lccc._num_classes > 0) {
 424       info->add_classes(lccc._list, lccc._num_classes, cld->is_unsafe_anonymous());
 425     }
 426   }
 427 
 428   LoaderTreeNode* find_node_or_add_empty_node(oop loader_oop) {
 429 
 430     assert(_root != NULL, "root node must exist");
 431 
 432     if (loader_oop == NULL) {
 433       return _root;
 434     }
 435 
 436     // Check if a node for this oop already exists.
 437     LoaderTreeNode* info = _root->find(loader_oop);
 438 
 439     if (info == NULL) {
 440       // It does not. Create a node.
 441       info = new LoaderTreeNode(loader_oop);
 442 
 443       // Add it to tree.
 444       LoaderTreeNode* parent_info = NULL;


 464     _root = new LoaderTreeNode(NULL);
 465   }
 466 
 467   void print_results(outputStream* st) const {
 468     _root->print_with_childs(st, _print_classes, _verbose);
 469   }
 470 
 471   void do_cld (ClassLoaderData* cld) {
 472 
 473     // We do not display unloading loaders, for now.
 474     if (!cld->is_alive()) {
 475       return;
 476     }
 477 
 478     const oop loader_oop = cld->class_loader();
 479 
 480     LoaderTreeNode* info = find_node_or_add_empty_node(loader_oop);
 481     assert(info != NULL, "must be");
 482 
 483     // Update CLD in node, but only if this is the primary CLD for this loader.
 484     if (cld->is_unsafe_anonymous() == false) {
 485       assert(info->cld() == NULL, "there should be only one primary CLD per loader");
 486       info->set_cld(cld);
 487     }
 488 
 489     // Add classes.
 490     fill_in_classes(info, cld);
 491   }
 492 
 493   void fold() {
 494     _root->fold_children();
 495   }
 496 
 497 };
 498 
 499 
 500 class ClassLoaderHierarchyVMOperation : public VM_Operation {
 501   outputStream* const _out;
 502   const bool _show_classes;
 503   const bool _verbose;
 504   const bool _fold;




 112     Mark(BranchTracker& tr, bool has_branch_here)
 113       : _tr(tr)  { _tr.push(has_branch_here); }
 114     ~Mark() { _tr.pop(); }
 115   };
 116 
 117 }; // end: BranchTracker
 118 
 119 struct LoadedClassInfo : public ResourceObj {
 120 public:
 121   LoadedClassInfo* _next;
 122   Klass* const _klass;
 123   const ClassLoaderData* const _cld;
 124 
 125   LoadedClassInfo(Klass* klass, const ClassLoaderData* cld)
 126     : _klass(klass), _cld(cld) {}
 127 
 128 };
 129 
 130 class LoaderTreeNode : public ResourceObj {
 131 
 132   // We walk the CLDG and, for each CLD which is findable, add
 133   // a tree node.
 134   // To add a node we need its parent node; if the parent node does not yet
 135   // exist - because we have not yet encountered the CLD for the parent loader -
 136   // we add a preliminary empty LoaderTreeNode for it. This preliminary node
 137   // just contains the loader oop and nothing else. Once we encounter the CLD of
 138   // this parent loader, we fill in all the other details.
 139 
 140   const oop _loader_oop;
 141   const ClassLoaderData* _cld;
 142 
 143   LoaderTreeNode* _child;
 144   LoaderTreeNode* _next;
 145 
 146   LoadedClassInfo* _classes;
 147   int _num_classes;
 148 
 149   LoadedClassInfo* _anon_classes;
 150   int _num_anon_classes;
 151 
 152   // In default view, similar tree nodes (same loader class, same name or no name)


 203       st->cr();
 204 
 205       const int indentation = 18;
 206 
 207       if (verbose) {
 208         branchtracker.print(st);
 209         st->print_cr("%*s " PTR_FORMAT, indentation, "Loader Oop:", p2i(_loader_oop));
 210         branchtracker.print(st);
 211         st->print_cr("%*s " PTR_FORMAT, indentation, "Loader Data:", p2i(_cld));
 212         branchtracker.print(st);
 213         st->print_cr("%*s " PTR_FORMAT, indentation, "Loader Klass:", p2i(loader_klass));
 214 
 215         // Empty line
 216         branchtracker.print(st);
 217         st->cr();
 218       }
 219 
 220       if (print_classes) {
 221         if (_classes != NULL) {
 222           for (LoadedClassInfo* lci = _classes; lci; lci = lci->_next) {
 223             // Nonfindable and unsafe anonymous classes should live in the primary CLD of its loader
 224             assert(lci->_cld == _cld, "must be");
 225 
 226             branchtracker.print(st);
 227             if (lci == _classes) { // first iteration
 228               st->print("%*s ", indentation, "Classes:");
 229             } else {
 230               st->print("%*s ", indentation, "");
 231             }
 232             st->print("%s", lci->_klass->external_name());
 233 
 234             // Special treatment for generated core reflection accessor classes: print invocation target.
 235             if (ReflectionAccessorImplKlassHelper::is_generated_accessor(lci->_klass)) {
 236               st->print(" (invokes: ");
 237               ReflectionAccessorImplKlassHelper::print_invocation_target(st, lci->_klass);
 238               st->print(")");
 239             }
 240 
 241             st->cr();
 242           }
 243           branchtracker.print(st);
 244           st->print("%*s ", indentation, "");
 245           st->print_cr("(%u class%s)", _num_classes, (_num_classes == 1) ? "" : "es");
 246 
 247           // Empty line
 248           branchtracker.print(st);
 249           st->cr();
 250         }
 251 
 252         if (_anon_classes != NULL) {
 253           for (LoadedClassInfo* lci = _anon_classes; lci; lci = lci->_next) {
 254             branchtracker.print(st);
 255             if (lci == _anon_classes) { // first iteration
 256               st->print("%*s ", indentation, "Unsafe Anonymous Classes:");
 257             } else {
 258               st->print("%*s ", indentation, "");
 259             }
 260             st->print("%s", lci->_klass->external_name());
 261             // For nonfindable and unsafe anonymous classes, also print CLD if verbose. Should be a different one than the primary CLD.
 262             assert(lci->_cld != _cld, "must be");
 263             if (verbose) {
 264               st->print("  (Loader Data: " PTR_FORMAT ")", p2i(lci->_cld));
 265             }
 266             st->cr();
 267           }
 268           branchtracker.print(st);
 269           st->print("%*s ", indentation, "");
 270           st->print_cr("(%u unsafe anonymous class%s)", _num_anon_classes, (_num_anon_classes == 1) ? "" : "es");
 271 
 272           // Empty line
 273           branchtracker.print(st);
 274           st->cr();
 275         }
 276 
 277       } // end: print_classes
 278 
 279     } // Pop branchtracker mark
 280 
 281     // Print children, recursively


 302     : _loader_oop(loader_oop), _cld(NULL), _child(NULL), _next(NULL),
 303       _classes(NULL), _num_classes(0), _anon_classes(NULL), _num_anon_classes(0),
 304       _num_folded(0)
 305     {}
 306 
 307   void set_cld(const ClassLoaderData* cld) {
 308     _cld = cld;
 309   }
 310 
 311   void add_child(LoaderTreeNode* info) {
 312     info->_next = _child;
 313     _child = info;
 314   }
 315 
 316   void add_sibling(LoaderTreeNode* info) {
 317     assert(info->_next == NULL, "must be");
 318     info->_next = _next;
 319     _next = info;
 320   }
 321 
 322   void add_classes(LoadedClassInfo* first_class, int num_classes, bool is_nonfindable) {
 323     LoadedClassInfo** p_list_to_add_to = is_nonfindable ? &_anon_classes : &_classes;
 324     // Search tail.
 325     while ((*p_list_to_add_to) != NULL) {
 326       p_list_to_add_to = &(*p_list_to_add_to)->_next;
 327     }
 328     *p_list_to_add_to = first_class;
 329     if (is_nonfindable) {
 330       _num_anon_classes += num_classes;
 331     } else {
 332       _num_classes += num_classes;
 333     }
 334   }
 335 
 336   const ClassLoaderData* cld() const {
 337     return _cld;
 338   }
 339 
 340   const oop loader_oop() const {
 341     return _loader_oop;
 342   }
 343 
 344   LoaderTreeNode* find(const oop loader_oop) {
 345     LoaderTreeNode* result = NULL;
 346     if (_loader_oop == loader_oop) {
 347       result = this;
 348     } else {
 349       LoaderTreeNode* c = _child;


 404     : _list(NULL), _cld(cld), _num_classes(0) {}
 405   void do_klass(Klass* k) {
 406     LoadedClassInfo* lki = new LoadedClassInfo(k, _cld);
 407     lki->_next = _list;
 408     _list = lki;
 409     _num_classes ++;
 410   }
 411 };
 412 
 413 class LoaderInfoScanClosure : public CLDClosure {
 414 
 415   const bool _print_classes;
 416   const bool _verbose;
 417   LoaderTreeNode* _root;
 418 
 419   static void fill_in_classes(LoaderTreeNode* info, const ClassLoaderData* cld) {
 420     assert(info != NULL && cld != NULL, "must be");
 421     LoadedClassCollectClosure lccc(cld);
 422     const_cast<ClassLoaderData*>(cld)->classes_do(&lccc);
 423     if (lccc._num_classes > 0) {
 424       info->add_classes(lccc._list, lccc._num_classes, cld->is_shortlived());
 425     }
 426   }
 427 
 428   LoaderTreeNode* find_node_or_add_empty_node(oop loader_oop) {
 429 
 430     assert(_root != NULL, "root node must exist");
 431 
 432     if (loader_oop == NULL) {
 433       return _root;
 434     }
 435 
 436     // Check if a node for this oop already exists.
 437     LoaderTreeNode* info = _root->find(loader_oop);
 438 
 439     if (info == NULL) {
 440       // It does not. Create a node.
 441       info = new LoaderTreeNode(loader_oop);
 442 
 443       // Add it to tree.
 444       LoaderTreeNode* parent_info = NULL;


 464     _root = new LoaderTreeNode(NULL);
 465   }
 466 
 467   void print_results(outputStream* st) const {
 468     _root->print_with_childs(st, _print_classes, _verbose);
 469   }
 470 
 471   void do_cld (ClassLoaderData* cld) {
 472 
 473     // We do not display unloading loaders, for now.
 474     if (!cld->is_alive()) {
 475       return;
 476     }
 477 
 478     const oop loader_oop = cld->class_loader();
 479 
 480     LoaderTreeNode* info = find_node_or_add_empty_node(loader_oop);
 481     assert(info != NULL, "must be");
 482 
 483     // Update CLD in node, but only if this is the primary CLD for this loader.
 484     if (cld->is_shortlived() == false) {
 485       assert(info->cld() == NULL, "there should be only one primary CLD per loader");
 486       info->set_cld(cld);
 487     }
 488 
 489     // Add classes.
 490     fill_in_classes(info, cld);
 491   }
 492 
 493   void fold() {
 494     _root->fold_children();
 495   }
 496 
 497 };
 498 
 499 
 500 class ClassLoaderHierarchyVMOperation : public VM_Operation {
 501   outputStream* const _out;
 502   const bool _show_classes;
 503   const bool _verbose;
 504   const bool _fold;


< prev index next >