< prev index next >

src/hotspot/share/cds/dynamicArchive.cpp

Print this page

 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 "cds/archiveBuilder.hpp"
 27 #include "cds/archiveHeapWriter.hpp"
 28 #include "cds/archiveUtils.inline.hpp"
 29 #include "cds/cds_globals.hpp"
 30 #include "cds/cdsConfig.hpp"
 31 #include "cds/classPrelinker.hpp"
 32 #include "cds/dynamicArchive.hpp"

 33 #include "cds/regeneratedClasses.hpp"

 34 #include "classfile/classLoaderData.inline.hpp"
 35 #include "classfile/symbolTable.hpp"
 36 #include "classfile/systemDictionaryShared.hpp"
 37 #include "classfile/vmSymbols.hpp"
 38 #include "gc/shared/collectedHeap.hpp"
 39 #include "gc/shared/gcVMOperations.hpp"
 40 #include "gc/shared/gc_globals.hpp"
 41 #include "jvm.h"
 42 #include "logging/log.hpp"
 43 #include "memory/metaspaceClosure.hpp"
 44 #include "memory/resourceArea.hpp"
 45 #include "oops/klass.inline.hpp"
 46 #include "runtime/arguments.hpp"
 47 #include "runtime/os.hpp"
 48 #include "runtime/sharedRuntime.hpp"
 49 #include "runtime/vmThread.hpp"
 50 #include "runtime/vmOperations.hpp"
 51 #include "utilities/align.hpp"
 52 #include "utilities/bitMap.inline.hpp"
 53 

101       log_info(cds)("Verify %s", info);
102       // Among other things, this ensures that Eden top is correct.
103       Universe::heap()->prepare_for_verify();
104       Universe::verify(info);
105     }
106   }
107 
108   void doit() {
109     verify_universe("Before CDS dynamic dump");
110     DEBUG_ONLY(SystemDictionaryShared::NoClassLoadingMark nclm);
111 
112     // Block concurrent class unloading from changing the _dumptime_table
113     MutexLocker ml(DumpTimeTable_lock, Mutex::_no_safepoint_check_flag);
114     SystemDictionaryShared::check_excluded_classes();
115 
116     if (SystemDictionaryShared::is_dumptime_table_empty()) {
117       log_warning(cds, dynamic)("There is no class to be included in the dynamic archive.");
118       return;
119     }
120 



121     init_header();
122     gather_source_objs();
123     gather_array_klasses();
124     reserve_buffer();
125 
126     log_info(cds, dynamic)("Copying %d klasses and %d symbols",
127                            klasses()->length(), symbols()->length());
128     dump_rw_metadata();
129     dump_ro_metadata();
130     relocate_metaspaceobj_embedded_pointers();
131 
132     verify_estimate_size(_estimated_metaspaceobj_bytes, "MetaspaceObjs");
133 










134     char* serialized_data;
135     {
136       // Write the symbol table and system dictionaries to the RO space.
137       // Note that these tables still point to the *original* objects, so
138       // they would need to call DynamicArchive::original_to_target() to
139       // get the correct addresses.
140       assert(current_dump_space() == ro_region(), "Must be RO space");
141       SymbolTable::write_to_archive(symbols());
142 
143       ArchiveBuilder::OtherROAllocMark mark;
144       SystemDictionaryShared::write_to_archive(false);

145       DynamicArchive::dump_array_klasses();


146 
147       serialized_data = ro_region()->top();
148       WriteClosure wc(ro_region());
149       ArchiveBuilder::serialize_dynamic_archivable_items(&wc);
150     }
151 
152     verify_estimate_size(_estimated_hashtable_bytes, "Hashtables");
153 
154     sort_methods();
155 
156     log_info(cds)("Make classes shareable");
157     make_klasses_shareable();
158 
159     log_info(cds)("Adjust lambda proxy class dictionary");
160     SystemDictionaryShared::adjust_lambda_proxy_class_dictionary();
161 






162     relocate_to_requested();
163 
164     write_archive(serialized_data);
165     release_header();
166     DynamicArchive::post_dump();
167 
168     post_dump();
169 
170     assert(_num_dump_regions_used == _total_dump_regions, "must be");
171     verify_universe("After CDS dynamic dump");
172   }
173 
174   virtual void iterate_roots(MetaspaceClosure* it) {
175     FileMapInfo::metaspace_pointers_do(it);
176     SystemDictionaryShared::dumptime_classes_do(it);

177     iterate_primitive_array_klasses(it);
178   }
179 
180   void iterate_primitive_array_klasses(MetaspaceClosure* it) {
181     for (int i = T_BOOLEAN; i <= T_LONG; i++) {
182       assert(is_java_primitive((BasicType)i), "sanity");
183       Klass* k = Universe::typeArrayKlassObj((BasicType)i);  // this give you "[I", etc
184       assert(MetaspaceShared::is_shared_static((void*)k),
185         "one-dimensional primitive array should be in static archive");
186       ArrayKlass* ak = ArrayKlass::cast(k);
187       while (ak != nullptr && ak->is_shared()) {
188         Klass* next_k = ak->array_klass_or_null();
189         if (next_k != nullptr) {
190           ak = ArrayKlass::cast(next_k);
191         } else {
192           ak = nullptr;
193         }
194       }
195       if (ak != nullptr) {
196         assert(ak->dimension() > 1, "sanity");

484     } else {
485       assert(ArchiveClassesAtExit != nullptr, "sanity");
486       log_warning(cds)("-XX:ArchiveClassesAtExit" __THEMSG);
487     }
488 #undef __THEMSG
489     CDSConfig::disable_dumping_dynamic_archive();
490   }
491 }
492 
493 void DynamicArchive::dump_at_exit(JavaThread* current, const char* archive_name) {
494   ExceptionMark em(current);
495   ResourceMark rm(current);
496 
497   if (!CDSConfig::is_dumping_dynamic_archive() || archive_name == nullptr) {
498     return;
499   }
500 
501   log_info(cds, dynamic)("Preparing for dynamic dump at exit in thread %s", current->name());
502 
503   JavaThread* THREAD = current; // For TRAPS processing related to link_shared_classes








504   MetaspaceShared::link_shared_classes(false/*not from jcmd*/, THREAD);
505   if (!HAS_PENDING_EXCEPTION) {
506     // copy shared path table to saved.

507     if (!HAS_PENDING_EXCEPTION) {
508       VM_PopulateDynamicDumpSharedSpace op(archive_name);
509       VMThread::execute(&op);
510       return;
511     }
512   }
513 
514   // One of the prepatory steps failed
515   oop ex = current->pending_exception();
516   log_error(cds)("Dynamic dump has failed");
517   log_error(cds)("%s: %s", ex->klass()->external_name(),
518                  java_lang_String::as_utf8_string(java_lang_Throwable::message(ex)));
519   CLEAR_PENDING_EXCEPTION;
520   CDSConfig::disable_dumping_dynamic_archive();  // Just for good measure
521 }
522 
523 // This is called by "jcmd VM.cds dynamic_dump"
524 void DynamicArchive::dump_for_jcmd(const char* archive_name, TRAPS) {
525   assert(UseSharedSpaces && RecordDynamicDumpInfo, "already checked in arguments.cpp");
526   assert(ArchiveClassesAtExit == nullptr, "already checked in arguments.cpp");
527   assert(CDSConfig::is_dumping_dynamic_archive(), "already checked by check_for_dynamic_dump() during VM startup");
528   MetaspaceShared::link_shared_classes(true/*from jcmd*/, CHECK);
529   // copy shared path table to saved.

530   VM_PopulateDynamicDumpSharedSpace op(archive_name);
531   VMThread::execute(&op);
532 }
533 
534 bool DynamicArchive::validate(FileMapInfo* dynamic_info) {
535   assert(!dynamic_info->is_static(), "must be");
536   // Check if the recorded base archive matches with the current one
537   FileMapInfo* base_info = FileMapInfo::current_info();
538   DynamicArchiveHeader* dynamic_header = dynamic_info->dynamic_header();
539 
540   // Check the header crc
541   if (dynamic_header->base_header_crc() != base_info->crc()) {
542     log_warning(cds)("Dynamic archive cannot be used: static archive header checksum verification failed.");
543     return false;
544   }
545 
546   // Check each space's crc
547   for (int i = 0; i < MetaspaceShared::n_regions; i++) {
548     if (dynamic_header->base_region_crc(i) != base_info->region_crc(i)) {
549       log_warning(cds)("Dynamic archive cannot be used: static archive region #%d checksum verification failed.", i);

 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 "cds/archiveBuilder.hpp"
 27 #include "cds/archiveHeapWriter.hpp"
 28 #include "cds/archiveUtils.inline.hpp"
 29 #include "cds/cds_globals.hpp"
 30 #include "cds/cdsConfig.hpp"
 31 #include "cds/classPrelinker.hpp"
 32 #include "cds/dynamicArchive.hpp"
 33 #include "cds/metaspaceShared.hpp"
 34 #include "cds/regeneratedClasses.hpp"
 35 #include "classfile/classLoader.hpp"
 36 #include "classfile/classLoaderData.inline.hpp"
 37 #include "classfile/symbolTable.hpp"
 38 #include "classfile/systemDictionaryShared.hpp"
 39 #include "classfile/vmSymbols.hpp"
 40 #include "gc/shared/collectedHeap.hpp"
 41 #include "gc/shared/gcVMOperations.hpp"
 42 #include "gc/shared/gc_globals.hpp"
 43 #include "jvm.h"
 44 #include "logging/log.hpp"
 45 #include "memory/metaspaceClosure.hpp"
 46 #include "memory/resourceArea.hpp"
 47 #include "oops/klass.inline.hpp"
 48 #include "runtime/arguments.hpp"
 49 #include "runtime/os.hpp"
 50 #include "runtime/sharedRuntime.hpp"
 51 #include "runtime/vmThread.hpp"
 52 #include "runtime/vmOperations.hpp"
 53 #include "utilities/align.hpp"
 54 #include "utilities/bitMap.inline.hpp"
 55 

103       log_info(cds)("Verify %s", info);
104       // Among other things, this ensures that Eden top is correct.
105       Universe::heap()->prepare_for_verify();
106       Universe::verify(info);
107     }
108   }
109 
110   void doit() {
111     verify_universe("Before CDS dynamic dump");
112     DEBUG_ONLY(SystemDictionaryShared::NoClassLoadingMark nclm);
113 
114     // Block concurrent class unloading from changing the _dumptime_table
115     MutexLocker ml(DumpTimeTable_lock, Mutex::_no_safepoint_check_flag);
116     SystemDictionaryShared::check_excluded_classes();
117 
118     if (SystemDictionaryShared::is_dumptime_table_empty()) {
119       log_warning(cds, dynamic)("There is no class to be included in the dynamic archive.");
120       return;
121     }
122 
123     log_info(cds,dynamic)("CDS dynamic dump: clinit = %ldms)",
124                           ClassLoader::class_init_time_ms());
125 
126     init_header();
127     gather_source_objs();
128     gather_array_klasses();
129     reserve_buffer();
130 
131     log_info(cds, dynamic)("Copying %d klasses and %d symbols",
132                            klasses()->length(), symbols()->length());
133     dump_rw_metadata();
134     dump_ro_metadata();
135     relocate_metaspaceobj_embedded_pointers();
136 
137     verify_estimate_size(_estimated_metaspaceobj_bytes, "MetaspaceObjs");
138 
139     sort_methods();
140 
141     {
142       ArchiveBuilder::OtherROAllocMark mark;
143       ClassPrelinker::record_preloaded_klasses(false);
144     }
145 
146     log_info(cds)("Make classes shareable");
147     make_klasses_shareable();
148 
149     char* serialized_data;
150     {
151       // Write the symbol table and system dictionaries to the RO space.
152       // Note that these tables still point to the *original* objects, so
153       // they would need to call DynamicArchive::original_to_target() to
154       // get the correct addresses.
155       assert(current_dump_space() == ro_region(), "Must be RO space");
156       SymbolTable::write_to_archive(symbols());
157 
158       ArchiveBuilder::OtherROAllocMark mark;
159       SystemDictionaryShared::write_to_archive(false);
160 
161       DynamicArchive::dump_array_klasses();
162       ClassPrelinker::record_initiated_klasses(false);
163       TrainingData::dump_training_data();
164 
165       serialized_data = ro_region()->top();
166       WriteClosure wc(ro_region());
167       ArchiveBuilder::serialize_dynamic_archivable_items(&wc);
168     }
169 
170     verify_estimate_size(_estimated_hashtable_bytes, "Hashtables");
171 





172     log_info(cds)("Adjust lambda proxy class dictionary");
173     SystemDictionaryShared::adjust_lambda_proxy_class_dictionary();
174 
175     log_info(cds)("Adjust method info dictionary");
176     SystemDictionaryShared::adjust_method_info_dictionary();
177 
178     log_info(cds)("Adjust training data dictionary");
179     TrainingData::adjust_training_data_dictionary();
180 
181     relocate_to_requested();
182 
183     write_archive(serialized_data);
184     release_header();
185     DynamicArchive::post_dump();
186 
187     post_dump();
188 
189     assert(_num_dump_regions_used == _total_dump_regions, "must be");
190     verify_universe("After CDS dynamic dump");
191   }
192 
193   virtual void iterate_roots(MetaspaceClosure* it) {
194     FileMapInfo::metaspace_pointers_do(it);
195     SystemDictionaryShared::dumptime_classes_do(it);
196     TrainingData::iterate_roots(it);
197     iterate_primitive_array_klasses(it);
198   }
199 
200   void iterate_primitive_array_klasses(MetaspaceClosure* it) {
201     for (int i = T_BOOLEAN; i <= T_LONG; i++) {
202       assert(is_java_primitive((BasicType)i), "sanity");
203       Klass* k = Universe::typeArrayKlassObj((BasicType)i);  // this give you "[I", etc
204       assert(MetaspaceShared::is_shared_static((void*)k),
205         "one-dimensional primitive array should be in static archive");
206       ArrayKlass* ak = ArrayKlass::cast(k);
207       while (ak != nullptr && ak->is_shared()) {
208         Klass* next_k = ak->array_klass_or_null();
209         if (next_k != nullptr) {
210           ak = ArrayKlass::cast(next_k);
211         } else {
212           ak = nullptr;
213         }
214       }
215       if (ak != nullptr) {
216         assert(ak->dimension() > 1, "sanity");

504     } else {
505       assert(ArchiveClassesAtExit != nullptr, "sanity");
506       log_warning(cds)("-XX:ArchiveClassesAtExit" __THEMSG);
507     }
508 #undef __THEMSG
509     CDSConfig::disable_dumping_dynamic_archive();
510   }
511 }
512 
513 void DynamicArchive::dump_at_exit(JavaThread* current, const char* archive_name) {
514   ExceptionMark em(current);
515   ResourceMark rm(current);
516 
517   if (!CDSConfig::is_dumping_dynamic_archive() || archive_name == nullptr) {
518     return;
519   }
520 
521   log_info(cds, dynamic)("Preparing for dynamic dump at exit in thread %s", current->name());
522 
523   JavaThread* THREAD = current; // For TRAPS processing related to link_shared_classes
524 
525   {
526     // FIXME-HACK - make sure we have at least one class in the dynamic archive
527     TempNewSymbol class_name = SymbolTable::new_symbol("sun/nio/cs/IBM850"); // unusual class; shouldn't be used by our tests cases.
528     SystemDictionary::resolve_or_null(class_name, Handle(), Handle(), THREAD);
529     guarantee(!HAS_PENDING_EXCEPTION, "must have this class");
530   }
531 
532   MetaspaceShared::link_shared_classes(false/*not from jcmd*/, THREAD);
533   if (!HAS_PENDING_EXCEPTION) {
534     // copy shared path table to saved.
535     TrainingData::init_dumptime_table(CHECK); // captures TrainingDataSetLocker
536     if (!HAS_PENDING_EXCEPTION) {
537       VM_PopulateDynamicDumpSharedSpace op(archive_name);
538       VMThread::execute(&op);
539       return;
540     }
541   }
542 
543   // One of the prepatory steps failed
544   oop ex = current->pending_exception();
545   log_error(cds)("Dynamic dump has failed");
546   log_error(cds)("%s: %s", ex->klass()->external_name(),
547                  java_lang_String::as_utf8_string(java_lang_Throwable::message(ex)));
548   CLEAR_PENDING_EXCEPTION;
549   CDSConfig::disable_dumping_dynamic_archive();  // Just for good measure
550 }
551 
552 // This is called by "jcmd VM.cds dynamic_dump"
553 void DynamicArchive::dump_for_jcmd(const char* archive_name, TRAPS) {
554   assert(UseSharedSpaces && RecordDynamicDumpInfo, "already checked in arguments.cpp");
555   assert(ArchiveClassesAtExit == nullptr, "already checked in arguments.cpp");
556   assert(CDSConfig::is_dumping_dynamic_archive(), "already checked by check_for_dynamic_dump() during VM startup");
557   MetaspaceShared::link_shared_classes(true/*from jcmd*/, CHECK);
558   // copy shared path table to saved.
559   TrainingData::init_dumptime_table(CHECK); // captures TrainingDataSetLocker
560   VM_PopulateDynamicDumpSharedSpace op(archive_name);
561   VMThread::execute(&op);
562 }
563 
564 bool DynamicArchive::validate(FileMapInfo* dynamic_info) {
565   assert(!dynamic_info->is_static(), "must be");
566   // Check if the recorded base archive matches with the current one
567   FileMapInfo* base_info = FileMapInfo::current_info();
568   DynamicArchiveHeader* dynamic_header = dynamic_info->dynamic_header();
569 
570   // Check the header crc
571   if (dynamic_header->base_header_crc() != base_info->crc()) {
572     log_warning(cds)("Dynamic archive cannot be used: static archive header checksum verification failed.");
573     return false;
574   }
575 
576   // Check each space's crc
577   for (int i = 0; i < MetaspaceShared::n_regions; i++) {
578     if (dynamic_header->base_region_crc(i) != base_info->region_crc(i)) {
579       log_warning(cds)("Dynamic archive cannot be used: static archive region #%d checksum verification failed.", i);
< prev index next >