< prev index next >

src/hotspot/share/classfile/systemDictionaryShared.cpp

Print this page


 488       Dictionary* dictionary = loader_data->dictionary();
 489 
 490       unsigned int d_hash = dictionary->compute_hash(name);
 491 
 492       bool DoObjectLock = true;
 493       if (is_parallelCapable(class_loader)) {
 494         DoObjectLock = false;
 495       }
 496 
 497       // Make sure we are synchronized on the class loader before we proceed
 498       //
 499       // Note: currently, find_or_load_shared_class is called only from
 500       // JVM_FindLoadedClass and used for PlatformClassLoader and AppClassLoader,
 501       // which are parallel-capable loaders, so this lock is NOT taken.
 502       Handle lockObject = compute_loader_lock_object(class_loader, THREAD);
 503       check_loader_lock_contention(lockObject, THREAD);
 504       ObjectLocker ol(lockObject, THREAD, DoObjectLock);
 505 
 506       {
 507         MutexLocker mu(SystemDictionary_lock, THREAD);
 508         Klass* check = find_class(d_hash, name, dictionary);
 509         if (check != NULL) {
 510           return InstanceKlass::cast(check);
 511         }
 512       }
 513 
 514       k = load_shared_class_for_builtin_loader(name, class_loader, THREAD);
 515       if (k != NULL) {
 516         define_instance_class(k, CHECK_NULL);
 517       }
 518     }
 519   }
 520   return k;
 521 }
 522 
 523 InstanceKlass* SystemDictionaryShared::load_shared_class_for_builtin_loader(
 524                  Symbol* class_name, Handle class_loader, TRAPS) {
 525   assert(UseSharedSpaces, "must be");
 526   assert(shared_dictionary() != NULL, "already checked");
 527   Klass* k = shared_dictionary()->find_class_for_builtin_loader(class_name);
 528 
 529   if (k != NULL) {
 530     InstanceKlass* ik = InstanceKlass::cast(k);
 531     if ((ik->is_shared_app_class() &&
 532          SystemDictionary::is_system_class_loader(class_loader()))  ||
 533         (ik->is_shared_platform_class() &&
 534          SystemDictionary::is_platform_class_loader(class_loader()))) {
 535       Handle protection_domain =
 536         SystemDictionaryShared::init_security_info(class_loader, ik, CHECK_NULL);
 537       return load_shared_class(ik, class_loader, protection_domain, THREAD);
 538     }
 539   }
 540 
 541   return NULL;
 542 }
 543 
 544 void SystemDictionaryShared::oops_do(OopClosure* f) {
 545   f->do_oop((oop*)&_shared_protection_domains);
 546   f->do_oop((oop*)&_shared_jar_urls);
 547   f->do_oop((oop*)&_shared_jar_manifests);
 548 }
 549 
 550 void SystemDictionaryShared::allocate_shared_protection_domain_array(int size, TRAPS) {


 577 // This function is called for loading only UNREGISTERED classes
 578 InstanceKlass* SystemDictionaryShared::lookup_from_stream(const Symbol* class_name,
 579                                                           Handle class_loader,
 580                                                           Handle protection_domain,
 581                                                           const ClassFileStream* cfs,
 582                                                           TRAPS) {
 583   if (shared_dictionary() == NULL) {
 584     return NULL;
 585   }
 586   if (class_name == NULL) {  // don't do this for anonymous classes
 587     return NULL;
 588   }
 589   if (class_loader.is_null() ||
 590       SystemDictionary::is_system_class_loader(class_loader()) ||
 591       SystemDictionary::is_platform_class_loader(class_loader())) {
 592     // Do nothing for the BUILTIN loaders.
 593     return NULL;
 594   }
 595 
 596   ClassLoaderData* loader_data = ClassLoaderData::class_loader_data(class_loader());
 597   Klass* k;
 598 
 599   { // UNREGISTERED loader
 600     if (!shared_dictionary()->class_exists_for_unregistered_loader(class_name)) {
 601       // No classes of this name for unregistered loaders.
 602       return NULL;
 603     }
 604 
 605     int clsfile_size  = cfs->length();
 606     int clsfile_crc32 = ClassLoader::crc32(0, (const char*)cfs->buffer(), cfs->length());
 607 
 608     k = shared_dictionary()->find_class_for_unregistered_loader(class_name,
 609                                                                 clsfile_size, clsfile_crc32);
 610   }
 611 
 612   if (k == NULL) { // not archived
 613     return NULL;
 614   }
 615 
 616   return acquire_class_for_current_thread(InstanceKlass::cast(k), class_loader,
 617                                           protection_domain, THREAD);
 618 }
 619 
 620 InstanceKlass* SystemDictionaryShared::acquire_class_for_current_thread(
 621                    InstanceKlass *ik,
 622                    Handle class_loader,
 623                    Handle protection_domain,
 624                    TRAPS) {
 625   ClassLoaderData* loader_data = ClassLoaderData::class_loader_data(class_loader());
 626 
 627   {
 628     MutexLocker mu(SharedDictionary_lock, THREAD);
 629     if (ik->class_loader_data() != NULL) {
 630       //    ik is already loaded (by this loader or by a different loader)
 631       // or ik is being loaded by a different thread (by this loader or by a different loader)
 632       return NULL;
 633     }
 634 
 635     // No other thread has acquired this yet, so give it to *this thread*
 636     ik->set_class_loader_data(loader_data);


 655                                                    InstanceKlass* k,
 656                                                    TRAPS) {
 657   assert(DumpSharedSpaces, "only when dumping");
 658   assert(boot_loader_dictionary() != NULL, "must be");
 659 
 660   if (boot_loader_dictionary()->add_non_builtin_klass(name, loader_data, k)) {
 661     MutexLocker mu_r(Compile_lock, THREAD); // not really necessary, but add_to_hierarchy asserts this.
 662     add_to_hierarchy(k, CHECK_0);
 663     return true;
 664   }
 665   return false;
 666 }
 667 
 668 // This function is called to resolve the super/interfaces of shared classes for
 669 // non-built-in loaders. E.g., ChildClass in the below example
 670 // where "super:" (and optionally "interface:") have been specified.
 671 //
 672 // java/lang/Object id: 0
 673 // Interface   id: 2 super: 0 source: cust.jar
 674 // ChildClass  id: 4 super: 0 interfaces: 2 source: cust.jar
 675 Klass* SystemDictionaryShared::dump_time_resolve_super_or_fail(
 676     Symbol* child_name, Symbol* class_name, Handle class_loader,
 677     Handle protection_domain, bool is_superclass, TRAPS) {
 678 
 679   assert(DumpSharedSpaces, "only when dumping");
 680 
 681   ClassListParser* parser = ClassListParser::instance();
 682   if (parser == NULL) {
 683     // We're still loading the well-known classes, before the ClassListParser is created.
 684     return NULL;
 685   }
 686   if (child_name->equals(parser->current_class_name())) {
 687     // When this function is called, all the numbered super and interface types
 688     // must have already been loaded. Hence this function is never recursively called.
 689     if (is_superclass) {
 690       return parser->lookup_super_for_current_class(class_name);
 691     } else {
 692       return parser->lookup_interface_for_current_class(class_name);
 693     }
 694   } else {
 695     // The VM is not trying to resolve a super type of parser->current_class_name().
 696     // Instead, it's resolving an error class (because parser->current_class_name() has
 697     // failed parsing or verification). Don't do anything here.
 698     return NULL;
 699   }
 700 }
 701 
 702 struct SharedMiscInfo {
 703   Klass* _klass;
 704   int _clsfile_size;
 705   int _clsfile_crc32;
 706 };
 707 
 708 static GrowableArray<SharedMiscInfo>* misc_info_array = NULL;
 709 
 710 void SystemDictionaryShared::set_shared_class_misc_info(Klass* k, ClassFileStream* cfs) {
 711   assert(DumpSharedSpaces, "only when dumping");
 712   int clsfile_size  = cfs->length();
 713   int clsfile_crc32 = ClassLoader::crc32(0, (const char*)cfs->buffer(), cfs->length());
 714 
 715   if (misc_info_array == NULL) {
 716     misc_info_array = new (ResourceObj::C_HEAP, mtClass) GrowableArray<SharedMiscInfo>(20, /*c heap*/ true);
 717   }
 718 
 719   SharedMiscInfo misc_info;
 720   DEBUG_ONLY({
 721       for (int i=0; i<misc_info_array->length(); i++) {
 722         misc_info = misc_info_array->at(i);
 723         assert(misc_info._klass != k, "cannot call set_shared_class_misc_info twice for the same class");
 724       }
 725     });
 726 
 727   misc_info._klass = k;
 728   misc_info._clsfile_size = clsfile_size;
 729   misc_info._clsfile_crc32 = clsfile_crc32;
 730 
 731   misc_info_array->append(misc_info);
 732 }
 733 
 734 void SystemDictionaryShared::init_shared_dictionary_entry(Klass* k, DictionaryEntry* ent) {
 735   SharedDictionaryEntry* entry = (SharedDictionaryEntry*)ent;
 736   entry->_id = -1;
 737   entry->_clsfile_size = -1;
 738   entry->_clsfile_crc32 = -1;
 739   entry->_verifier_constraints = NULL;
 740   entry->_verifier_constraint_flags = NULL;
 741 
 742   if (misc_info_array != NULL) {
 743     for (int i=0; i<misc_info_array->length(); i++) {
 744       SharedMiscInfo misc_info = misc_info_array->at(i);
 745       if (misc_info._klass == k) {
 746         entry->_clsfile_size = misc_info._clsfile_size;
 747         entry->_clsfile_crc32 = misc_info._clsfile_crc32;
 748         misc_info_array->remove_at(i);
 749         return;
 750       }
 751     }
 752   }
 753 }
 754 
 755 bool SystemDictionaryShared::add_verification_constraint(Klass* k, Symbol* name,
 756          Symbol* from_name, bool from_field_is_protected, bool from_is_array, bool from_is_object) {
 757   assert(DumpSharedSpaces, "called at dump time only");
 758 
 759   // Skip anonymous classes, which are not archived as they are not in
 760   // dictionary (see assert_no_anonymoys_classes_in_dictionaries() in
 761   // VM_PopulateDumpSharedSpace::doit()).
 762   if (k->class_loader_data()->is_anonymous()) {
 763     return true; // anonymous classes are not archived, skip
 764   }
 765 
 766   SharedDictionaryEntry* entry = ((SharedDictionary*)(k->class_loader_data()->dictionary()))->find_entry_for(k);
 767   ResourceMark rm;
 768   // Lambda classes are not archived and will be regenerated at runtime.
 769   if (entry == NULL) {
 770     guarantee(strstr(k->name()->as_C_string(), "Lambda$") != NULL,
 771               "class should be in dictionary before being verified");
 772     return true;
 773   }
 774   entry->add_verification_constraint(name, from_name, from_field_is_protected,
 775                                      from_is_array, from_is_object);


 779     return false;
 780   } else {
 781     // For non-builtin class loaders, we cannot complete the verification check at dump time,
 782     // because at dump time we don't know how to resolve classes for such loaders.
 783     return true;
 784   }
 785 }
 786 
 787 void SystemDictionaryShared::finalize_verification_constraints() {
 788   boot_loader_dictionary()->finalize_verification_constraints();
 789 }
 790 
 791 void SystemDictionaryShared::check_verification_constraints(InstanceKlass* klass,
 792                                                              TRAPS) {
 793   assert(!DumpSharedSpaces && UseSharedSpaces, "called at run time with CDS enabled only");
 794   SharedDictionaryEntry* entry = shared_dictionary()->find_entry_for(klass);
 795   assert(entry != NULL, "call this only for shared classes");
 796   entry->check_verification_constraints(klass, THREAD);
 797 }
 798 
 799 SharedDictionaryEntry* SharedDictionary::find_entry_for(Klass* klass) {
 800   Symbol* class_name = klass->name();
 801   unsigned int hash = compute_hash(class_name);
 802   int index = hash_to_index(hash);
 803 
 804   for (SharedDictionaryEntry* entry = bucket(index);
 805                               entry != NULL;
 806                               entry = entry->next()) {
 807     if (entry->hash() == hash && entry->literal() == klass) {
 808       return entry;
 809     }
 810   }
 811 
 812   return NULL;
 813 }
 814 
 815 void SharedDictionary::finalize_verification_constraints() {
 816   int bytes = 0, count = 0;
 817   for (int index = 0; index < table_size(); index++) {
 818     for (SharedDictionaryEntry *probe = bucket(index);
 819                                 probe != NULL;


 953 bool SharedDictionary::add_non_builtin_klass(const Symbol* class_name,
 954                                              ClassLoaderData* loader_data,
 955                                              InstanceKlass* klass) {
 956 
 957   assert(DumpSharedSpaces, "supported only when dumping");
 958   assert(klass != NULL, "adding NULL klass");
 959   assert(klass->name() == class_name, "sanity check on name");
 960   assert(klass->shared_classpath_index() < 0,
 961          "the shared classpath index should not be set for shared class loaded by the custom loaders");
 962 
 963   // Add an entry for a non-builtin class.
 964   // For a shared class for custom class loaders, SystemDictionary::resolve_or_null will
 965   // not find this class, because is_builtin() is false.
 966   unsigned int hash = compute_hash(class_name);
 967   int index = hash_to_index(hash);
 968 
 969   for (SharedDictionaryEntry* entry = bucket(index);
 970                               entry != NULL;
 971                               entry = entry->next()) {
 972     if (entry->hash() == hash) {
 973       Klass* klass = (Klass*)entry->literal();
 974       if (klass->name() == class_name && klass->class_loader_data() == loader_data) {
 975         // There is already a class defined with the same name
 976         return false;
 977       }
 978     }
 979   }
 980 
 981   assert(Dictionary::entry_size() >= sizeof(SharedDictionaryEntry), "must be big enough");
 982   SharedDictionaryEntry* entry = (SharedDictionaryEntry*)new_entry(hash, klass);
 983   add_entry(index, entry);
 984 
 985   assert(entry->is_unregistered(), "sanity");
 986   assert(!entry->is_builtin(), "sanity");
 987   return true;
 988 }
 989 
 990 
 991 //-----------------
 992 // SharedDictionary
 993 //-----------------
 994 
 995 
 996 Klass* SharedDictionary::find_class_for_builtin_loader(const Symbol* name) const {
 997   SharedDictionaryEntry* entry = get_entry_for_builtin_loader(name);
 998   return entry != NULL ? entry->instance_klass() : (Klass*)NULL;
 999 }
1000 
1001 Klass* SharedDictionary::find_class_for_unregistered_loader(const Symbol* name,
1002                                                             int clsfile_size,
1003                                                             int clsfile_crc32) const {
1004 
1005   const SharedDictionaryEntry* entry = get_entry_for_unregistered_loader(name,
1006                                                                          clsfile_size,
1007                                                                          clsfile_crc32);
1008   return entry != NULL ? entry->instance_klass() : (Klass*)NULL;
1009 }
1010 
1011 void SharedDictionary::update_entry(Klass* klass, int id) {
1012   assert(DumpSharedSpaces, "supported only when dumping");
1013   Symbol* class_name = klass->name();
1014   unsigned int hash = compute_hash(class_name);
1015   int index = hash_to_index(hash);
1016 
1017   for (SharedDictionaryEntry* entry = bucket(index);
1018                               entry != NULL;
1019                               entry = entry->next()) {
1020     if (entry->hash() == hash && entry->literal() == klass) {
1021       entry->_id = id;
1022       return;
1023     }
1024   }
1025 
1026   ShouldNotReachHere();
1027 }
1028 
1029 SharedDictionaryEntry* SharedDictionary::get_entry_for_builtin_loader(const Symbol* class_name) const {
1030   assert(!DumpSharedSpaces, "supported only when at runtime");
1031   unsigned int hash = compute_hash(class_name);




 488       Dictionary* dictionary = loader_data->dictionary();
 489 
 490       unsigned int d_hash = dictionary->compute_hash(name);
 491 
 492       bool DoObjectLock = true;
 493       if (is_parallelCapable(class_loader)) {
 494         DoObjectLock = false;
 495       }
 496 
 497       // Make sure we are synchronized on the class loader before we proceed
 498       //
 499       // Note: currently, find_or_load_shared_class is called only from
 500       // JVM_FindLoadedClass and used for PlatformClassLoader and AppClassLoader,
 501       // which are parallel-capable loaders, so this lock is NOT taken.
 502       Handle lockObject = compute_loader_lock_object(class_loader, THREAD);
 503       check_loader_lock_contention(lockObject, THREAD);
 504       ObjectLocker ol(lockObject, THREAD, DoObjectLock);
 505 
 506       {
 507         MutexLocker mu(SystemDictionary_lock, THREAD);
 508         InstanceKlass* check = find_class(d_hash, name, dictionary);
 509         if (check != NULL) {
 510           return check;
 511         }
 512       }
 513 
 514       k = load_shared_class_for_builtin_loader(name, class_loader, THREAD);
 515       if (k != NULL) {
 516         define_instance_class(k, CHECK_NULL);
 517       }
 518     }
 519   }
 520   return k;
 521 }
 522 
 523 InstanceKlass* SystemDictionaryShared::load_shared_class_for_builtin_loader(
 524                  Symbol* class_name, Handle class_loader, TRAPS) {
 525   assert(UseSharedSpaces, "must be");
 526   assert(shared_dictionary() != NULL, "already checked");
 527   InstanceKlass* ik = shared_dictionary()->find_class_for_builtin_loader(class_name);
 528 
 529   if (ik != NULL) {

 530     if ((ik->is_shared_app_class() &&
 531          SystemDictionary::is_system_class_loader(class_loader()))  ||
 532         (ik->is_shared_platform_class() &&
 533          SystemDictionary::is_platform_class_loader(class_loader()))) {
 534       Handle protection_domain =
 535         SystemDictionaryShared::init_security_info(class_loader, ik, CHECK_NULL);
 536       return load_shared_class(ik, class_loader, protection_domain, THREAD);
 537     }
 538   }
 539 
 540   return NULL;
 541 }
 542 
 543 void SystemDictionaryShared::oops_do(OopClosure* f) {
 544   f->do_oop((oop*)&_shared_protection_domains);
 545   f->do_oop((oop*)&_shared_jar_urls);
 546   f->do_oop((oop*)&_shared_jar_manifests);
 547 }
 548 
 549 void SystemDictionaryShared::allocate_shared_protection_domain_array(int size, TRAPS) {


 576 // This function is called for loading only UNREGISTERED classes
 577 InstanceKlass* SystemDictionaryShared::lookup_from_stream(const Symbol* class_name,
 578                                                           Handle class_loader,
 579                                                           Handle protection_domain,
 580                                                           const ClassFileStream* cfs,
 581                                                           TRAPS) {
 582   if (shared_dictionary() == NULL) {
 583     return NULL;
 584   }
 585   if (class_name == NULL) {  // don't do this for anonymous classes
 586     return NULL;
 587   }
 588   if (class_loader.is_null() ||
 589       SystemDictionary::is_system_class_loader(class_loader()) ||
 590       SystemDictionary::is_platform_class_loader(class_loader())) {
 591     // Do nothing for the BUILTIN loaders.
 592     return NULL;
 593   }
 594 
 595   ClassLoaderData* loader_data = ClassLoaderData::class_loader_data(class_loader());
 596   InstanceKlass* k;
 597 
 598   { // UNREGISTERED loader
 599     if (!shared_dictionary()->class_exists_for_unregistered_loader(class_name)) {
 600       // No classes of this name for unregistered loaders.
 601       return NULL;
 602     }
 603 
 604     int clsfile_size  = cfs->length();
 605     int clsfile_crc32 = ClassLoader::crc32(0, (const char*)cfs->buffer(), cfs->length());
 606 
 607     k = shared_dictionary()->find_class_for_unregistered_loader(class_name,
 608                                                                 clsfile_size, clsfile_crc32);
 609   }
 610 
 611   if (k == NULL) { // not archived
 612     return NULL;
 613   }
 614 
 615   return acquire_class_for_current_thread(k, class_loader,
 616                                           protection_domain, THREAD);
 617 }
 618 
 619 InstanceKlass* SystemDictionaryShared::acquire_class_for_current_thread(
 620                    InstanceKlass *ik,
 621                    Handle class_loader,
 622                    Handle protection_domain,
 623                    TRAPS) {
 624   ClassLoaderData* loader_data = ClassLoaderData::class_loader_data(class_loader());
 625 
 626   {
 627     MutexLocker mu(SharedDictionary_lock, THREAD);
 628     if (ik->class_loader_data() != NULL) {
 629       //    ik is already loaded (by this loader or by a different loader)
 630       // or ik is being loaded by a different thread (by this loader or by a different loader)
 631       return NULL;
 632     }
 633 
 634     // No other thread has acquired this yet, so give it to *this thread*
 635     ik->set_class_loader_data(loader_data);


 654                                                    InstanceKlass* k,
 655                                                    TRAPS) {
 656   assert(DumpSharedSpaces, "only when dumping");
 657   assert(boot_loader_dictionary() != NULL, "must be");
 658 
 659   if (boot_loader_dictionary()->add_non_builtin_klass(name, loader_data, k)) {
 660     MutexLocker mu_r(Compile_lock, THREAD); // not really necessary, but add_to_hierarchy asserts this.
 661     add_to_hierarchy(k, CHECK_0);
 662     return true;
 663   }
 664   return false;
 665 }
 666 
 667 // This function is called to resolve the super/interfaces of shared classes for
 668 // non-built-in loaders. E.g., ChildClass in the below example
 669 // where "super:" (and optionally "interface:") have been specified.
 670 //
 671 // java/lang/Object id: 0
 672 // Interface   id: 2 super: 0 source: cust.jar
 673 // ChildClass  id: 4 super: 0 interfaces: 2 source: cust.jar
 674 InstanceKlass* SystemDictionaryShared::dump_time_resolve_super_or_fail(
 675     Symbol* child_name, Symbol* class_name, Handle class_loader,
 676     Handle protection_domain, bool is_superclass, TRAPS) {
 677 
 678   assert(DumpSharedSpaces, "only when dumping");
 679 
 680   ClassListParser* parser = ClassListParser::instance();
 681   if (parser == NULL) {
 682     // We're still loading the well-known classes, before the ClassListParser is created.
 683     return NULL;
 684   }
 685   if (child_name->equals(parser->current_class_name())) {
 686     // When this function is called, all the numbered super and interface types
 687     // must have already been loaded. Hence this function is never recursively called.
 688     if (is_superclass) {
 689       return parser->lookup_super_for_current_class(class_name);
 690     } else {
 691       return parser->lookup_interface_for_current_class(class_name);
 692     }
 693   } else {
 694     // The VM is not trying to resolve a super type of parser->current_class_name().
 695     // Instead, it's resolving an error class (because parser->current_class_name() has
 696     // failed parsing or verification). Don't do anything here.
 697     return NULL;
 698   }
 699 }
 700 
 701 struct SharedMiscInfo {
 702   InstanceKlass* _klass;
 703   int _clsfile_size;
 704   int _clsfile_crc32;
 705 };
 706 
 707 static GrowableArray<SharedMiscInfo>* misc_info_array = NULL;
 708 
 709 void SystemDictionaryShared::set_shared_class_misc_info(InstanceKlass* k, ClassFileStream* cfs) {
 710   assert(DumpSharedSpaces, "only when dumping");
 711   int clsfile_size  = cfs->length();
 712   int clsfile_crc32 = ClassLoader::crc32(0, (const char*)cfs->buffer(), cfs->length());
 713 
 714   if (misc_info_array == NULL) {
 715     misc_info_array = new (ResourceObj::C_HEAP, mtClass) GrowableArray<SharedMiscInfo>(20, /*c heap*/ true);
 716   }
 717 
 718   SharedMiscInfo misc_info;
 719   DEBUG_ONLY({
 720       for (int i=0; i<misc_info_array->length(); i++) {
 721         misc_info = misc_info_array->at(i);
 722         assert(misc_info._klass != k, "cannot call set_shared_class_misc_info twice for the same class");
 723       }
 724     });
 725 
 726   misc_info._klass = k;
 727   misc_info._clsfile_size = clsfile_size;
 728   misc_info._clsfile_crc32 = clsfile_crc32;
 729 
 730   misc_info_array->append(misc_info);
 731 }
 732 
 733 void SystemDictionaryShared::init_shared_dictionary_entry(InstanceKlass* k, DictionaryEntry* ent) {
 734   SharedDictionaryEntry* entry = (SharedDictionaryEntry*)ent;
 735   entry->_id = -1;
 736   entry->_clsfile_size = -1;
 737   entry->_clsfile_crc32 = -1;
 738   entry->_verifier_constraints = NULL;
 739   entry->_verifier_constraint_flags = NULL;
 740 
 741   if (misc_info_array != NULL) {
 742     for (int i=0; i<misc_info_array->length(); i++) {
 743       SharedMiscInfo misc_info = misc_info_array->at(i);
 744       if (misc_info._klass == k) {
 745         entry->_clsfile_size = misc_info._clsfile_size;
 746         entry->_clsfile_crc32 = misc_info._clsfile_crc32;
 747         misc_info_array->remove_at(i);
 748         return;
 749       }
 750     }
 751   }
 752 }
 753 
 754 bool SystemDictionaryShared::add_verification_constraint(InstanceKlass* k, Symbol* name,
 755          Symbol* from_name, bool from_field_is_protected, bool from_is_array, bool from_is_object) {
 756   assert(DumpSharedSpaces, "called at dump time only");
 757 
 758   // Skip anonymous classes, which are not archived as they are not in
 759   // dictionary (see assert_no_anonymoys_classes_in_dictionaries() in
 760   // VM_PopulateDumpSharedSpace::doit()).
 761   if (k->class_loader_data()->is_anonymous()) {
 762     return true; // anonymous classes are not archived, skip
 763   }
 764 
 765   SharedDictionaryEntry* entry = ((SharedDictionary*)(k->class_loader_data()->dictionary()))->find_entry_for(k);
 766   ResourceMark rm;
 767   // Lambda classes are not archived and will be regenerated at runtime.
 768   if (entry == NULL) {
 769     guarantee(strstr(k->name()->as_C_string(), "Lambda$") != NULL,
 770               "class should be in dictionary before being verified");
 771     return true;
 772   }
 773   entry->add_verification_constraint(name, from_name, from_field_is_protected,
 774                                      from_is_array, from_is_object);


 778     return false;
 779   } else {
 780     // For non-builtin class loaders, we cannot complete the verification check at dump time,
 781     // because at dump time we don't know how to resolve classes for such loaders.
 782     return true;
 783   }
 784 }
 785 
 786 void SystemDictionaryShared::finalize_verification_constraints() {
 787   boot_loader_dictionary()->finalize_verification_constraints();
 788 }
 789 
 790 void SystemDictionaryShared::check_verification_constraints(InstanceKlass* klass,
 791                                                              TRAPS) {
 792   assert(!DumpSharedSpaces && UseSharedSpaces, "called at run time with CDS enabled only");
 793   SharedDictionaryEntry* entry = shared_dictionary()->find_entry_for(klass);
 794   assert(entry != NULL, "call this only for shared classes");
 795   entry->check_verification_constraints(klass, THREAD);
 796 }
 797 
 798 SharedDictionaryEntry* SharedDictionary::find_entry_for(InstanceKlass* klass) {
 799   Symbol* class_name = klass->name();
 800   unsigned int hash = compute_hash(class_name);
 801   int index = hash_to_index(hash);
 802 
 803   for (SharedDictionaryEntry* entry = bucket(index);
 804                               entry != NULL;
 805                               entry = entry->next()) {
 806     if (entry->hash() == hash && entry->literal() == klass) {
 807       return entry;
 808     }
 809   }
 810 
 811   return NULL;
 812 }
 813 
 814 void SharedDictionary::finalize_verification_constraints() {
 815   int bytes = 0, count = 0;
 816   for (int index = 0; index < table_size(); index++) {
 817     for (SharedDictionaryEntry *probe = bucket(index);
 818                                 probe != NULL;


 952 bool SharedDictionary::add_non_builtin_klass(const Symbol* class_name,
 953                                              ClassLoaderData* loader_data,
 954                                              InstanceKlass* klass) {
 955 
 956   assert(DumpSharedSpaces, "supported only when dumping");
 957   assert(klass != NULL, "adding NULL klass");
 958   assert(klass->name() == class_name, "sanity check on name");
 959   assert(klass->shared_classpath_index() < 0,
 960          "the shared classpath index should not be set for shared class loaded by the custom loaders");
 961 
 962   // Add an entry for a non-builtin class.
 963   // For a shared class for custom class loaders, SystemDictionary::resolve_or_null will
 964   // not find this class, because is_builtin() is false.
 965   unsigned int hash = compute_hash(class_name);
 966   int index = hash_to_index(hash);
 967 
 968   for (SharedDictionaryEntry* entry = bucket(index);
 969                               entry != NULL;
 970                               entry = entry->next()) {
 971     if (entry->hash() == hash) {
 972       InstanceKlass* klass = entry->instance_klass();
 973       if (klass->name() == class_name && klass->class_loader_data() == loader_data) {
 974         // There is already a class defined with the same name
 975         return false;
 976       }
 977     }
 978   }
 979 
 980   assert(Dictionary::entry_size() >= sizeof(SharedDictionaryEntry), "must be big enough");
 981   SharedDictionaryEntry* entry = (SharedDictionaryEntry*)new_entry(hash, klass);
 982   add_entry(index, entry);
 983 
 984   assert(entry->is_unregistered(), "sanity");
 985   assert(!entry->is_builtin(), "sanity");
 986   return true;
 987 }
 988 
 989 
 990 //-----------------
 991 // SharedDictionary
 992 //-----------------
 993 
 994 
 995 InstanceKlass* SharedDictionary::find_class_for_builtin_loader(const Symbol* name) const {
 996   SharedDictionaryEntry* entry = get_entry_for_builtin_loader(name);
 997   return entry != NULL ? entry->instance_klass() : (InstanceKlass*)NULL;
 998 }
 999 
1000 InstanceKlass* SharedDictionary::find_class_for_unregistered_loader(const Symbol* name,
1001                                                             int clsfile_size,
1002                                                             int clsfile_crc32) const {
1003 
1004   const SharedDictionaryEntry* entry = get_entry_for_unregistered_loader(name,
1005                                                                          clsfile_size,
1006                                                                          clsfile_crc32);
1007   return entry != NULL ? entry->instance_klass() : NULL;
1008 }
1009 
1010 void SharedDictionary::update_entry(InstanceKlass* klass, int id) {
1011   assert(DumpSharedSpaces, "supported only when dumping");
1012   Symbol* class_name = klass->name();
1013   unsigned int hash = compute_hash(class_name);
1014   int index = hash_to_index(hash);
1015 
1016   for (SharedDictionaryEntry* entry = bucket(index);
1017                               entry != NULL;
1018                               entry = entry->next()) {
1019     if (entry->hash() == hash && entry->literal() == klass) {
1020       entry->_id = id;
1021       return;
1022     }
1023   }
1024 
1025   ShouldNotReachHere();
1026 }
1027 
1028 SharedDictionaryEntry* SharedDictionary::get_entry_for_builtin_loader(const Symbol* class_name) const {
1029   assert(!DumpSharedSpaces, "supported only when at runtime");
1030   unsigned int hash = compute_hash(class_name);


< prev index next >