< prev index next >

src/hotspot/share/classfile/systemDictionaryShared.cpp

Print this page

  36 #include "classfile/systemDictionaryShared.hpp"
  37 #include "classfile/verificationType.hpp"
  38 #include "classfile/vmSymbols.hpp"
  39 #include "jfr/jfrEvents.hpp"
  40 #include "logging/log.hpp"
  41 #include "memory/allocation.hpp"
  42 #include "memory/archiveUtils.hpp"
  43 #include "memory/dynamicArchive.hpp"
  44 #include "memory/filemap.hpp"
  45 #include "memory/heapShared.hpp"
  46 #include "memory/metadataFactory.hpp"
  47 #include "memory/metaspaceClosure.hpp"
  48 #include "memory/oopFactory.hpp"
  49 #include "memory/resourceArea.hpp"
  50 #include "memory/universe.hpp"
  51 #include "oops/instanceKlass.hpp"
  52 #include "oops/klass.inline.hpp"
  53 #include "oops/objArrayOop.inline.hpp"
  54 #include "oops/oop.inline.hpp"
  55 #include "oops/typeArrayOop.inline.hpp"

  56 #include "runtime/handles.inline.hpp"
  57 #include "runtime/java.hpp"
  58 #include "runtime/javaCalls.hpp"
  59 #include "runtime/mutexLocker.hpp"
  60 #include "utilities/hashtable.inline.hpp"
  61 #include "utilities/resourceHash.hpp"
  62 #include "utilities/stringUtils.hpp"
  63 
  64 
  65 OopHandle SystemDictionaryShared::_shared_protection_domains;
  66 OopHandle SystemDictionaryShared::_shared_jar_urls;
  67 OopHandle SystemDictionaryShared::_shared_jar_manifests;
  68 DEBUG_ONLY(bool SystemDictionaryShared::_no_class_loading_should_happen = false;)
  69 bool SystemDictionaryShared::_dump_in_progress = false;
  70 
  71 class DumpTimeSharedClassInfo: public CHeapObj<mtClass> {
  72   bool                         _excluded;

  73 public:
  74   struct DTLoaderConstraint {
  75     Symbol* _name;
  76     char _loader_type1;
  77     char _loader_type2;
  78     DTLoaderConstraint(Symbol* name, char l1, char l2) : _name(name), _loader_type1(l1), _loader_type2(l2) {
  79       _name->increment_refcount();
  80     }
  81     DTLoaderConstraint() : _name(NULL), _loader_type1('0'), _loader_type2('0') {}
  82     bool equals(const DTLoaderConstraint& t) {
  83       return t._name == _name &&
  84              ((t._loader_type1 == _loader_type1 && t._loader_type2 == _loader_type2) ||
  85               (t._loader_type2 == _loader_type1 && t._loader_type1 == _loader_type2));
  86     }
  87   };
  88 
  89   struct DTVerifierConstraint {
  90     Symbol* _name;
  91     Symbol* _from_name;
  92     DTVerifierConstraint() : _name(NULL), _from_name(NULL) {}

  97   };
  98 
  99   InstanceKlass*               _klass;
 100   bool                         _failed_verification;
 101   bool                         _is_archived_lambda_proxy;
 102   int                          _id;
 103   int                          _clsfile_size;
 104   int                          _clsfile_crc32;
 105   GrowableArray<DTVerifierConstraint>* _verifier_constraints;
 106   GrowableArray<char>*                 _verifier_constraint_flags;
 107   GrowableArray<DTLoaderConstraint>* _loader_constraints;
 108 
 109   DumpTimeSharedClassInfo() {
 110     _klass = NULL;
 111     _failed_verification = false;
 112     _is_archived_lambda_proxy = false;
 113     _id = -1;
 114     _clsfile_size = -1;
 115     _clsfile_crc32 = -1;
 116     _excluded = false;

 117     _verifier_constraints = NULL;
 118     _verifier_constraint_flags = NULL;
 119     _loader_constraints = NULL;
 120   }
 121 
 122   void add_verification_constraint(InstanceKlass* k, Symbol* name,
 123          Symbol* from_name, bool from_field_is_protected, bool from_is_array, bool from_is_object);
 124   void record_linking_constraint(Symbol* name, Handle loader1, Handle loader2);
 125 
 126   bool is_builtin() {
 127     return SystemDictionaryShared::is_builtin(_klass);
 128   }
 129 
 130   int num_verifier_constraints() {
 131     if (_verifier_constraint_flags != NULL) {
 132       return _verifier_constraint_flags->length();
 133     } else {
 134       return 0;
 135     }
 136   }

 152         it->push(&cons->_from_name);
 153       }
 154     }
 155     if (_loader_constraints != NULL) {
 156       for (int i = 0; i < _loader_constraints->length(); i++) {
 157         DTLoaderConstraint* lc = _loader_constraints->adr_at(i);
 158         it->push(&lc->_name);
 159       }
 160     }
 161   }
 162 
 163   void set_excluded() {
 164     _excluded = true;
 165   }
 166 
 167   bool is_excluded() {
 168     // _klass may become NULL due to DynamicArchiveBuilder::set_to_null
 169     return _excluded || _failed_verification || _klass == NULL;
 170   }
 171 




 172   void set_failed_verification() {
 173     _failed_verification = true;
 174   }
 175 
 176   bool failed_verification() {
 177     return _failed_verification;
 178   }
 179 };
 180 
 181 inline unsigned DumpTimeSharedClassTable_hash(InstanceKlass* const& k) {
 182   if (DumpSharedSpaces) {
 183     // Deterministic archive contents
 184     uintx delta = k->name() - MetaspaceShared::symbol_rs_base();
 185     return primitive_hash<uintx>(delta);
 186   } else {
 187     // Deterministic archive is not possible because classes can be loaded
 188     // in multiple threads.
 189     return primitive_hash<InstanceKlass*>(k);
 190   }
 191 }

1255     }
1256     k = k->java_super();
1257   }
1258   return false;
1259 }
1260 
1261 bool SystemDictionaryShared::is_registered_lambda_proxy_class(InstanceKlass* ik) {
1262   DumpTimeSharedClassInfo* info = _dumptime_table->get(ik);
1263   return (info != NULL) ? info->_is_archived_lambda_proxy : false;
1264 }
1265 
1266 bool SystemDictionaryShared::is_hidden_lambda_proxy(InstanceKlass* ik) {
1267   assert(ik->is_shared(), "applicable to only a shared class");
1268   if (ik->is_hidden()) {
1269     return true;
1270   } else {
1271     return false;
1272   }
1273 }
1274 





1275 void SystemDictionaryShared::warn_excluded(InstanceKlass* k, const char* reason) {
1276   ResourceMark rm;
1277   log_warning(cds)("Skipping %s: %s", k->name()->as_C_string(), reason);
1278 }
1279 
1280 bool SystemDictionaryShared::should_be_excluded(InstanceKlass* k) {
1281 
1282   if (k->is_unsafe_anonymous()) {
1283     warn_excluded(k, "Unsafe anonymous class");
1284     return true; // unsafe anonymous classes are not archived, skip
1285   }
1286 
1287   if (k->is_in_error_state()) {
1288     warn_excluded(k, "In error state");
1289     return true;
1290   }
1291   if (k->has_been_redefined()) {
1292     warn_excluded(k, "Has been redefined");
1293     return true;
1294   }

2123       _lambda_proxy_class_dictionary.print_table_statistics(st, "Lambda Shared Dictionary");
2124     }
2125   }
2126 }
2127 
2128 bool SystemDictionaryShared::empty_dumptime_table() {
2129   if (_dumptime_table == NULL) {
2130     return true;
2131   }
2132   _dumptime_table->update_counts();
2133   if (_dumptime_table->count_of(true) == 0 && _dumptime_table->count_of(false) == 0){
2134     return true;
2135   }
2136   return false;
2137 }
2138 
2139 #if INCLUDE_CDS_JAVA_HEAP
2140 
2141 class ArchivedMirrorPatcher {
2142   static void update(Klass* k) {
2143     if (k->has_raw_archived_mirror()) {
2144       oop m = HeapShared::materialize_archived_object(k->archived_java_mirror_raw_narrow());
2145       if (m != NULL) {
2146         java_lang_Class::update_archived_mirror_native_pointers(m);
2147       }
2148     }
2149   }
2150 
2151 public:
2152   static void update_array_klasses(Klass* ak) {
2153     while (ak != NULL) {
2154       update(ak);
2155       ak = ArrayKlass::cast(ak)->higher_dimension();
2156     }
2157   }
2158 
2159   void do_value(const RunTimeSharedClassInfo* info) {
2160     InstanceKlass* ik = info->_klass;
2161     update(ik);
2162     update_array_klasses(ik->array_klasses());
2163   }
2164 };

  36 #include "classfile/systemDictionaryShared.hpp"
  37 #include "classfile/verificationType.hpp"
  38 #include "classfile/vmSymbols.hpp"
  39 #include "jfr/jfrEvents.hpp"
  40 #include "logging/log.hpp"
  41 #include "memory/allocation.hpp"
  42 #include "memory/archiveUtils.hpp"
  43 #include "memory/dynamicArchive.hpp"
  44 #include "memory/filemap.hpp"
  45 #include "memory/heapShared.hpp"
  46 #include "memory/metadataFactory.hpp"
  47 #include "memory/metaspaceClosure.hpp"
  48 #include "memory/oopFactory.hpp"
  49 #include "memory/resourceArea.hpp"
  50 #include "memory/universe.hpp"
  51 #include "oops/instanceKlass.hpp"
  52 #include "oops/klass.inline.hpp"
  53 #include "oops/objArrayOop.inline.hpp"
  54 #include "oops/oop.inline.hpp"
  55 #include "oops/typeArrayOop.inline.hpp"
  56 #include "prims/jvmtiExport.hpp"
  57 #include "runtime/handles.inline.hpp"
  58 #include "runtime/java.hpp"
  59 #include "runtime/javaCalls.hpp"
  60 #include "runtime/mutexLocker.hpp"
  61 #include "utilities/hashtable.inline.hpp"
  62 #include "utilities/resourceHash.hpp"
  63 #include "utilities/stringUtils.hpp"
  64 
  65 
  66 OopHandle SystemDictionaryShared::_shared_protection_domains;
  67 OopHandle SystemDictionaryShared::_shared_jar_urls;
  68 OopHandle SystemDictionaryShared::_shared_jar_manifests;
  69 DEBUG_ONLY(bool SystemDictionaryShared::_no_class_loading_should_happen = false;)
  70 bool SystemDictionaryShared::_dump_in_progress = false;
  71 
  72 class DumpTimeSharedClassInfo: public CHeapObj<mtClass> {
  73   bool                         _excluded;
  74   bool                         _is_early_klass;
  75 public:
  76   struct DTLoaderConstraint {
  77     Symbol* _name;
  78     char _loader_type1;
  79     char _loader_type2;
  80     DTLoaderConstraint(Symbol* name, char l1, char l2) : _name(name), _loader_type1(l1), _loader_type2(l2) {
  81       _name->increment_refcount();
  82     }
  83     DTLoaderConstraint() : _name(NULL), _loader_type1('0'), _loader_type2('0') {}
  84     bool equals(const DTLoaderConstraint& t) {
  85       return t._name == _name &&
  86              ((t._loader_type1 == _loader_type1 && t._loader_type2 == _loader_type2) ||
  87               (t._loader_type2 == _loader_type1 && t._loader_type1 == _loader_type2));
  88     }
  89   };
  90 
  91   struct DTVerifierConstraint {
  92     Symbol* _name;
  93     Symbol* _from_name;
  94     DTVerifierConstraint() : _name(NULL), _from_name(NULL) {}

  99   };
 100 
 101   InstanceKlass*               _klass;
 102   bool                         _failed_verification;
 103   bool                         _is_archived_lambda_proxy;
 104   int                          _id;
 105   int                          _clsfile_size;
 106   int                          _clsfile_crc32;
 107   GrowableArray<DTVerifierConstraint>* _verifier_constraints;
 108   GrowableArray<char>*                 _verifier_constraint_flags;
 109   GrowableArray<DTLoaderConstraint>* _loader_constraints;
 110 
 111   DumpTimeSharedClassInfo() {
 112     _klass = NULL;
 113     _failed_verification = false;
 114     _is_archived_lambda_proxy = false;
 115     _id = -1;
 116     _clsfile_size = -1;
 117     _clsfile_crc32 = -1;
 118     _excluded = false;
 119     _is_early_klass = JvmtiExport::is_early_phase();
 120     _verifier_constraints = NULL;
 121     _verifier_constraint_flags = NULL;
 122     _loader_constraints = NULL;
 123   }
 124 
 125   void add_verification_constraint(InstanceKlass* k, Symbol* name,
 126          Symbol* from_name, bool from_field_is_protected, bool from_is_array, bool from_is_object);
 127   void record_linking_constraint(Symbol* name, Handle loader1, Handle loader2);
 128 
 129   bool is_builtin() {
 130     return SystemDictionaryShared::is_builtin(_klass);
 131   }
 132 
 133   int num_verifier_constraints() {
 134     if (_verifier_constraint_flags != NULL) {
 135       return _verifier_constraint_flags->length();
 136     } else {
 137       return 0;
 138     }
 139   }

 155         it->push(&cons->_from_name);
 156       }
 157     }
 158     if (_loader_constraints != NULL) {
 159       for (int i = 0; i < _loader_constraints->length(); i++) {
 160         DTLoaderConstraint* lc = _loader_constraints->adr_at(i);
 161         it->push(&lc->_name);
 162       }
 163     }
 164   }
 165 
 166   void set_excluded() {
 167     _excluded = true;
 168   }
 169 
 170   bool is_excluded() {
 171     // _klass may become NULL due to DynamicArchiveBuilder::set_to_null
 172     return _excluded || _failed_verification || _klass == NULL;
 173   }
 174 
 175   // Was this class loaded while JvmtiExport::is_early_phase()==true
 176   bool is_early_klass() {
 177     return _is_early_klass;
 178   }
 179   void set_failed_verification() {
 180     _failed_verification = true;
 181   }
 182 
 183   bool failed_verification() {
 184     return _failed_verification;
 185   }
 186 };
 187 
 188 inline unsigned DumpTimeSharedClassTable_hash(InstanceKlass* const& k) {
 189   if (DumpSharedSpaces) {
 190     // Deterministic archive contents
 191     uintx delta = k->name() - MetaspaceShared::symbol_rs_base();
 192     return primitive_hash<uintx>(delta);
 193   } else {
 194     // Deterministic archive is not possible because classes can be loaded
 195     // in multiple threads.
 196     return primitive_hash<InstanceKlass*>(k);
 197   }
 198 }

1262     }
1263     k = k->java_super();
1264   }
1265   return false;
1266 }
1267 
1268 bool SystemDictionaryShared::is_registered_lambda_proxy_class(InstanceKlass* ik) {
1269   DumpTimeSharedClassInfo* info = _dumptime_table->get(ik);
1270   return (info != NULL) ? info->_is_archived_lambda_proxy : false;
1271 }
1272 
1273 bool SystemDictionaryShared::is_hidden_lambda_proxy(InstanceKlass* ik) {
1274   assert(ik->is_shared(), "applicable to only a shared class");
1275   if (ik->is_hidden()) {
1276     return true;
1277   } else {
1278     return false;
1279   }
1280 }
1281 
1282 bool SystemDictionaryShared::is_early_klass(InstanceKlass* ik) {
1283   DumpTimeSharedClassInfo* info = _dumptime_table->get(ik);
1284   return (info != NULL) ? info->is_early_klass() : false;
1285 }
1286 
1287 void SystemDictionaryShared::warn_excluded(InstanceKlass* k, const char* reason) {
1288   ResourceMark rm;
1289   log_warning(cds)("Skipping %s: %s", k->name()->as_C_string(), reason);
1290 }
1291 
1292 bool SystemDictionaryShared::should_be_excluded(InstanceKlass* k) {
1293 
1294   if (k->is_unsafe_anonymous()) {
1295     warn_excluded(k, "Unsafe anonymous class");
1296     return true; // unsafe anonymous classes are not archived, skip
1297   }
1298 
1299   if (k->is_in_error_state()) {
1300     warn_excluded(k, "In error state");
1301     return true;
1302   }
1303   if (k->has_been_redefined()) {
1304     warn_excluded(k, "Has been redefined");
1305     return true;
1306   }

2135       _lambda_proxy_class_dictionary.print_table_statistics(st, "Lambda Shared Dictionary");
2136     }
2137   }
2138 }
2139 
2140 bool SystemDictionaryShared::empty_dumptime_table() {
2141   if (_dumptime_table == NULL) {
2142     return true;
2143   }
2144   _dumptime_table->update_counts();
2145   if (_dumptime_table->count_of(true) == 0 && _dumptime_table->count_of(false) == 0){
2146     return true;
2147   }
2148   return false;
2149 }
2150 
2151 #if INCLUDE_CDS_JAVA_HEAP
2152 
2153 class ArchivedMirrorPatcher {
2154   static void update(Klass* k) {
2155     if (k->has_archived_mirror_index()) {
2156       oop m = k->archived_java_mirror();
2157       if (m != NULL) {
2158         java_lang_Class::update_archived_mirror_native_pointers(m);
2159       }
2160     }
2161   }
2162 
2163 public:
2164   static void update_array_klasses(Klass* ak) {
2165     while (ak != NULL) {
2166       update(ak);
2167       ak = ArrayKlass::cast(ak)->higher_dimension();
2168     }
2169   }
2170 
2171   void do_value(const RunTimeSharedClassInfo* info) {
2172     InstanceKlass* ik = info->_klass;
2173     update(ik);
2174     update_array_klasses(ik->array_klasses());
2175   }
2176 };
< prev index next >