< prev index next >

src/hotspot/share/memory/metaspaceShared.cpp

Print this page




1797       Universe::heap()->collect(GCCause::_archive_time_gc);
1798       Universe::heap()->soft_ref_policy()->set_should_clear_all_soft_refs(false);
1799     }
1800 
1801     VM_PopulateDumpSharedSpace op;
1802     VMThread::execute(&op);
1803   }
1804 }
1805 
1806 
1807 int MetaspaceShared::preload_classes(const char* class_list_path, TRAPS) {
1808   ClassListParser parser(class_list_path);
1809   int class_count = 0;
1810 
1811   while (parser.parse_one_line()) {
1812     Klass* klass = parser.load_current_class(THREAD);
1813     if (HAS_PENDING_EXCEPTION) {
1814       if (klass == NULL &&
1815           (PENDING_EXCEPTION->klass()->name() == vmSymbols::java_lang_ClassNotFoundException())) {
1816         // print a warning only when the pending exception is class not found
1817         tty->print_cr("Preload Warning: Cannot find %s", parser.current_class_name());
1818       }
1819       CLEAR_PENDING_EXCEPTION;
1820     }
1821     if (klass != NULL) {
1822       if (log_is_enabled(Trace, cds)) {
1823         ResourceMark rm;
1824         log_trace(cds)("Shared spaces preloaded: %s", klass->external_name());
1825       }
1826 
1827       if (klass->is_instance_klass()) {
1828         InstanceKlass* ik = InstanceKlass::cast(klass);
1829 
1830         // Link the class to cause the bytecodes to be rewritten and the
1831         // cpcache to be created. The linking is done as soon as classes
1832         // are loaded in order that the related data structures (klass and
1833         // cpCache) are located together.
1834         try_link_class(ik, THREAD);
1835         guarantee(!HAS_PENDING_EXCEPTION, "exception in link_class");
1836       }
1837 


1843 }
1844 
1845 // Returns true if the class's status has changed
1846 bool MetaspaceShared::try_link_class(InstanceKlass* ik, TRAPS) {
1847   assert(DumpSharedSpaces, "should only be called during dumping");
1848   if (ik->init_state() < InstanceKlass::linked) {
1849     bool saved = BytecodeVerificationLocal;
1850     if (ik->loader_type() == 0 && ik->class_loader() == NULL) {
1851       // The verification decision is based on BytecodeVerificationRemote
1852       // for non-system classes. Since we are using the NULL classloader
1853       // to load non-system classes for customized class loaders during dumping,
1854       // we need to temporarily change BytecodeVerificationLocal to be the same as
1855       // BytecodeVerificationRemote. Note this can cause the parent system
1856       // classes also being verified. The extra overhead is acceptable during
1857       // dumping.
1858       BytecodeVerificationLocal = BytecodeVerificationRemote;
1859     }
1860     ik->link_class(THREAD);
1861     if (HAS_PENDING_EXCEPTION) {
1862       ResourceMark rm;
1863       tty->print_cr("Preload Warning: Verification failed for %s",
1864                     ik->external_name());
1865       CLEAR_PENDING_EXCEPTION;
1866       ik->set_in_error_state();
1867       _has_error_classes = true;
1868     }
1869     BytecodeVerificationLocal = saved;
1870     return true;
1871   } else {
1872     return false;
1873   }
1874 }
1875 
1876 #if INCLUDE_CDS_JAVA_HEAP
1877 void VM_PopulateDumpSharedSpace::dump_java_heap_objects() {
1878   // The closed and open archive heap space has maximum two regions.
1879   // See FileMapInfo::write_archive_heap_regions() for details.
1880   _closed_archive_heap_regions = new GrowableArray<MemRegion>(2);
1881   _open_archive_heap_regions = new GrowableArray<MemRegion>(2);
1882   HeapShared::archive_java_heap_objects(_closed_archive_heap_regions,
1883                                         _open_archive_heap_regions);




1797       Universe::heap()->collect(GCCause::_archive_time_gc);
1798       Universe::heap()->soft_ref_policy()->set_should_clear_all_soft_refs(false);
1799     }
1800 
1801     VM_PopulateDumpSharedSpace op;
1802     VMThread::execute(&op);
1803   }
1804 }
1805 
1806 
1807 int MetaspaceShared::preload_classes(const char* class_list_path, TRAPS) {
1808   ClassListParser parser(class_list_path);
1809   int class_count = 0;
1810 
1811   while (parser.parse_one_line()) {
1812     Klass* klass = parser.load_current_class(THREAD);
1813     if (HAS_PENDING_EXCEPTION) {
1814       if (klass == NULL &&
1815           (PENDING_EXCEPTION->klass()->name() == vmSymbols::java_lang_ClassNotFoundException())) {
1816         // print a warning only when the pending exception is class not found
1817         log_warning(cds)("Preload Warning: Cannot find %s", parser.current_class_name());
1818       }
1819       CLEAR_PENDING_EXCEPTION;
1820     }
1821     if (klass != NULL) {
1822       if (log_is_enabled(Trace, cds)) {
1823         ResourceMark rm;
1824         log_trace(cds)("Shared spaces preloaded: %s", klass->external_name());
1825       }
1826 
1827       if (klass->is_instance_klass()) {
1828         InstanceKlass* ik = InstanceKlass::cast(klass);
1829 
1830         // Link the class to cause the bytecodes to be rewritten and the
1831         // cpcache to be created. The linking is done as soon as classes
1832         // are loaded in order that the related data structures (klass and
1833         // cpCache) are located together.
1834         try_link_class(ik, THREAD);
1835         guarantee(!HAS_PENDING_EXCEPTION, "exception in link_class");
1836       }
1837 


1843 }
1844 
1845 // Returns true if the class's status has changed
1846 bool MetaspaceShared::try_link_class(InstanceKlass* ik, TRAPS) {
1847   assert(DumpSharedSpaces, "should only be called during dumping");
1848   if (ik->init_state() < InstanceKlass::linked) {
1849     bool saved = BytecodeVerificationLocal;
1850     if (ik->loader_type() == 0 && ik->class_loader() == NULL) {
1851       // The verification decision is based on BytecodeVerificationRemote
1852       // for non-system classes. Since we are using the NULL classloader
1853       // to load non-system classes for customized class loaders during dumping,
1854       // we need to temporarily change BytecodeVerificationLocal to be the same as
1855       // BytecodeVerificationRemote. Note this can cause the parent system
1856       // classes also being verified. The extra overhead is acceptable during
1857       // dumping.
1858       BytecodeVerificationLocal = BytecodeVerificationRemote;
1859     }
1860     ik->link_class(THREAD);
1861     if (HAS_PENDING_EXCEPTION) {
1862       ResourceMark rm;
1863       log_warning(cds)("Preload Warning: Verification failed for %s",
1864                     ik->external_name());
1865       CLEAR_PENDING_EXCEPTION;
1866       ik->set_in_error_state();
1867       _has_error_classes = true;
1868     }
1869     BytecodeVerificationLocal = saved;
1870     return true;
1871   } else {
1872     return false;
1873   }
1874 }
1875 
1876 #if INCLUDE_CDS_JAVA_HEAP
1877 void VM_PopulateDumpSharedSpace::dump_java_heap_objects() {
1878   // The closed and open archive heap space has maximum two regions.
1879   // See FileMapInfo::write_archive_heap_regions() for details.
1880   _closed_archive_heap_regions = new GrowableArray<MemRegion>(2);
1881   _open_archive_heap_regions = new GrowableArray<MemRegion>(2);
1882   HeapShared::archive_java_heap_objects(_closed_archive_heap_regions,
1883                                         _open_archive_heap_regions);


< prev index next >