31
31
#include " classfile/classLoaderData.inline.hpp"
32
32
#include " classfile/javaClasses.inline.hpp"
33
33
#include " classfile/moduleEntry.hpp"
34
+ #include " classfile/systemDictionary.hpp"
34
35
#include " jni.h"
35
36
#include " logging/log.hpp"
37
+ #include " logging/logStream.hpp"
36
38
#include " memory/resourceArea.hpp"
37
39
#include " memory/universe.hpp"
38
40
#include " oops/oopHandle.inline.hpp"
@@ -386,20 +388,38 @@ typedef ResourceHashtable<
386
388
AnyObj::C_HEAP> ArchivedModuleEntries;
387
389
static ArchivedModuleEntries* _archive_modules_entries = NULL ;
388
390
391
+ #ifndef PRODUCT
392
+ static int _num_archived_module_entries = 0 ;
393
+ static int _num_inited_module_entries = 0 ;
394
+ #endif
395
+
389
396
ModuleEntry* ModuleEntry::allocate_archived_entry () const {
390
397
assert (is_named (), " unnamed packages/modules are not archived" );
391
398
ModuleEntry* archived_entry = (ModuleEntry*)ArchiveBuilder::rw_region_alloc (sizeof (ModuleEntry));
392
399
memcpy ((void *)archived_entry, (void *)this , sizeof (ModuleEntry));
400
+ archived_entry->_archived_module_index = -1 ;
393
401
394
402
if (_archive_modules_entries == NULL ) {
395
403
_archive_modules_entries = new (mtClass)ArchivedModuleEntries ();
396
404
}
397
405
assert (_archive_modules_entries->get (this ) == NULL , " Each ModuleEntry must not be shared across ModuleEntryTables" );
398
406
_archive_modules_entries->put (this , archived_entry);
407
+ DEBUG_ONLY (_num_archived_module_entries++);
399
408
409
+ if (log_is_enabled (Info, cds, module)) {
410
+ ResourceMark rm;
411
+ LogStream ls (Log (cds, module)::info ());
412
+ ls.print (" Stored in archive: " );
413
+ archived_entry->print (&ls);
414
+ }
400
415
return archived_entry;
401
416
}
402
417
418
+ bool ModuleEntry::has_been_archived () {
419
+ assert (!ArchiveBuilder::current ()->is_in_buffer_space (this ), " must be called on original ModuleEntry" );
420
+ return _archive_modules_entries->contains (this );
421
+ }
422
+
403
423
ModuleEntry* ModuleEntry::get_archived_entry (ModuleEntry* orig_entry) {
404
424
ModuleEntry** ptr = _archive_modules_entries->get (orig_entry);
405
425
assert (ptr != NULL && *ptr != NULL , " must have been allocated" );
@@ -467,27 +487,39 @@ void ModuleEntry::init_as_archived_entry() {
467
487
ArchivePtrMarker::mark_pointer ((address*)&_location);
468
488
}
469
489
470
- void ModuleEntry::init_archived_oops ( ) {
490
+ void ModuleEntry::update_oops_in_archived_module ( int root_oop_index ) {
471
491
assert (DumpSharedSpaces, " static dump only" );
472
- oop module_obj = module ();
473
- if (module_obj != NULL ) {
474
- oop m = HeapShared::find_archived_heap_object (module_obj);
475
- assert (m != NULL , " sanity" );
476
- _archived_module_index = HeapShared::append_root (m);
477
- }
492
+ assert (_archived_module_index == -1 , " must be set exactly once" );
493
+ assert (root_oop_index >= 0 , " sanity" );
494
+
495
+ _archived_module_index = root_oop_index;
496
+
478
497
assert (shared_protection_domain () == NULL , " never set during -Xshare:dump" );
479
498
// Clear handles and restore at run time. Handles cannot be archived.
480
499
OopHandle null_handle;
481
500
_module = null_handle;
501
+
502
+ // For verify_archived_module_entries()
503
+ DEBUG_ONLY (_num_inited_module_entries++);
482
504
}
483
505
506
+ #ifndef PRODUCT
507
+ void ModuleEntry::verify_archived_module_entries () {
508
+ assert (_num_archived_module_entries == _num_inited_module_entries,
509
+ " %d ModuleEntries have been archived but %d of them have been properly initialized with archived java.lang.Module objects" ,
510
+ _num_archived_module_entries, _num_inited_module_entries);
511
+ }
512
+ #endif // PRODUCT
513
+
484
514
void ModuleEntry::load_from_archive (ClassLoaderData* loader_data) {
515
+ assert (UseSharedSpaces, " runtime only" );
485
516
set_loader_data (loader_data);
486
517
_reads = restore_growable_array ((Array<ModuleEntry*>*)_reads);
487
518
JFR_ONLY (INIT_ID (this );)
488
519
}
489
520
490
521
void ModuleEntry::restore_archived_oops (ClassLoaderData* loader_data) {
522
+ assert (UseSharedSpaces, " runtime only" );
491
523
Handle module_handle (Thread::current (), HeapShared::get_root (_archived_module_index, /* clear=*/ true ));
492
524
assert (module_handle.not_null (), " huh" );
493
525
set_module (loader_data->add_handle (module_handle));
@@ -496,12 +528,19 @@ void ModuleEntry::restore_archived_oops(ClassLoaderData* loader_data) {
496
528
// because it may be affected by archive relocation.
497
529
java_lang_Module::set_module_entry (module_handle (), this );
498
530
499
- if (loader_data->class_loader () != NULL ) {
500
- java_lang_Module::set_loader (module_handle (), loader_data->class_loader ());
531
+ assert (java_lang_Module::loader (module_handle ()) == loader_data->class_loader (),
532
+ " must be set in dump time" );
533
+
534
+ if (log_is_enabled (Info, cds, module)) {
535
+ ResourceMark rm;
536
+ LogStream ls (Log (cds, module)::info ());
537
+ ls.print (" Restored from archive: " );
538
+ print (&ls);
501
539
}
502
540
}
503
541
504
542
void ModuleEntry::clear_archived_oops () {
543
+ assert (UseSharedSpaces, " runtime only" );
505
544
HeapShared::clear_root (_archived_module_index);
506
545
}
507
546
@@ -544,14 +583,6 @@ void ModuleEntryTable::init_archived_entries(Array<ModuleEntry*>* archived_modul
544
583
}
545
584
}
546
585
547
- void ModuleEntryTable::init_archived_oops (Array<ModuleEntry*>* archived_modules) {
548
- assert (DumpSharedSpaces, " dump time only" );
549
- for (int i = 0 ; i < archived_modules->length (); i++) {
550
- ModuleEntry* archived_entry = archived_modules->at (i);
551
- archived_entry->init_archived_oops ();
552
- }
553
- }
554
-
555
586
void ModuleEntryTable::load_archived_entries (ClassLoaderData* loader_data,
556
587
Array<ModuleEntry*>* archived_modules) {
557
588
assert (UseSharedSpaces, " runtime only" );
0 commit comments