hotspot/src/share/vm/classfile/systemDictionary.cpp
changeset 34666 1c7168ea0034
parent 34317 e93b85bf4cc2
child 35543 0961315f4016
child 35475 c5e6cb508475
equal deleted inserted replaced
34665:9fdcc78b5398 34666:1c7168ea0034
    21  * questions.
    21  * questions.
    22  *
    22  *
    23  */
    23  */
    24 
    24 
    25 #include "precompiled.hpp"
    25 #include "precompiled.hpp"
       
    26 #include "classfile/classFileParser.hpp"
       
    27 #include "classfile/classFileStream.hpp"
       
    28 #include "classfile/classLoader.hpp"
    26 #include "classfile/classLoaderData.inline.hpp"
    29 #include "classfile/classLoaderData.inline.hpp"
       
    30 #include "classfile/classLoaderExt.hpp"
    27 #include "classfile/dictionary.hpp"
    31 #include "classfile/dictionary.hpp"
    28 #include "classfile/javaClasses.inline.hpp"
    32 #include "classfile/javaClasses.inline.hpp"
       
    33 #include "classfile/klassFactory.hpp"
    29 #include "classfile/loaderConstraints.hpp"
    34 #include "classfile/loaderConstraints.hpp"
    30 #include "classfile/placeholders.hpp"
    35 #include "classfile/placeholders.hpp"
    31 #include "classfile/resolutionErrors.hpp"
    36 #include "classfile/resolutionErrors.hpp"
    32 #include "classfile/stringTable.hpp"
    37 #include "classfile/stringTable.hpp"
    33 #include "classfile/systemDictionary.hpp"
    38 #include "classfile/systemDictionary.hpp"
   614     }
   619     }
   615   }
   620   }
   616   return (nh);
   621   return (nh);
   617 }
   622 }
   618 
   623 
       
   624 // utility function for class load event
       
   625 static void post_class_load_event(const Ticks& start_time,
       
   626                                   instanceKlassHandle k,
       
   627                                   Handle initiating_loader) {
       
   628 #if INCLUDE_TRACE
       
   629   EventClassLoad event(UNTIMED);
       
   630   if (event.should_commit()) {
       
   631     event.set_starttime(start_time);
       
   632     event.set_loadedClass(k());
       
   633     oop defining_class_loader = k->class_loader();
       
   634     event.set_definingClassLoader(defining_class_loader != NULL ?
       
   635       defining_class_loader->klass() : (Klass*)NULL);
       
   636     oop class_loader = initiating_loader.is_null() ? (oop)NULL : initiating_loader();
       
   637     event.set_initiatingClassLoader(class_loader != NULL ?
       
   638       class_loader->klass() : (Klass*)NULL);
       
   639     event.commit();
       
   640   }
       
   641 #endif // INCLUDE_TRACE
       
   642 }
   619 
   643 
   620 Klass* SystemDictionary::resolve_instance_class_or_null(Symbol* name,
   644 Klass* SystemDictionary::resolve_instance_class_or_null(Symbol* name,
   621                                                         Handle class_loader,
   645                                                         Handle class_loader,
   622                                                         Handle protection_domain,
   646                                                         Handle protection_domain,
   623                                                         TRAPS) {
   647                                                         TRAPS) {
   982 // TODO consolidate the two methods with a helper routine?
  1006 // TODO consolidate the two methods with a helper routine?
   983 Klass* SystemDictionary::parse_stream(Symbol* class_name,
  1007 Klass* SystemDictionary::parse_stream(Symbol* class_name,
   984                                       Handle class_loader,
  1008                                       Handle class_loader,
   985                                       Handle protection_domain,
  1009                                       Handle protection_domain,
   986                                       ClassFileStream* st,
  1010                                       ClassFileStream* st,
   987                                       KlassHandle host_klass,
  1011                                       const Klass* host_klass,
   988                                       GrowableArray<Handle>* cp_patches,
  1012                                       GrowableArray<Handle>* cp_patches,
   989                                       TRAPS) {
  1013                                       TRAPS) {
   990   TempNewSymbol parsed_name = NULL;
       
   991 
  1014 
   992   Ticks class_load_start_time = Ticks::now();
  1015   Ticks class_load_start_time = Ticks::now();
   993 
  1016 
   994   ClassLoaderData* loader_data;
  1017   ClassLoaderData* loader_data;
   995   if (host_klass.not_null()) {
  1018   if (host_klass != NULL) {
   996     // Create a new CLD for anonymous class, that uses the same class loader
  1019     // Create a new CLD for anonymous class, that uses the same class loader
   997     // as the host_klass
  1020     // as the host_klass
   998     guarantee(host_klass->class_loader() == class_loader(), "should be the same");
  1021     guarantee(host_klass->class_loader() == class_loader(), "should be the same");
   999     guarantee(!DumpSharedSpaces, "must not create anonymous classes when dumping");
  1022     guarantee(!DumpSharedSpaces, "must not create anonymous classes when dumping");
  1000     loader_data = ClassLoaderData::anonymous_class_loader_data(class_loader(), CHECK_NULL);
  1023     loader_data = ClassLoaderData::anonymous_class_loader_data(class_loader(), CHECK_NULL);
  1001     loader_data->record_dependency(host_klass(), CHECK_NULL);
  1024     loader_data->record_dependency(host_klass, CHECK_NULL);
  1002   } else {
  1025   } else {
  1003     loader_data = ClassLoaderData::class_loader_data(class_loader());
  1026     loader_data = ClassLoaderData::class_loader_data(class_loader());
  1004   }
  1027   }
  1005 
  1028 
  1006   // Parse the stream. Note that we do this even though this klass might
  1029   assert(st != NULL, "invariant");
       
  1030   assert(st->need_verify(), "invariant");
       
  1031 
       
  1032   // Parse stream and create a klass.
       
  1033   // Note that we do this even though this klass might
  1007   // already be present in the SystemDictionary, otherwise we would not
  1034   // already be present in the SystemDictionary, otherwise we would not
  1008   // throw potential ClassFormatErrors.
  1035   // throw potential ClassFormatErrors.
  1009   //
  1036 
  1010   // Note: "name" is updated.
  1037   instanceKlassHandle k = KlassFactory::create_from_stream(st,
  1011 
  1038                                                            class_name,
  1012   instanceKlassHandle k = ClassFileParser(st).parseClassFile(class_name,
  1039                                                            loader_data,
  1013                                                              loader_data,
  1040                                                            protection_domain,
  1014                                                              protection_domain,
  1041                                                            host_klass,
  1015                                                              host_klass,
  1042                                                            cp_patches,
  1016                                                              cp_patches,
  1043                                                            NULL, // parsed_name
  1017                                                              parsed_name,
  1044                                                            THREAD);
  1018                                                              true,
  1045 
  1019                                                              THREAD);
  1046   if (host_klass != NULL && k.not_null()) {
  1020 
       
  1021 
       
  1022   if (host_klass.not_null() && k.not_null()) {
       
  1023     // If it's anonymous, initialize it now, since nobody else will.
  1047     // If it's anonymous, initialize it now, since nobody else will.
  1024 
  1048 
  1025     {
  1049     {
  1026       MutexLocker mu_r(Compile_lock, THREAD);
  1050       MutexLocker mu_r(Compile_lock, THREAD);
  1027 
  1051 
  1048         JvmtiExport::post_class_load((JavaThread *) THREAD, k());
  1072         JvmtiExport::post_class_load((JavaThread *) THREAD, k());
  1049     }
  1073     }
  1050 
  1074 
  1051     post_class_load_event(class_load_start_time, k, class_loader);
  1075     post_class_load_event(class_load_start_time, k, class_loader);
  1052   }
  1076   }
  1053   assert(host_klass.not_null() || cp_patches == NULL,
  1077   assert(host_klass != NULL || NULL == cp_patches,
  1054          "cp_patches only found with host_klass");
  1078          "cp_patches only found with host_klass");
  1055 
  1079 
  1056   return k();
  1080   return k();
  1057 }
  1081 }
  1058 
  1082 
  1063 
  1087 
  1064 Klass* SystemDictionary::resolve_from_stream(Symbol* class_name,
  1088 Klass* SystemDictionary::resolve_from_stream(Symbol* class_name,
  1065                                              Handle class_loader,
  1089                                              Handle class_loader,
  1066                                              Handle protection_domain,
  1090                                              Handle protection_domain,
  1067                                              ClassFileStream* st,
  1091                                              ClassFileStream* st,
  1068                                              bool verify,
       
  1069                                              TRAPS) {
  1092                                              TRAPS) {
  1070 
  1093 
  1071   // Classloaders that support parallelism, e.g. bootstrap classloader,
  1094   // Classloaders that support parallelism, e.g. bootstrap classloader,
  1072   // or all classloaders with UnsyncloadClass do not acquire lock here
  1095   // or all classloaders with UnsyncloadClass do not acquire lock here
  1073   bool DoObjectLock = true;
  1096   bool DoObjectLock = true;
  1080   // Make sure we are synchronized on the class loader before we proceed
  1103   // Make sure we are synchronized on the class loader before we proceed
  1081   Handle lockObject = compute_loader_lock_object(class_loader, THREAD);
  1104   Handle lockObject = compute_loader_lock_object(class_loader, THREAD);
  1082   check_loader_lock_contention(lockObject, THREAD);
  1105   check_loader_lock_contention(lockObject, THREAD);
  1083   ObjectLocker ol(lockObject, THREAD, DoObjectLock);
  1106   ObjectLocker ol(lockObject, THREAD, DoObjectLock);
  1084 
  1107 
  1085   TempNewSymbol parsed_name = NULL;
  1108   assert(st != NULL, "invariant");
  1086 
  1109 
  1087   // Parse the stream. Note that we do this even though this klass might
  1110   // Parse the stream and create a klass.
       
  1111   // Note that we do this even though this klass might
  1088   // already be present in the SystemDictionary, otherwise we would not
  1112   // already be present in the SystemDictionary, otherwise we would not
  1089   // throw potential ClassFormatErrors.
  1113   // throw potential ClassFormatErrors.
  1090   //
  1114   //
  1091   // Note: "name" is updated.
  1115   // Note: "parsed_name" is updated.
  1092 
  1116   TempNewSymbol parsed_name = NULL;
  1093   instanceKlassHandle k;
  1117 
       
  1118  instanceKlassHandle k;
  1094 
  1119 
  1095 #if INCLUDE_CDS
  1120 #if INCLUDE_CDS
  1096   k = SystemDictionaryShared::lookup_from_stream(class_name,
  1121   k = SystemDictionaryShared::lookup_from_stream(class_name,
  1097                                                  class_loader,
  1122                                                  class_loader,
  1098                                                  protection_domain,
  1123                                                  protection_domain,
  1099                                                  st,
  1124                                                  st,
  1100                                                  verify,
       
  1101                                                  CHECK_NULL);
  1125                                                  CHECK_NULL);
  1102 #endif
  1126 #endif
  1103 
  1127 
  1104   if (k.not_null()) {
  1128   if (k.not_null()) {
  1105     parsed_name = k->name();
  1129     parsed_name = k->name();
  1106   } else {
  1130   } else {
  1107     if (st->buffer() == NULL) {
  1131     if (st->buffer() == NULL) {
  1108       return NULL;
  1132       return NULL;
  1109     }
  1133     }
  1110     k = ClassFileParser(st).parseClassFile(class_name,
  1134     k = KlassFactory::create_from_stream(st,
  1111                                            loader_data,
  1135                                          class_name,
  1112                                            protection_domain,
  1136                                          loader_data,
  1113                                            parsed_name,
  1137                                          protection_domain,
  1114                                            verify,
  1138                                          NULL, // host_klass
  1115                                            THREAD);
  1139                                          NULL, // cp_patches
       
  1140                                          &parsed_name,
       
  1141                                          THREAD);
  1116   }
  1142   }
  1117 
  1143 
  1118   const char* pkg = "java/";
  1144   const char* pkg = "java/";
  1119   if (!HAS_PENDING_EXCEPTION &&
  1145   if (!HAS_PENDING_EXCEPTION &&
  1120       !class_loader.is_null() &&
  1146       !class_loader.is_null() &&
  1317     }
  1343     }
  1318 
  1344 
  1319     if (k.is_null()) {
  1345     if (k.is_null()) {
  1320       // Use VM class loader
  1346       // Use VM class loader
  1321       PerfTraceTime vmtimer(ClassLoader::perf_sys_classload_time());
  1347       PerfTraceTime vmtimer(ClassLoader::perf_sys_classload_time());
  1322       k = ClassLoader::load_classfile(class_name, CHECK_(nh));
  1348       k = ClassLoader::load_class(class_name, CHECK_(nh));
  1323     }
  1349     }
  1324 
  1350 
  1325     // find_or_define_instance_class may return a different InstanceKlass
  1351     // find_or_define_instance_class may return a different InstanceKlass
  1326     if (!k.is_null()) {
  1352     if (!k.is_null()) {
  1327       k = find_or_define_instance_class(class_name, class_loader, k, CHECK_(nh));
  1353       k = find_or_define_instance_class(class_name, class_loader, k, CHECK_(nh));
  2702   // Verify constraint table
  2728   // Verify constraint table
  2703   guarantee(constraints() != NULL, "Verify of loader constraints failed");
  2729   guarantee(constraints() != NULL, "Verify of loader constraints failed");
  2704   constraints()->verify(dictionary(), placeholders());
  2730   constraints()->verify(dictionary(), placeholders());
  2705 }
  2731 }
  2706 
  2732 
  2707 // utility function for class load event
  2733 // caller needs ResourceMark
  2708 void SystemDictionary::post_class_load_event(const Ticks& start_time,
  2734 const char* SystemDictionary::loader_name(const oop loader) {
  2709                                              instanceKlassHandle k,
  2735   return ((loader) == NULL ? "<bootloader>" :
  2710                                              Handle initiating_loader) {
  2736     InstanceKlass::cast((loader)->klass())->name()->as_C_string());
  2711 #if INCLUDE_TRACE
  2737 }
  2712   EventClassLoad event(UNTIMED);
  2738 
  2713   if (event.should_commit()) {
  2739 // caller needs ResourceMark
  2714     event.set_starttime(start_time);
  2740 const char* SystemDictionary::loader_name(const ClassLoaderData* loader_data) {
  2715     event.set_loadedClass(k());
  2741   return (loader_data->class_loader() == NULL ? "<bootloader>" :
  2716     oop defining_class_loader = k->class_loader();
  2742     InstanceKlass::cast((loader_data->class_loader())->klass())->name()->as_C_string());
  2717     event.set_definingClassLoader(defining_class_loader !=  NULL ?
  2743 }
  2718                                     defining_class_loader->klass() : (Klass*)NULL);
       
  2719     oop class_loader = initiating_loader.is_null() ? (oop)NULL : initiating_loader();
       
  2720     event.set_initiatingClassLoader(class_loader != NULL ?
       
  2721                                       class_loader->klass() : (Klass*)NULL);
       
  2722     event.commit();
       
  2723   }
       
  2724 #endif // INCLUDE_TRACE
       
  2725 }
       
  2726