diff --git a/src/hotspot/cpu/ppc/templateTable_ppc_64.cpp b/src/hotspot/cpu/ppc/templateTable_ppc_64.cpp index fedb8ad86e9..7d6e14d26c1 100644 --- a/src/hotspot/cpu/ppc/templateTable_ppc_64.cpp +++ b/src/hotspot/cpu/ppc/templateTable_ppc_64.cpp @@ -25,6 +25,7 @@ #include "precompiled.hpp" #include "asm/macroAssembler.inline.hpp" +#include "cds/cdsConfig.hpp" #include "compiler/disassembler.hpp" #include "gc/shared/barrierSetAssembler.hpp" #include "gc/shared/tlab_globals.hpp" @@ -3483,7 +3484,7 @@ void TemplateTable::invokevirtual(int byte_no) { __ testbitdi(CCR0, R0, Rflags, ResolvedMethodEntry::is_vfinal_shift); __ bfalse(CCR0, LnotFinal); - if (RewriteBytecodes && !UseSharedSpaces && !DumpSharedSpaces) { + if (RewriteBytecodes && !UseSharedSpaces && !CDSConfig::is_dumping_static_archive()) { patch_bytecode(Bytecodes::_fast_invokevfinal, Rnew_bc, R12_scratch2); } invokevfinal_helper(Rcache, R11_scratch1, R12_scratch2, Rflags /* tmp */); diff --git a/src/hotspot/share/cds/archiveBuilder.cpp b/src/hotspot/share/cds/archiveBuilder.cpp index 0bc204d270b..d563e8f2649 100644 --- a/src/hotspot/share/cds/archiveBuilder.cpp +++ b/src/hotspot/share/cds/archiveBuilder.cpp @@ -239,7 +239,7 @@ void ArchiveBuilder::gather_klasses_and_symbols() { #endif doit.finish(); - if (DumpSharedSpaces) { + if (CDSConfig::is_dumping_static_archive()) { // To ensure deterministic contents in the static archive, we need to ensure that // we iterate the MetaspaceObjs in a deterministic order. It doesn't matter where // the MetaspaceObjs are located originally, as they are copied sequentially into @@ -339,7 +339,7 @@ address ArchiveBuilder::reserve_buffer() { // The bottom of the archive (that I am writing now) should be mapped at this address by default. address my_archive_requested_bottom; - if (DumpSharedSpaces) { + if (CDSConfig::is_dumping_static_archive()) { my_archive_requested_bottom = _requested_static_archive_bottom; } else { _mapped_static_archive_bottom = (address)MetaspaceObj::shared_metaspace_base(); @@ -367,7 +367,7 @@ address ArchiveBuilder::reserve_buffer() { MetaspaceShared::unrecoverable_writing_error(); } - if (DumpSharedSpaces) { + if (CDSConfig::is_dumping_static_archive()) { // We don't want any valid object to be at the very bottom of the archive. // See ArchivePtrMarker::mark_pointer(). rw_region()->allocate(16); @@ -642,7 +642,7 @@ void ArchiveBuilder::make_shallow_copy(DumpRegion *dump_region, SourceObjInfo* s memcpy(dest, src, bytes); // Update the hash of buffered sorted symbols for static dump so that the symbols have deterministic contents - if (DumpSharedSpaces && (src_info->msotype() == MetaspaceObj::SymbolType)) { + if (CDSConfig::is_dumping_static_archive() && (src_info->msotype() == MetaspaceObj::SymbolType)) { Symbol* buffered_symbol = (Symbol*)dest; assert(((Symbol*)src)->is_permanent(), "archived symbols must be permanent"); buffered_symbol->update_identity_hash(); @@ -825,7 +825,7 @@ uintx ArchiveBuilder::any_to_offset(address p) const { #if INCLUDE_CDS_JAVA_HEAP narrowKlass ArchiveBuilder::get_requested_narrow_klass(Klass* k) { - assert(DumpSharedSpaces, "sanity"); + assert(CDSConfig::is_dumping_heap(), "sanity"); k = get_buffered_klass(k); Klass* requested_k = to_requested(k); address narrow_klass_base = _requested_static_archive_bottom; // runtime encoding base == runtime mapping start @@ -916,7 +916,7 @@ void ArchiveBuilder::relocate_to_requested() { size_t my_archive_size = buffer_top() - buffer_bottom(); - if (DumpSharedSpaces) { + if (CDSConfig::is_dumping_static_archive()) { _requested_static_archive_top = _requested_static_archive_bottom + my_archive_size; RelocateBufferToRequested patcher(this); patcher.doit(); @@ -1238,7 +1238,7 @@ public: static void log(ArchiveBuilder* builder, FileMapInfo* mapinfo, ArchiveHeapInfo* heap_info, char* bitmap, size_t bitmap_size_in_bytes) { - log_info(cds, map)("%s CDS archive map for %s", DumpSharedSpaces ? "Static" : "Dynamic", mapinfo->full_path()); + log_info(cds, map)("%s CDS archive map for %s", CDSConfig::is_dumping_static_archive() ? "Static" : "Dynamic", mapinfo->full_path()); address header = address(mapinfo->header()); address header_end = header + mapinfo->header()->header_size(); diff --git a/src/hotspot/share/cds/cdsConfig.cpp b/src/hotspot/share/cds/cdsConfig.cpp index 20e407defaf..6261321fc1f 100644 --- a/src/hotspot/share/cds/cdsConfig.cpp +++ b/src/hotspot/share/cds/cdsConfig.cpp @@ -29,6 +29,7 @@ #include "classfile/classLoaderDataShared.hpp" #include "logging/log.hpp" +bool CDSConfig::_is_dumping_static_archive = false; bool CDSConfig::_is_dumping_dynamic_archive = false; // The ability to dump the FMG depends on many factors checked by @@ -37,10 +38,6 @@ bool CDSConfig::_is_dumping_dynamic_archive = false; bool CDSConfig::_dumping_full_module_graph_disabled = false; bool CDSConfig::_loading_full_module_graph_disabled = false; -bool CDSConfig::is_dumping_static_archive() { - return DumpSharedSpaces; -} - #if INCLUDE_CDS_JAVA_HEAP bool CDSConfig::is_dumping_heap() { // heap dump is not supported in dynamic dump diff --git a/src/hotspot/share/cds/cdsConfig.hpp b/src/hotspot/share/cds/cdsConfig.hpp index ff75de741a6..cc3c5556d0a 100644 --- a/src/hotspot/share/cds/cdsConfig.hpp +++ b/src/hotspot/share/cds/cdsConfig.hpp @@ -30,6 +30,7 @@ class CDSConfig : public AllStatic { #if INCLUDE_CDS + static bool _is_dumping_static_archive; static bool _is_dumping_dynamic_archive; static bool _dumping_full_module_graph_disabled; static bool _loading_full_module_graph_disabled; @@ -38,7 +39,8 @@ class CDSConfig : public AllStatic { public: // Basic CDS features static bool is_dumping_archive() { return is_dumping_static_archive() || is_dumping_dynamic_archive(); } - static bool is_dumping_static_archive() NOT_CDS_RETURN_(false); + static bool is_dumping_static_archive() { return CDS_ONLY(_is_dumping_static_archive) NOT_CDS(false); } + static void enable_dumping_static_archive() { CDS_ONLY(_is_dumping_static_archive = true); } static bool is_dumping_dynamic_archive() { return CDS_ONLY(_is_dumping_dynamic_archive) NOT_CDS(false); } static void enable_dumping_dynamic_archive() { CDS_ONLY(_is_dumping_dynamic_archive = true); } static void disable_dumping_dynamic_archive() { CDS_ONLY(_is_dumping_dynamic_archive = false); } diff --git a/src/hotspot/share/cds/classPrelinker.cpp b/src/hotspot/share/cds/classPrelinker.cpp index abc1e62ec1f..21946ebe9c0 100644 --- a/src/hotspot/share/cds/classPrelinker.cpp +++ b/src/hotspot/share/cds/classPrelinker.cpp @@ -24,6 +24,7 @@ #include "precompiled.hpp" #include "cds/archiveBuilder.hpp" +#include "cds/cdsConfig.hpp" #include "cds/classPrelinker.hpp" #include "classfile/systemDictionary.hpp" #include "classfile/vmClasses.hpp" @@ -182,13 +183,10 @@ Klass* ClassPrelinker::maybe_resolve_class(constantPoolHandle cp, int cp_index, #if INCLUDE_CDS_JAVA_HEAP void ClassPrelinker::resolve_string(constantPoolHandle cp, int cp_index, TRAPS) { - if (!DumpSharedSpaces) { - // The archive heap is not supported for the dynamic archive. - return; + if (CDSConfig::is_dumping_heap()) { + int cache_index = cp->cp_to_object_index(cp_index); + ConstantPool::string_at_impl(cp, cp_index, cache_index, CHECK); } - - int cache_index = cp->cp_to_object_index(cp_index); - ConstantPool::string_at_impl(cp, cp_index, cache_index, CHECK); } #endif diff --git a/src/hotspot/share/cds/cppVtables.cpp b/src/hotspot/share/cds/cppVtables.cpp index e737052621e..c339ce9c0de 100644 --- a/src/hotspot/share/cds/cppVtables.cpp +++ b/src/hotspot/share/cds/cppVtables.cpp @@ -216,7 +216,7 @@ void CppVtableCloner::init_orig_cpp_vtptr(int kind) { CppVtableInfo** CppVtables::_index = nullptr; char* CppVtables::dumptime_init(ArchiveBuilder* builder) { - assert(DumpSharedSpaces, "must"); + assert(CDSConfig::is_dumping_static_archive(), "cpp tables are only dumped into static archive"); size_t vtptrs_bytes = _num_cloned_vtable_kinds * sizeof(CppVtableInfo*); _index = (CppVtableInfo**)builder->rw_region()->allocate(vtptrs_bytes); @@ -284,7 +284,7 @@ intptr_t* CppVtables::get_archived_vtable(MetaspaceObj::Type msotype, address ob } void CppVtables::zero_archived_vtables() { - assert(DumpSharedSpaces, "dump-time only"); + assert(CDSConfig::is_dumping_static_archive(), "cpp tables are only dumped into static archive"); for (int kind = 0; kind < _num_cloned_vtable_kinds; kind ++) { _index[kind]->zero(); } diff --git a/src/hotspot/share/cds/dumpTimeClassInfo.hpp b/src/hotspot/share/cds/dumpTimeClassInfo.hpp index 30b64fcb2ad..5ba79e54c79 100644 --- a/src/hotspot/share/cds/dumpTimeClassInfo.hpp +++ b/src/hotspot/share/cds/dumpTimeClassInfo.hpp @@ -24,8 +24,10 @@ #ifndef SHARE_CDS_DUMPTIMECLASSINFO_HPP #define SHARE_CDS_DUMPTIMECLASSINFO_HPP + #include "cds/archiveBuilder.hpp" #include "cds/archiveUtils.hpp" +#include "cds/cdsConfig.hpp" #include "cds/metaspaceShared.hpp" #include "classfile/compactHashtable.hpp" #include "memory/metaspaceClosure.hpp" @@ -217,7 +219,7 @@ public: template inline unsigned DumpTimeSharedClassTable_hash(T* const& k) { - if (DumpSharedSpaces) { + if (CDSConfig::is_dumping_static_archive()) { // Deterministic archive contents uintx delta = k->name() - MetaspaceShared::symbol_rs_base(); return primitive_hash(delta); diff --git a/src/hotspot/share/cds/lambdaFormInvokers.cpp b/src/hotspot/share/cds/lambdaFormInvokers.cpp index fec81184470..8a556a48624 100644 --- a/src/hotspot/share/cds/lambdaFormInvokers.cpp +++ b/src/hotspot/share/cds/lambdaFormInvokers.cpp @@ -127,7 +127,7 @@ void LambdaFormInvokers::regenerate_holder_classes(TRAPS) { if (!PENDING_EXCEPTION->is_a(vmClasses::OutOfMemoryError_klass())) { log_error(cds)("%s: %s", PENDING_EXCEPTION->klass()->external_name(), java_lang_String::as_utf8_string(java_lang_Throwable::message(PENDING_EXCEPTION))); - if (DumpSharedSpaces) { + if (CDSConfig::is_dumping_static_archive()) { log_error(cds)("Failed to generate LambdaForm holder classes. Is your classlist out of date?"); } else { log_error(cds)("Failed to generate LambdaForm holder classes. Was the base archive generated with an outdated classlist?"); diff --git a/src/hotspot/share/cds/metaspaceShared.cpp b/src/hotspot/share/cds/metaspaceShared.cpp index cd59977b6a2..0c70dab3f60 100644 --- a/src/hotspot/share/cds/metaspaceShared.cpp +++ b/src/hotspot/share/cds/metaspaceShared.cpp @@ -244,7 +244,7 @@ static char* compute_shared_base(size_t cds_max) { } void MetaspaceShared::initialize_for_static_dump() { - assert(DumpSharedSpaces, "should be called for dump time only"); + assert(CDSConfig::is_dumping_static_archive(), "sanity"); log_info(cds)("Core region alignment: " SIZE_FORMAT, core_region_alignment()); // The max allowed size for CDS archive. We use this to limit SharedBaseAddress // to avoid address space wrap around. diff --git a/src/hotspot/share/cds/unregisteredClasses.cpp b/src/hotspot/share/cds/unregisteredClasses.cpp index 06d006ea1bb..91346a20085 100644 --- a/src/hotspot/share/cds/unregisteredClasses.cpp +++ b/src/hotspot/share/cds/unregisteredClasses.cpp @@ -44,7 +44,7 @@ // a JAR file. InstanceKlass* UnregisteredClasses::load_class(Symbol* name, const char* path, TRAPS) { assert(name != nullptr, "invariant"); - assert(DumpSharedSpaces, "this function is only used with -Xshare:dump"); + assert(CDSConfig::is_dumping_static_archive(), "this function is only used with -Xshare:dump"); PerfClassTraceTime vmtimer(ClassLoader::perf_app_classload_time(), THREAD->get_thread_stat()->perf_timers_addr(), diff --git a/src/hotspot/share/classfile/classFileParser.cpp b/src/hotspot/share/classfile/classFileParser.cpp index 7e39cafa811..a7447211a1c 100644 --- a/src/hotspot/share/classfile/classFileParser.cpp +++ b/src/hotspot/share/classfile/classFileParser.cpp @@ -5519,7 +5519,7 @@ ClassFileParser::ClassFileParser(ClassFileStream* stream, assert(0 == _access_flags.as_int(), "invariant"); // Figure out whether we can skip format checking (matching classic VM behavior) - if (DumpSharedSpaces) { + if (CDSConfig::is_dumping_static_archive()) { // verify == true means it's a 'remote' class (i.e., non-boot class) // Verification decision is based on BytecodeVerificationRemote flag // for those classes. @@ -5850,7 +5850,7 @@ void ClassFileParser::mangle_hidden_class_name(InstanceKlass* const ik) { // use an illegal char such as ';' because that causes serialization issues // and issues with hidden classes that create their own hidden classes. char addr_buf[20]; - if (DumpSharedSpaces) { + if (CDSConfig::is_dumping_static_archive()) { // We want stable names for the archived hidden classes (only for static // archive for now). Spaces under default_SharedBaseAddress() will be // occupied by the archive at run time, so we know that no dynamically diff --git a/src/hotspot/share/classfile/classLoader.cpp b/src/hotspot/share/classfile/classLoader.cpp index 6d37710f4ff..43aa82b67f8 100644 --- a/src/hotspot/share/classfile/classLoader.cpp +++ b/src/hotspot/share/classfile/classLoader.cpp @@ -1129,7 +1129,7 @@ InstanceKlass* ClassLoader::load_class(Symbol* name, bool search_append_only, TR // Dynamic dumping requires UseSharedSpaces to be enabled. Since --patch-module // is not supported with UseSharedSpaces, we can never come here during dynamic dumping. assert(!CDSConfig::is_dumping_dynamic_archive(), "sanity"); - if (!DumpSharedSpaces) { + if (!CDSConfig::is_dumping_static_archive()) { stream = search_module_entries(THREAD, _patch_mod_entries, class_name, file_name); } } @@ -1490,8 +1490,7 @@ void ClassLoader::classLoader_init2(JavaThread* current) { // As more modules are defined during module system initialization, more // entries will be added to the exploded build array. if (!has_jrt_entry()) { - assert(!DumpSharedSpaces, "DumpSharedSpaces not supported with exploded module builds"); - assert(!CDSConfig::is_dumping_dynamic_archive(), "not supported with exploded module builds"); + assert(!CDSConfig::is_dumping_archive(), "not supported with exploded module builds"); assert(!UseSharedSpaces, "UsedSharedSpaces not supported with exploded module builds"); // Set up the boot loader's _exploded_entries list. Note that this gets // done before loading any classes, by the same thread that will diff --git a/src/hotspot/share/classfile/classLoaderDataShared.cpp b/src/hotspot/share/classfile/classLoaderDataShared.cpp index 5e68aaea41e..e6f34b2b8b9 100644 --- a/src/hotspot/share/classfile/classLoaderDataShared.cpp +++ b/src/hotspot/share/classfile/classLoaderDataShared.cpp @@ -71,7 +71,7 @@ static ArchivedClassLoaderData _archived_system_loader_data; static ModuleEntry* _archived_javabase_moduleEntry = nullptr; void ArchivedClassLoaderData::iterate_symbols(ClassLoaderData* loader_data, MetaspaceClosure* closure) { - assert(DumpSharedSpaces, "must be"); + assert(CDSConfig::is_dumping_full_module_graph(), "must be"); assert_valid(loader_data); if (loader_data != nullptr) { loader_data->packages()->iterate_symbols(closure); @@ -80,7 +80,7 @@ void ArchivedClassLoaderData::iterate_symbols(ClassLoaderData* loader_data, Meta } void ArchivedClassLoaderData::allocate(ClassLoaderData* loader_data) { - assert(DumpSharedSpaces, "must be"); + assert(CDSConfig::is_dumping_full_module_graph(), "must be"); assert_valid(loader_data); if (loader_data != nullptr) { // We can't create hashtables at dump time because the hashcode depends on the @@ -93,7 +93,7 @@ void ArchivedClassLoaderData::allocate(ClassLoaderData* loader_data) { } void ArchivedClassLoaderData::init_archived_entries(ClassLoaderData* loader_data) { - assert(DumpSharedSpaces, "must be"); + assert(CDSConfig::is_dumping_full_module_graph(), "must be"); assert_valid(loader_data); if (loader_data != nullptr) { loader_data->packages()->init_archived_entries(_packages); diff --git a/src/hotspot/share/classfile/classLoaderExt.cpp b/src/hotspot/share/classfile/classLoaderExt.cpp index 92511d762fb..506d50e99c1 100644 --- a/src/hotspot/share/classfile/classLoaderExt.cpp +++ b/src/hotspot/share/classfile/classLoaderExt.cpp @@ -276,11 +276,11 @@ void ClassLoaderExt::record_result(const s2 classpath_index, InstanceKlass* resu result->set_shared_classpath_index(classpath_index); result->set_shared_class_loader_type(classloader_type); #if INCLUDE_CDS_JAVA_HEAP - if (DumpSharedSpaces && AllowArchivingWithJavaAgent && classloader_type == ClassLoader::BOOT_LOADER && - classpath_index < 0 && HeapShared::can_write() && redefined) { - // During static dump, classes for the built-in loaders are always loaded from - // known locations (jimage, classpath or modulepath), so classpath_index should - // always be >= 0. + if (CDSConfig::is_dumping_heap() && AllowArchivingWithJavaAgent && classloader_type == ClassLoader::BOOT_LOADER && + classpath_index < 0 && redefined) { + // When dumping the heap (which happens only during static dump), classes for the built-in + // loaders are always loaded from known locations (jimage, classpath or modulepath), + // so classpath_index should always be >= 0. // The only exception is when a java agent is used during dump time (for testing // purposes only). If a class is transformed by the agent, the CodeSource of // this class may point to an unknown location. This may break heap object archiving, diff --git a/src/hotspot/share/classfile/javaClasses.cpp b/src/hotspot/share/classfile/javaClasses.cpp index 8ff8258b93c..c3946c86236 100644 --- a/src/hotspot/share/classfile/javaClasses.cpp +++ b/src/hotspot/share/classfile/javaClasses.cpp @@ -802,9 +802,7 @@ GrowableArray* java_lang_Class::_fixup_module_field_list = nullptr; inline static void assert_valid_static_string_field(fieldDescriptor* fd) { assert(fd->has_initial_value(), "caller should have checked this"); assert(fd->field_type() == T_OBJECT, "caller should have checked this"); - // Can't use vmSymbols::string_signature() as fd->signature() may have been relocated - // during DumpSharedSpaces - assert(fd->signature()->equals("Ljava/lang/String;"), "just checking"); + assert(fd->signature() == vmSymbols::string_signature(), "just checking"); } #endif diff --git a/src/hotspot/share/classfile/moduleEntry.cpp b/src/hotspot/share/classfile/moduleEntry.cpp index b636976d096..24beecdcaf7 100644 --- a/src/hotspot/share/classfile/moduleEntry.cpp +++ b/src/hotspot/share/classfile/moduleEntry.cpp @@ -25,6 +25,7 @@ #include "precompiled.hpp" #include "cds/archiveBuilder.hpp" #include "cds/archiveUtils.hpp" +#include "cds/cdsConfig.hpp" #include "cds/filemap.hpp" #include "cds/heapShared.hpp" #include "classfile/classLoader.hpp" @@ -488,7 +489,7 @@ void ModuleEntry::init_as_archived_entry() { } void ModuleEntry::update_oops_in_archived_module(int root_oop_index) { - assert(DumpSharedSpaces, "static dump only"); + assert(CDSConfig::is_dumping_full_module_graph(), "sanity"); assert(_archived_module_index == -1, "must be set exactly once"); assert(root_oop_index >= 0, "sanity"); @@ -576,7 +577,7 @@ Array* ModuleEntryTable::allocate_archived_entries() { } void ModuleEntryTable::init_archived_entries(Array* archived_modules) { - assert(DumpSharedSpaces, "dump time only"); + assert(CDSConfig::is_dumping_full_module_graph(), "sanity"); for (int i = 0; i < archived_modules->length(); i++) { ModuleEntry* archived_entry = archived_modules->at(i); archived_entry->init_as_archived_entry(); diff --git a/src/hotspot/share/classfile/modules.cpp b/src/hotspot/share/classfile/modules.cpp index 18ae48560fa..bd4be93b868 100644 --- a/src/hotspot/share/classfile/modules.cpp +++ b/src/hotspot/share/classfile/modules.cpp @@ -486,7 +486,6 @@ static bool _seen_system_unnamed_module = false; // // Returns true iff the oop has an archived ModuleEntry. bool Modules::check_archived_module_oop(oop orig_module_obj) { - assert(DumpSharedSpaces, "must be"); assert(CDSConfig::is_dumping_full_module_graph(), "must be"); assert(java_lang_Module::is_instance(orig_module_obj), "must be"); @@ -641,7 +640,7 @@ void Modules::define_archived_modules(Handle h_platform_loader, Handle h_system_ } void Modules::check_cds_restrictions(TRAPS) { - if (DumpSharedSpaces && Universe::is_module_initialized() && CDSConfig::is_dumping_full_module_graph()) { + if (CDSConfig::is_dumping_full_module_graph() && Universe::is_module_initialized()) { THROW_MSG(vmSymbols::java_lang_UnsupportedOperationException(), "During -Xshare:dump, module system cannot be modified after it's initialized"); } diff --git a/src/hotspot/share/classfile/symbolTable.cpp b/src/hotspot/share/classfile/symbolTable.cpp index 51124e5a225..53c6bb06bec 100644 --- a/src/hotspot/share/classfile/symbolTable.cpp +++ b/src/hotspot/share/classfile/symbolTable.cpp @@ -155,8 +155,9 @@ public: assert(value.is_permanent() || (value.refcount() == 1) || (value.refcount() == 0), "refcount %d", value.refcount()); #if INCLUDE_CDS - if (DumpSharedSpaces) { - // no deallocation is needed + if (CDSConfig::is_dumping_static_archive()) { + // We have allocated with MetaspaceShared::symbol_space_alloc(). No deallocation is needed. + // Unreferenced Symbols will not be copied into the archive. return; } #endif @@ -183,7 +184,7 @@ private: static void* allocate_node_impl(size_t size, Value const& value) { size_t alloc_size = size + value.byte_size() + value.effective_length(); #if INCLUDE_CDS - if (DumpSharedSpaces) { + if (CDSConfig::is_dumping_static_archive()) { MutexLocker ml(DumpRegion_lock, Mutex::_no_safepoint_check_flag); // To get deterministic output from -Xshare:dump, we ensure that Symbols are allocated in // increasing addresses. When the symbols are copied into the archive, we preserve their @@ -492,7 +493,7 @@ Symbol* SymbolTable::do_add_if_needed(const char* name, int len, uintx hash, boo const int alloc_size = Symbol::byte_size(len); u1* u1_buf = NEW_RESOURCE_ARRAY_IN_THREAD(current, u1, alloc_size); Symbol* tmp = ::new ((void*)u1_buf) Symbol((const u1*)name, len, - (is_permanent || DumpSharedSpaces) ? PERM_REFCOUNT : 1); + (is_permanent || CDSConfig::is_dumping_static_archive()) ? PERM_REFCOUNT : 1); do { if (_local_table->insert(current, lookup, *tmp, &rehash_warning, &clean_hint)) { diff --git a/src/hotspot/share/classfile/systemDictionary.cpp b/src/hotspot/share/classfile/systemDictionary.cpp index dc5c86e060c..e635c825633 100644 --- a/src/hotspot/share/classfile/systemDictionary.cpp +++ b/src/hotspot/share/classfile/systemDictionary.cpp @@ -414,7 +414,7 @@ InstanceKlass* SystemDictionary::resolve_super_or_fail(Symbol* class_name, assert(super_name != nullptr, "null superclass for resolving"); assert(!Signature::is_array(super_name), "invalid superclass name"); #if INCLUDE_CDS - if (DumpSharedSpaces) { + if (CDSConfig::is_dumping_static_archive()) { // Special processing for handling UNREGISTERED shared classes. InstanceKlass* k = SystemDictionaryShared::lookup_super_for_unregistered_class(class_name, super_name, is_superclass); @@ -878,7 +878,7 @@ InstanceKlass* SystemDictionary::resolve_class_from_stream( InstanceKlass* k = nullptr; #if INCLUDE_CDS - if (!DumpSharedSpaces) { + if (!CDSConfig::is_dumping_static_archive()) { k = SystemDictionaryShared::lookup_from_stream(class_name, class_loader, cl_info.protection_domain(), diff --git a/src/hotspot/share/classfile/systemDictionaryShared.cpp b/src/hotspot/share/classfile/systemDictionaryShared.cpp index cd1d0751016..29748352684 100644 --- a/src/hotspot/share/classfile/systemDictionaryShared.cpp +++ b/src/hotspot/share/classfile/systemDictionaryShared.cpp @@ -460,7 +460,7 @@ bool SystemDictionaryShared::add_unregistered_class(Thread* current, InstanceKla InstanceKlass* SystemDictionaryShared::lookup_super_for_unregistered_class( Symbol* class_name, Symbol* super_name, bool is_superclass) { - assert(DumpSharedSpaces, "only when static dumping"); + assert(CDSConfig::is_dumping_static_archive(), "only when static dumping"); if (!ClassListParser::is_parsing_thread()) { // Unregistered classes can be created only by ClassListParser::_parsing_thread. @@ -723,7 +723,7 @@ bool SystemDictionaryShared::add_verification_constraint(InstanceKlass* k, Symbo } void SystemDictionaryShared::add_enum_klass_static_field(InstanceKlass* ik, int root_index) { - assert(DumpSharedSpaces, "static dump only"); + assert(CDSConfig::is_dumping_heap(), "sanity"); DumpTimeClassInfo* info = get_info_locked(ik); info->add_enum_klass_static_field(root_index); } @@ -841,7 +841,7 @@ InstanceKlass* SystemDictionaryShared::retrieve_lambda_proxy_class(const RunTime } InstanceKlass* SystemDictionaryShared::get_shared_nest_host(InstanceKlass* lambda_ik) { - assert(!DumpSharedSpaces && UseSharedSpaces, "called at run time with CDS enabled only"); + assert(!CDSConfig::is_dumping_static_archive() && UseSharedSpaces, "called at run time with CDS enabled only"); RunTimeClassInfo* record = RunTimeClassInfo::get_for(lambda_ik); return record->nest_host(); } @@ -892,7 +892,7 @@ InstanceKlass* SystemDictionaryShared::prepare_shared_lambda_proxy_class(Instanc void SystemDictionaryShared::check_verification_constraints(InstanceKlass* klass, TRAPS) { - assert(!DumpSharedSpaces && UseSharedSpaces, "called at run time with CDS enabled only"); + assert(!CDSConfig::is_dumping_static_archive() && UseSharedSpaces, "called at run time with CDS enabled only"); RunTimeClassInfo* record = RunTimeClassInfo::get_for(klass); int length = record->_num_verifier_constraints; @@ -1002,7 +1002,7 @@ void SystemDictionaryShared::record_linking_constraint(Symbol* name, InstanceKla // returns true IFF there's no need to re-initialize the i/v-tables for klass for // the purpose of checking class loader constraints. bool SystemDictionaryShared::check_linking_constraints(Thread* current, InstanceKlass* klass) { - assert(!DumpSharedSpaces && UseSharedSpaces, "called at run time with CDS enabled only"); + assert(!CDSConfig::is_dumping_static_archive() && UseSharedSpaces, "called at run time with CDS enabled only"); LogTarget(Info, class, loader, constraints) log; if (klass->is_shared_boot_class()) { // No class loader constraint check performed for boot classes. @@ -1343,7 +1343,7 @@ InstanceKlass* SystemDictionaryShared::find_builtin_class(Symbol* name) { } void SystemDictionaryShared::update_shared_entry(InstanceKlass* k, int id) { - assert(DumpSharedSpaces, "supported only when dumping"); + assert(CDSConfig::is_dumping_static_archive(), "class ID is used only for static dump (from classlist)"); DumpTimeClassInfo* info = get_info(k); info->_id = id; } diff --git a/src/hotspot/share/classfile/verifier.cpp b/src/hotspot/share/classfile/verifier.cpp index 0978d874ff0..4aa95aff0e1 100644 --- a/src/hotspot/share/classfile/verifier.cpp +++ b/src/hotspot/share/classfile/verifier.cpp @@ -23,6 +23,7 @@ */ #include "precompiled.hpp" +#include "cds/cdsConfig.hpp" #include "classfile/classFileStream.hpp" #include "classfile/classLoader.hpp" #include "classfile/javaClasses.hpp" @@ -198,12 +199,12 @@ bool Verifier::verify(InstanceKlass* klass, bool should_verify_class, TRAPS) { split_verifier.verify_class(THREAD); exception_name = split_verifier.result(); - // If DumpSharedSpaces is set then don't fall back to the old verifier on + // If dumping static archive then don't fall back to the old verifier on // verification failure. If a class fails verification with the split verifier, // it might fail the CDS runtime verifier constraint check. In that case, we // don't want to share the class. We only archive classes that pass the split // verifier. - bool can_failover = !DumpSharedSpaces && + bool can_failover = !CDSConfig::is_dumping_static_archive() && klass->major_version() < NOFAILOVER_MAJOR_VERSION; if (can_failover && !HAS_PENDING_EXCEPTION && // Split verifier doesn't set PENDING_EXCEPTION for failure diff --git a/src/hotspot/share/gc/g1/g1Arguments.cpp b/src/hotspot/share/gc/g1/g1Arguments.cpp index 10136c33abc..b8a7c677f7f 100644 --- a/src/hotspot/share/gc/g1/g1Arguments.cpp +++ b/src/hotspot/share/gc/g1/g1Arguments.cpp @@ -24,6 +24,7 @@ */ #include "precompiled.hpp" +#include "cds/cdsConfig.hpp" #include "gc/g1/g1Arguments.hpp" #include "gc/g1/g1CardSet.hpp" #include "gc/g1/g1CardSetContainers.inline.hpp" @@ -173,10 +174,10 @@ void G1Arguments::initialize() { vm_exit_during_initialization("The flag -XX:+UseG1GC can not be combined with -XX:ParallelGCThreads=0", nullptr); } - // When dumping the CDS archive we want to reduce fragmentation by + // When dumping the CDS heap we want to reduce fragmentation by // triggering a full collection. To get as low fragmentation as // possible we only use one worker thread. - if (DumpSharedSpaces) { + if (CDSConfig::is_dumping_heap()) { FLAG_SET_ERGO(ParallelGCThreads, 1); } diff --git a/src/hotspot/share/jfr/recorder/service/jfrOptionSet.cpp b/src/hotspot/share/jfr/recorder/service/jfrOptionSet.cpp index a077ec53c90..595fcc9c65d 100644 --- a/src/hotspot/share/jfr/recorder/service/jfrOptionSet.cpp +++ b/src/hotspot/share/jfr/recorder/service/jfrOptionSet.cpp @@ -23,6 +23,7 @@ */ #include "precompiled.hpp" +#include "cds/cdsConfig.hpp" #include "classfile/javaClasses.hpp" #include "jfr/dcmd/jfrDcmds.hpp" #include "jfr/recorder/service/jfrMemorySizer.hpp" @@ -150,7 +151,7 @@ bool JfrOptionSet::allow_retransforms() { } bool JfrOptionSet::allow_event_retransforms() { - return allow_retransforms() && (DumpSharedSpaces || can_retransform()); + return allow_retransforms() && (CDSConfig::is_dumping_static_archive() || can_retransform()); } // default options for the dcmd parser diff --git a/src/hotspot/share/memory/metaspace.cpp b/src/hotspot/share/memory/metaspace.cpp index de36cd8c7a8..1aa0923ff9c 100644 --- a/src/hotspot/share/memory/metaspace.cpp +++ b/src/hotspot/share/memory/metaspace.cpp @@ -24,6 +24,7 @@ */ #include "precompiled.hpp" +#include "cds/cdsConfig.hpp" #include "cds/metaspaceShared.hpp" #include "classfile/classLoaderData.hpp" #include "gc/shared/collectedHeap.hpp" @@ -725,7 +726,7 @@ void Metaspace::global_initialize() { metaspace::ChunkHeaderPool::initialize(); - if (DumpSharedSpaces) { + if (CDSConfig::is_dumping_static_archive()) { assert(!UseSharedSpaces, "sanity"); MetaspaceShared::initialize_for_static_dump(); } diff --git a/src/hotspot/share/memory/metaspace/metaspaceReporter.cpp b/src/hotspot/share/memory/metaspace/metaspaceReporter.cpp index a417ed00328..a7674fb1b81 100644 --- a/src/hotspot/share/memory/metaspace/metaspaceReporter.cpp +++ b/src/hotspot/share/memory/metaspace/metaspaceReporter.cpp @@ -24,6 +24,7 @@ */ #include "precompiled.hpp" +#include "cds/cdsConfig.hpp" #include "classfile/classLoaderData.hpp" #include "classfile/classLoaderDataGraph.hpp" #include "memory/metaspace.hpp" @@ -115,7 +116,7 @@ static void print_settings(outputStream* out, size_t scale) { out->print("Current GC threshold: "); print_human_readable_size(out, MetaspaceGC::capacity_until_GC(), scale); out->cr(); - out->print_cr("CDS: %s", (UseSharedSpaces ? "on" : (DumpSharedSpaces ? "dump" : "off"))); + out->print_cr("CDS: %s", (UseSharedSpaces ? "on" : (CDSConfig::is_dumping_static_archive() ? "dump" : "off"))); Settings::print_on(out); } diff --git a/src/hotspot/share/memory/universe.cpp b/src/hotspot/share/memory/universe.cpp index 1c0a5461ffe..21601a93037 100644 --- a/src/hotspot/share/memory/universe.cpp +++ b/src/hotspot/share/memory/universe.cpp @@ -240,7 +240,7 @@ void Universe::metaspace_pointers_do(MetaspaceClosure* it) { #if INCLUDE_CDS_JAVA_HEAP void Universe::set_archived_basic_type_mirror_index(BasicType t, int index) { - assert(DumpSharedSpaces, "dump-time only"); + assert(CDSConfig::is_dumping_heap(), "sanity"); assert(!is_reference_type(t), "sanity"); _archived_basic_type_mirror_indices[t] = index; } @@ -484,7 +484,7 @@ void Universe::initialize_basic_type_mirrors(TRAPS) { CDS_JAVA_HEAP_ONLY(_archived_basic_type_mirror_indices[i] = -1); } } - if (DumpSharedSpaces) { + if (CDSConfig::is_dumping_heap()) { HeapShared::init_scratch_objects(CHECK); } } @@ -804,8 +804,6 @@ jint universe_init() { return JNI_EINVAL; } - // Create memory for metadata. Must be after initializing heap for - // DumpSharedSpaces. ClassLoaderData::init_null_class_loader_data(); // We have a heap so create the Method* caches before diff --git a/src/hotspot/share/oops/arrayKlass.cpp b/src/hotspot/share/oops/arrayKlass.cpp index 486f317dadd..60382daf9a4 100644 --- a/src/hotspot/share/oops/arrayKlass.cpp +++ b/src/hotspot/share/oops/arrayKlass.cpp @@ -23,6 +23,7 @@ */ #include "precompiled.hpp" +#include "cds/cdsConfig.hpp" #include "cds/metaspaceShared.hpp" #include "classfile/javaClasses.hpp" #include "classfile/moduleEntry.hpp" @@ -41,6 +42,10 @@ #include "oops/oop.inline.hpp" #include "runtime/handles.inline.hpp" +ArrayKlass::ArrayKlass() { + assert(CDSConfig::is_dumping_static_archive() || UseSharedSpaces, "only for CDS"); +} + int ArrayKlass::static_size(int header_size) { // size of an array klass object assert(header_size <= InstanceKlass::header_size(), "bad header size"); diff --git a/src/hotspot/share/oops/arrayKlass.hpp b/src/hotspot/share/oops/arrayKlass.hpp index b3d7ca5b32a..681d101e0e2 100644 --- a/src/hotspot/share/oops/arrayKlass.hpp +++ b/src/hotspot/share/oops/arrayKlass.hpp @@ -47,7 +47,7 @@ class ArrayKlass: public Klass { // The constructor with the Symbol argument does the real array // initialization, the other is a dummy ArrayKlass(Symbol* name, KlassKind kind); - ArrayKlass() { assert(DumpSharedSpaces || UseSharedSpaces, "only for cds"); } + ArrayKlass(); public: // Testing operation diff --git a/src/hotspot/share/oops/constantPool.cpp b/src/hotspot/share/oops/constantPool.cpp index 36747bcc0b7..623d8e326b0 100644 --- a/src/hotspot/share/oops/constantPool.cpp +++ b/src/hotspot/share/oops/constantPool.cpp @@ -104,6 +104,10 @@ static bool tag_array_is_zero_initialized(Array* tags) { #endif +ConstantPool::ConstantPool() { + assert(CDSConfig::is_dumping_static_archive() || UseSharedSpaces, "only for CDS"); +} + ConstantPool::ConstantPool(Array* tags) : _tags(tags), _length(tags->length()) { diff --git a/src/hotspot/share/oops/constantPool.hpp b/src/hotspot/share/oops/constantPool.hpp index 31d0239f50b..a5a82d937ed 100644 --- a/src/hotspot/share/oops/constantPool.hpp +++ b/src/hotspot/share/oops/constantPool.hpp @@ -162,7 +162,7 @@ class ConstantPool : public Metadata { } ConstantPool(Array* tags); - ConstantPool() { assert(DumpSharedSpaces || UseSharedSpaces, "only for CDS"); } + ConstantPool(); public: static ConstantPool* allocate(ClassLoaderData* loader_data, int length, TRAPS); diff --git a/src/hotspot/share/oops/cpCache.cpp b/src/hotspot/share/oops/cpCache.cpp index c32566ea699..daa094baa7e 100644 --- a/src/hotspot/share/oops/cpCache.cpp +++ b/src/hotspot/share/oops/cpCache.cpp @@ -447,7 +447,7 @@ void ConstantPoolCache::clear_archived_references() { } void ConstantPoolCache::set_archived_references(int root_index) { - assert(DumpSharedSpaces, "called only during runtime"); + assert(CDSConfig::is_dumping_heap(), "sanity"); _archived_references_index = root_index; } #endif diff --git a/src/hotspot/share/oops/instanceClassLoaderKlass.cpp b/src/hotspot/share/oops/instanceClassLoaderKlass.cpp new file mode 100644 index 00000000000..fc6981009b8 --- /dev/null +++ b/src/hotspot/share/oops/instanceClassLoaderKlass.cpp @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + * + */ + +#include "precompiled.hpp" +#include "cds/cdsConfig.hpp" +#include "oops/instanceClassLoaderKlass.hpp" + +InstanceClassLoaderKlass::InstanceClassLoaderKlass() { + assert(CDSConfig::is_dumping_static_archive() || UseSharedSpaces, "only for CDS"); +} diff --git a/src/hotspot/share/oops/instanceClassLoaderKlass.hpp b/src/hotspot/share/oops/instanceClassLoaderKlass.hpp index f5a6135c049..985c81c3cd6 100644 --- a/src/hotspot/share/oops/instanceClassLoaderKlass.hpp +++ b/src/hotspot/share/oops/instanceClassLoaderKlass.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 2023, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -46,7 +46,7 @@ private: InstanceClassLoaderKlass(const ClassFileParser& parser) : InstanceKlass(parser, Kind) {} public: - InstanceClassLoaderKlass() { assert(DumpSharedSpaces || UseSharedSpaces, "only for CDS"); } + InstanceClassLoaderKlass(); // Oop fields (and metadata) iterators // diff --git a/src/hotspot/share/oops/instanceKlass.cpp b/src/hotspot/share/oops/instanceKlass.cpp index c4acf1fb3ac..fa595142c68 100644 --- a/src/hotspot/share/oops/instanceKlass.cpp +++ b/src/hotspot/share/oops/instanceKlass.cpp @@ -501,6 +501,10 @@ static Monitor* create_init_monitor(const char* name) { return new Monitor(Mutex::safepoint, name); } +InstanceKlass::InstanceKlass() { + assert(CDSConfig::is_dumping_static_archive() || UseSharedSpaces, "only for CDS"); +} + InstanceKlass::InstanceKlass(const ClassFileParser& parser, KlassKind kind, ReferenceType reference_type) : Klass(kind), _nest_members(nullptr), @@ -822,8 +826,8 @@ bool InstanceKlass::link_class_or_fail(TRAPS) { } bool InstanceKlass::link_class_impl(TRAPS) { - if (DumpSharedSpaces && SystemDictionaryShared::has_class_failed_verification(this)) { - // This is for CDS dumping phase only -- we use the in_error_state to indicate that + if (CDSConfig::is_dumping_static_archive() && SystemDictionaryShared::has_class_failed_verification(this)) { + // This is for CDS static dump only -- we use the in_error_state to indicate that // the class has failed verification. Throwing the NoClassDefFoundError here is just // a convenient way to stop repeat attempts to verify the same (bad) class. // diff --git a/src/hotspot/share/oops/instanceKlass.hpp b/src/hotspot/share/oops/instanceKlass.hpp index 58ed347f6af..13cc080be5b 100644 --- a/src/hotspot/share/oops/instanceKlass.hpp +++ b/src/hotspot/share/oops/instanceKlass.hpp @@ -145,7 +145,7 @@ class InstanceKlass: public Klass { InstanceKlass(const ClassFileParser& parser, KlassKind kind = Kind, ReferenceType reference_type = REF_NONE); public: - InstanceKlass() { assert(DumpSharedSpaces || UseSharedSpaces, "only for CDS"); } + InstanceKlass(); // See "The Java Virtual Machine Specification" section 2.16.2-5 for a detailed description // of the class loading & initialization procedure, and the use of the states. diff --git a/src/hotspot/share/oops/instanceMirrorKlass.cpp b/src/hotspot/share/oops/instanceMirrorKlass.cpp index e1748090a18..993e693ddb3 100644 --- a/src/hotspot/share/oops/instanceMirrorKlass.cpp +++ b/src/hotspot/share/oops/instanceMirrorKlass.cpp @@ -23,6 +23,7 @@ */ #include "precompiled.hpp" +#include "cds/cdsConfig.hpp" #include "cds/serializeClosure.hpp" #include "classfile/javaClasses.inline.hpp" #include "gc/shared/collectedHeap.inline.hpp" @@ -39,6 +40,10 @@ int InstanceMirrorKlass::_offset_of_static_fields = 0; +InstanceMirrorKlass::InstanceMirrorKlass() { + assert(CDSConfig::is_dumping_static_archive() || UseSharedSpaces, "only for CDS"); +} + size_t InstanceMirrorKlass::instance_size(Klass* k) { if (k != nullptr && k->is_instance_klass()) { return align_object_size(size_helper() + InstanceKlass::cast(k)->static_field_size()); diff --git a/src/hotspot/share/oops/instanceMirrorKlass.hpp b/src/hotspot/share/oops/instanceMirrorKlass.hpp index cb1ee2efba4..9783d416a1d 100644 --- a/src/hotspot/share/oops/instanceMirrorKlass.hpp +++ b/src/hotspot/share/oops/instanceMirrorKlass.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 2023, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -53,7 +53,7 @@ class InstanceMirrorKlass: public InstanceKlass { InstanceMirrorKlass(const ClassFileParser& parser) : InstanceKlass(parser, Kind) {} public: - InstanceMirrorKlass() { assert(DumpSharedSpaces || UseSharedSpaces, "only for CDS"); } + InstanceMirrorKlass(); static InstanceMirrorKlass* cast(Klass* k) { return const_cast(cast(const_cast(k))); diff --git a/src/hotspot/share/oops/instanceRefKlass.cpp b/src/hotspot/share/oops/instanceRefKlass.cpp index 3af465d718a..b549f00b82f 100644 --- a/src/hotspot/share/oops/instanceRefKlass.cpp +++ b/src/hotspot/share/oops/instanceRefKlass.cpp @@ -23,6 +23,7 @@ */ #include "precompiled.hpp" +#include "cds/cdsConfig.hpp" #include "classfile/classFileParser.hpp" #include "classfile/javaClasses.hpp" #include "classfile/vmClasses.hpp" @@ -30,6 +31,10 @@ #include "oops/instanceRefKlass.inline.hpp" #include "oops/oop.inline.hpp" +InstanceRefKlass::InstanceRefKlass() { + assert(CDSConfig::is_dumping_static_archive() || UseSharedSpaces, "only for CDS"); +} + static ReferenceType reference_subclass_name_to_type(const Symbol* name) { if ( name == vmSymbols::java_lang_ref_SoftReference()) { return REF_SOFT; diff --git a/src/hotspot/share/oops/instanceRefKlass.hpp b/src/hotspot/share/oops/instanceRefKlass.hpp index 13d218723e3..e58f5cf083b 100644 --- a/src/hotspot/share/oops/instanceRefKlass.hpp +++ b/src/hotspot/share/oops/instanceRefKlass.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2023, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -56,7 +56,7 @@ class InstanceRefKlass: public InstanceKlass { InstanceRefKlass(const ClassFileParser& parser); public: - InstanceRefKlass() { assert(DumpSharedSpaces || UseSharedSpaces, "only for CDS"); } + InstanceRefKlass(); // Oop fields (and metadata) iterators // diff --git a/src/hotspot/share/oops/instanceStackChunkKlass.cpp b/src/hotspot/share/oops/instanceStackChunkKlass.cpp index 7e49db27875..0164ad0a9ba 100644 --- a/src/hotspot/share/oops/instanceStackChunkKlass.cpp +++ b/src/hotspot/share/oops/instanceStackChunkKlass.cpp @@ -23,6 +23,7 @@ */ #include "precompiled.hpp" +#include "cds/cdsConfig.hpp" #include "cds/serializeClosure.hpp" #include "classfile/vmClasses.hpp" #include "compiler/oopMap.inline.hpp" @@ -51,6 +52,10 @@ void InstanceStackChunkKlass::serialize_offsets(SerializeClosure* f) { } #endif +InstanceStackChunkKlass::InstanceStackChunkKlass() { + assert(CDSConfig::is_dumping_static_archive() || UseSharedSpaces, "only for CDS"); +} + InstanceStackChunkKlass::InstanceStackChunkKlass(const ClassFileParser& parser) : InstanceKlass(parser, Kind) { // Change the layout_helper to use the slow path because StackChunkOops are diff --git a/src/hotspot/share/oops/instanceStackChunkKlass.hpp b/src/hotspot/share/oops/instanceStackChunkKlass.hpp index 3c6ac01d7f5..aa59b46f42c 100644 --- a/src/hotspot/share/oops/instanceStackChunkKlass.hpp +++ b/src/hotspot/share/oops/instanceStackChunkKlass.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2020, 2023, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -113,7 +113,7 @@ private: InstanceStackChunkKlass(const ClassFileParser& parser); public: - InstanceStackChunkKlass() { assert(DumpSharedSpaces || UseSharedSpaces, "only for CDS"); } + InstanceStackChunkKlass(); // Casting from Klass* static InstanceStackChunkKlass* cast(Klass* k) { diff --git a/src/hotspot/share/oops/klass.cpp b/src/hotspot/share/oops/klass.cpp index 3af4bffaeaa..2a28978816d 100644 --- a/src/hotspot/share/oops/klass.cpp +++ b/src/hotspot/share/oops/klass.cpp @@ -195,6 +195,10 @@ void* Klass::operator new(size_t size, ClassLoaderData* loader_data, size_t word return Metaspace::allocate(loader_data, word_size, MetaspaceObj::ClassType, THREAD); } +Klass::Klass() : _kind(UnknownKlassKind) { + assert(CDSConfig::is_dumping_static_archive() || UseSharedSpaces, "only for cds"); +} + // "Normal" instantiation is preceded by a MetaspaceObj allocation // which zeros out memory - calloc equivalent. // The constructor is also used from CppVtableCloner, diff --git a/src/hotspot/share/oops/klass.hpp b/src/hotspot/share/oops/klass.hpp index 9d15894a490..96f8f8efdb6 100644 --- a/src/hotspot/share/oops/klass.hpp +++ b/src/hotspot/share/oops/klass.hpp @@ -193,9 +193,8 @@ private: protected: - // Constructor Klass(KlassKind kind); - Klass() : _kind(UnknownKlassKind) { assert(DumpSharedSpaces || UseSharedSpaces, "only for cds"); } + Klass(); void* operator new(size_t size, ClassLoaderData* loader_data, size_t word_size, TRAPS) throw(); diff --git a/src/hotspot/share/prims/jvm.cpp b/src/hotspot/share/prims/jvm.cpp index 162811870b2..539122746b2 100644 --- a/src/hotspot/share/prims/jvm.cpp +++ b/src/hotspot/share/prims/jvm.cpp @@ -2945,7 +2945,7 @@ static void thread_entry(JavaThread* thread, TRAPS) { JVM_ENTRY(void, JVM_StartThread(JNIEnv* env, jobject jthread)) #if INCLUDE_CDS - if (DumpSharedSpaces) { + if (CDSConfig::is_dumping_static_archive()) { // During java -Xshare:dump, if we allow multiple Java threads to // execute in parallel, symbols and classes may be loaded in // random orders which will make the resulting CDS archive @@ -3703,7 +3703,8 @@ JVM_LEAF(jboolean, JVM_IsSharingEnabled(JNIEnv* env)) JVM_END JVM_ENTRY_NO_ENV(jlong, JVM_GetRandomSeedForDumping()) - if (DumpSharedSpaces) { + if (CDSConfig::is_dumping_static_archive()) { + // We do this so that the default CDS archive can be deterministic. const char* release = VM_Version::vm_release(); const char* dbg_level = VM_Version::jdk_debug_level(); const char* version = VM_Version::internal_vm_info_string(); diff --git a/src/hotspot/share/runtime/arguments.cpp b/src/hotspot/share/runtime/arguments.cpp index d0fdb55d84b..c2e42e31dbb 100644 --- a/src/hotspot/share/runtime/arguments.cpp +++ b/src/hotspot/share/runtime/arguments.cpp @@ -2615,7 +2615,7 @@ jint Arguments::parse_each_vm_init_arg(const JavaVMInitArgs* args, bool* patch_m mode_flag_cmd_line = true; // -Xshare:dump } else if (match_option(option, "-Xshare:dump")) { - DumpSharedSpaces = true; + CDSConfig::enable_dumping_static_archive(); // -Xshare:on } else if (match_option(option, "-Xshare:on")) { UseSharedSpaces = true; @@ -3036,7 +3036,7 @@ jint Arguments::finalize_vm_init_args(bool patch_mod_javabase) { } #if INCLUDE_CDS - if (DumpSharedSpaces) { + if (CDSConfig::is_dumping_static_archive()) { if (!mode_flag_cmd_line) { // By default, -Xshare:dump runs in interpreter-only mode, which is required for deterministic archive. // @@ -3083,7 +3083,7 @@ jint Arguments::finalize_vm_init_args(bool patch_mod_javabase) { if (UseSharedSpaces && patch_mod_javabase) { no_shared_spaces("CDS is disabled when " JAVA_BASE_NAME " module is patched."); } - if (UseSharedSpaces && !DumpSharedSpaces && check_unsupported_cds_runtime_properties()) { + if (UseSharedSpaces && check_unsupported_cds_runtime_properties()) { UseSharedSpaces = false; } @@ -3364,7 +3364,7 @@ jint Arguments::parse_options_buffer(const char* name, char* buffer, const size_ } void Arguments::set_shared_spaces_flags_and_archive_paths() { - if (DumpSharedSpaces) { + if (CDSConfig::is_dumping_static_archive()) { if (RequireSharedSpaces) { warning("Cannot dump shared archive while using shared archive"); } @@ -3375,7 +3375,7 @@ void Arguments::set_shared_spaces_flags_and_archive_paths() { // This must be after set_ergonomics_flags() called so flag UseCompressedOops is set properly. // // UseSharedSpaces may be disabled if -XX:SharedArchiveFile is invalid. - if (DumpSharedSpaces || UseSharedSpaces) { + if (CDSConfig::is_dumping_static_archive() || UseSharedSpaces) { init_shared_archive_paths(); } #endif // INCLUDE_CDS @@ -3445,7 +3445,7 @@ void Arguments::extract_shared_archive_paths(const char* archive_path, void Arguments::init_shared_archive_paths() { if (ArchiveClassesAtExit != nullptr) { assert(!RecordDynamicDumpInfo, "already checked"); - if (DumpSharedSpaces) { + if (CDSConfig::is_dumping_static_archive()) { vm_exit_during_initialization("-XX:ArchiveClassesAtExit cannot be used with -Xshare:dump"); } check_unsupported_dumping_properties(); @@ -3467,7 +3467,7 @@ void Arguments::init_shared_archive_paths() { "Cannot have more than 1 archive file specified in -XX:SharedArchiveFile during CDS dumping"); } - if (DumpSharedSpaces) { + if (CDSConfig::is_dumping_static_archive()) { assert(archives == 1, "must be"); // Static dump is simple: only one archive is allowed in SharedArchiveFile. This file // will be overwritten no matter regardless of its contents @@ -3932,7 +3932,7 @@ jint Arguments::parse(const JavaVMInitArgs* initial_cmd_args) { set_object_alignment(); #if !INCLUDE_CDS - if (DumpSharedSpaces || RequireSharedSpaces) { + if (CDSConfig::is_dumping_static_archive() || RequireSharedSpaces) { jio_fprintf(defaultStream::error_stream(), "Shared spaces are not supported in this VM\n"); return JNI_ERR; diff --git a/src/hotspot/share/runtime/os.cpp b/src/hotspot/share/runtime/os.cpp index 0fea576269b..cafc9b10cbb 100644 --- a/src/hotspot/share/runtime/os.cpp +++ b/src/hotspot/share/runtime/os.cpp @@ -23,6 +23,7 @@ */ #include "precompiled.hpp" +#include "cds/cdsConfig.hpp" #include "classfile/javaClasses.hpp" #include "classfile/moduleEntry.hpp" #include "classfile/systemDictionary.hpp" @@ -630,7 +631,7 @@ void* os::malloc(size_t size, MEMFLAGS memflags, const NativeCallStack& stack) { // Special handling for NMT preinit phase before arguments are parsed void* rc = nullptr; if (NMTPreInit::handle_malloc(&rc, size)) { - // No need to fill with 0 because DumpSharedSpaces doesn't use these + // No need to fill with 0 because CDS static dumping doesn't use these // early allocations. return rc; } @@ -661,7 +662,7 @@ void* os::malloc(size_t size, MEMFLAGS memflags, const NativeCallStack& stack) { void* const inner_ptr = MemTracker::record_malloc((address)outer_ptr, size, memflags, stack); - if (DumpSharedSpaces) { + if (CDSConfig::is_dumping_static_archive()) { // Need to deterministically fill all the alignment gaps in C++ structures. ::memset(inner_ptr, 0, size); } else { diff --git a/src/hotspot/share/runtime/reflection.cpp b/src/hotspot/share/runtime/reflection.cpp index 88f1694c113..f0597b00527 100644 --- a/src/hotspot/share/runtime/reflection.cpp +++ b/src/hotspot/share/runtime/reflection.cpp @@ -23,6 +23,7 @@ */ #include "precompiled.hpp" +#include "cds/cdsConfig.hpp" #include "classfile/javaClasses.inline.hpp" #include "classfile/moduleEntry.hpp" #include "classfile/packageEntry.hpp" @@ -457,9 +458,9 @@ Reflection::VerifyClassAccessResults Reflection::verify_class_access( // module boundaries if (new_class->is_public()) { - // Ignore modules for DumpSharedSpaces because we do not have any package + // Ignore modules for -Xshare:dump because we do not have any package // or module information for modules other than java.base. - if (DumpSharedSpaces) { + if (CDSConfig::is_dumping_static_archive()) { return ACCESS_OK; } diff --git a/src/hotspot/share/runtime/threads.cpp b/src/hotspot/share/runtime/threads.cpp index b6ef42cd1d2..237e3a22451 100644 --- a/src/hotspot/share/runtime/threads.cpp +++ b/src/hotspot/share/runtime/threads.cpp @@ -25,6 +25,7 @@ #include "precompiled.hpp" #include "cds/cds_globals.hpp" +#include "cds/cdsConfig.hpp" #include "cds/metaspaceShared.hpp" #include "classfile/classLoader.hpp" #include "classfile/javaClasses.hpp" @@ -815,7 +816,7 @@ jint Threads::create_vm(JavaVMInitArgs* args, bool* canTryAgain) { _vm_complete = true; #endif - if (DumpSharedSpaces) { + if (CDSConfig::is_dumping_static_archive()) { MetaspaceShared::preload_and_dump(); } diff --git a/src/hotspot/share/utilities/globalDefinitions.cpp b/src/hotspot/share/utilities/globalDefinitions.cpp index 621951fc7d5..27af0fd6e83 100644 --- a/src/hotspot/share/utilities/globalDefinitions.cpp +++ b/src/hotspot/share/utilities/globalDefinitions.cpp @@ -40,7 +40,6 @@ int BytesPerHeapOop = 0; int BitsPerHeapOop = 0; // Old CDS options -bool DumpSharedSpaces; bool RequireSharedSpaces; extern "C" { JNIEXPORT jboolean UseSharedSpaces = true; diff --git a/src/hotspot/share/utilities/globalDefinitions.hpp b/src/hotspot/share/utilities/globalDefinitions.hpp index fc72ed73438..60938408dba 100644 --- a/src/hotspot/share/utilities/globalDefinitions.hpp +++ b/src/hotspot/share/utilities/globalDefinitions.hpp @@ -553,7 +553,6 @@ const int max_method_code_size = 64*K - 1; // JVM spec, 2nd ed. section 4.8.1 ( //---------------------------------------------------------------------------------------------------- // old CDS options -extern bool DumpSharedSpaces; extern bool RequireSharedSpaces; extern "C" { // Make sure UseSharedSpaces is accessible to the serviceability agent.