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
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
3739bool CDSConfig::_is_dumping_static_archive = false ;
3840bool 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
4645char * CDSConfig::_default_archive_path = nullptr ;
4746char * CDSConfig::_static_archive_path = nullptr ;
4847char * 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+
5058void 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
6779char * CDSConfig::default_archive_path () {
@@ -225,14 +237,14 @@ void CDSConfig::init_shared_archive_paths() {
225237
226238void 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
359385bool 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 }
0 commit comments