src/share/vm/classfile/classLoaderData.cpp

Print this page
rev 5685 : 8028128: Add a type safe alternative for working with counter based data
Reviewed-by:


  45 //
  46 // The bootstrap loader (represented by NULL) also has a ClassLoaderData,
  47 // the singleton class the_null_class_loader_data().
  48 
  49 #include "precompiled.hpp"
  50 #include "classfile/classLoaderData.hpp"
  51 #include "classfile/classLoaderData.inline.hpp"
  52 #include "classfile/javaClasses.hpp"
  53 #include "classfile/metadataOnStackMark.hpp"
  54 #include "classfile/systemDictionary.hpp"
  55 #include "code/codeCache.hpp"
  56 #include "memory/gcLocker.hpp"
  57 #include "memory/metadataFactory.hpp"
  58 #include "memory/metaspaceShared.hpp"
  59 #include "memory/oopFactory.hpp"
  60 #include "runtime/jniHandles.hpp"
  61 #include "runtime/mutex.hpp"
  62 #include "runtime/safepoint.hpp"
  63 #include "runtime/synchronizer.hpp"
  64 #include "utilities/growableArray.hpp"

  65 #include "utilities/ostream.hpp"
  66 
  67 #if INCLUDE_TRACE
  68  #include "trace/tracing.hpp"
  69 #endif
  70 
  71 
  72 ClassLoaderData * ClassLoaderData::_the_null_class_loader_data = NULL;
  73 
  74 ClassLoaderData::ClassLoaderData(Handle h_class_loader, bool is_anonymous, Dependencies dependencies) :
  75   _class_loader(h_class_loader()),
  76   _is_anonymous(is_anonymous), _keep_alive(is_anonymous), // initially
  77   _metaspace(NULL), _unloading(false), _klasses(NULL),
  78   _claimed(0), _jmethod_ids(NULL), _handles(NULL), _deallocate_list(NULL),
  79   _next(NULL), _dependencies(dependencies),
  80   _metaspace_lock(new Mutex(Monitor::leaf+1, "Metaspace allocation lock", true)) {
  81     // empty
  82 }
  83 
  84 void ClassLoaderData::init_dependencies(TRAPS) {
  85   assert(!Universe::is_fully_initialized(), "should only be called when initializing");
  86   assert(is_the_null_class_loader_data(), "should only call this for the null class loader");
  87   _dependencies.init(CHECK);
  88 }
  89 
  90 void ClassLoaderData::Dependencies::init(TRAPS) {
  91   // Create empty dependencies array to add to. CMS requires this to be


 737 }
 738 
 739 void ClassLoaderDataGraph::purge() {
 740   ClassLoaderData* list = _unloading;
 741   _unloading = NULL;
 742   ClassLoaderData* next = list;
 743   while (next != NULL) {
 744     ClassLoaderData* purge_me = next;
 745     next = purge_me->next();
 746     delete purge_me;
 747   }
 748   Metaspace::purge();
 749 }
 750 
 751 void ClassLoaderDataGraph::post_class_unload_events(void) {
 752 #if INCLUDE_TRACE
 753   assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint!");
 754   if (Tracing::enabled()) {
 755     if (Tracing::is_event_enabled(TraceClassUnloadEvent)) {
 756       assert(_unloading != NULL, "need class loader data unload list!");
 757       _class_unload_time = Tracing::time();
 758       classes_unloading_do(&class_unload_event);
 759     }
 760     Tracing::on_unloading_classes();
 761   }
 762 #endif
 763 }
 764 
 765 // CDS support
 766 
 767 // Global metaspaces for writing information to the shared archive.  When
 768 // application CDS is supported, we may need one per metaspace, so this
 769 // sort of looks like it.
 770 Metaspace* ClassLoaderData::_ro_metaspace = NULL;
 771 Metaspace* ClassLoaderData::_rw_metaspace = NULL;
 772 static bool _shared_metaspaces_initialized = false;
 773 
 774 // Initialize shared metaspaces (change to call from somewhere not lazily)
 775 void ClassLoaderData::initialize_shared_metaspaces() {
 776   assert(DumpSharedSpaces, "only use this for dumping shared spaces");
 777   assert(this == ClassLoaderData::the_null_class_loader_data(),


 815 
 816 void ClassLoaderDataGraph::dump_on(outputStream * const out) {
 817   for (ClassLoaderData* data = _head; data != NULL; data = data->next()) {
 818     data->dump(out);
 819   }
 820   MetaspaceAux::dump(out);
 821 }
 822 #endif // PRODUCT
 823 
 824 void ClassLoaderData::print_value_on(outputStream* out) const {
 825   if (class_loader() == NULL) {
 826     out->print("NULL class_loader");
 827   } else {
 828     out->print("class loader "PTR_FORMAT, this);
 829     class_loader()->print_value_on(out);
 830   }
 831 }
 832 
 833 #if INCLUDE_TRACE
 834 
 835 TracingTime ClassLoaderDataGraph::_class_unload_time;
 836 
 837 void ClassLoaderDataGraph::class_unload_event(Klass* const k) {
 838 
 839   // post class unload event
 840   EventClassUnload event(UNTIMED);
 841   event.set_endtime(_class_unload_time);
 842   event.set_unloadedClass(k);
 843   oop defining_class_loader = k->class_loader();
 844   event.set_definingClassLoader(defining_class_loader != NULL ?
 845                                 defining_class_loader->klass() : (Klass*)NULL);
 846   event.commit();
 847 }
 848 
 849 #endif /* INCLUDE_TRACE */


  45 //
  46 // The bootstrap loader (represented by NULL) also has a ClassLoaderData,
  47 // the singleton class the_null_class_loader_data().
  48 
  49 #include "precompiled.hpp"
  50 #include "classfile/classLoaderData.hpp"
  51 #include "classfile/classLoaderData.inline.hpp"
  52 #include "classfile/javaClasses.hpp"
  53 #include "classfile/metadataOnStackMark.hpp"
  54 #include "classfile/systemDictionary.hpp"
  55 #include "code/codeCache.hpp"
  56 #include "memory/gcLocker.hpp"
  57 #include "memory/metadataFactory.hpp"
  58 #include "memory/metaspaceShared.hpp"
  59 #include "memory/oopFactory.hpp"
  60 #include "runtime/jniHandles.hpp"
  61 #include "runtime/mutex.hpp"
  62 #include "runtime/safepoint.hpp"
  63 #include "runtime/synchronizer.hpp"
  64 #include "utilities/growableArray.hpp"
  65 #include "utilities/macros.hpp"
  66 #include "utilities/ostream.hpp"
  67 
  68 #if INCLUDE_TRACE
  69  #include "trace/tracing.hpp"
  70 #endif
  71 

  72 ClassLoaderData * ClassLoaderData::_the_null_class_loader_data = NULL;
  73 
  74 ClassLoaderData::ClassLoaderData(Handle h_class_loader, bool is_anonymous, Dependencies dependencies) :
  75   _class_loader(h_class_loader()),
  76   _is_anonymous(is_anonymous), _keep_alive(is_anonymous), // initially
  77   _metaspace(NULL), _unloading(false), _klasses(NULL),
  78   _claimed(0), _jmethod_ids(NULL), _handles(NULL), _deallocate_list(NULL),
  79   _next(NULL), _dependencies(dependencies),
  80   _metaspace_lock(new Mutex(Monitor::leaf+1, "Metaspace allocation lock", true)) {
  81     // empty
  82 }
  83 
  84 void ClassLoaderData::init_dependencies(TRAPS) {
  85   assert(!Universe::is_fully_initialized(), "should only be called when initializing");
  86   assert(is_the_null_class_loader_data(), "should only call this for the null class loader");
  87   _dependencies.init(CHECK);
  88 }
  89 
  90 void ClassLoaderData::Dependencies::init(TRAPS) {
  91   // Create empty dependencies array to add to. CMS requires this to be


 737 }
 738 
 739 void ClassLoaderDataGraph::purge() {
 740   ClassLoaderData* list = _unloading;
 741   _unloading = NULL;
 742   ClassLoaderData* next = list;
 743   while (next != NULL) {
 744     ClassLoaderData* purge_me = next;
 745     next = purge_me->next();
 746     delete purge_me;
 747   }
 748   Metaspace::purge();
 749 }
 750 
 751 void ClassLoaderDataGraph::post_class_unload_events(void) {
 752 #if INCLUDE_TRACE
 753   assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint!");
 754   if (Tracing::enabled()) {
 755     if (Tracing::is_event_enabled(TraceClassUnloadEvent)) {
 756       assert(_unloading != NULL, "need class loader data unload list!");
 757       _class_unload_time = Ticks::now();
 758       classes_unloading_do(&class_unload_event);
 759     }
 760     Tracing::on_unloading_classes();
 761   }
 762 #endif
 763 }
 764 
 765 // CDS support
 766 
 767 // Global metaspaces for writing information to the shared archive.  When
 768 // application CDS is supported, we may need one per metaspace, so this
 769 // sort of looks like it.
 770 Metaspace* ClassLoaderData::_ro_metaspace = NULL;
 771 Metaspace* ClassLoaderData::_rw_metaspace = NULL;
 772 static bool _shared_metaspaces_initialized = false;
 773 
 774 // Initialize shared metaspaces (change to call from somewhere not lazily)
 775 void ClassLoaderData::initialize_shared_metaspaces() {
 776   assert(DumpSharedSpaces, "only use this for dumping shared spaces");
 777   assert(this == ClassLoaderData::the_null_class_loader_data(),


 815 
 816 void ClassLoaderDataGraph::dump_on(outputStream * const out) {
 817   for (ClassLoaderData* data = _head; data != NULL; data = data->next()) {
 818     data->dump(out);
 819   }
 820   MetaspaceAux::dump(out);
 821 }
 822 #endif // PRODUCT
 823 
 824 void ClassLoaderData::print_value_on(outputStream* out) const {
 825   if (class_loader() == NULL) {
 826     out->print("NULL class_loader");
 827   } else {
 828     out->print("class loader "PTR_FORMAT, this);
 829     class_loader()->print_value_on(out);
 830   }
 831 }
 832 
 833 #if INCLUDE_TRACE
 834 
 835 Ticks ClassLoaderDataGraph::_class_unload_time;
 836 
 837 void ClassLoaderDataGraph::class_unload_event(Klass* const k) {
 838 
 839   // post class unload event
 840   EventClassUnload event(UNTIMED);
 841   event.set_endtime(_class_unload_time);
 842   event.set_unloadedClass(k);
 843   oop defining_class_loader = k->class_loader();
 844   event.set_definingClassLoader(defining_class_loader != NULL ?
 845                                 defining_class_loader->klass() : (Klass*)NULL);
 846   event.commit();
 847 }
 848 
 849 #endif /* INCLUDE_TRACE */