@@ -541,132 +541,103 @@ void Modules::verify_archived_modules() {
541
541
ModuleEntry::verify_archived_module_entries ();
542
542
}
543
543
544
- char * Modules::_archived_main_module_name = nullptr ;
545
- char * Modules::_archived_addmods_names = nullptr ;
546
- char * Modules::_archived_native_access_flags = nullptr ;
547
-
548
- void Modules::dump_main_module_name () {
549
- const char * module_name = Arguments::get_property (" jdk.module.main" );
550
- if (module_name != nullptr ) {
551
- _archived_main_module_name = ArchiveBuilder::current ()->ro_strdup (module_name);
552
- }
553
- }
554
-
555
- void Modules::check_archived_flag_consistency (char * archived_flag, const char * runtime_flag, const char * property) {
556
- log_info (cds)(" %s %s" , property,
557
- archived_flag != nullptr ? archived_flag : " (null)" );
558
- bool disable = false ;
559
- if (runtime_flag == nullptr ) {
560
- if (archived_flag != nullptr ) {
561
- log_info (cds)(" Mismatched values for property %s: %s specified during dump time but not during runtime" , property, archived_flag);
562
- disable = true ;
563
- }
564
- } else {
565
- if (archived_flag == nullptr ) {
566
- log_info (cds)(" Mismatched values for property %s: %s specified during runtime but not during dump time" , property, runtime_flag);
567
- disable = true ;
568
- } else if (strcmp (runtime_flag, archived_flag) != 0 ) {
569
- log_info (cds)(" Mismatched values for property %s: runtime %s dump time %s" , property, runtime_flag, archived_flag);
570
- disable = true ;
544
+ class Modules ::ArchivedProperty {
545
+ const char * _prop;
546
+ const bool _numbered;
547
+ const char * _archived_value;
548
+
549
+ const char * get_flattened_value () const {
550
+ if (_numbered) {
551
+ return get_numbered_property_as_sorted_string ();
552
+ } else {
553
+ return Arguments::get_property (_prop);
571
554
}
572
555
}
573
556
574
- if (disable) {
575
- log_info (cds)(" Disabling optimized module handling" );
576
- CDSConfig::stop_using_optimized_module_handling ();
577
- }
578
- log_info (cds)(" optimized module handling: %s" , CDSConfig::is_using_optimized_module_handling () ? " enabled" : " disabled" );
579
- log_info (cds)(" full module graph: %s" , CDSConfig::is_using_full_module_graph () ? " enabled" : " disabled" );
580
- }
557
+ void runtime_check () const ;
558
+ const char * get_numbered_property_as_sorted_string () const ;
581
559
582
- void Modules::dump_archived_module_info () {
583
- // Write module name into archive
584
- CDS_JAVA_HEAP_ONLY (Modules::dump_main_module_name ();)
585
- // Write module names from --add-modules into archive
586
- CDS_JAVA_HEAP_ONLY (Modules::dump_addmods_names ();)
587
- // Write native enable-native-access flag into archive
588
- CDS_JAVA_HEAP_ONLY (Modules::dump_native_access_flag ());
589
- }
590
-
591
- void Modules::serialize_archived_module_info (SerializeClosure* soc) {
592
- CDS_JAVA_HEAP_ONLY (Modules::serialize (soc);)
593
- CDS_JAVA_HEAP_ONLY (Modules::serialize_addmods_names (soc);)
594
- CDS_JAVA_HEAP_ONLY (Modules::serialize_native_access_flags (soc);)
595
- }
560
+ public:
561
+ ArchivedProperty (const char * prop, bool numbered)
562
+ : _prop(prop), _numbered(numbered), _archived_value(nullptr ) {}
596
563
597
- void Modules::serialize (SerializeClosure* soc) {
598
- soc->do_ptr (&_archived_main_module_name);
599
- if (soc->reading ()) {
600
- const char * runtime_main_module = Arguments::get_property (" jdk.module.main" );
601
- log_info (cds)(" _archived_main_module_name %s" ,
602
- _archived_main_module_name != nullptr ? _archived_main_module_name : " (null)" );
603
-
604
- check_archived_flag_consistency (_archived_main_module_name, runtime_main_module, " jdk.module.main" );
605
-
606
- // Don't hold onto the pointer, in case we might decide to unmap the archive.
607
- _archived_main_module_name = nullptr ;
564
+ void dump () {
565
+ ResourceMark rm;
566
+ const char * str = get_flattened_value ();
567
+ if (str != nullptr ) {
568
+ _archived_value = ArchiveBuilder::current ()->ro_strdup (str);
569
+ }
608
570
}
609
- }
610
571
611
- void Modules::dump_native_access_flag () {
612
- ResourceMark rm;
613
- const char * native_access_names = get_native_access_flags_as_sorted_string ();
614
- if (native_access_names != nullptr ) {
615
- _archived_native_access_flags = ArchiveBuilder::current ()->ro_strdup (native_access_names);
572
+ void serialize (SerializeClosure* soc) {
573
+ soc->do_ptr (&_archived_value);
574
+ if (soc->reading ()) {
575
+ runtime_check ();
576
+ // Don't hold onto the pointer, in case we might decide to unmap the archive.
577
+ _archived_value = nullptr ;
578
+ }
616
579
}
617
- }
580
+ };
618
581
619
- // Caller needs ResourceMark
620
- const char * Modules::get_native_access_flags_as_sorted_string () {
621
- return get_numbered_property_as_sorted_string (" jdk.module.enable.native.access" );
622
- }
582
+ Modules::ArchivedProperty Modules::_archived_props[] = {
583
+ // numbered
584
+ {" jdk.module.main" , false },
623
585
624
- void Modules::serialize_native_access_flags (SerializeClosure* soc) {
625
- soc-> do_ptr (&_archived_native_access_flags);
626
- if (soc-> reading ()) {
627
- ResourceMark rm;
628
- check_archived_flag_consistency (_archived_native_access_flags, get_native_access_flags_as_sorted_string (), " jdk.module.enable.native.access " ) ;
586
+ // non-numbered
587
+ { " jdk.module.addexports " , true }, // --add-exports
588
+ { " jdk.module.addmods " , true }, // --add-modules
589
+ { " jdk.module.enable.native.access " , true }, // --enable-native-access
590
+ } ;
629
591
630
- // Don't hold onto the pointer, in case we might decide to unmap the archive.
631
- _archived_native_access_flags = nullptr ;
632
- }
592
+ constexpr size_t Modules::num_archived_props () {
593
+ return sizeof (_archived_props) / sizeof (_archived_props[0 ]);
633
594
}
634
595
635
- void Modules::dump_addmods_names () {
636
- ResourceMark rm;
637
- const char * addmods_names = get_addmods_names_as_sorted_string ();
638
- if (addmods_names != nullptr ) {
639
- _archived_addmods_names = ArchiveBuilder::current ()->ro_strdup (addmods_names);
640
- }
596
+ Modules::ArchivedProperty& Modules::archived_prop (size_t i) {
597
+ assert (i < num_archived_props (), " oob" );
598
+ return _archived_props[i];
641
599
}
642
600
643
- // Caller needs ResourceMark
644
- const char * Modules::get_addmods_names_as_sorted_string () {
645
- return get_numbered_property_as_sorted_string (" jdk.module.addmods" );
646
- }
601
+ void Modules::ArchivedProperty::runtime_check () const {
602
+ ResourceMark rm;
603
+ const char * runtime_value = get_flattened_value ();
604
+ log_info (cds)(" archived module property %s: %s" , _prop,
605
+ _archived_value != nullptr ? _archived_value : " (null)" );
647
606
648
- void Modules::serialize_addmods_names (SerializeClosure* soc) {
649
- soc->do_ptr (&_archived_addmods_names);
650
- if (soc->reading ()) {
651
- ResourceMark rm;
652
- check_archived_flag_consistency (_archived_addmods_names, get_addmods_names_as_sorted_string (), " jdk.module.addmods" );
607
+ bool disable = false ;
608
+ if (runtime_value == nullptr ) {
609
+ if (_archived_value != nullptr ) {
610
+ log_info (cds)(" Mismatched values for property %s: %s specified during dump time but not during runtime" , _prop, _archived_value);
611
+ disable = true ;
612
+ }
613
+ } else {
614
+ if (_archived_value == nullptr ) {
615
+ log_info (cds)(" Mismatched values for property %s: %s specified during runtime but not during dump time" , _prop, runtime_value);
616
+ disable = true ;
617
+ } else if (strcmp (runtime_value, _archived_value) != 0 ) {
618
+ log_info (cds)(" Mismatched values for property %s: runtime %s dump time %s" , _prop, runtime_value, _archived_value);
619
+ disable = true ;
620
+ }
621
+ }
653
622
654
- // Don't hold onto the pointer, in case we might decide to unmap the archive.
655
- _archived_addmods_names = nullptr ;
623
+ if (disable) {
624
+ log_info (cds)(" Disabling optimized module handling" );
625
+ CDSConfig::stop_using_optimized_module_handling ();
656
626
}
657
627
}
658
628
659
629
// Caller needs ResourceMark
660
- const char * Modules::get_numbered_property_as_sorted_string (const char * property) {
630
+ const char * Modules::ArchivedProperty::get_numbered_property_as_sorted_string () const {
631
+ assert (_numbered, " sanity" );
661
632
// theoretical string size limit for decimal int, but the following loop will end much sooner due to
662
633
// OS command-line size limit.
663
634
const int max_digits = 10 ;
664
635
const int extra_symbols_count = 2 ; // includes '.', '\0'
665
- size_t prop_len = strlen (property ) + max_digits + extra_symbols_count;
636
+ size_t prop_len = strlen (_prop ) + max_digits + extra_symbols_count;
666
637
char * prop_name = resource_allocate_bytes (prop_len);
667
638
GrowableArray<const char *> list;
668
639
for (unsigned int i = 0 ;; i++) {
669
- jio_snprintf (prop_name, prop_len, " %s.%d" , property , i);
640
+ jio_snprintf (prop_name, prop_len, " %s.%d" , _prop , i);
670
641
const char * prop_value = Arguments::get_property (prop_name);
671
642
if (prop_value == nullptr ) {
672
643
break ;
@@ -713,6 +684,22 @@ const char* Modules::get_numbered_property_as_sorted_string(const char* property
713
684
return (st.size () > 0 ) ? st.as_string () : nullptr ; // Example: "java.base,java.compiler"
714
685
}
715
686
687
+ void Modules::dump_archived_module_info () {
688
+ for (size_t i = 0 ; i < num_archived_props (); i++) {
689
+ archived_prop (i).dump ();
690
+ }
691
+ }
692
+
693
+ void Modules::serialize_archived_module_info (SerializeClosure* soc) {
694
+ for (size_t i = 0 ; i < num_archived_props (); i++) {
695
+ archived_prop (i).serialize (soc);
696
+ }
697
+ if (soc->reading ()) {
698
+ log_info (cds)(" optimized module handling: %s" , CDSConfig::is_using_optimized_module_handling () ? " enabled" : " disabled" );
699
+ log_info (cds)(" full module graph: %s" , CDSConfig::is_using_full_module_graph () ? " enabled" : " disabled" );
700
+ }
701
+ }
702
+
716
703
void Modules::define_archived_modules (Handle h_platform_loader, Handle h_system_loader, TRAPS) {
717
704
assert (CDSConfig::is_using_full_module_graph (), " must be" );
718
705
0 commit comments