8327138: Clean up status management in cdsConfig.hpp and CDS.java

Reviewed-by: ccheung, matsaave
This commit is contained in:
Ioi Lam 2024-03-09 03:48:38 +00:00
parent 53628f2ea9
commit 761ed250ec
19 changed files with 162 additions and 162 deletions

@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2024, 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
@ -88,7 +88,7 @@ void ArchiveHeapLoader::fixup_region() {
fill_failed_loaded_heap();
}
if (is_in_use()) {
if (!CDSConfig::is_loading_full_module_graph()) {
if (!CDSConfig::is_using_full_module_graph()) {
// Need to remove all the archived java.lang.Module objects from HeapShared::roots().
ClassLoaderDataShared::clear_archived_oops();
}

@ -1,5 +1,5 @@
/*
* Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2023, 2024, 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
@ -25,28 +25,36 @@
#include "precompiled.hpp"
#include "cds/archiveHeapLoader.hpp"
#include "cds/cdsConfig.hpp"
#include "cds/classListWriter.hpp"
#include "cds/heapShared.hpp"
#include "classfile/classLoaderDataShared.hpp"
#include "classfile/moduleEntry.hpp"
#include "include/jvm_io.h"
#include "logging/log.hpp"
#include "memory/universe.hpp"
#include "runtime/arguments.hpp"
#include "runtime/java.hpp"
#include "utilities/defaultStream.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
// is_dumping_full_module_graph(), but can be unconditionally disabled by
// _dumping_full_module_graph_disabled. (Ditto for loading the FMG).
bool CDSConfig::_dumping_full_module_graph_disabled = false;
bool CDSConfig::_loading_full_module_graph_disabled = false;
bool CDSConfig::_is_using_optimized_module_handling = true;
bool CDSConfig::_is_dumping_full_module_graph = true;
bool CDSConfig::_is_using_full_module_graph = true;
char* CDSConfig::_default_archive_path = nullptr;
char* CDSConfig::_static_archive_path = nullptr;
char* CDSConfig::_dynamic_archive_path = nullptr;
int CDSConfig::get_status() {
assert(Universe::is_fully_initialized(), "status is finalized only after Universe is initialized");
return (is_dumping_archive() ? IS_DUMPING_ARCHIVE : 0) |
(is_dumping_static_archive() ? IS_DUMPING_STATIC_ARCHIVE : 0) |
(is_logging_lambda_form_invokers() ? IS_LOGGING_LAMBDA_FORM_INVOKERS : 0) |
(is_using_archive() ? IS_USING_ARCHIVE : 0);
}
void CDSConfig::initialize() {
if (is_dumping_static_archive()) {
if (RequireSharedSpaces) {
@ -62,6 +70,10 @@ void CDSConfig::initialize() {
if (is_dumping_static_archive() || UseSharedSpaces) {
init_shared_archive_paths();
}
if (!is_dumping_heap()) {
_is_dumping_full_module_graph = false;
}
}
char* CDSConfig::default_archive_path() {
@ -225,14 +237,14 @@ void CDSConfig::init_shared_archive_paths() {
void CDSConfig::check_system_property(const char* key, const char* value) {
if (Arguments::is_internal_module_property(key)) {
MetaspaceShared::disable_optimized_module_handling();
stop_using_optimized_module_handling();
log_info(cds)("optimized module handling: disabled due to incompatible property: %s=%s", key, value);
}
if (strcmp(key, "jdk.module.showModuleResolution") == 0 ||
strcmp(key, "jdk.module.validation") == 0 ||
strcmp(key, "java.system.class.loader") == 0) {
disable_loading_full_module_graph();
disable_dumping_full_module_graph();
stop_dumping_full_module_graph();
stop_using_full_module_graph();
log_info(cds)("full module graph: disabled due to incompatible property: %s=%s", key, value);
}
}
@ -355,53 +367,59 @@ bool CDSConfig::check_vm_args_consistency(bool patch_mod_javabase, bool mode_fl
return true;
}
bool CDSConfig::is_using_archive() {
return UseSharedSpaces; // TODO: UseSharedSpaces will be eventually replaced by CDSConfig::is_using_archive()
}
bool CDSConfig::is_logging_lambda_form_invokers() {
return ClassListWriter::is_enabled() || is_dumping_dynamic_archive();
}
void CDSConfig::stop_using_optimized_module_handling() {
_is_using_optimized_module_handling = false;
_is_dumping_full_module_graph = false; // This requires is_using_optimized_module_handling()
_is_using_full_module_graph = false; // This requires is_using_optimized_module_handling()
}
#if INCLUDE_CDS_JAVA_HEAP
bool CDSConfig::is_dumping_heap() {
// heap dump is not supported in dynamic dump
return is_dumping_static_archive() && HeapShared::can_write();
}
bool CDSConfig::is_dumping_full_module_graph() {
if (!_dumping_full_module_graph_disabled &&
is_dumping_heap() &&
MetaspaceShared::use_optimized_module_handling()) {
return true;
} else {
return false;
}
}
bool CDSConfig::is_loading_full_module_graph() {
bool CDSConfig::is_using_full_module_graph() {
if (ClassLoaderDataShared::is_full_module_graph_loaded()) {
return true;
}
if (!_loading_full_module_graph_disabled &&
UseSharedSpaces &&
ArchiveHeapLoader::can_use() &&
MetaspaceShared::use_optimized_module_handling()) {
if (!_is_using_full_module_graph) {
return false;
}
if (UseSharedSpaces && ArchiveHeapLoader::can_use()) {
// Classes used by the archived full module graph are loaded in JVMTI early phase.
assert(!(JvmtiExport::should_post_class_file_load_hook() && JvmtiExport::has_early_class_hook_env()),
"CDS should be disabled if early class hooks are enabled");
return true;
} else {
_is_using_full_module_graph = false;
return false;
}
}
void CDSConfig::disable_dumping_full_module_graph(const char* reason) {
if (!_dumping_full_module_graph_disabled) {
_dumping_full_module_graph_disabled = true;
void CDSConfig::stop_dumping_full_module_graph(const char* reason) {
if (_is_dumping_full_module_graph) {
_is_dumping_full_module_graph = false;
if (reason != nullptr) {
log_info(cds)("full module graph cannot be dumped: %s", reason);
}
}
}
void CDSConfig::disable_loading_full_module_graph(const char* reason) {
void CDSConfig::stop_using_full_module_graph(const char* reason) {
assert(!ClassLoaderDataShared::is_full_module_graph_loaded(), "you call this function too late!");
if (!_loading_full_module_graph_disabled) {
_loading_full_module_graph_disabled = true;
if (_is_using_full_module_graph) {
_is_using_full_module_graph = false;
if (reason != nullptr) {
log_info(cds)("full module graph cannot be loaded: %s", reason);
}

@ -1,5 +1,5 @@
/*
* Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2023, 2024, 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
@ -33,12 +33,13 @@ 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;
static bool _is_using_optimized_module_handling;
static bool _is_dumping_full_module_graph;
static bool _is_using_full_module_graph;
static char* _default_archive_path;
static char* _static_archive_path;
static char* _dynamic_archive_path;
static char* _default_archive_path;
static char* _static_archive_path;
static char* _dynamic_archive_path;
#endif
static void extract_shared_archive_paths(const char* archive_path,
@ -48,38 +49,59 @@ class CDSConfig : public AllStatic {
static bool check_unsupported_cds_runtime_properties();
public:
// Used by jdk.internal.misc.CDS.getCDSConfigStatus();
static const int IS_DUMPING_ARCHIVE = 1 << 0;
static const int IS_DUMPING_STATIC_ARCHIVE = 1 << 1;
static const int IS_LOGGING_LAMBDA_FORM_INVOKERS = 1 << 2;
static const int IS_USING_ARCHIVE = 1 << 3;
static int get_status() NOT_CDS_RETURN_(0);
// Initialization and command-line checking
static void initialize() NOT_CDS_RETURN;
static void check_system_property(const char* key, const char* value) NOT_CDS_RETURN;
static void check_unsupported_dumping_properties() NOT_CDS_RETURN;
static bool check_vm_args_consistency(bool patch_mod_javabase, bool mode_flag_cmd_line) NOT_CDS_RETURN_(true);
// Basic CDS features
static bool is_dumping_archive() { return is_dumping_static_archive() || is_dumping_dynamic_archive(); }
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); }
// --- Basic CDS features
// archive(s) in general
static bool is_dumping_archive() { return is_dumping_static_archive() || is_dumping_dynamic_archive(); }
static bool is_using_archive() NOT_CDS_RETURN_(false);
static int num_archives(const char* archive_path) NOT_CDS_RETURN_(0);
// static_archive
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); }
// dynamic_archive
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); }
// Archive paths
// optimized_module_handling -- can we skip some expensive operations related to modules?
static bool is_using_optimized_module_handling() { return CDS_ONLY(_is_using_optimized_module_handling) NOT_CDS(false); }
static void stop_using_optimized_module_handling() NOT_CDS_RETURN;
static bool is_logging_lambda_form_invokers() NOT_CDS_RETURN_(false);
// archive_path
// Points to the classes.jsa in $JAVA_HOME
static char* default_archive_path() NOT_CDS_RETURN_(nullptr);
static char* default_archive_path() NOT_CDS_RETURN_(nullptr);
// The actual static archive (if any) selected at runtime
static const char* static_archive_path() { return CDS_ONLY(_static_archive_path) NOT_CDS(nullptr); }
// The actual dynamic archive (if any) selected at runtime
static const char* dynamic_archive_path() { return CDS_ONLY(_dynamic_archive_path) NOT_CDS(nullptr); }
static int num_archives(const char* archive_path) NOT_CDS_RETURN_(0);
// --- Archived java objects
static bool is_dumping_heap() NOT_CDS_JAVA_HEAP_RETURN_(false);
// CDS archived heap
static bool is_dumping_heap() NOT_CDS_JAVA_HEAP_RETURN_(false);
static void disable_dumping_full_module_graph(const char* reason = nullptr) NOT_CDS_JAVA_HEAP_RETURN;
static bool is_dumping_full_module_graph() NOT_CDS_JAVA_HEAP_RETURN_(false);
static void disable_loading_full_module_graph(const char* reason = nullptr) NOT_CDS_JAVA_HEAP_RETURN;
static bool is_loading_full_module_graph() NOT_CDS_JAVA_HEAP_RETURN_(false);
// full_module_graph (requires optimized_module_handling)
static bool is_dumping_full_module_graph() { return CDS_ONLY(_is_dumping_full_module_graph) NOT_CDS(false); }
static bool is_using_full_module_graph() NOT_CDS_JAVA_HEAP_RETURN_(false);
static void stop_dumping_full_module_graph(const char* reason = nullptr) NOT_CDS_JAVA_HEAP_RETURN;
static void stop_using_full_module_graph(const char* reason = nullptr) NOT_CDS_JAVA_HEAP_RETURN;
};
#endif // SHARE_CDS_CDSCONFIG_HPP

@ -1,5 +1,5 @@
/*
* Copyright (c) 2021, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2021, 2024, 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
@ -119,7 +119,7 @@ Handle CDSProtectionDomain::get_package_name(Symbol* class_name, TRAPS) {
PackageEntry* CDSProtectionDomain::get_package_entry_from_class(InstanceKlass* ik, Handle class_loader) {
PackageEntry* pkg_entry = ik->package();
if (CDSConfig::is_loading_full_module_graph() && ik->is_shared() && pkg_entry != nullptr) {
if (CDSConfig::is_using_full_module_graph() && ik->is_shared() && pkg_entry != nullptr) {
assert(MetaspaceShared::is_in_shared_metaspace(pkg_entry), "must be");
assert(!ik->is_shared_unregistered_class(), "unexpected archived package entry for an unregistered class");
assert(ik->module()->is_named(), "unexpected archived package entry for a class in an unnamed module");

@ -212,7 +212,7 @@ void FileMapHeader::populate(FileMapInfo *info, size_t core_region_alignment,
_compressed_oops = UseCompressedOops;
_compressed_class_ptrs = UseCompressedClassPointers;
_max_heap_size = MaxHeapSize;
_use_optimized_module_handling = MetaspaceShared::use_optimized_module_handling();
_use_optimized_module_handling = CDSConfig::is_using_optimized_module_handling();
_has_full_module_graph = CDSConfig::is_dumping_full_module_graph();
// The following fields are for sanity checks for whether this archive
@ -1977,7 +1977,7 @@ void FileMapInfo::map_or_load_heap_region() {
}
if (!success) {
CDSConfig::disable_loading_full_module_graph();
CDSConfig::stop_using_full_module_graph();
}
}
@ -2393,13 +2393,13 @@ bool FileMapHeader::validate() {
}
if (!_use_optimized_module_handling) {
MetaspaceShared::disable_optimized_module_handling();
CDSConfig::stop_using_optimized_module_handling();
log_info(cds)("optimized module handling: disabled because archive was created without optimized module handling");
}
if (is_static() && !_has_full_module_graph) {
// Only the static archive can contain the full module graph.
CDSConfig::disable_loading_full_module_graph("archive was created without full module graph");
CDSConfig::stop_using_full_module_graph("archive was created without full module graph");
}
return true;

@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2024, 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
@ -972,7 +972,7 @@ HeapShared::resolve_or_init_classes_for_subgraph_of(Klass* k, bool do_init, TRAP
}
return nullptr;
} else {
if (record->is_full_module_graph() && !CDSConfig::is_loading_full_module_graph()) {
if (record->is_full_module_graph() && !CDSConfig::is_using_full_module_graph()) {
if (log_is_enabled(Info, cds, heap)) {
ResourceMark rm(THREAD);
log_info(cds, heap)("subgraph %s cannot be used because full module graph is disabled",

@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2024, 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
@ -96,7 +96,6 @@ bool MetaspaceShared::_remapped_readwrite = false;
void* MetaspaceShared::_shared_metaspace_static_top = nullptr;
intx MetaspaceShared::_relocation_delta;
char* MetaspaceShared::_requested_base_address;
bool MetaspaceShared::_use_optimized_module_handling = true;
// The CDS archive is divided into the following regions:
// rw - read-write metadata
@ -784,7 +783,7 @@ void MetaspaceShared::preload_and_dump_impl(TRAPS) {
if (CDSConfig::is_dumping_heap()) {
if (!HeapShared::is_archived_boot_layer_available(THREAD)) {
log_info(cds)("archivedBootLayer not available, disabling full module graph");
CDSConfig::disable_dumping_full_module_graph();
CDSConfig::stop_dumping_full_module_graph();
}
HeapShared::init_for_dumping(CHECK);
ArchiveHeapWriter::init();
@ -1176,8 +1175,8 @@ MapArchiveResult MetaspaceShared::map_archives(FileMapInfo* static_mapinfo, File
static_mapinfo->map_or_load_heap_region();
}
#endif // _LP64
log_info(cds)("initial optimized module handling: %s", MetaspaceShared::use_optimized_module_handling() ? "enabled" : "disabled");
log_info(cds)("initial full module graph: %s", CDSConfig::is_loading_full_module_graph() ? "enabled" : "disabled");
log_info(cds)("initial optimized module handling: %s", CDSConfig::is_using_optimized_module_handling() ? "enabled" : "disabled");
log_info(cds)("initial full module graph: %s", CDSConfig::is_using_full_module_graph() ? "enabled" : "disabled");
} else {
unmap_archive(static_mapinfo);
unmap_archive(dynamic_mapinfo);

@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2024, 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
@ -52,7 +52,6 @@ class MetaspaceShared : AllStatic {
static void* _shared_metaspace_static_top;
static intx _relocation_delta;
static char* _requested_base_address;
static bool _use_optimized_module_handling;
public:
enum {
// core archive spaces
@ -159,10 +158,6 @@ public:
return is_windows;
}
// Can we skip some expensive operations related to modules?
static bool use_optimized_module_handling() { return NOT_CDS(false) CDS_ONLY(_use_optimized_module_handling); }
static void disable_optimized_module_handling() { _use_optimized_module_handling = false; }
private:
static void read_extra_data(JavaThread* current, const char* filename) NOT_CDS_RETURN;
static FileMapInfo* open_static_archive();

@ -1,5 +1,5 @@
/*
* Copyright (c) 2020, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2020, 2024, 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
@ -172,7 +172,7 @@ void ClassLoaderDataShared::serialize(SerializeClosure* f) {
_archived_system_loader_data.serialize(f);
f->do_ptr(&_archived_javabase_moduleEntry);
if (f->reading() && CDSConfig::is_loading_full_module_graph()) {
if (f->reading() && CDSConfig::is_using_full_module_graph()) {
// Must be done before ClassLoader::create_javabase()
_archived_boot_loader_data.restore(null_class_loader_data(), true, false);
ModuleEntryTable::set_javabase_moduleEntry(_archived_javabase_moduleEntry);
@ -182,25 +182,25 @@ void ClassLoaderDataShared::serialize(SerializeClosure* f) {
}
void ClassLoaderDataShared::clear_archived_oops() {
assert(!CDSConfig::is_loading_full_module_graph(), "must be");
assert(!CDSConfig::is_using_full_module_graph(), "must be");
_archived_boot_loader_data.clear_archived_oops();
_archived_platform_loader_data.clear_archived_oops();
_archived_system_loader_data.clear_archived_oops();
}
oop ClassLoaderDataShared::restore_archived_oops_for_null_class_loader_data() {
assert(CDSConfig::is_loading_full_module_graph(), "must be");
assert(CDSConfig::is_using_full_module_graph(), "must be");
_archived_boot_loader_data.restore(null_class_loader_data(), false, true);
return _archived_javabase_moduleEntry->module();
}
void ClassLoaderDataShared::restore_java_platform_loader_from_archive(ClassLoaderData* loader_data) {
assert(CDSConfig::is_loading_full_module_graph(), "must be");
assert(CDSConfig::is_using_full_module_graph(), "must be");
_archived_platform_loader_data.restore(loader_data, true, true);
}
void ClassLoaderDataShared::restore_java_system_loader_from_archive(ClassLoaderData* loader_data) {
assert(CDSConfig::is_loading_full_module_graph(), "must be");
assert(CDSConfig::is_using_full_module_graph(), "must be");
_archived_system_loader_data.restore(loader_data, true, true);
_full_module_graph_loaded = true;
}

@ -596,15 +596,15 @@ void Modules::serialize(SerializeClosure* soc) {
if (disable) {
log_info(cds)("Disabling optimized module handling");
MetaspaceShared::disable_optimized_module_handling();
CDSConfig::stop_using_optimized_module_handling();
}
log_info(cds)("optimized module handling: %s", MetaspaceShared::use_optimized_module_handling() ? "enabled" : "disabled");
log_info(cds)("full module graph: %s", CDSConfig::is_loading_full_module_graph() ? "enabled" : "disabled");
log_info(cds)("optimized module handling: %s", CDSConfig::is_using_optimized_module_handling() ? "enabled" : "disabled");
log_info(cds)("full module graph: %s", CDSConfig::is_using_full_module_graph() ? "enabled" : "disabled");
}
}
void Modules::define_archived_modules(Handle h_platform_loader, Handle h_system_loader, TRAPS) {
assert(CDSConfig::is_loading_full_module_graph(), "must be");
assert(CDSConfig::is_using_full_module_graph(), "must be");
// We don't want the classes used by the archived full module graph to be redefined by JVMTI.
// Luckily, such classes are loaded in the JVMTI "early" phase, and CDS is disabled if a JVMTI

@ -140,7 +140,7 @@ void SystemDictionary::compute_java_loaders(TRAPS) {
} else {
// It must have been restored from the archived module graph
assert(UseSharedSpaces, "must be");
assert(CDSConfig::is_loading_full_module_graph(), "must be");
assert(CDSConfig::is_using_full_module_graph(), "must be");
DEBUG_ONLY(
oop system_loader = get_system_class_loader_impl(CHECK);
assert(_java_system_loader.resolve() == system_loader, "must be");
@ -153,7 +153,7 @@ void SystemDictionary::compute_java_loaders(TRAPS) {
} else {
// It must have been restored from the archived module graph
assert(UseSharedSpaces, "must be");
assert(CDSConfig::is_loading_full_module_graph(), "must be");
assert(CDSConfig::is_using_full_module_graph(), "must be");
DEBUG_ONLY(
oop platform_loader = get_platform_class_loader_impl(CHECK);
assert(_java_platform_loader.resolve() == platform_loader, "must be");
@ -965,7 +965,7 @@ bool SystemDictionary::is_shared_class_visible(Symbol* class_name,
// (2) Check if we are loading into the same module from the same location as in dump time.
if (MetaspaceShared::use_optimized_module_handling()) {
if (CDSConfig::is_using_optimized_module_handling()) {
// Class visibility has not changed between dump time and run time, so a class
// that was visible (and thus archived) during dump time is always visible during runtime.
assert(SystemDictionary::is_shared_class_visible_impl(class_name, ik, pkg_entry, class_loader),

@ -197,14 +197,8 @@ JVM_LookupLambdaProxyClassFromArchive(JNIEnv* env, jclass caller,
jobject implementationMember,
jobject dynamicMethodType);
JNIEXPORT jboolean JNICALL
JVM_IsCDSDumpingEnabled(JNIEnv* env);
JNIEXPORT jboolean JNICALL
JVM_IsSharingEnabled(JNIEnv* env);
JNIEXPORT jboolean JNICALL
JVM_IsDumpingClassList(JNIEnv* env);
JNIEXPORT jint JNICALL
JVM_GetCDSConfigStatus();
JNIEXPORT jlong JNICALL
JVM_GetRandomSeedForDumping();

@ -2704,7 +2704,7 @@ void InstanceKlass::init_shared_package_entry() {
_package_entry = PackageEntry::get_archived_entry(_package_entry);
}
} else if (CDSConfig::is_dumping_dynamic_archive() &&
CDSConfig::is_loading_full_module_graph() &&
CDSConfig::is_using_full_module_graph() &&
MetaspaceShared::is_in_shared_metaspace(_package_entry)) {
// _package_entry is an archived package in the base archive. Leave it as is.
} else {
@ -3030,7 +3030,7 @@ void InstanceKlass::set_package(ClassLoaderData* loader_data, PackageEntry* pkg_
}
if (is_shared() && _package_entry != nullptr) {
if (CDSConfig::is_loading_full_module_graph() && _package_entry == pkg_entry) {
if (CDSConfig::is_using_full_module_graph() && _package_entry == pkg_entry) {
// we can use the saved package
assert(MetaspaceShared::is_in_shared_metaspace(_package_entry), "must be");
return;

@ -3688,14 +3688,6 @@ JVM_ENTRY(jclass, JVM_LookupLambdaProxyClassFromArchive(JNIEnv* env,
#endif // INCLUDE_CDS
JVM_END
JVM_LEAF(jboolean, JVM_IsCDSDumpingEnabled(JNIEnv* env))
return CDSConfig::is_dumping_archive();
JVM_END
JVM_LEAF(jboolean, JVM_IsSharingEnabled(JNIEnv* env))
return UseSharedSpaces;
JVM_END
JVM_ENTRY_NO_ENV(jlong, JVM_GetRandomSeedForDumping())
if (CDSConfig::is_dumping_static_archive()) {
// We do this so that the default CDS archive can be deterministic.
@ -3719,17 +3711,13 @@ JVM_ENTRY_NO_ENV(jlong, JVM_GetRandomSeedForDumping())
}
JVM_END
JVM_LEAF(jboolean, JVM_IsDumpingClassList(JNIEnv *env))
#if INCLUDE_CDS
return ClassListWriter::is_enabled() || CDSConfig::is_dumping_dynamic_archive();
#else
return false;
#endif // INCLUDE_CDS
JVM_ENTRY_NO_ENV(jint, JVM_GetCDSConfigStatus())
return CDSConfig::get_status();
JVM_END
JVM_ENTRY(void, JVM_LogLambdaFormInvoker(JNIEnv *env, jstring line))
#if INCLUDE_CDS
assert(ClassListWriter::is_enabled() || CDSConfig::is_dumping_dynamic_archive(), "Should be set and open or do dynamic dump");
assert(CDSConfig::is_logging_lambda_form_invokers(), "sanity");
if (line != nullptr) {
ResourceMark rm(THREAD);
Handle h_line (THREAD, JNIHandles::resolve_non_null(line));

@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2024, 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
@ -255,7 +255,7 @@ import static jdk.internal.org.objectweb.asm.Opcodes.*;
private Class<?> spinInnerClass() throws LambdaConversionException {
// CDS does not handle disableEagerInitialization or useImplMethodHandle
if (!disableEagerInitialization && !useImplMethodHandle) {
if (CDS.isSharingEnabled()) {
if (CDS.isUsingArchive()) {
// load from CDS archive if present
Class<?> innerClass = LambdaProxyClassArchive.find(targetClass,
interfaceMethodName,

@ -1,5 +1,5 @@
/*
* Copyright (c) 2020, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2020, 2024, 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
@ -102,7 +102,7 @@ final class LambdaProxyClassArchive {
Class<?>[] altInterfaces,
MethodType[] altMethods) {
if (!loadedByBuiltinLoader(caller) ||
!CDS.isSharingEnabled() || isSerializable || altInterfaces.length > 0 || altMethods.length > 0)
!CDS.isUsingArchive() || isSerializable || altInterfaces.length > 0 || altMethods.length > 0)
return null;
return findFromArchive(caller, interfaceMethodName, factoryType, interfaceMethodType,

@ -1,5 +1,5 @@
/*
* Copyright (c) 2011, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2011, 2024, 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
@ -134,8 +134,8 @@ class MethodHandleStatics {
shortenSignature(basicTypeSignature(type)) +
(resolvedMember != null ? " (success)" : " (fail)"));
}
if (CDS.isDumpingClassList()) {
CDS.traceLambdaFormInvoker("[LF_RESOLVE]", holder.getName(), name, shortenSignature(basicTypeSignature(type)));
if (CDS.isLoggingLambdaFormInvokers()) {
CDS.logLambdaFormInvoker("[LF_RESOLVE]", holder.getName(), name, shortenSignature(basicTypeSignature(type)));
}
}
@ -148,8 +148,8 @@ class MethodHandleStatics {
if (TRACE_RESOLVE) {
System.out.println("[SPECIES_RESOLVE] " + cn + (salvage != null ? " (salvaged)" : " (generated)"));
}
if (CDS.isDumpingClassList()) {
CDS.traceSpeciesType("[SPECIES_RESOLVE]", cn);
if (CDS.isLoggingLambdaFormInvokers()) {
CDS.logSpeciesType("[SPECIES_RESOLVE]", cn);
}
}
// handy shared exception makers (they simplify the common case code)

@ -1,5 +1,5 @@
/*
* Copyright (c) 2020, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2020, 2024, 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
@ -41,48 +41,42 @@ import java.util.stream.Stream;
import jdk.internal.access.SharedSecrets;
public class CDS {
private static final boolean isDumpingClassList;
private static final boolean isDumpingArchive;
private static final boolean isSharingEnabled;
private static final boolean isDumpingStaticArchive;
static {
isDumpingClassList = isDumpingClassList0();
isDumpingArchive = isDumpingArchive0();
isSharingEnabled = isSharingEnabled0();
isDumpingStaticArchive = isDumpingArchive && !isSharingEnabled;
}
// Must be in sync with cdsConfig.hpp
private static final int IS_DUMPING_ARCHIVE = 1 << 0;
private static final int IS_DUMPING_STATIC_ARCHIVE = 1 << 1;
private static final int IS_LOGGING_LAMBDA_FORM_INVOKERS = 1 << 2;
private static final int IS_USING_ARCHIVE = 1 << 3;
private static final int configStatus = getCDSConfigStatus();
/**
* indicator for dumping class list.
*/
public static boolean isDumpingClassList() {
return isDumpingClassList;
* Should we log the use of lambda form invokers?
*/
public static boolean isLoggingLambdaFormInvokers() {
return (configStatus & IS_LOGGING_LAMBDA_FORM_INVOKERS) != 0;
}
/**
* Is the VM writing to a (static or dynamic) CDS archive.
*/
public static boolean isDumpingArchive() {
return isDumpingArchive;
return (configStatus & IS_DUMPING_ARCHIVE) != 0;
}
/**
* Is sharing enabled.
* Is the VM using at least one CDS archive?
*/
public static boolean isSharingEnabled() {
return isSharingEnabled;
public static boolean isUsingArchive() {
return (configStatus & IS_USING_ARCHIVE) != 0;
}
/**
* Is dumping static archive.
*/
public static boolean isDumpingStaticArchive() {
return isDumpingStaticArchive;
return (configStatus & IS_DUMPING_STATIC_ARCHIVE) != 0;
}
private static native boolean isDumpingClassList0();
private static native boolean isDumpingArchive0();
private static native boolean isSharingEnabled0();
private static native int getCDSConfigStatus();
private static native void logLambdaFormInvoker(String line);
/**
@ -112,8 +106,8 @@ public class CDS {
/**
* log lambda form invoker holder, name and method type
*/
public static void traceLambdaFormInvoker(String prefix, String holder, String name, String type) {
if (isDumpingClassList) {
public static void logLambdaFormInvoker(String prefix, String holder, String name, String type) {
if (isLoggingLambdaFormInvokers()) {
logLambdaFormInvoker(prefix + " " + holder + " " + name + " " + type);
}
}
@ -121,8 +115,8 @@ public class CDS {
/**
* log species
*/
public static void traceSpeciesType(String prefix, String cn) {
if (isDumpingClassList) {
public static void logSpeciesType(String prefix, String cn) {
if (isLoggingLambdaFormInvokers()) {
logLambdaFormInvoker(prefix + " " + cn);
}
}

@ -1,5 +1,5 @@
/*
* Copyright (c) 2020, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2020, 2024, 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
@ -44,19 +44,9 @@ Java_jdk_internal_misc_CDS_getRandomSeedForDumping(JNIEnv *env, jclass ignore) {
return JVM_GetRandomSeedForDumping();
}
JNIEXPORT jboolean JNICALL
Java_jdk_internal_misc_CDS_isDumpingArchive0(JNIEnv *env, jclass jcls) {
return JVM_IsCDSDumpingEnabled(env);
}
JNIEXPORT jboolean JNICALL
Java_jdk_internal_misc_CDS_isSharingEnabled0(JNIEnv *env, jclass jcls) {
return JVM_IsSharingEnabled(env);
}
JNIEXPORT jboolean JNICALL
Java_jdk_internal_misc_CDS_isDumpingClassList0(JNIEnv *env, jclass jcls) {
return JVM_IsDumpingClassList(env);
JNIEXPORT jint JNICALL
Java_jdk_internal_misc_CDS_getCDSConfigStatus(JNIEnv *env, jclass jcls) {
return JVM_GetCDSConfigStatus();
}
JNIEXPORT void JNICALL