Skip to content

Commit

Permalink
8327138: Clean up status management in cdsConfig.hpp and CDS.java
Browse files Browse the repository at this point in the history
Reviewed-by: ccheung, matsaave
  • Loading branch information
iklam committed Mar 9, 2024
1 parent 53628f2 commit 761ed25
Show file tree
Hide file tree
Showing 19 changed files with 161 additions and 161 deletions.
4 changes: 2 additions & 2 deletions src/hotspot/share/cds/archiveHeapLoader.cpp
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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();
}
Expand Down
78 changes: 48 additions & 30 deletions src/hotspot/share/cds/cdsConfig.cpp
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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) {
Expand All @@ -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() {
Expand Down Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -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()) {
bool CDSConfig::is_using_full_module_graph() {
if (ClassLoaderDataShared::is_full_module_graph_loaded()) {
return true;
} else {
return false;
}
}

bool CDSConfig::is_loading_full_module_graph() {
if (ClassLoaderDataShared::is_full_module_graph_loaded()) {
return true;
if (!_is_using_full_module_graph) {
return false;
}

if (!_loading_full_module_graph_disabled &&
UseSharedSpaces &&
ArchiveHeapLoader::can_use() &&
MetaspaceShared::use_optimized_module_handling()) {
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);
}
Expand Down
66 changes: 44 additions & 22 deletions src/hotspot/share/cds/cdsConfig.hpp
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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

// 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);
static bool is_dumping_heap() 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
4 changes: 2 additions & 2 deletions src/hotspot/share/cds/cdsProtectionDomain.cpp
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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");
Expand Down
8 changes: 4 additions & 4 deletions src/hotspot/share/cds/filemap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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();
}
}

Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/hotspot/share/cds/heapShared.cpp
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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",
Expand Down
9 changes: 4 additions & 5 deletions src/hotspot/share/cds/metaspaceShared.cpp
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand Down
Loading

1 comment on commit 761ed25

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.