Skip to content

Commit 761ed25

Browse files
committed
8327138: Clean up status management in cdsConfig.hpp and CDS.java
Reviewed-by: ccheung, matsaave
1 parent 53628f2 commit 761ed25

File tree

19 files changed

+161
-161
lines changed

19 files changed

+161
-161
lines changed

src/hotspot/share/cds/archiveHeapLoader.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -88,7 +88,7 @@ void ArchiveHeapLoader::fixup_region() {
8888
fill_failed_loaded_heap();
8989
}
9090
if (is_in_use()) {
91-
if (!CDSConfig::is_loading_full_module_graph()) {
91+
if (!CDSConfig::is_using_full_module_graph()) {
9292
// Need to remove all the archived java.lang.Module objects from HeapShared::roots().
9393
ClassLoaderDataShared::clear_archived_oops();
9494
}

src/hotspot/share/cds/cdsConfig.cpp

Lines changed: 48 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2023, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -25,28 +25,36 @@
2525
#include "precompiled.hpp"
2626
#include "cds/archiveHeapLoader.hpp"
2727
#include "cds/cdsConfig.hpp"
28+
#include "cds/classListWriter.hpp"
2829
#include "cds/heapShared.hpp"
2930
#include "classfile/classLoaderDataShared.hpp"
3031
#include "classfile/moduleEntry.hpp"
3132
#include "include/jvm_io.h"
3233
#include "logging/log.hpp"
34+
#include "memory/universe.hpp"
3335
#include "runtime/arguments.hpp"
3436
#include "runtime/java.hpp"
3537
#include "utilities/defaultStream.hpp"
3638

3739
bool CDSConfig::_is_dumping_static_archive = false;
3840
bool CDSConfig::_is_dumping_dynamic_archive = false;
39-
40-
// The ability to dump the FMG depends on many factors checked by
41-
// is_dumping_full_module_graph(), but can be unconditionally disabled by
42-
// _dumping_full_module_graph_disabled. (Ditto for loading the FMG).
43-
bool CDSConfig::_dumping_full_module_graph_disabled = false;
44-
bool CDSConfig::_loading_full_module_graph_disabled = false;
41+
bool CDSConfig::_is_using_optimized_module_handling = true;
42+
bool CDSConfig::_is_dumping_full_module_graph = true;
43+
bool CDSConfig::_is_using_full_module_graph = true;
4544

4645
char* CDSConfig::_default_archive_path = nullptr;
4746
char* CDSConfig::_static_archive_path = nullptr;
4847
char* CDSConfig::_dynamic_archive_path = nullptr;
4948

49+
int CDSConfig::get_status() {
50+
assert(Universe::is_fully_initialized(), "status is finalized only after Universe is initialized");
51+
return (is_dumping_archive() ? IS_DUMPING_ARCHIVE : 0) |
52+
(is_dumping_static_archive() ? IS_DUMPING_STATIC_ARCHIVE : 0) |
53+
(is_logging_lambda_form_invokers() ? IS_LOGGING_LAMBDA_FORM_INVOKERS : 0) |
54+
(is_using_archive() ? IS_USING_ARCHIVE : 0);
55+
}
56+
57+
5058
void CDSConfig::initialize() {
5159
if (is_dumping_static_archive()) {
5260
if (RequireSharedSpaces) {
@@ -62,6 +70,10 @@ void CDSConfig::initialize() {
6270
if (is_dumping_static_archive() || UseSharedSpaces) {
6371
init_shared_archive_paths();
6472
}
73+
74+
if (!is_dumping_heap()) {
75+
_is_dumping_full_module_graph = false;
76+
}
6577
}
6678

6779
char* CDSConfig::default_archive_path() {
@@ -225,14 +237,14 @@ void CDSConfig::init_shared_archive_paths() {
225237

226238
void CDSConfig::check_system_property(const char* key, const char* value) {
227239
if (Arguments::is_internal_module_property(key)) {
228-
MetaspaceShared::disable_optimized_module_handling();
240+
stop_using_optimized_module_handling();
229241
log_info(cds)("optimized module handling: disabled due to incompatible property: %s=%s", key, value);
230242
}
231243
if (strcmp(key, "jdk.module.showModuleResolution") == 0 ||
232244
strcmp(key, "jdk.module.validation") == 0 ||
233245
strcmp(key, "java.system.class.loader") == 0) {
234-
disable_loading_full_module_graph();
235-
disable_dumping_full_module_graph();
246+
stop_dumping_full_module_graph();
247+
stop_using_full_module_graph();
236248
log_info(cds)("full module graph: disabled due to incompatible property: %s=%s", key, value);
237249
}
238250
}
@@ -355,53 +367,59 @@ bool CDSConfig::check_vm_args_consistency(bool patch_mod_javabase, bool mode_fl
355367
return true;
356368
}
357369

370+
bool CDSConfig::is_using_archive() {
371+
return UseSharedSpaces; // TODO: UseSharedSpaces will be eventually replaced by CDSConfig::is_using_archive()
372+
}
373+
374+
bool CDSConfig::is_logging_lambda_form_invokers() {
375+
return ClassListWriter::is_enabled() || is_dumping_dynamic_archive();
376+
}
377+
378+
void CDSConfig::stop_using_optimized_module_handling() {
379+
_is_using_optimized_module_handling = false;
380+
_is_dumping_full_module_graph = false; // This requires is_using_optimized_module_handling()
381+
_is_using_full_module_graph = false; // This requires is_using_optimized_module_handling()
382+
}
383+
358384
#if INCLUDE_CDS_JAVA_HEAP
359385
bool CDSConfig::is_dumping_heap() {
360386
// heap dump is not supported in dynamic dump
361387
return is_dumping_static_archive() && HeapShared::can_write();
362388
}
363389

364-
bool CDSConfig::is_dumping_full_module_graph() {
365-
if (!_dumping_full_module_graph_disabled &&
366-
is_dumping_heap() &&
367-
MetaspaceShared::use_optimized_module_handling()) {
390+
bool CDSConfig::is_using_full_module_graph() {
391+
if (ClassLoaderDataShared::is_full_module_graph_loaded()) {
368392
return true;
369-
} else {
370-
return false;
371393
}
372-
}
373394

374-
bool CDSConfig::is_loading_full_module_graph() {
375-
if (ClassLoaderDataShared::is_full_module_graph_loaded()) {
376-
return true;
395+
if (!_is_using_full_module_graph) {
396+
return false;
377397
}
378398

379-
if (!_loading_full_module_graph_disabled &&
380-
UseSharedSpaces &&
381-
ArchiveHeapLoader::can_use() &&
382-
MetaspaceShared::use_optimized_module_handling()) {
399+
if (UseSharedSpaces && ArchiveHeapLoader::can_use()) {
383400
// Classes used by the archived full module graph are loaded in JVMTI early phase.
384401
assert(!(JvmtiExport::should_post_class_file_load_hook() && JvmtiExport::has_early_class_hook_env()),
385402
"CDS should be disabled if early class hooks are enabled");
386403
return true;
387404
} else {
405+
_is_using_full_module_graph = false;
388406
return false;
389407
}
390408
}
391409

392-
void CDSConfig::disable_dumping_full_module_graph(const char* reason) {
393-
if (!_dumping_full_module_graph_disabled) {
394-
_dumping_full_module_graph_disabled = true;
410+
void CDSConfig::stop_dumping_full_module_graph(const char* reason) {
411+
if (_is_dumping_full_module_graph) {
412+
_is_dumping_full_module_graph = false;
395413
if (reason != nullptr) {
396414
log_info(cds)("full module graph cannot be dumped: %s", reason);
397415
}
398416
}
399417
}
400418

401-
void CDSConfig::disable_loading_full_module_graph(const char* reason) {
419+
void CDSConfig::stop_using_full_module_graph(const char* reason) {
402420
assert(!ClassLoaderDataShared::is_full_module_graph_loaded(), "you call this function too late!");
403-
if (!_loading_full_module_graph_disabled) {
404-
_loading_full_module_graph_disabled = true;
421+
if (_is_using_full_module_graph) {
422+
_is_using_full_module_graph = false;
405423
if (reason != nullptr) {
406424
log_info(cds)("full module graph cannot be loaded: %s", reason);
407425
}

src/hotspot/share/cds/cdsConfig.hpp

Lines changed: 44 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2023, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -33,12 +33,13 @@ class CDSConfig : public AllStatic {
3333
#if INCLUDE_CDS
3434
static bool _is_dumping_static_archive;
3535
static bool _is_dumping_dynamic_archive;
36-
static bool _dumping_full_module_graph_disabled;
37-
static bool _loading_full_module_graph_disabled;
36+
static bool _is_using_optimized_module_handling;
37+
static bool _is_dumping_full_module_graph;
38+
static bool _is_using_full_module_graph;
3839

39-
static char* _default_archive_path;
40-
static char* _static_archive_path;
41-
static char* _dynamic_archive_path;
40+
static char* _default_archive_path;
41+
static char* _static_archive_path;
42+
static char* _dynamic_archive_path;
4243
#endif
4344

4445
static void extract_shared_archive_paths(const char* archive_path,
@@ -48,38 +49,59 @@ class CDSConfig : public AllStatic {
4849
static bool check_unsupported_cds_runtime_properties();
4950

5051
public:
52+
// Used by jdk.internal.misc.CDS.getCDSConfigStatus();
53+
static const int IS_DUMPING_ARCHIVE = 1 << 0;
54+
static const int IS_DUMPING_STATIC_ARCHIVE = 1 << 1;
55+
static const int IS_LOGGING_LAMBDA_FORM_INVOKERS = 1 << 2;
56+
static const int IS_USING_ARCHIVE = 1 << 3;
57+
static int get_status() NOT_CDS_RETURN_(0);
58+
5159
// Initialization and command-line checking
5260
static void initialize() NOT_CDS_RETURN;
5361
static void check_system_property(const char* key, const char* value) NOT_CDS_RETURN;
5462
static void check_unsupported_dumping_properties() NOT_CDS_RETURN;
5563
static bool check_vm_args_consistency(bool patch_mod_javabase, bool mode_flag_cmd_line) NOT_CDS_RETURN_(true);
5664

57-
// Basic CDS features
58-
static bool is_dumping_archive() { return is_dumping_static_archive() || is_dumping_dynamic_archive(); }
59-
static bool is_dumping_static_archive() { return CDS_ONLY(_is_dumping_static_archive) NOT_CDS(false); }
60-
static void enable_dumping_static_archive() { CDS_ONLY(_is_dumping_static_archive = true); }
61-
static bool is_dumping_dynamic_archive() { return CDS_ONLY(_is_dumping_dynamic_archive) NOT_CDS(false); }
62-
static void enable_dumping_dynamic_archive() { CDS_ONLY(_is_dumping_dynamic_archive = true); }
65+
// --- Basic CDS features
66+
67+
// archive(s) in general
68+
static bool is_dumping_archive() { return is_dumping_static_archive() || is_dumping_dynamic_archive(); }
69+
static bool is_using_archive() NOT_CDS_RETURN_(false);
70+
static int num_archives(const char* archive_path) NOT_CDS_RETURN_(0);
71+
72+
// static_archive
73+
static bool is_dumping_static_archive() { return CDS_ONLY(_is_dumping_static_archive) NOT_CDS(false); }
74+
static void enable_dumping_static_archive() { CDS_ONLY(_is_dumping_static_archive = true); }
75+
76+
// dynamic_archive
77+
static bool is_dumping_dynamic_archive() { return CDS_ONLY(_is_dumping_dynamic_archive) NOT_CDS(false); }
78+
static void enable_dumping_dynamic_archive() { CDS_ONLY(_is_dumping_dynamic_archive = true); }
6379
static void disable_dumping_dynamic_archive() { CDS_ONLY(_is_dumping_dynamic_archive = false); }
6480

65-
// Archive paths
81+
// optimized_module_handling -- can we skip some expensive operations related to modules?
82+
static bool is_using_optimized_module_handling() { return CDS_ONLY(_is_using_optimized_module_handling) NOT_CDS(false); }
83+
static void stop_using_optimized_module_handling() NOT_CDS_RETURN;
84+
85+
static bool is_logging_lambda_form_invokers() NOT_CDS_RETURN_(false);
86+
87+
// archive_path
88+
6689
// Points to the classes.jsa in $JAVA_HOME
67-
static char* default_archive_path() NOT_CDS_RETURN_(nullptr);
90+
static char* default_archive_path() NOT_CDS_RETURN_(nullptr);
6891
// The actual static archive (if any) selected at runtime
6992
static const char* static_archive_path() { return CDS_ONLY(_static_archive_path) NOT_CDS(nullptr); }
7093
// The actual dynamic archive (if any) selected at runtime
7194
static const char* dynamic_archive_path() { return CDS_ONLY(_dynamic_archive_path) NOT_CDS(nullptr); }
7295

73-
static int num_archives(const char* archive_path) NOT_CDS_RETURN_(0);
74-
96+
// --- Archived java objects
7597

76-
// CDS archived heap
77-
static bool is_dumping_heap() NOT_CDS_JAVA_HEAP_RETURN_(false);
78-
static void disable_dumping_full_module_graph(const char* reason = nullptr) NOT_CDS_JAVA_HEAP_RETURN;
79-
static bool is_dumping_full_module_graph() NOT_CDS_JAVA_HEAP_RETURN_(false);
80-
static void disable_loading_full_module_graph(const char* reason = nullptr) NOT_CDS_JAVA_HEAP_RETURN;
81-
static bool is_loading_full_module_graph() NOT_CDS_JAVA_HEAP_RETURN_(false);
98+
static bool is_dumping_heap() NOT_CDS_JAVA_HEAP_RETURN_(false);
8299

100+
// full_module_graph (requires optimized_module_handling)
101+
static bool is_dumping_full_module_graph() { return CDS_ONLY(_is_dumping_full_module_graph) NOT_CDS(false); }
102+
static bool is_using_full_module_graph() NOT_CDS_JAVA_HEAP_RETURN_(false);
103+
static void stop_dumping_full_module_graph(const char* reason = nullptr) NOT_CDS_JAVA_HEAP_RETURN;
104+
static void stop_using_full_module_graph(const char* reason = nullptr) NOT_CDS_JAVA_HEAP_RETURN;
83105
};
84106

85107
#endif // SHARE_CDS_CDSCONFIG_HPP

src/hotspot/share/cds/cdsProtectionDomain.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2021, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2021, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* 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) {
119119

120120
PackageEntry* CDSProtectionDomain::get_package_entry_from_class(InstanceKlass* ik, Handle class_loader) {
121121
PackageEntry* pkg_entry = ik->package();
122-
if (CDSConfig::is_loading_full_module_graph() && ik->is_shared() && pkg_entry != nullptr) {
122+
if (CDSConfig::is_using_full_module_graph() && ik->is_shared() && pkg_entry != nullptr) {
123123
assert(MetaspaceShared::is_in_shared_metaspace(pkg_entry), "must be");
124124
assert(!ik->is_shared_unregistered_class(), "unexpected archived package entry for an unregistered class");
125125
assert(ik->module()->is_named(), "unexpected archived package entry for a class in an unnamed module");

src/hotspot/share/cds/filemap.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ void FileMapHeader::populate(FileMapInfo *info, size_t core_region_alignment,
212212
_compressed_oops = UseCompressedOops;
213213
_compressed_class_ptrs = UseCompressedClassPointers;
214214
_max_heap_size = MaxHeapSize;
215-
_use_optimized_module_handling = MetaspaceShared::use_optimized_module_handling();
215+
_use_optimized_module_handling = CDSConfig::is_using_optimized_module_handling();
216216
_has_full_module_graph = CDSConfig::is_dumping_full_module_graph();
217217

218218
// The following fields are for sanity checks for whether this archive
@@ -1977,7 +1977,7 @@ void FileMapInfo::map_or_load_heap_region() {
19771977
}
19781978

19791979
if (!success) {
1980-
CDSConfig::disable_loading_full_module_graph();
1980+
CDSConfig::stop_using_full_module_graph();
19811981
}
19821982
}
19831983

@@ -2393,13 +2393,13 @@ bool FileMapHeader::validate() {
23932393
}
23942394

23952395
if (!_use_optimized_module_handling) {
2396-
MetaspaceShared::disable_optimized_module_handling();
2396+
CDSConfig::stop_using_optimized_module_handling();
23972397
log_info(cds)("optimized module handling: disabled because archive was created without optimized module handling");
23982398
}
23992399

24002400
if (is_static() && !_has_full_module_graph) {
24012401
// Only the static archive can contain the full module graph.
2402-
CDSConfig::disable_loading_full_module_graph("archive was created without full module graph");
2402+
CDSConfig::stop_using_full_module_graph("archive was created without full module graph");
24032403
}
24042404

24052405
return true;

src/hotspot/share/cds/heapShared.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* 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
972972
}
973973
return nullptr;
974974
} else {
975-
if (record->is_full_module_graph() && !CDSConfig::is_loading_full_module_graph()) {
975+
if (record->is_full_module_graph() && !CDSConfig::is_using_full_module_graph()) {
976976
if (log_is_enabled(Info, cds, heap)) {
977977
ResourceMark rm(THREAD);
978978
log_info(cds, heap)("subgraph %s cannot be used because full module graph is disabled",

src/hotspot/share/cds/metaspaceShared.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2012, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2012, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -96,7 +96,6 @@ bool MetaspaceShared::_remapped_readwrite = false;
9696
void* MetaspaceShared::_shared_metaspace_static_top = nullptr;
9797
intx MetaspaceShared::_relocation_delta;
9898
char* MetaspaceShared::_requested_base_address;
99-
bool MetaspaceShared::_use_optimized_module_handling = true;
10099

101100
// The CDS archive is divided into the following regions:
102101
// rw - read-write metadata
@@ -784,7 +783,7 @@ void MetaspaceShared::preload_and_dump_impl(TRAPS) {
784783
if (CDSConfig::is_dumping_heap()) {
785784
if (!HeapShared::is_archived_boot_layer_available(THREAD)) {
786785
log_info(cds)("archivedBootLayer not available, disabling full module graph");
787-
CDSConfig::disable_dumping_full_module_graph();
786+
CDSConfig::stop_dumping_full_module_graph();
788787
}
789788
HeapShared::init_for_dumping(CHECK);
790789
ArchiveHeapWriter::init();
@@ -1176,8 +1175,8 @@ MapArchiveResult MetaspaceShared::map_archives(FileMapInfo* static_mapinfo, File
11761175
static_mapinfo->map_or_load_heap_region();
11771176
}
11781177
#endif // _LP64
1179-
log_info(cds)("initial optimized module handling: %s", MetaspaceShared::use_optimized_module_handling() ? "enabled" : "disabled");
1180-
log_info(cds)("initial full module graph: %s", CDSConfig::is_loading_full_module_graph() ? "enabled" : "disabled");
1178+
log_info(cds)("initial optimized module handling: %s", CDSConfig::is_using_optimized_module_handling() ? "enabled" : "disabled");
1179+
log_info(cds)("initial full module graph: %s", CDSConfig::is_using_full_module_graph() ? "enabled" : "disabled");
11811180
} else {
11821181
unmap_archive(static_mapinfo);
11831182
unmap_archive(dynamic_mapinfo);

0 commit comments

Comments
 (0)