< prev index next >

src/hotspot/share/classfile/systemDictionary.cpp

Print this page




  95 PlaceholderTable*      SystemDictionary::_placeholders        = NULL;
  96 LoaderConstraintTable* SystemDictionary::_loader_constraints  = NULL;
  97 ResolutionErrorTable*  SystemDictionary::_resolution_errors   = NULL;
  98 SymbolPropertyTable*   SystemDictionary::_invoke_method_table = NULL;
  99 ProtectionDomainCacheTable*   SystemDictionary::_pd_cache_table = NULL;
 100 
 101 oop         SystemDictionary::_system_loader_lock_obj     =  NULL;
 102 
 103 InstanceKlass*      SystemDictionary::_well_known_klasses[SystemDictionary::WKID_LIMIT]
 104                                                           =  { NULL /*, NULL...*/ };
 105 
 106 InstanceKlass*      SystemDictionary::_box_klasses[T_VOID+1]      =  { NULL /*, NULL...*/ };
 107 
 108 oop         SystemDictionary::_java_system_loader         =  NULL;
 109 oop         SystemDictionary::_java_platform_loader       =  NULL;
 110 
 111 // Default ProtectionDomainCacheSize value
 112 
 113 const int defaultProtectionDomainCacheSize = 1009;
 114 








































 115 // ----------------------------------------------------------------------------
 116 // Java-level SystemLoader and PlatformLoader
 117 
 118 oop SystemDictionary::java_system_loader() {
 119   return _java_system_loader;
 120 }
 121 
 122 oop SystemDictionary::java_platform_loader() {
 123   return _java_platform_loader;
 124 }
 125 
 126 void SystemDictionary::compute_java_loaders(TRAPS) {
 127   JavaValue result(T_OBJECT);
 128   InstanceKlass* class_loader_klass = SystemDictionary::ClassLoader_klass();
 129   JavaCalls::call_static(&result,
 130                          class_loader_klass,
 131                          vmSymbols::getSystemClassLoader_name(),
 132                          vmSymbols::void_classloader_signature(),
 133                          CHECK);
 134 


 965     // dimension and object_key in FieldArrayInfo are assigned as a
 966     // side-effect of this call
 967     FieldArrayInfo fd;
 968     BasicType t = FieldType::get_array_info(class_name, fd, CHECK_(NULL));
 969     if (t != T_OBJECT) {
 970       k = Universe::typeArrayKlassObj(t);
 971     } else {
 972       k = SystemDictionary::find(fd.object_key(), class_loader, protection_domain, THREAD);
 973     }
 974     if (k != NULL) {
 975       k = k->array_klass_or_null(fd.dimension());
 976     }
 977   } else {
 978     k = find(class_name, class_loader, protection_domain, THREAD);
 979   }
 980   return k;
 981 }
 982 
 983 // Note: this method is much like resolve_from_stream, but
 984 // does not publish the classes via the SystemDictionary.
 985 // Handles unsafe_DefineAnonymousClass and redefineclasses
 986 // RedefinedClasses do not add to the class hierarchy
 987 InstanceKlass* SystemDictionary::parse_stream(Symbol* class_name,
 988                                               Handle class_loader,
 989                                               Handle protection_domain,
 990                                               ClassFileStream* st,
 991                                               const InstanceKlass* unsafe_anonymous_host,
 992                                               GrowableArray<Handle>* cp_patches,
 993                                               TRAPS) {
 994 
 995   EventClassLoad class_load_start_event;
 996 
 997   ClassLoaderData* loader_data;
 998   if (unsafe_anonymous_host != NULL) {
 999     // Create a new CLD for an unsafe anonymous class, that uses the same class loader
1000     // as the unsafe_anonymous_host
1001     guarantee(unsafe_anonymous_host->class_loader() == class_loader(), "should be the same");
1002     loader_data = ClassLoaderData::unsafe_anonymous_class_loader_data(class_loader);












1003   } else {
1004     loader_data = ClassLoaderData::class_loader_data(class_loader());
1005   }
1006 
1007   assert(st != NULL, "invariant");
1008   assert(st->need_verify(), "invariant");
1009 
1010   // Parse stream and create a klass.
1011   // Note that we do this even though this klass might
1012   // already be present in the SystemDictionary, otherwise we would not
1013   // throw potential ClassFormatErrors.
1014 
1015   InstanceKlass* k = KlassFactory::create_from_stream(st,
1016                                                       class_name,
1017                                                       loader_data,
1018                                                       protection_domain,
1019                                                       unsafe_anonymous_host,
1020                                                       cp_patches,
1021                                                       CHECK_NULL);
1022 
1023   if (unsafe_anonymous_host != NULL && k != NULL) {
1024     // Unsafe anonymous classes must update ClassLoaderData holder (was unsafe_anonymous_host loader)
1025     // so that they can be unloaded when the mirror is no longer referenced.

1026     k->class_loader_data()->initialize_holder(Handle(THREAD, k->java_mirror()));

1027 
1028     {
1029       MutexLocker mu_r(Compile_lock, THREAD);
1030 
1031       // Add to class hierarchy, initialize vtables, and do possible
1032       // deoptimizations.
1033       add_to_hierarchy(k, CHECK_NULL); // No exception, but can block
1034       // But, do not add to dictionary.
1035     }
1036 
1037     // Rewrite and patch constant pool here.
1038     k->link_class(CHECK_NULL);
1039     if (cp_patches != NULL) {
1040       k->constants()->patch_resolved_references(cp_patches);
1041     }
1042 
1043     // If it's anonymous, initialize it now, since nobody else will.

1044     k->eager_initialize(CHECK_NULL);

1045 
1046     // notify jvmti
1047     if (JvmtiExport::should_post_class_load()) {
1048         assert(THREAD->is_Java_thread(), "thread->is_Java_thread()");
1049         JvmtiExport::post_class_load((JavaThread *) THREAD, k);
1050     }
1051     if (class_load_start_event.should_commit()) {
1052       post_class_load_event(&class_load_start_event, k, loader_data);
1053     }
1054   }
1055   assert(unsafe_anonymous_host != NULL || NULL == cp_patches,
1056          "cp_patches only found with unsafe_anonymous_host");
1057 
1058   return k;
1059 }
1060 
1061 // Add a klass to the system from a stream (called by jni_DefineClass and
1062 // JVM_DefineClass).
1063 // Note: class_name can be NULL. In that case we do not know the name of
1064 // the class until we have parsed the stream.
1065 
1066 InstanceKlass* SystemDictionary::resolve_from_stream(Symbol* class_name,
1067                                                      Handle class_loader,
1068                                                      Handle protection_domain,
1069                                                      ClassFileStream* st,
1070                                                      TRAPS) {
1071 
1072   HandleMark hm(THREAD);
1073 
1074   // Classloaders that support parallelism, e.g. bootstrap classloader,
1075   // do not acquire lock here


1090   // Parse the stream and create a klass.
1091   // Note that we do this even though this klass might
1092   // already be present in the SystemDictionary, otherwise we would not
1093   // throw potential ClassFormatErrors.
1094  InstanceKlass* k = NULL;
1095 
1096 #if INCLUDE_CDS
1097   if (!DumpSharedSpaces) {
1098     k = SystemDictionaryShared::lookup_from_stream(class_name,
1099                                                    class_loader,
1100                                                    protection_domain,
1101                                                    st,
1102                                                    CHECK_NULL);
1103   }
1104 #endif
1105 
1106   if (k == NULL) {
1107     if (st->buffer() == NULL) {
1108       return NULL;
1109     }
1110     k = KlassFactory::create_from_stream(st,
1111                                          class_name,
1112                                          loader_data,
1113                                          protection_domain,
1114                                          NULL, // unsafe_anonymous_host
1115                                          NULL, // cp_patches
1116                                          CHECK_NULL);
1117   }
1118 
1119   assert(k != NULL, "no klass created");
1120   Symbol* h_name = k->name();
1121   assert(class_name == NULL || class_name == h_name, "name mismatch");
1122 
1123   // Add class just loaded
1124   // If a class loader supports parallel classloading handle parallel define requests
1125   // find_or_define_instance_class may return a different InstanceKlass
1126   if (is_parallelCapable(class_loader)) {
1127     InstanceKlass* defined_k = find_or_define_instance_class(h_name, class_loader, k, THREAD);
1128     if (!HAS_PENDING_EXCEPTION && defined_k != k) {
1129       // If a parallel capable class loader already defined this class, register 'k' for cleanup.
1130       assert(defined_k != NULL, "Should have a klass if there's no exception");
1131       loader_data->add_to_deallocate_list(k);
1132       k = defined_k;
1133     }
1134   } else {
1135     define_instance_class(k, THREAD);
1136   }




  95 PlaceholderTable*      SystemDictionary::_placeholders        = NULL;
  96 LoaderConstraintTable* SystemDictionary::_loader_constraints  = NULL;
  97 ResolutionErrorTable*  SystemDictionary::_resolution_errors   = NULL;
  98 SymbolPropertyTable*   SystemDictionary::_invoke_method_table = NULL;
  99 ProtectionDomainCacheTable*   SystemDictionary::_pd_cache_table = NULL;
 100 
 101 oop         SystemDictionary::_system_loader_lock_obj     =  NULL;
 102 
 103 InstanceKlass*      SystemDictionary::_well_known_klasses[SystemDictionary::WKID_LIMIT]
 104                                                           =  { NULL /*, NULL...*/ };
 105 
 106 InstanceKlass*      SystemDictionary::_box_klasses[T_VOID+1]      =  { NULL /*, NULL...*/ };
 107 
 108 oop         SystemDictionary::_java_system_loader         =  NULL;
 109 oop         SystemDictionary::_java_platform_loader       =  NULL;
 110 
 111 // Default ProtectionDomainCacheSize value
 112 
 113 const int defaultProtectionDomainCacheSize = 1009;
 114 
 115 ClassLoadInfo::ClassLoadInfo() {
 116   _protection_domain = Handle();
 117   _unsafe_anonymous_host = NULL;
 118   _cp_patches = NULL;
 119   _class_hidden_info._dynamic_nest_host = NULL;
 120   _class_hidden_info._class_data = Handle();
 121   _is_hidden = false;
 122   _is_weak_hidden = false;
 123   _can_access_vm_annotations = false;
 124 }
 125 
 126 ClassLoadInfo::ClassLoadInfo(Handle protection_domain) {
 127   _protection_domain = protection_domain;
 128   _unsafe_anonymous_host = NULL;
 129   _cp_patches = NULL;
 130   _class_hidden_info._dynamic_nest_host = NULL;
 131   _class_hidden_info._class_data = Handle();
 132   _is_hidden = false;
 133   _is_weak_hidden = false;
 134   _can_access_vm_annotations = false;
 135 }
 136 
 137 ClassLoadInfo::ClassLoadInfo(Handle protection_domain,
 138                              const InstanceKlass* unsafe_anonymous_host,
 139                              GrowableArray<Handle>* cp_patches,
 140                              InstanceKlass* dynamic_nest_host,
 141                              Handle class_data,
 142                              bool is_hidden,
 143                              bool is_weak_hidden,
 144                              bool can_access_vm_annotations) {
 145   _protection_domain = protection_domain;
 146   _unsafe_anonymous_host = unsafe_anonymous_host;
 147   _cp_patches = cp_patches;
 148   _class_hidden_info._dynamic_nest_host = dynamic_nest_host;
 149   _class_hidden_info._class_data = class_data;
 150   _is_hidden = is_hidden;
 151   _is_weak_hidden = is_weak_hidden;
 152   _can_access_vm_annotations = can_access_vm_annotations;
 153 }
 154 
 155 // ----------------------------------------------------------------------------
 156 // Java-level SystemLoader and PlatformLoader
 157 
 158 oop SystemDictionary::java_system_loader() {
 159   return _java_system_loader;
 160 }
 161 
 162 oop SystemDictionary::java_platform_loader() {
 163   return _java_platform_loader;
 164 }
 165 
 166 void SystemDictionary::compute_java_loaders(TRAPS) {
 167   JavaValue result(T_OBJECT);
 168   InstanceKlass* class_loader_klass = SystemDictionary::ClassLoader_klass();
 169   JavaCalls::call_static(&result,
 170                          class_loader_klass,
 171                          vmSymbols::getSystemClassLoader_name(),
 172                          vmSymbols::void_classloader_signature(),
 173                          CHECK);
 174 


1005     // dimension and object_key in FieldArrayInfo are assigned as a
1006     // side-effect of this call
1007     FieldArrayInfo fd;
1008     BasicType t = FieldType::get_array_info(class_name, fd, CHECK_(NULL));
1009     if (t != T_OBJECT) {
1010       k = Universe::typeArrayKlassObj(t);
1011     } else {
1012       k = SystemDictionary::find(fd.object_key(), class_loader, protection_domain, THREAD);
1013     }
1014     if (k != NULL) {
1015       k = k->array_klass_or_null(fd.dimension());
1016     }
1017   } else {
1018     k = find(class_name, class_loader, protection_domain, THREAD);
1019   }
1020   return k;
1021 }
1022 
1023 // Note: this method is much like resolve_from_stream, but
1024 // does not publish the classes via the SystemDictionary.
1025 // Handles Lookup.defineClass hidden, unsafe_DefineAnonymousClass
1026 // and redefineclasses. RedefinedClasses do not add to the class hierarchy.
1027 InstanceKlass* SystemDictionary::parse_stream(Symbol* class_name,
1028                                               Handle class_loader,

1029                                               ClassFileStream* st,
1030                                               const ClassLoadInfo& cl_info,

1031                                               TRAPS) {
1032 
1033   EventClassLoad class_load_start_event;
1034 
1035   ClassLoaderData* loader_data;
1036 
1037   if (cl_info.unsafe_anonymous_host() != NULL) {
1038     // - for unsafe anonymous class: create a new short-lived CLD that uses the same
1039     //                               class loader as the unsafe_anonymous_host.
1040     guarantee(cl_info.unsafe_anonymous_host()->class_loader() == class_loader(),
1041               "should be the same");
1042     loader_data = ClassLoaderData::shortlived_class_loader_data(class_loader);
1043   } else if (cl_info.is_hidden()) {
1044     // - for weak hidden class: create a new short-lived CLD whose loader is
1045     //                               the Lookup class' loader.
1046     // - for hidden class: add the class to the Lookup class' loader's CLD.
1047     if (cl_info.is_weak_hidden()) {
1048       loader_data = ClassLoaderData::shortlived_class_loader_data(class_loader);
1049     } else {
1050       // This hidden class goes into the regular CLD pool for this loader.
1051       loader_data = register_loader(class_loader);
1052     }
1053   } else {
1054     loader_data = ClassLoaderData::class_loader_data(class_loader());
1055   }
1056 
1057   assert(st != NULL, "invariant");
1058   assert(st->need_verify(), "invariant");
1059 
1060   // Parse stream and create a klass.
1061   // Note that we do this even though this klass might
1062   // already be present in the SystemDictionary, otherwise we would not
1063   // throw potential ClassFormatErrors.
1064 
1065   InstanceKlass* k = KlassFactory::create_from_stream(st,
1066                                                       class_name,
1067                                                       loader_data,
1068                                                       cl_info,


1069                                                       CHECK_NULL);
1070 
1071   if ((cl_info.is_hidden() || (cl_info.unsafe_anonymous_host() != NULL)) && k != NULL) {
1072     // Weak hidden and unsafe anonymous classes must update ClassLoaderData holder
1073     // so that they can be unloaded when the mirror is no longer referenced.
1074     if (cl_info.is_weak_hidden() || (cl_info.unsafe_anonymous_host() != NULL)) {
1075       k->class_loader_data()->initialize_holder(Handle(THREAD, k->java_mirror()));
1076     }
1077 
1078     {
1079       MutexLocker mu_r(Compile_lock, THREAD);
1080 
1081       // Add to class hierarchy, initialize vtables, and do possible
1082       // deoptimizations.
1083       add_to_hierarchy(k, CHECK_NULL); // No exception, but can block
1084       // But, do not add to dictionary.
1085     }
1086 
1087     // Rewrite and patch constant pool here.
1088     k->link_class(CHECK_NULL);
1089     if (cl_info.cp_patches() != NULL) {
1090       k->constants()->patch_resolved_references(cl_info.cp_patches());
1091     }
1092 
1093     // If it's anonymous, initialize it now, since nobody else will.
1094     if (cl_info.unsafe_anonymous_host() != NULL) {
1095       k->eager_initialize(CHECK_NULL);
1096     }
1097 
1098     // notify jvmti
1099     if (JvmtiExport::should_post_class_load()) {
1100         assert(THREAD->is_Java_thread(), "thread->is_Java_thread()");
1101         JvmtiExport::post_class_load((JavaThread *) THREAD, k);
1102     }
1103     if (class_load_start_event.should_commit()) {
1104       post_class_load_event(&class_load_start_event, k, loader_data);
1105     }
1106   }
1107   assert(cl_info.unsafe_anonymous_host() != NULL || NULL == cl_info.cp_patches(),
1108          "cp_patches only found with unsafe_anonymous_host");
1109 
1110   return k;
1111 }
1112 
1113 // Add a klass to the system from a stream (called by jni_DefineClass and
1114 // JVM_DefineClass).
1115 // Note: class_name can be NULL. In that case we do not know the name of
1116 // the class until we have parsed the stream.
1117 
1118 InstanceKlass* SystemDictionary::resolve_from_stream(Symbol* class_name,
1119                                                      Handle class_loader,
1120                                                      Handle protection_domain,
1121                                                      ClassFileStream* st,
1122                                                      TRAPS) {
1123 
1124   HandleMark hm(THREAD);
1125 
1126   // Classloaders that support parallelism, e.g. bootstrap classloader,
1127   // do not acquire lock here


1142   // Parse the stream and create a klass.
1143   // Note that we do this even though this klass might
1144   // already be present in the SystemDictionary, otherwise we would not
1145   // throw potential ClassFormatErrors.
1146  InstanceKlass* k = NULL;
1147 
1148 #if INCLUDE_CDS
1149   if (!DumpSharedSpaces) {
1150     k = SystemDictionaryShared::lookup_from_stream(class_name,
1151                                                    class_loader,
1152                                                    protection_domain,
1153                                                    st,
1154                                                    CHECK_NULL);
1155   }
1156 #endif
1157 
1158   if (k == NULL) {
1159     if (st->buffer() == NULL) {
1160       return NULL;
1161     }
1162     ClassLoadInfo cl_info(protection_domain);
1163     k = KlassFactory::create_from_stream(st, class_name, loader_data, cl_info, CHECK_NULL);





1164   }
1165 
1166   assert(k != NULL, "no klass created");
1167   Symbol* h_name = k->name();
1168   assert(class_name == NULL || class_name == h_name, "name mismatch");
1169 
1170   // Add class just loaded
1171   // If a class loader supports parallel classloading handle parallel define requests
1172   // find_or_define_instance_class may return a different InstanceKlass
1173   if (is_parallelCapable(class_loader)) {
1174     InstanceKlass* defined_k = find_or_define_instance_class(h_name, class_loader, k, THREAD);
1175     if (!HAS_PENDING_EXCEPTION && defined_k != k) {
1176       // If a parallel capable class loader already defined this class, register 'k' for cleanup.
1177       assert(defined_k != NULL, "Should have a klass if there's no exception");
1178       loader_data->add_to_deallocate_list(k);
1179       k = defined_k;
1180     }
1181   } else {
1182     define_instance_class(k, THREAD);
1183   }


< prev index next >