< prev index next >

src/hotspot/share/classfile/systemDictionaryShared.cpp

Print this page


 889 
 890 // This function is called for loading only UNREGISTERED classes
 891 InstanceKlass* SystemDictionaryShared::lookup_from_stream(Symbol* class_name,
 892                                                           Handle class_loader,
 893                                                           Handle protection_domain,
 894                                                           const ClassFileStream* cfs,
 895                                                           TRAPS) {
 896   if (!UseSharedSpaces) {
 897     return NULL;
 898   }
 899   if (class_name == NULL) {  // don't do this for anonymous classes
 900     return NULL;
 901   }
 902   if (class_loader.is_null() ||
 903       SystemDictionary::is_system_class_loader(class_loader()) ||
 904       SystemDictionary::is_platform_class_loader(class_loader())) {
 905     // Do nothing for the BUILTIN loaders.
 906     return NULL;
 907   }
 908 
 909   const RunTimeSharedClassInfo* record = find_record(&_unregistered_dictionary, class_name);
 910   if (record == NULL) {
 911     if (DynamicArchive::is_mapped()) {
 912       record = find_record(&_dynamic_unregistered_dictionary, class_name);
 913     }
 914     if (record == NULL) {
 915       return NULL;
 916     }
 917   }
 918 
 919   int clsfile_size  = cfs->length();
 920   int clsfile_crc32 = ClassLoader::crc32(0, (const char*)cfs->buffer(), cfs->length());
 921 
 922   if (!record->matches(clsfile_size, clsfile_crc32)) {
 923     return NULL;
 924   }
 925 
 926   return acquire_class_for_current_thread(record->_klass, class_loader,
 927                                           protection_domain, cfs,
 928                                           THREAD);
 929 }
 930 
 931 InstanceKlass* SystemDictionaryShared::acquire_class_for_current_thread(
 932                    InstanceKlass *ik,
 933                    Handle class_loader,
 934                    Handle protection_domain,
 935                    const ClassFileStream *cfs,
 936                    TRAPS) {
 937   ClassLoaderData* loader_data = ClassLoaderData::class_loader_data(class_loader());


1396     write_dictionary(&_builtin_dictionary, true);
1397     write_dictionary(&_unregistered_dictionary, false);
1398   } else {
1399     write_dictionary(&_dynamic_builtin_dictionary, true);
1400     write_dictionary(&_dynamic_unregistered_dictionary, false);
1401   }
1402 }
1403 
1404 void SystemDictionaryShared::serialize_dictionary_headers(SerializeClosure* soc,
1405                                                           bool is_static_archive) {
1406   if (is_static_archive) {
1407     _builtin_dictionary.serialize_header(soc);
1408     _unregistered_dictionary.serialize_header(soc);
1409   } else {
1410     _dynamic_builtin_dictionary.serialize_header(soc);
1411     _dynamic_unregistered_dictionary.serialize_header(soc);
1412   }
1413 }
1414 
1415 const RunTimeSharedClassInfo*
1416 SystemDictionaryShared::find_record(RunTimeSharedDictionary* dict, Symbol* name) {
1417   if (UseSharedSpaces) {
1418     unsigned int hash = primitive_hash<Symbol*>(name);
1419     return dict->lookup(name, hash, 0);
1420   } else {
1421     return NULL;
1422   }
1423 }
1424 
1425 InstanceKlass* SystemDictionaryShared::find_builtin_class(Symbol* name) {
1426   const RunTimeSharedClassInfo* record = find_record(&_builtin_dictionary, name);
1427   if (record) {
1428     return record->_klass;


1429   }
1430 
1431   if (DynamicArchive::is_mapped()) {
1432     record = find_record(&_dynamic_builtin_dictionary, name);
1433     if (record) {
1434       return record->_klass;
1435     }
1436   }
1437 








1438   return NULL;

1439 }
1440 
1441 void SystemDictionaryShared::update_shared_entry(InstanceKlass* k, int id) {
1442   assert(DumpSharedSpaces, "supported only when dumping");
1443   DumpTimeSharedClassInfo* info = find_or_allocate_info_for(k);
1444   info->_id = id;
1445 }
1446 
1447 class SharedDictionaryPrinter : StackObj {
1448   outputStream* _st;
1449   int _index;
1450 public:
1451   SharedDictionaryPrinter(outputStream* st) : _st(st), _index(0) {}
1452 
1453   void do_value(const RunTimeSharedClassInfo* record) {
1454     ResourceMark rm;
1455     _st->print_cr("%4d:  %s", (_index++), record->_klass->external_name());
1456   }
1457 };
1458 




 889 
 890 // This function is called for loading only UNREGISTERED classes
 891 InstanceKlass* SystemDictionaryShared::lookup_from_stream(Symbol* class_name,
 892                                                           Handle class_loader,
 893                                                           Handle protection_domain,
 894                                                           const ClassFileStream* cfs,
 895                                                           TRAPS) {
 896   if (!UseSharedSpaces) {
 897     return NULL;
 898   }
 899   if (class_name == NULL) {  // don't do this for anonymous classes
 900     return NULL;
 901   }
 902   if (class_loader.is_null() ||
 903       SystemDictionary::is_system_class_loader(class_loader()) ||
 904       SystemDictionary::is_platform_class_loader(class_loader())) {
 905     // Do nothing for the BUILTIN loaders.
 906     return NULL;
 907   }
 908 
 909   const RunTimeSharedClassInfo* record = find_record(&_unregistered_dictionary, &_dynamic_unregistered_dictionary, class_name);




 910   if (record == NULL) {
 911     return NULL;
 912   }

 913 
 914   int clsfile_size  = cfs->length();
 915   int clsfile_crc32 = ClassLoader::crc32(0, (const char*)cfs->buffer(), cfs->length());
 916 
 917   if (!record->matches(clsfile_size, clsfile_crc32)) {
 918     return NULL;
 919   }
 920 
 921   return acquire_class_for_current_thread(record->_klass, class_loader,
 922                                           protection_domain, cfs,
 923                                           THREAD);
 924 }
 925 
 926 InstanceKlass* SystemDictionaryShared::acquire_class_for_current_thread(
 927                    InstanceKlass *ik,
 928                    Handle class_loader,
 929                    Handle protection_domain,
 930                    const ClassFileStream *cfs,
 931                    TRAPS) {
 932   ClassLoaderData* loader_data = ClassLoaderData::class_loader_data(class_loader());


1391     write_dictionary(&_builtin_dictionary, true);
1392     write_dictionary(&_unregistered_dictionary, false);
1393   } else {
1394     write_dictionary(&_dynamic_builtin_dictionary, true);
1395     write_dictionary(&_dynamic_unregistered_dictionary, false);
1396   }
1397 }
1398 
1399 void SystemDictionaryShared::serialize_dictionary_headers(SerializeClosure* soc,
1400                                                           bool is_static_archive) {
1401   if (is_static_archive) {
1402     _builtin_dictionary.serialize_header(soc);
1403     _unregistered_dictionary.serialize_header(soc);
1404   } else {
1405     _dynamic_builtin_dictionary.serialize_header(soc);
1406     _dynamic_unregistered_dictionary.serialize_header(soc);
1407   }
1408 }
1409 
1410 const RunTimeSharedClassInfo*
1411 SystemDictionaryShared::find_record(RunTimeSharedDictionary* static_dict, RunTimeSharedDictionary* dynamic_dict, Symbol* name) {
1412   if (!UseSharedSpaces || !name->is_shared()) {
1413     // The names of all shared classes must also be a shared Symbol.


1414     return NULL;
1415   }

1416 
1417   unsigned int hash = primitive_hash<Symbol*>(name);
1418   const RunTimeSharedClassInfo* record = NULL;
1419   if (!MetaspaceShared::is_shared_dynamic(name)) {
1420     // The names of all shared classes in the static dict must also be in the
1421     // static archive
1422     record = static_dict->lookup(name, hash, 0);
1423   }
1424 
1425   if (record == NULL && DynamicArchive::is_mapped()) {
1426     record = dynamic_dict->lookup(name, hash, 0);



1427   }
1428 
1429   return record;
1430 }
1431 
1432 InstanceKlass* SystemDictionaryShared::find_builtin_class(Symbol* name) {
1433   const RunTimeSharedClassInfo* record = find_record(&_builtin_dictionary, &_dynamic_builtin_dictionary, name);
1434   if (record != NULL) {
1435     return record->_klass;
1436   } else {
1437     return NULL;
1438   }
1439 }
1440 
1441 void SystemDictionaryShared::update_shared_entry(InstanceKlass* k, int id) {
1442   assert(DumpSharedSpaces, "supported only when dumping");
1443   DumpTimeSharedClassInfo* info = find_or_allocate_info_for(k);
1444   info->_id = id;
1445 }
1446 
1447 class SharedDictionaryPrinter : StackObj {
1448   outputStream* _st;
1449   int _index;
1450 public:
1451   SharedDictionaryPrinter(outputStream* st) : _st(st), _index(0) {}
1452 
1453   void do_value(const RunTimeSharedClassInfo* record) {
1454     ResourceMark rm;
1455     _st->print_cr("%4d:  %s", (_index++), record->_klass->external_name());
1456   }
1457 };
1458 


< prev index next >