src/share/vm/classfile/systemDictionary.cpp

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


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


  58 
  59 #if INCLUDE_TRACE
  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 Klass*      SystemDictionary::_well_known_klasses[SystemDictionary::WKID_LIMIT]
  81                                                           =  { NULL /*, NULL...*/ };
  82 
  83 Klass*      SystemDictionary::_box_klasses[T_VOID+1]      =  { NULL /*, NULL...*/ };
  84 


 581         } else {
 582           double_lock_wait(lockObject, THREAD);
 583         }
 584       } else {
 585         // If not in SD and not in PH, other thread's load must have failed
 586         super_load_in_progress = false;
 587       }
 588     }
 589   }
 590   return (nh);
 591 }
 592 
 593 
 594 Klass* SystemDictionary::resolve_instance_class_or_null(Symbol* name,
 595                                                         Handle class_loader,
 596                                                         Handle protection_domain,
 597                                                         TRAPS) {
 598   assert(name != NULL && !FieldType::is_array(name) &&
 599          !FieldType::is_obj(name), "invalid class name");
 600 
 601   TracingTime class_load_start_time = Tracing::time();
 602 
 603   // UseNewReflection
 604   // Fix for 4474172; see evaluation for more details
 605   class_loader = Handle(THREAD, java_lang_ClassLoader::non_reflection_class_loader(class_loader()));
 606   ClassLoaderData *loader_data = register_loader(class_loader, CHECK_NULL);
 607 
 608   // Do lookup to see if class already exist and the protection domain
 609   // has the right access
 610   // This call uses find which checks protection domain already matches
 611   // All subsequent calls use find_class, and set has_loaded_class so that
 612   // before we return a result we call out to java to check for valid protection domain
 613   // to allow returning the Klass* and add it to the pd_set if it is valid
 614   unsigned int d_hash = dictionary()->compute_hash(name, loader_data);
 615   int d_index = dictionary()->hash_to_index(d_hash);
 616   Klass* probe = dictionary()->find(d_index, d_hash, name, loader_data,
 617                                       protection_domain, THREAD);
 618   if (probe != NULL) return probe;
 619 
 620 
 621   // Non-bootstrap class loaders will call out to class loader and


 989       k = k->array_klass_or_null(fd.dimension());
 990     }
 991   } else {
 992     k = find(class_name, class_loader, protection_domain, THREAD);
 993   }
 994   return k;
 995 }
 996 
 997 // Note: this method is much like resolve_from_stream, but
 998 // updates no supplemental data structures.
 999 // TODO consolidate the two methods with a helper routine?
1000 Klass* SystemDictionary::parse_stream(Symbol* class_name,
1001                                       Handle class_loader,
1002                                       Handle protection_domain,
1003                                       ClassFileStream* st,
1004                                       KlassHandle host_klass,
1005                                       GrowableArray<Handle>* cp_patches,
1006                                       TRAPS) {
1007   TempNewSymbol parsed_name = NULL;
1008 
1009   TracingTime class_load_start_time = Tracing::time();
1010 
1011   ClassLoaderData* loader_data;
1012   if (host_klass.not_null()) {
1013     // Create a new CLD for anonymous class, that uses the same class loader
1014     // as the host_klass
1015     assert(EnableInvokeDynamic, "");
1016     guarantee(host_klass->class_loader() == class_loader(), "should be the same");
1017     loader_data = ClassLoaderData::anonymous_class_loader_data(class_loader(), CHECK_NULL);
1018     loader_data->record_dependency(host_klass(), CHECK_NULL);
1019   } else {
1020     loader_data = ClassLoaderData::class_loader_data(class_loader());
1021   }
1022 
1023   // Parse the stream. Note that we do this even though this klass might
1024   // already be present in the SystemDictionary, otherwise we would not
1025   // throw potential ClassFormatErrors.
1026   //
1027   // Note: "name" is updated.
1028 
1029   instanceKlassHandle k = ClassFileParser(st).parseClassFile(class_name,


2648 }
2649 
2650 
2651 void SystemDictionary::verify_obj_klass_present(Symbol* class_name,
2652                                                 ClassLoaderData* loader_data) {
2653   GCMutexLocker mu(SystemDictionary_lock);
2654   Symbol* name;
2655 
2656   Klass* probe = find_class(class_name, loader_data);
2657   if (probe == NULL) {
2658     probe = SystemDictionary::find_shared_class(class_name);
2659     if (probe == NULL) {
2660       name = find_placeholder(class_name, loader_data);
2661     }
2662   }
2663   guarantee(probe != NULL || name != NULL,
2664             "Loaded klasses should be in SystemDictionary");
2665 }
2666 
2667 // utility function for class load event
2668 void SystemDictionary::post_class_load_event(TracingTime start_time,
2669                                              instanceKlassHandle k,
2670                                              Handle initiating_loader) {
2671 #if INCLUDE_TRACE
2672   EventClassLoad event(UNTIMED);
2673   if (event.should_commit()) {
2674     event.set_endtime(Tracing::time());
2675     event.set_starttime(start_time);
2676     event.set_loadedClass(k());
2677     oop defining_class_loader = k->class_loader();
2678     event.set_definingClassLoader(defining_class_loader !=  NULL ?
2679                                     defining_class_loader->klass() : (Klass*)NULL);
2680     oop class_loader = initiating_loader.is_null() ? (oop)NULL : initiating_loader();
2681     event.set_initiatingClassLoader(class_loader != NULL ?
2682                                       class_loader->klass() : (Klass*)NULL);
2683     event.commit();
2684   }
2685 #endif /* INCLUDE_TRACE */
2686 }
2687 
2688 #ifndef PRODUCT
2689 
2690 // statistics code
2691 class ClassStatistics: AllStatic {
2692  private:
2693   static int nclasses;        // number of classes
2694   static int nmethods;        // number of methods




  38 #include "memory/oopFactory.hpp"
  39 #include "oops/instanceKlass.hpp"
  40 #include "oops/instanceRefKlass.hpp"
  41 #include "oops/klass.inline.hpp"
  42 #include "oops/methodData.hpp"
  43 #include "oops/objArrayKlass.hpp"
  44 #include "oops/oop.inline.hpp"
  45 #include "oops/oop.inline2.hpp"
  46 #include "oops/typeArrayKlass.hpp"
  47 #include "prims/jvmtiEnvBase.hpp"
  48 #include "prims/methodHandles.hpp"
  49 #include "runtime/biasedLocking.hpp"
  50 #include "runtime/fieldType.hpp"
  51 #include "runtime/handles.inline.hpp"
  52 #include "runtime/java.hpp"
  53 #include "runtime/javaCalls.hpp"
  54 #include "runtime/mutexLocker.hpp"
  55 #include "runtime/signature.hpp"
  56 #include "services/classLoadingService.hpp"
  57 #include "services/threadService.hpp"
  58 #include "utilities/macros.hpp"
  59 #include "utilities/ticks.hpp"
  60 
  61 #if INCLUDE_TRACE
  62  #include "trace/tracing.hpp"

  63 #endif
  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 Klass*      SystemDictionary::_well_known_klasses[SystemDictionary::WKID_LIMIT]
  81                                                           =  { NULL /*, NULL...*/ };
  82 
  83 Klass*      SystemDictionary::_box_klasses[T_VOID+1]      =  { NULL /*, NULL...*/ };
  84 


 581         } else {
 582           double_lock_wait(lockObject, THREAD);
 583         }
 584       } else {
 585         // If not in SD and not in PH, other thread's load must have failed
 586         super_load_in_progress = false;
 587       }
 588     }
 589   }
 590   return (nh);
 591 }
 592 
 593 
 594 Klass* SystemDictionary::resolve_instance_class_or_null(Symbol* name,
 595                                                         Handle class_loader,
 596                                                         Handle protection_domain,
 597                                                         TRAPS) {
 598   assert(name != NULL && !FieldType::is_array(name) &&
 599          !FieldType::is_obj(name), "invalid class name");
 600 
 601   Ticks class_load_start_time = Ticks::now();
 602 
 603   // UseNewReflection
 604   // Fix for 4474172; see evaluation for more details
 605   class_loader = Handle(THREAD, java_lang_ClassLoader::non_reflection_class_loader(class_loader()));
 606   ClassLoaderData *loader_data = register_loader(class_loader, CHECK_NULL);
 607 
 608   // Do lookup to see if class already exist and the protection domain
 609   // has the right access
 610   // This call uses find which checks protection domain already matches
 611   // All subsequent calls use find_class, and set has_loaded_class so that
 612   // before we return a result we call out to java to check for valid protection domain
 613   // to allow returning the Klass* and add it to the pd_set if it is valid
 614   unsigned int d_hash = dictionary()->compute_hash(name, loader_data);
 615   int d_index = dictionary()->hash_to_index(d_hash);
 616   Klass* probe = dictionary()->find(d_index, d_hash, name, loader_data,
 617                                       protection_domain, THREAD);
 618   if (probe != NULL) return probe;
 619 
 620 
 621   // Non-bootstrap class loaders will call out to class loader and


 989       k = k->array_klass_or_null(fd.dimension());
 990     }
 991   } else {
 992     k = find(class_name, class_loader, protection_domain, THREAD);
 993   }
 994   return k;
 995 }
 996 
 997 // Note: this method is much like resolve_from_stream, but
 998 // updates no supplemental data structures.
 999 // TODO consolidate the two methods with a helper routine?
1000 Klass* SystemDictionary::parse_stream(Symbol* class_name,
1001                                       Handle class_loader,
1002                                       Handle protection_domain,
1003                                       ClassFileStream* st,
1004                                       KlassHandle host_klass,
1005                                       GrowableArray<Handle>* cp_patches,
1006                                       TRAPS) {
1007   TempNewSymbol parsed_name = NULL;
1008 
1009   Ticks class_load_start_time = Ticks::now();
1010 
1011   ClassLoaderData* loader_data;
1012   if (host_klass.not_null()) {
1013     // Create a new CLD for anonymous class, that uses the same class loader
1014     // as the host_klass
1015     assert(EnableInvokeDynamic, "");
1016     guarantee(host_klass->class_loader() == class_loader(), "should be the same");
1017     loader_data = ClassLoaderData::anonymous_class_loader_data(class_loader(), CHECK_NULL);
1018     loader_data->record_dependency(host_klass(), CHECK_NULL);
1019   } else {
1020     loader_data = ClassLoaderData::class_loader_data(class_loader());
1021   }
1022 
1023   // Parse the stream. Note that we do this even though this klass might
1024   // already be present in the SystemDictionary, otherwise we would not
1025   // throw potential ClassFormatErrors.
1026   //
1027   // Note: "name" is updated.
1028 
1029   instanceKlassHandle k = ClassFileParser(st).parseClassFile(class_name,


2648 }
2649 
2650 
2651 void SystemDictionary::verify_obj_klass_present(Symbol* class_name,
2652                                                 ClassLoaderData* loader_data) {
2653   GCMutexLocker mu(SystemDictionary_lock);
2654   Symbol* name;
2655 
2656   Klass* probe = find_class(class_name, loader_data);
2657   if (probe == NULL) {
2658     probe = SystemDictionary::find_shared_class(class_name);
2659     if (probe == NULL) {
2660       name = find_placeholder(class_name, loader_data);
2661     }
2662   }
2663   guarantee(probe != NULL || name != NULL,
2664             "Loaded klasses should be in SystemDictionary");
2665 }
2666 
2667 // utility function for class load event
2668 void SystemDictionary::post_class_load_event(const Ticks& start_time,
2669                                              instanceKlassHandle k,
2670                                              Handle initiating_loader) {
2671 #if INCLUDE_TRACE
2672   EventClassLoad event(UNTIMED);
2673   if (event.should_commit()) {

2674     event.set_starttime(start_time);
2675     event.set_loadedClass(k());
2676     oop defining_class_loader = k->class_loader();
2677     event.set_definingClassLoader(defining_class_loader !=  NULL ?
2678                                     defining_class_loader->klass() : (Klass*)NULL);
2679     oop class_loader = initiating_loader.is_null() ? (oop)NULL : initiating_loader();
2680     event.set_initiatingClassLoader(class_loader != NULL ?
2681                                       class_loader->klass() : (Klass*)NULL);
2682     event.commit();
2683   }
2684 #endif /* INCLUDE_TRACE */
2685 }
2686 
2687 #ifndef PRODUCT
2688 
2689 // statistics code
2690 class ClassStatistics: AllStatic {
2691  private:
2692   static int nclasses;        // number of classes
2693   static int nmethods;        // number of methods