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

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

134     relocate_metaspaceobj_embedded_pointers();
135 
136     verify_estimate_size(_estimated_metaspaceobj_bytes, "MetaspaceObjs");
137 
138     sort_methods();
139 
140     log_info(cds)("Make classes shareable");
141     make_klasses_shareable();
142 
143     char* serialized_data;
144     {
145       // Write the symbol table and system dictionaries to the RO space.
146       // Note that these tables still point to the *original* objects, so
147       // they would need to call DynamicArchive::original_to_target() to
148       // get the correct addresses.
149       assert(current_dump_region() == ro_region(), "Must be RO space");
150       SymbolTable::write_to_archive(symbols());
151 
152       ArchiveBuilder::OtherROAllocMark mark;
153       SystemDictionaryShared::write_to_archive(false);

154       DynamicArchive::dump_array_klasses();
155       AOTClassLinker::write_to_archive();

156 
157       serialized_data = ro_region()->top();
158       WriteClosure wc(ro_region());
159       ArchiveBuilder::serialize_dynamic_archivable_items(&wc);
160     }
161 
162     verify_estimate_size(_estimated_hashtable_bytes, "Hashtables");
163 
164     log_info(cds)("Adjust lambda proxy class dictionary");
165     SystemDictionaryShared::adjust_lambda_proxy_class_dictionary();
166 



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

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

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








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

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

537   VM_PopulateDynamicDumpSharedSpace op(archive_name);
538   VMThread::execute(&op);
539 }
540 
541 bool DynamicArchive::validate(FileMapInfo* dynamic_info) {
542   assert(!dynamic_info->is_static(), "must be");
543   // Check if the recorded base archive matches with the current one
544   FileMapInfo* base_info = FileMapInfo::current_info();
545   DynamicArchiveHeader* dynamic_header = dynamic_info->dynamic_header();
546 
547   // Check the header crc
548   if (dynamic_header->base_header_crc() != base_info->crc()) {
549     log_warning(cds)("Dynamic archive cannot be used: static archive header checksum verification failed.");
550     return false;
551   }
552 
553   // Check each space's crc
554   for (int i = 0; i < MetaspaceShared::n_regions; i++) {
555     if (dynamic_header->base_region_crc(i) != base_info->region_crc(i)) {
556       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/aotClassLinker.hpp"
 27 #include "cds/archiveBuilder.hpp"
 28 #include "cds/archiveHeapWriter.hpp"
 29 #include "cds/archiveUtils.inline.hpp"
 30 #include "cds/cds_globals.hpp"
 31 #include "cds/cdsConfig.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/vmOperations.hpp"
 52 #include "runtime/vmThread.hpp"
 53 #include "utilities/align.hpp"

135     relocate_metaspaceobj_embedded_pointers();
136 
137     verify_estimate_size(_estimated_metaspaceobj_bytes, "MetaspaceObjs");
138 
139     sort_methods();
140 
141     log_info(cds)("Make classes shareable");
142     make_klasses_shareable();
143 
144     char* serialized_data;
145     {
146       // Write the symbol table and system dictionaries to the RO space.
147       // Note that these tables still point to the *original* objects, so
148       // they would need to call DynamicArchive::original_to_target() to
149       // get the correct addresses.
150       assert(current_dump_region() == ro_region(), "Must be RO space");
151       SymbolTable::write_to_archive(symbols());
152 
153       ArchiveBuilder::OtherROAllocMark mark;
154       SystemDictionaryShared::write_to_archive(false);
155 
156       DynamicArchive::dump_array_klasses();
157       AOTClassLinker::write_to_archive();
158       TrainingData::dump_training_data();
159 
160       serialized_data = ro_region()->top();
161       WriteClosure wc(ro_region());
162       ArchiveBuilder::serialize_dynamic_archivable_items(&wc);
163     }
164 
165     verify_estimate_size(_estimated_hashtable_bytes, "Hashtables");
166 
167     log_info(cds)("Adjust lambda proxy class dictionary");
168     SystemDictionaryShared::adjust_lambda_proxy_class_dictionary();
169 
170     log_info(cds)("Make training data shareable");
171     make_training_data_shareable();
172 
173     relocate_to_requested();
174 
175     write_archive(serialized_data);
176     release_header();
177     DynamicArchive::post_dump();
178 
179     post_dump();
180 
181     assert(_num_dump_regions_used == _total_dump_regions, "must be");
182     verify_universe("After CDS dynamic dump");
183   }
184 
185   virtual void iterate_roots(MetaspaceClosure* it) {
186     FileMapInfo::metaspace_pointers_do(it);
187     SystemDictionaryShared::dumptime_classes_do(it);
188     TrainingData::iterate_roots(it);
189     iterate_primitive_array_klasses(it);
190   }
191 
192   void iterate_primitive_array_klasses(MetaspaceClosure* it) {
193     for (int i = T_BOOLEAN; i <= T_LONG; i++) {
194       assert(is_java_primitive((BasicType)i), "sanity");
195       Klass* k = Universe::typeArrayKlass((BasicType)i);  // this give you "[I", etc
196       assert(MetaspaceShared::is_shared_static((void*)k),
197         "one-dimensional primitive array should be in static archive");
198       ArrayKlass* ak = ArrayKlass::cast(k);
199       while (ak != nullptr && ak->is_shared()) {
200         Klass* next_k = ak->array_klass_or_null();
201         if (next_k != nullptr) {
202           ak = ArrayKlass::cast(next_k);
203         } else {
204           ak = nullptr;
205         }
206       }
207       if (ak != nullptr) {
208         assert(ak->dimension() > 1, "sanity");

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