437 // CDS code for dumping shared archive. 438 439 // Global object for holding classes that have been loaded. Since this 440 // is run at a safepoint just before exit, this is the entire set of classes. 441 static GrowableArray<Klass*>* _global_klass_objects; 442 443 static void collect_array_classes(Klass* k) { 444 _global_klass_objects->append_if_missing(k); 445 if (k->is_array_klass()) { 446 // Add in the array classes too 447 ArrayKlass* ak = ArrayKlass::cast(k); 448 Klass* h = ak->higher_dimension(); 449 if (h != NULL) { 450 h->array_klasses_do(collect_array_classes); 451 } 452 } 453 } 454 455 class CollectClassesClosure : public KlassClosure { 456 void do_klass(Klass* k) { 457 if (!UseAppCDS && !k->class_loader_data()->is_the_null_class_loader_data()) { 458 // AppCDS is not enabled. Let's omit non-boot classes. 459 return; 460 } 461 462 if (!(k->is_instance_klass() && InstanceKlass::cast(k)->is_in_error_state())) { 463 if (k->is_instance_klass() && InstanceKlass::cast(k)->signers() != NULL) { 464 // Mark any class with signers and don't add to the _global_klass_objects 465 k->set_has_signer_and_not_archived(); 466 } else { 467 _global_klass_objects->append_if_missing(k); 468 } 469 } 470 if (k->is_array_klass()) { 471 // Add in the array classes too 472 ArrayKlass* ak = ArrayKlass::cast(k); 473 Klass* h = ak->higher_dimension(); 474 if (h != NULL) { 475 h->array_klasses_do(collect_array_classes); 476 } 477 } 478 } 479 }; 480 481 static void remove_unshareable_in_classes() { 1309 1310 size_t buckets_bytes = SystemDictionary::count_bytes_for_buckets(); 1311 char* buckets_top = _ro_region.allocate(buckets_bytes, sizeof(intptr_t)); 1312 SystemDictionary::copy_buckets(buckets_top, _ro_region.top()); 1313 1314 size_t table_bytes = SystemDictionary::count_bytes_for_table(); 1315 char* table_top = _ro_region.allocate(table_bytes, sizeof(intptr_t)); 1316 SystemDictionary::copy_table(table_top, _ro_region.top()); 1317 1318 // Write the other data to the output array. 1319 WriteClosure wc(&_ro_region); 1320 MetaspaceShared::serialize(&wc); 1321 1322 char* newtop = _ro_region.top(); 1323 ArchiveCompactor::alloc_stats()->record_other_type(int(newtop - oldtop), true); 1324 return buckets_top; 1325 } 1326 1327 void VM_PopulateDumpSharedSpace::doit() { 1328 Thread* THREAD = VMThread::vm_thread(); 1329 1330 NOT_PRODUCT(SystemDictionary::verify();) 1331 // The following guarantee is meant to ensure that no loader constraints 1332 // exist yet, since the constraints table is not shared. This becomes 1333 // more important now that we don't re-initialize vtables/itables for 1334 // shared classes at runtime, where constraints were previously created. 1335 guarantee(SystemDictionary::constraints()->number_of_entries() == 0, 1336 "loader constraints are not saved"); 1337 guarantee(SystemDictionary::placeholders()->number_of_entries() == 0, 1338 "placeholders are not saved"); 1339 // Revisit and implement this if we prelink method handle call sites: 1340 guarantee(SystemDictionary::invoke_method_table() == NULL || 1341 SystemDictionary::invoke_method_table()->number_of_entries() == 0, 1342 "invoke method table is not saved"); 1343 1344 // At this point, many classes have been loaded. 1345 // Gather systemDictionary classes in a global array and do everything to 1346 // that so we don't have to walk the SystemDictionary again. 1347 _global_klass_objects = new GrowableArray<Klass*>(1000); 1348 CollectClassesClosure collect_classes; | 437 // CDS code for dumping shared archive. 438 439 // Global object for holding classes that have been loaded. Since this 440 // is run at a safepoint just before exit, this is the entire set of classes. 441 static GrowableArray<Klass*>* _global_klass_objects; 442 443 static void collect_array_classes(Klass* k) { 444 _global_klass_objects->append_if_missing(k); 445 if (k->is_array_klass()) { 446 // Add in the array classes too 447 ArrayKlass* ak = ArrayKlass::cast(k); 448 Klass* h = ak->higher_dimension(); 449 if (h != NULL) { 450 h->array_klasses_do(collect_array_classes); 451 } 452 } 453 } 454 455 class CollectClassesClosure : public KlassClosure { 456 void do_klass(Klass* k) { 457 if (!(k->is_instance_klass() && InstanceKlass::cast(k)->is_in_error_state())) { 458 if (k->is_instance_klass() && InstanceKlass::cast(k)->signers() != NULL) { 459 // Mark any class with signers and don't add to the _global_klass_objects 460 k->set_has_signer_and_not_archived(); 461 } else { 462 _global_klass_objects->append_if_missing(k); 463 } 464 } 465 if (k->is_array_klass()) { 466 // Add in the array classes too 467 ArrayKlass* ak = ArrayKlass::cast(k); 468 Klass* h = ak->higher_dimension(); 469 if (h != NULL) { 470 h->array_klasses_do(collect_array_classes); 471 } 472 } 473 } 474 }; 475 476 static void remove_unshareable_in_classes() { 1304 1305 size_t buckets_bytes = SystemDictionary::count_bytes_for_buckets(); 1306 char* buckets_top = _ro_region.allocate(buckets_bytes, sizeof(intptr_t)); 1307 SystemDictionary::copy_buckets(buckets_top, _ro_region.top()); 1308 1309 size_t table_bytes = SystemDictionary::count_bytes_for_table(); 1310 char* table_top = _ro_region.allocate(table_bytes, sizeof(intptr_t)); 1311 SystemDictionary::copy_table(table_top, _ro_region.top()); 1312 1313 // Write the other data to the output array. 1314 WriteClosure wc(&_ro_region); 1315 MetaspaceShared::serialize(&wc); 1316 1317 char* newtop = _ro_region.top(); 1318 ArchiveCompactor::alloc_stats()->record_other_type(int(newtop - oldtop), true); 1319 return buckets_top; 1320 } 1321 1322 void VM_PopulateDumpSharedSpace::doit() { 1323 Thread* THREAD = VMThread::vm_thread(); 1324 1325 FileMapInfo::check_nonempty_dir_in_shared_path_table(); 1326 1327 NOT_PRODUCT(SystemDictionary::verify();) 1328 // The following guarantee is meant to ensure that no loader constraints 1329 // exist yet, since the constraints table is not shared. This becomes 1330 // more important now that we don't re-initialize vtables/itables for 1331 // shared classes at runtime, where constraints were previously created. 1332 guarantee(SystemDictionary::constraints()->number_of_entries() == 0, 1333 "loader constraints are not saved"); 1334 guarantee(SystemDictionary::placeholders()->number_of_entries() == 0, 1335 "placeholders are not saved"); 1336 // Revisit and implement this if we prelink method handle call sites: 1337 guarantee(SystemDictionary::invoke_method_table() == NULL || 1338 SystemDictionary::invoke_method_table()->number_of_entries() == 0, 1339 "invoke method table is not saved"); 1340 1341 // At this point, many classes have been loaded. 1342 // Gather systemDictionary classes in a global array and do everything to 1343 // that so we don't have to walk the SystemDictionary again. 1344 _global_klass_objects = new GrowableArray<Klass*>(1000); 1345 CollectClassesClosure collect_classes; |