< prev index next >

src/hotspot/share/classfile/systemDictionaryShared.cpp

Print this page


  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "classfile/classFileStream.hpp"
  27 #include "classfile/classListParser.hpp"
  28 #include "classfile/classLoader.hpp"
  29 #include "classfile/classLoaderData.inline.hpp"

  30 #include "classfile/classLoaderExt.hpp"
  31 #include "classfile/dictionary.hpp"
  32 #include "classfile/javaClasses.hpp"
  33 #include "classfile/symbolTable.hpp"
  34 #include "classfile/systemDictionary.hpp"
  35 #include "classfile/systemDictionaryShared.hpp"
  36 #include "classfile/verificationType.hpp"
  37 #include "classfile/vmSymbols.hpp"
  38 #include "logging/log.hpp"
  39 #include "memory/allocation.hpp"
  40 #include "memory/filemap.hpp"
  41 #include "memory/metadataFactory.hpp"
  42 #include "memory/metaspaceClosure.hpp"
  43 #include "memory/oopFactory.hpp"
  44 #include "memory/resourceArea.hpp"
  45 #include "oops/instanceKlass.hpp"
  46 #include "oops/klass.inline.hpp"
  47 #include "oops/objArrayOop.inline.hpp"
  48 #include "oops/oop.inline.hpp"
  49 #include "oops/typeArrayOop.inline.hpp"


 765   ResourceMark rm;
 766   // Lambda classes are not archived and will be regenerated at runtime.
 767   if (entry == NULL) {
 768     guarantee(strstr(k->name()->as_C_string(), "Lambda$") != NULL,
 769               "class should be in dictionary before being verified");
 770     return true;
 771   }
 772   entry->add_verification_constraint(name, from_name, from_field_is_protected,
 773                                      from_is_array, from_is_object);
 774   if (entry->is_builtin()) {
 775     // For builtin class loaders, we can try to complete the verification check at dump time,
 776     // because we can resolve all the constraint classes.
 777     return false;
 778   } else {
 779     // For non-builtin class loaders, we cannot complete the verification check at dump time,
 780     // because at dump time we don't know how to resolve classes for such loaders.
 781     return true;
 782   }
 783 }
 784 







 785 void SystemDictionaryShared::finalize_verification_constraints() {
 786   boot_loader_dictionary()->finalize_verification_constraints();

 787 }
 788 
 789 void SystemDictionaryShared::check_verification_constraints(InstanceKlass* klass,
 790                                                              TRAPS) {
 791   assert(!DumpSharedSpaces && UseSharedSpaces, "called at run time with CDS enabled only");
 792   SharedDictionaryEntry* entry = shared_dictionary()->find_entry_for(klass);
 793   assert(entry != NULL, "call this only for shared classes");
 794   entry->check_verification_constraints(klass, THREAD);
 795 }
 796 
 797 SharedDictionaryEntry* SharedDictionary::find_entry_for(InstanceKlass* klass) {
 798   Symbol* class_name = klass->name();
 799   unsigned int hash = compute_hash(class_name);
 800   int index = hash_to_index(hash);
 801 
 802   for (SharedDictionaryEntry* entry = bucket(index);
 803                               entry != NULL;
 804                               entry = entry->next()) {
 805     if (entry->hash() == hash && entry->literal() == klass) {
 806       return entry;
 807     }
 808   }
 809 
 810   return NULL;
 811 }
 812 
 813 void SharedDictionary::finalize_verification_constraints() {
 814   int bytes = 0, count = 0;
 815   for (int index = 0; index < table_size(); index++) {
 816     for (SharedDictionaryEntry *probe = bucket(index);
 817                                 probe != NULL;
 818                                probe = probe->next()) {
 819       int n = probe->finalize_verification_constraints();
 820       if (n > 0) {
 821         bytes += n;
 822         count ++;
 823       }
 824     }
 825   }
 826   if (log_is_enabled(Info, cds, verification)) {
 827     double avg = 0;
 828     if (count > 0) {
 829       avg = double(bytes) / double(count);
 830     }
 831     log_info(cds, verification)("Recorded verification constraints for %d classes = %d bytes (avg = %.2f bytes) ", count, bytes, avg);
 832   }
 833 }
 834 
 835 void SharedDictionaryEntry::add_verification_constraint(Symbol* name,
 836          Symbol* from_name, bool from_field_is_protected, bool from_is_array, bool from_is_object) {
 837   if (_verifier_constraints == NULL) {
 838     _verifier_constraints = new(ResourceObj::C_HEAP, mtClass) GrowableArray<Symbol*>(8, true, mtClass);
 839   }
 840   if (_verifier_constraint_flags == NULL) {
 841     _verifier_constraint_flags = new(ResourceObj::C_HEAP, mtClass) GrowableArray<char>(4, true, mtClass);
 842   }
 843   GrowableArray<Symbol*>* vc_array = (GrowableArray<Symbol*>*)_verifier_constraints;
 844   for (int i=0; i<vc_array->length(); i+= 2) {
 845     if (name      == vc_array->at(i) &&
 846         from_name == vc_array->at(i+1)) {
 847       return;
 848     }
 849   }
 850   vc_array->append(name);
 851   vc_array->append(from_name);
 852 




  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "classfile/classFileStream.hpp"
  27 #include "classfile/classListParser.hpp"
  28 #include "classfile/classLoader.hpp"
  29 #include "classfile/classLoaderData.inline.hpp"
  30 #include "classfile/classLoaderDataGraph.hpp"
  31 #include "classfile/classLoaderExt.hpp"
  32 #include "classfile/dictionary.hpp"
  33 #include "classfile/javaClasses.hpp"
  34 #include "classfile/symbolTable.hpp"
  35 #include "classfile/systemDictionary.hpp"
  36 #include "classfile/systemDictionaryShared.hpp"
  37 #include "classfile/verificationType.hpp"
  38 #include "classfile/vmSymbols.hpp"
  39 #include "logging/log.hpp"
  40 #include "memory/allocation.hpp"
  41 #include "memory/filemap.hpp"
  42 #include "memory/metadataFactory.hpp"
  43 #include "memory/metaspaceClosure.hpp"
  44 #include "memory/oopFactory.hpp"
  45 #include "memory/resourceArea.hpp"
  46 #include "oops/instanceKlass.hpp"
  47 #include "oops/klass.inline.hpp"
  48 #include "oops/objArrayOop.inline.hpp"
  49 #include "oops/oop.inline.hpp"
  50 #include "oops/typeArrayOop.inline.hpp"


 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);
 775   if (entry->is_builtin()) {
 776     // For builtin class loaders, we can try to complete the verification check at dump time,
 777     // because we can resolve all the constraint classes.
 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_for(InstanceKlass* k) {
 787   if (!k->is_unsafe_anonymous()) {
 788     SharedDictionaryEntry* entry = ((SharedDictionary*)(k->class_loader_data()->dictionary()))->find_entry_for(k);
 789     entry->finalize_verification_constraints();
 790   }
 791 }
 792 
 793 void SystemDictionaryShared::finalize_verification_constraints() {
 794   MutexLocker mcld(ClassLoaderDataGraph_lock);
 795   ClassLoaderDataGraph::dictionary_classes_do(finalize_verification_constraints_for);
 796 }
 797 
 798 void SystemDictionaryShared::check_verification_constraints(InstanceKlass* klass,
 799                                                              TRAPS) {
 800   assert(!DumpSharedSpaces && UseSharedSpaces, "called at run time with CDS enabled only");
 801   SharedDictionaryEntry* entry = shared_dictionary()->find_entry_for(klass);
 802   assert(entry != NULL, "call this only for shared classes");
 803   entry->check_verification_constraints(klass, THREAD);
 804 }
 805 
 806 SharedDictionaryEntry* SharedDictionary::find_entry_for(InstanceKlass* klass) {
 807   Symbol* class_name = klass->name();
 808   unsigned int hash = compute_hash(class_name);
 809   int index = hash_to_index(hash);
 810 
 811   for (SharedDictionaryEntry* entry = bucket(index);
 812                               entry != NULL;
 813                               entry = entry->next()) {
 814     if (entry->hash() == hash && entry->literal() == klass) {
 815       return entry;
 816     }
 817   }
 818 
 819   return NULL;






















 820 }
 821 
 822 void SharedDictionaryEntry::add_verification_constraint(Symbol* name,
 823          Symbol* from_name, bool from_field_is_protected, bool from_is_array, bool from_is_object) {
 824   if (_verifier_constraints == NULL) {
 825     _verifier_constraints = new(ResourceObj::C_HEAP, mtClass) GrowableArray<Symbol*>(8, true, mtClass);
 826   }
 827   if (_verifier_constraint_flags == NULL) {
 828     _verifier_constraint_flags = new(ResourceObj::C_HEAP, mtClass) GrowableArray<char>(4, true, mtClass);
 829   }
 830   GrowableArray<Symbol*>* vc_array = (GrowableArray<Symbol*>*)_verifier_constraints;
 831   for (int i=0; i<vc_array->length(); i+= 2) {
 832     if (name      == vc_array->at(i) &&
 833         from_name == vc_array->at(i+1)) {
 834       return;
 835     }
 836   }
 837   vc_array->append(name);
 838   vc_array->append(from_name);
 839 


< prev index next >