src/share/vm/classfile/systemDictionary.cpp

Print this page
rev 4372 : 8012182: Add information about class loading and unloading to event based tracing framework
Reviewed-by:


  37 #include "memory/oopFactory.hpp"
  38 #include "oops/instanceKlass.hpp"
  39 #include "oops/instanceRefKlass.hpp"
  40 #include "oops/klass.inline.hpp"
  41 #include "oops/methodDataOop.hpp"
  42 #include "oops/objArrayKlass.hpp"
  43 #include "oops/oop.inline.hpp"
  44 #include "oops/oop.inline2.hpp"
  45 #include "oops/typeArrayKlass.hpp"
  46 #include "prims/jvmtiEnvBase.hpp"
  47 #include "prims/methodHandles.hpp"
  48 #include "runtime/biasedLocking.hpp"
  49 #include "runtime/fieldType.hpp"
  50 #include "runtime/handles.inline.hpp"
  51 #include "runtime/java.hpp"
  52 #include "runtime/javaCalls.hpp"
  53 #include "runtime/mutexLocker.hpp"
  54 #include "runtime/signature.hpp"
  55 #include "services/classLoadingService.hpp"
  56 #include "services/threadService.hpp"
  57 #include "trace/traceMacros.hpp"





  58 
  59 
  60 Dictionary*            SystemDictionary::_dictionary          = NULL;
  61 PlaceholderTable*      SystemDictionary::_placeholders        = NULL;
  62 Dictionary*            SystemDictionary::_shared_dictionary   = NULL;
  63 LoaderConstraintTable* SystemDictionary::_loader_constraints  = NULL;
  64 ResolutionErrorTable*  SystemDictionary::_resolution_errors   = NULL;
  65 SymbolPropertyTable*   SystemDictionary::_invoke_method_table = NULL;
  66 
  67 
  68 int         SystemDictionary::_number_of_modifications = 0;
  69 int         SystemDictionary::_sdgeneration               = 0;
  70 const int   SystemDictionary::_primelist[_prime_array_size] = {1009,2017,4049,5051,10103,
  71               20201,40423,99991};
  72 
  73 oop         SystemDictionary::_system_loader_lock_obj     =  NULL;
  74 
  75 klassOop    SystemDictionary::_well_known_klasses[SystemDictionary::WKID_LIMIT]
  76                                                           =  { NULL /*, NULL...*/ };
  77 


 564         // We also get here for parallel bootstrap classloader
 565         if (class_loader.is_null()) {
 566           SystemDictionary_lock->wait();
 567         } else {
 568           double_lock_wait(lockObject, THREAD);
 569         }
 570       } else {
 571         // If not in SD and not in PH, other thread's load must have failed
 572         super_load_in_progress = false;
 573       }
 574     }
 575   }
 576   return (nh);
 577 }
 578 
 579 
 580 klassOop SystemDictionary::resolve_instance_class_or_null(Symbol* name, Handle class_loader, Handle protection_domain, TRAPS) {
 581   assert(name != NULL && !FieldType::is_array(name) &&
 582          !FieldType::is_obj(name), "invalid class name");
 583 


 584   // UseNewReflection
 585   // Fix for 4474172; see evaluation for more details
 586   class_loader = Handle(THREAD, java_lang_ClassLoader::non_reflection_class_loader(class_loader()));
 587 
 588   // Do lookup to see if class already exist and the protection domain
 589   // has the right access
 590   unsigned int d_hash = dictionary()->compute_hash(name, class_loader);
 591   int d_index = dictionary()->hash_to_index(d_hash);
 592   klassOop probe = dictionary()->find(d_index, d_hash, name, class_loader,
 593                                       protection_domain, THREAD);
 594   if (probe != NULL) return probe;
 595 
 596 
 597   // Non-bootstrap class loaders will call out to class loader and
 598   // define via jvm/jni_DefineClass which will acquire the
 599   // class loader object lock to protect against multiple threads
 600   // defining the class in parallel by accident.
 601   // This lock must be acquired here so the waiter will find
 602   // any successful result in the SystemDictionary and not attempt
 603   // the define


 771             CLEAR_PENDING_EXCEPTION;
 772             guarantee((!class_loader.is_null()), "dup definition for bootstrap loader?");
 773           }
 774         }
 775       }
 776 
 777       // clean up placeholder entries for success or error
 778       // This cleans up LOAD_INSTANCE entries
 779       // It also cleans up LOAD_SUPER entries on errors from
 780       // calling load_instance_class
 781       {
 782         MutexLocker mu(SystemDictionary_lock, THREAD);
 783         PlaceholderEntry* probe = placeholders()->get_entry(p_index, p_hash, name, class_loader);
 784         if (probe != NULL) {
 785           probe->remove_seen_thread(THREAD, PlaceholderTable::LOAD_INSTANCE);
 786           placeholders()->find_and_remove(p_index, p_hash, name, class_loader, THREAD);
 787           SystemDictionary_lock->notify_all();
 788         }
 789       }
 790 
 791       // If everything was OK (no exceptions, no null return value), and
 792       // class_loader is NOT the defining loader, do a little more bookkeeping.
 793       if (!HAS_PENDING_EXCEPTION && !k.is_null() &&
 794         k->class_loader() != class_loader()) {
 795 


 796         check_constraints(d_index, d_hash, k, class_loader, false, THREAD);
 797 
 798         // Need to check for a PENDING_EXCEPTION again; check_constraints
 799         // can throw and doesn't use the CHECK macro.
 800         if (!HAS_PENDING_EXCEPTION) {
 801           { // Grabbing the Compile_lock prevents systemDictionary updates
 802             // during compilations.
 803             MutexLocker mu(Compile_lock, THREAD);
 804             update_dictionary(d_index, d_hash, p_index, p_hash,
 805                             k, class_loader, THREAD);
 806           }

 807           if (JvmtiExport::should_post_class_load()) {
 808             Thread *thread = THREAD;
 809             assert(thread->is_Java_thread(), "thread->is_Java_thread()");
 810             JvmtiExport::post_class_load((JavaThread *) thread, k());
 811           }
 812         }
 813       }

 814       if (HAS_PENDING_EXCEPTION || k.is_null()) {
 815         // On error, clean up placeholders
 816         {
 817           MutexLocker mu(SystemDictionary_lock, THREAD);
 818           placeholders()->find_and_remove(p_index, p_hash, name, class_loader, THREAD);
 819           SystemDictionary_lock->notify_all();
 820         }
 821         return NULL;
 822       }
 823     }
 824   }
 825 
 826 #ifdef ASSERT
 827   {
 828     Handle loader (THREAD, k->class_loader());
 829     MutexLocker mu(SystemDictionary_lock, THREAD);
 830     oop kk = find_class(name, loader);
 831     assert(kk == k(), "should be present in dictionary");
 832   }
 833 #endif


 922       k = Klass::cast(k)->array_klass_or_null(fd.dimension());
 923     }
 924   } else {
 925     k = find(class_name, class_loader, protection_domain, THREAD);
 926   }
 927   return k;
 928 }
 929 
 930 // Note: this method is much like resolve_from_stream, but
 931 // updates no supplemental data structures.
 932 // TODO consolidate the two methods with a helper routine?
 933 klassOop SystemDictionary::parse_stream(Symbol* class_name,
 934                                         Handle class_loader,
 935                                         Handle protection_domain,
 936                                         ClassFileStream* st,
 937                                         KlassHandle host_klass,
 938                                         GrowableArray<Handle>* cp_patches,
 939                                         TRAPS) {
 940   TempNewSymbol parsed_name = NULL;
 941 


 942   // Parse the stream. Note that we do this even though this klass might
 943   // already be present in the SystemDictionary, otherwise we would not
 944   // throw potential ClassFormatErrors.
 945   //
 946   // Note: "name" is updated.
 947   // Further note:  a placeholder will be added for this class when
 948   //   super classes are loaded (resolve_super_or_fail). We expect this
 949   //   to be called for all classes but java.lang.Object; and we preload
 950   //   java.lang.Object through resolve_or_fail, not this path.
 951 
 952   instanceKlassHandle k = ClassFileParser(st).parseClassFile(class_name,
 953                                                              class_loader,
 954                                                              protection_domain,
 955                                                              host_klass,
 956                                                              cp_patches,
 957                                                              parsed_name,
 958                                                              true,
 959                                                              THREAD);
 960 
 961   // We don't redefine the class, so we just need to clean up whether there


 974     }
 975   }
 976 
 977   if (host_klass.not_null() && k.not_null()) {
 978     assert(EnableInvokeDynamic, "");
 979     // If it's anonymous, initialize it now, since nobody else will.
 980     k->set_host_klass(host_klass());
 981 
 982     {
 983       MutexLocker mu_r(Compile_lock, THREAD);
 984 
 985       // Add to class hierarchy, initialize vtables, and do possible
 986       // deoptimizations.
 987       add_to_hierarchy(k, CHECK_NULL); // No exception, but can block
 988 
 989       // But, do not add to system dictionary.
 990     }
 991 
 992     k->eager_initialize(THREAD);
 993 


 994     // notify jvmti
 995     if (JvmtiExport::should_post_class_load()) {
 996         assert(THREAD->is_Java_thread(), "thread->is_Java_thread()");
 997         JvmtiExport::post_class_load((JavaThread *) THREAD, k());
 998     }
 999   }
1000 
1001   return k();
1002 }
1003 
1004 // Add a klass to the system from a stream (called by jni_DefineClass and
1005 // JVM_DefineClass).
1006 // Note: class_name can be NULL. In that case we do not know the name of
1007 // the class until we have parsed the stream.
1008 
1009 klassOop SystemDictionary::resolve_from_stream(Symbol* class_name,
1010                                                Handle class_loader,
1011                                                Handle protection_domain,
1012                                                ClassFileStream* st,
1013                                                bool verify,


1637 
1638 void SystemDictionary::placeholders_do(OopClosure* blk) {
1639   placeholders()->oops_do(blk);
1640 }
1641 
1642 // Calculate a "good" systemdictionary size based
1643 // on predicted or current loaded classes count
1644 int SystemDictionary::calculate_systemdictionary_size(int classcount) {
1645   int newsize = _old_default_sdsize;
1646   if ((classcount > 0)  && !DumpSharedSpaces) {
1647     int desiredsize = classcount/_average_depth_goal;
1648     for (newsize = _primelist[_sdgeneration]; _sdgeneration < _prime_array_size -1;
1649          newsize = _primelist[++_sdgeneration]) {
1650       if (desiredsize <=  newsize) {
1651         break;
1652       }
1653     }
1654   }
1655   return newsize;
1656 }

1657 bool SystemDictionary::do_unloading(BoolObjectClosure* is_alive) {

1658   bool result = dictionary()->do_unloading(is_alive);
1659   constraints()->purge_loader_constraints(is_alive);
1660   resolution_errors()->purge_resolution_errors(is_alive);
1661   return result;
1662 }
1663 
1664 
1665 // The mirrors are scanned by shared_oops_do() which is
1666 // not called by oops_do().  In order to process oops in
1667 // a necessary order, shared_oops_do() is call by
1668 // Universe::oops_do().
1669 void SystemDictionary::oops_do(OopClosure* f) {
1670   // Adjust preloaded classes and system loader object
1671   f->do_oop(&_java_system_loader);
1672   preloaded_oops_do(f);
1673 
1674   lazily_loaded_oops_do(f);
1675 
1676   // Adjust dictionary
1677   dictionary()->oops_do(f);


2583   constraints()->verify(dictionary(), placeholders());
2584 }
2585 
2586 
2587 void SystemDictionary::verify_obj_klass_present(Handle obj,
2588                                                 Symbol* class_name,
2589                                                 Handle class_loader) {
2590   GCMutexLocker mu(SystemDictionary_lock);
2591   Symbol* name;
2592 
2593   klassOop probe = find_class(class_name, class_loader);
2594   if (probe == NULL) {
2595     probe = SystemDictionary::find_shared_class(class_name);
2596     if (probe == NULL) {
2597       name = find_placeholder(class_name, class_loader);
2598     }
2599   }
2600   guarantee(probe != NULL || name != NULL,
2601             "Loaded klasses should be in SystemDictionary");
2602 }








































































2603 
2604 #ifndef PRODUCT
2605 
2606 // statistics code
2607 class ClassStatistics: AllStatic {
2608  private:
2609   static int nclasses;        // number of classes
2610   static int nmethods;        // number of methods
2611   static int nmethoddata;     // number of methodData
2612   static int class_size;      // size of class objects in words
2613   static int method_size;     // size of method objects in words
2614   static int debug_size;      // size of debug info in methods
2615   static int methoddata_size; // size of methodData objects in words
2616 
2617   static void do_class(klassOop k) {
2618     nclasses++;
2619     class_size += k->size();
2620     if (k->klass_part()->oop_is_instance()) {
2621       instanceKlass* ik = (instanceKlass*)k->klass_part();
2622       class_size += ik->methods()->size();




  37 #include "memory/oopFactory.hpp"
  38 #include "oops/instanceKlass.hpp"
  39 #include "oops/instanceRefKlass.hpp"
  40 #include "oops/klass.inline.hpp"
  41 #include "oops/methodDataOop.hpp"
  42 #include "oops/objArrayKlass.hpp"
  43 #include "oops/oop.inline.hpp"
  44 #include "oops/oop.inline2.hpp"
  45 #include "oops/typeArrayKlass.hpp"
  46 #include "prims/jvmtiEnvBase.hpp"
  47 #include "prims/methodHandles.hpp"
  48 #include "runtime/biasedLocking.hpp"
  49 #include "runtime/fieldType.hpp"
  50 #include "runtime/handles.inline.hpp"
  51 #include "runtime/java.hpp"
  52 #include "runtime/javaCalls.hpp"
  53 #include "runtime/mutexLocker.hpp"
  54 #include "runtime/signature.hpp"
  55 #include "services/classLoadingService.hpp"
  56 #include "services/threadService.hpp"
  57 
  58 #if INCLUDE_TRACE
  59  #include "memory/iterator.hpp"
  60  #include "trace/tracing.hpp"
  61  #include "trace/traceMacros.hpp"
  62 #endif
  63 
  64 
  65 Dictionary*            SystemDictionary::_dictionary          = NULL;
  66 PlaceholderTable*      SystemDictionary::_placeholders        = NULL;
  67 Dictionary*            SystemDictionary::_shared_dictionary   = NULL;
  68 LoaderConstraintTable* SystemDictionary::_loader_constraints  = NULL;
  69 ResolutionErrorTable*  SystemDictionary::_resolution_errors   = NULL;
  70 SymbolPropertyTable*   SystemDictionary::_invoke_method_table = NULL;
  71 
  72 
  73 int         SystemDictionary::_number_of_modifications = 0;
  74 int         SystemDictionary::_sdgeneration               = 0;
  75 const int   SystemDictionary::_primelist[_prime_array_size] = {1009,2017,4049,5051,10103,
  76               20201,40423,99991};
  77 
  78 oop         SystemDictionary::_system_loader_lock_obj     =  NULL;
  79 
  80 klassOop    SystemDictionary::_well_known_klasses[SystemDictionary::WKID_LIMIT]
  81                                                           =  { NULL /*, NULL...*/ };
  82 


 569         // We also get here for parallel bootstrap classloader
 570         if (class_loader.is_null()) {
 571           SystemDictionary_lock->wait();
 572         } else {
 573           double_lock_wait(lockObject, THREAD);
 574         }
 575       } else {
 576         // If not in SD and not in PH, other thread's load must have failed
 577         super_load_in_progress = false;
 578       }
 579     }
 580   }
 581   return (nh);
 582 }
 583 
 584 
 585 klassOop SystemDictionary::resolve_instance_class_or_null(Symbol* name, Handle class_loader, Handle protection_domain, TRAPS) {
 586   assert(name != NULL && !FieldType::is_array(name) &&
 587          !FieldType::is_obj(name), "invalid class name");
 588 
 589   jlong class_load_start_time = class_load_tracing_begin();
 590 
 591   // UseNewReflection
 592   // Fix for 4474172; see evaluation for more details
 593   class_loader = Handle(THREAD, java_lang_ClassLoader::non_reflection_class_loader(class_loader()));
 594 
 595   // Do lookup to see if class already exist and the protection domain
 596   // has the right access
 597   unsigned int d_hash = dictionary()->compute_hash(name, class_loader);
 598   int d_index = dictionary()->hash_to_index(d_hash);
 599   klassOop probe = dictionary()->find(d_index, d_hash, name, class_loader,
 600                                       protection_domain, THREAD);
 601   if (probe != NULL) return probe;
 602 
 603 
 604   // Non-bootstrap class loaders will call out to class loader and
 605   // define via jvm/jni_DefineClass which will acquire the
 606   // class loader object lock to protect against multiple threads
 607   // defining the class in parallel by accident.
 608   // This lock must be acquired here so the waiter will find
 609   // any successful result in the SystemDictionary and not attempt
 610   // the define


 778             CLEAR_PENDING_EXCEPTION;
 779             guarantee((!class_loader.is_null()), "dup definition for bootstrap loader?");
 780           }
 781         }
 782       }
 783 
 784       // clean up placeholder entries for success or error
 785       // This cleans up LOAD_INSTANCE entries
 786       // It also cleans up LOAD_SUPER entries on errors from
 787       // calling load_instance_class
 788       {
 789         MutexLocker mu(SystemDictionary_lock, THREAD);
 790         PlaceholderEntry* probe = placeholders()->get_entry(p_index, p_hash, name, class_loader);
 791         if (probe != NULL) {
 792           probe->remove_seen_thread(THREAD, PlaceholderTable::LOAD_INSTANCE);
 793           placeholders()->find_and_remove(p_index, p_hash, name, class_loader, THREAD);
 794           SystemDictionary_lock->notify_all();
 795         }
 796       }
 797 
 798       // If everything was OK (no exceptions, no null return value)
 799       if (!HAS_PENDING_EXCEPTION && !k.is_null()) {
 800         post_class_load_event(class_load_start_time, k, class_loader);

 801 
 802         // class_loader is NOT the defining loader, do a little more bookkeeping.
 803         if (k->class_loader() != class_loader()) {
 804           check_constraints(d_index, d_hash, k, class_loader, false, THREAD);
 805 
 806           // Need to check for a PENDING_EXCEPTION again; check_constraints
 807           // can throw and doesn't use the CHECK macro.
 808           if (!HAS_PENDING_EXCEPTION) {
 809             { // Grabbing the Compile_lock prevents systemDictionary updates
 810               // during compilations.
 811               MutexLocker mu(Compile_lock, THREAD);
 812               update_dictionary(d_index, d_hash, p_index, p_hash,
 813                               k, class_loader, THREAD);
 814             }
 815 
 816             if (JvmtiExport::should_post_class_load()) {
 817               Thread *thread = THREAD;
 818               assert(thread->is_Java_thread(), "thread->is_Java_thread()");
 819               JvmtiExport::post_class_load((JavaThread *) thread, k());
 820             }
 821           }
 822         }
 823       }
 824       if (HAS_PENDING_EXCEPTION || k.is_null()) {
 825         // On error, clean up placeholders
 826         {
 827           MutexLocker mu(SystemDictionary_lock, THREAD);
 828           placeholders()->find_and_remove(p_index, p_hash, name, class_loader, THREAD);
 829           SystemDictionary_lock->notify_all();
 830         }
 831         return NULL;
 832       }
 833     }
 834   }
 835 
 836 #ifdef ASSERT
 837   {
 838     Handle loader (THREAD, k->class_loader());
 839     MutexLocker mu(SystemDictionary_lock, THREAD);
 840     oop kk = find_class(name, loader);
 841     assert(kk == k(), "should be present in dictionary");
 842   }
 843 #endif


 932       k = Klass::cast(k)->array_klass_or_null(fd.dimension());
 933     }
 934   } else {
 935     k = find(class_name, class_loader, protection_domain, THREAD);
 936   }
 937   return k;
 938 }
 939 
 940 // Note: this method is much like resolve_from_stream, but
 941 // updates no supplemental data structures.
 942 // TODO consolidate the two methods with a helper routine?
 943 klassOop SystemDictionary::parse_stream(Symbol* class_name,
 944                                         Handle class_loader,
 945                                         Handle protection_domain,
 946                                         ClassFileStream* st,
 947                                         KlassHandle host_klass,
 948                                         GrowableArray<Handle>* cp_patches,
 949                                         TRAPS) {
 950   TempNewSymbol parsed_name = NULL;
 951 
 952   jlong class_load_start_time = class_load_tracing_begin();
 953 
 954   // Parse the stream. Note that we do this even though this klass might
 955   // already be present in the SystemDictionary, otherwise we would not
 956   // throw potential ClassFormatErrors.
 957   //
 958   // Note: "name" is updated.
 959   // Further note:  a placeholder will be added for this class when
 960   //   super classes are loaded (resolve_super_or_fail). We expect this
 961   //   to be called for all classes but java.lang.Object; and we preload
 962   //   java.lang.Object through resolve_or_fail, not this path.
 963 
 964   instanceKlassHandle k = ClassFileParser(st).parseClassFile(class_name,
 965                                                              class_loader,
 966                                                              protection_domain,
 967                                                              host_klass,
 968                                                              cp_patches,
 969                                                              parsed_name,
 970                                                              true,
 971                                                              THREAD);
 972 
 973   // We don't redefine the class, so we just need to clean up whether there


 986     }
 987   }
 988 
 989   if (host_klass.not_null() && k.not_null()) {
 990     assert(EnableInvokeDynamic, "");
 991     // If it's anonymous, initialize it now, since nobody else will.
 992     k->set_host_klass(host_klass());
 993 
 994     {
 995       MutexLocker mu_r(Compile_lock, THREAD);
 996 
 997       // Add to class hierarchy, initialize vtables, and do possible
 998       // deoptimizations.
 999       add_to_hierarchy(k, CHECK_NULL); // No exception, but can block
1000 
1001       // But, do not add to system dictionary.
1002     }
1003 
1004     k->eager_initialize(THREAD);
1005 
1006     post_class_load_event(class_load_start_time, k, class_loader);
1007 
1008     // notify jvmti
1009     if (JvmtiExport::should_post_class_load()) {
1010         assert(THREAD->is_Java_thread(), "thread->is_Java_thread()");
1011         JvmtiExport::post_class_load((JavaThread *) THREAD, k());
1012     }
1013   }
1014 
1015   return k();
1016 }
1017 
1018 // Add a klass to the system from a stream (called by jni_DefineClass and
1019 // JVM_DefineClass).
1020 // Note: class_name can be NULL. In that case we do not know the name of
1021 // the class until we have parsed the stream.
1022 
1023 klassOop SystemDictionary::resolve_from_stream(Symbol* class_name,
1024                                                Handle class_loader,
1025                                                Handle protection_domain,
1026                                                ClassFileStream* st,
1027                                                bool verify,


1651 
1652 void SystemDictionary::placeholders_do(OopClosure* blk) {
1653   placeholders()->oops_do(blk);
1654 }
1655 
1656 // Calculate a "good" systemdictionary size based
1657 // on predicted or current loaded classes count
1658 int SystemDictionary::calculate_systemdictionary_size(int classcount) {
1659   int newsize = _old_default_sdsize;
1660   if ((classcount > 0)  && !DumpSharedSpaces) {
1661     int desiredsize = classcount/_average_depth_goal;
1662     for (newsize = _primelist[_sdgeneration]; _sdgeneration < _prime_array_size -1;
1663          newsize = _primelist[++_sdgeneration]) {
1664       if (desiredsize <=  newsize) {
1665         break;
1666       }
1667     }
1668   }
1669   return newsize;
1670 }
1671 
1672 bool SystemDictionary::do_unloading(BoolObjectClosure* is_alive) {
1673   post_class_unload_events(is_alive);
1674   bool result = dictionary()->do_unloading(is_alive);
1675   constraints()->purge_loader_constraints(is_alive);
1676   resolution_errors()->purge_resolution_errors(is_alive);
1677   return result;
1678 }
1679 
1680 
1681 // The mirrors are scanned by shared_oops_do() which is
1682 // not called by oops_do().  In order to process oops in
1683 // a necessary order, shared_oops_do() is call by
1684 // Universe::oops_do().
1685 void SystemDictionary::oops_do(OopClosure* f) {
1686   // Adjust preloaded classes and system loader object
1687   f->do_oop(&_java_system_loader);
1688   preloaded_oops_do(f);
1689 
1690   lazily_loaded_oops_do(f);
1691 
1692   // Adjust dictionary
1693   dictionary()->oops_do(f);


2599   constraints()->verify(dictionary(), placeholders());
2600 }
2601 
2602 
2603 void SystemDictionary::verify_obj_klass_present(Handle obj,
2604                                                 Symbol* class_name,
2605                                                 Handle class_loader) {
2606   GCMutexLocker mu(SystemDictionary_lock);
2607   Symbol* name;
2608 
2609   klassOop probe = find_class(class_name, class_loader);
2610   if (probe == NULL) {
2611     probe = SystemDictionary::find_shared_class(class_name);
2612     if (probe == NULL) {
2613       name = find_placeholder(class_name, class_loader);
2614     }
2615   }
2616   guarantee(probe != NULL || name != NULL,
2617             "Loaded klasses should be in SystemDictionary");
2618 }
2619 
2620 jlong SystemDictionary::class_load_tracing_begin(void) {
2621 #if INCLUDE_TRACE
2622   return os::elapsed_counter();
2623 #endif
2624   return 0;
2625 }
2626 
2627 // utililty function for class load event
2628 void SystemDictionary::post_class_load_event(jlong start_time,
2629   instanceKlassHandle k, Handle initiating_loader) {
2630 #if INCLUDE_TRACE
2631   EventClassLoad event(UNTIMED);
2632   if (event.should_commit()) {
2633     event.set_endtime(os::elapsed_counter());
2634     event.set_starttime(start_time);
2635     event.set_loadedClass(k());
2636     oop defining_class_loader = k->class_loader();
2637     event.set_definingClassLoader(defining_class_loader != NULL ?
2638                                     defining_class_loader->klass() : NULL);
2639     oop class_loader = initiating_loader.is_null() ? (oop)NULL : initiating_loader();
2640     event.set_initiatingClassLoader(class_loader != NULL ?
2641                                       class_loader->klass() : NULL);
2642     event.commit();
2643   }
2644 #endif /* INCLUDE_TRACE */
2645 }
2646 
2647 void SystemDictionary::post_class_unload_events(BoolObjectClosure* is_alive) {
2648 #if INCLUDE_TRACE
2649   assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint!");
2650   if (Tracing::enabled()) {
2651     _should_write_unload_events = Tracing::is_event_enabled(TraceClassUnloadEvent);
2652     _class_unload_time = Tracing::time();
2653     _is_alive = is_alive;
2654     classes_do(&class_unload_event);
2655 
2656     if (_no_of_classes_unloading > 0) {
2657       Tracing::on_unloading_classes(is_alive, _no_of_classes_unloading);
2658       _no_of_classes_unloading = 0;
2659     }
2660     _should_write_unload_events = false;
2661     _is_alive = NULL;
2662   }
2663 #endif /* INCLUDE_TRACE */
2664 }
2665 
2666 #if INCLUDE_TRACE
2667 TracingTime SystemDictionary::_class_unload_time;
2668 BoolObjectClosure* SystemDictionary::_is_alive = NULL;
2669 int SystemDictionary::_no_of_classes_unloading = 0;
2670 bool SystemDictionary::_should_write_unload_events = false;
2671 
2672 void SystemDictionary::class_unload_event(klassOop curklass) {
2673 
2674   Klass* myklass = curklass->klass_part();
2675   oop class_loader = myklass->class_loader();
2676 
2677   if (class_loader != NULL && _is_alive != NULL && !_is_alive->do_object_b(class_loader)) {
2678     _no_of_classes_unloading++;
2679     if (_should_write_unload_events) {
2680       // post class unload event
2681       EventClassUnload event(UNTIMED);
2682       event.set_endtime(_class_unload_time);
2683       event.set_unloadedClass(curklass);
2684       event.set_definingClassLoader(class_loader->klass());
2685       event.commit();
2686     }
2687   }
2688 }
2689 
2690 #endif /* INCLUDE_TRACE */
2691 
2692 #ifndef PRODUCT
2693 
2694 // statistics code
2695 class ClassStatistics: AllStatic {
2696  private:
2697   static int nclasses;        // number of classes
2698   static int nmethods;        // number of methods
2699   static int nmethoddata;     // number of methodData
2700   static int class_size;      // size of class objects in words
2701   static int method_size;     // size of method objects in words
2702   static int debug_size;      // size of debug info in methods
2703   static int methoddata_size; // size of methodData objects in words
2704 
2705   static void do_class(klassOop k) {
2706     nclasses++;
2707     class_size += k->size();
2708     if (k->klass_part()->oop_is_instance()) {
2709       instanceKlass* ik = (instanceKlass*)k->klass_part();
2710       class_size += ik->methods()->size();