1 /* 2 * Copyright (c) 2023, 2024, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 * 23 */ 24 25 #ifndef SHARE_CDS_CDSCONFIG_HPP 26 #define SHARE_CDS_CDSCONFIG_HPP 27 28 #include "memory/allStatic.hpp" 29 #include "utilities/globalDefinitions.hpp" 30 #include "utilities/macros.hpp" 31 32 class InstanceKlass; 33 class JavaThread; 34 35 class CDSConfig : public AllStatic { 36 #if INCLUDE_CDS 37 static bool _is_dumping_static_archive; 38 static bool _is_dumping_dynamic_archive; 39 static bool _is_using_optimized_module_handling; 40 static bool _is_dumping_full_module_graph; 41 static bool _is_using_full_module_graph; 42 static bool _has_aot_linked_classes; 43 static bool _has_archived_invokedynamic; 44 static bool _is_loading_packages; 45 static bool _is_loading_protection_domains; 46 static bool _is_security_manager_allowed; 47 48 static char* _default_archive_path; 49 static char* _static_archive_path; 50 static char* _dynamic_archive_path; 51 52 static bool _old_cds_flags_used; 53 54 static JavaThread* _dumper_thread; 55 #endif 56 57 static void extract_shared_archive_paths(const char* archive_path, 58 char** base_archive_path, 59 char** top_archive_path); 60 static void init_shared_archive_paths(); 61 62 static void check_flag_alias(bool alias_is_default, const char* alias_name); 63 static void check_flag_aliases(); 64 65 public: 66 // Used by jdk.internal.misc.CDS.getCDSConfigStatus(); 67 static const int IS_DUMPING_ARCHIVE = 1 << 0; 68 static const int IS_DUMPING_STATIC_ARCHIVE = 1 << 1; 69 static const int IS_LOGGING_LAMBDA_FORM_INVOKERS = 1 << 2; 70 static const int IS_USING_ARCHIVE = 1 << 3; 71 static const int IS_DUMPING_HEAP = 1 << 4; 72 static const int IS_LOGGING_DYNAMIC_PROXIES = 1 << 5; 73 static const int IS_DUMPING_PACKAGES = 1 << 6; 74 static const int IS_DUMPING_PROTECTION_DOMAINS = 1 << 7; 75 static int get_status() NOT_CDS_RETURN_(0); 76 77 // Initialization and command-line checking 78 static void initialize() NOT_CDS_RETURN; 79 static void set_old_cds_flags_used() { CDS_ONLY(_old_cds_flags_used = true); } 80 static bool old_cds_flags_used() { return CDS_ONLY(_old_cds_flags_used) NOT_CDS(false); } 81 static void check_internal_module_property(const char* key, const char* value) NOT_CDS_RETURN; 82 static void check_incompatible_property(const char* key, const char* value) NOT_CDS_RETURN; 83 static void check_unsupported_dumping_module_options() NOT_CDS_RETURN; 84 static bool has_unsupported_runtime_module_options() NOT_CDS_RETURN_(false); 85 static bool check_vm_args_consistency(bool patch_mod_javabase, bool mode_flag_cmd_line, bool xshare_auto_cmd_line) NOT_CDS_RETURN_(true); 86 87 // --- Basic CDS features 88 89 // archive(s) in general 90 static bool is_dumping_archive() { return is_dumping_static_archive() || is_dumping_dynamic_archive(); } 91 static bool is_using_archive() NOT_CDS_RETURN_(false); 92 static int num_archives(const char* archive_path) NOT_CDS_RETURN_(0); 93 94 // static_archive 95 static bool is_dumping_static_archive() { return (CDS_ONLY(_is_dumping_static_archive) NOT_CDS(false)) 96 || is_dumping_final_static_archive(); } 97 static void enable_dumping_static_archive() { CDS_ONLY(_is_dumping_static_archive = true); } 98 99 static bool is_dumping_classic_static_archive() NOT_CDS_RETURN_(false); // -Xshare:dump 100 static bool is_dumping_preimage_static_archive() NOT_CDS_RETURN_(false); // 1st phase of -XX:CacheDataStore dumping 101 static bool is_dumping_preimage_static_archive_with_triggers() NOT_CDS_RETURN_(false); // 1st phase of -XX:CacheDataStore dumping with triggers 102 static bool is_dumping_final_static_archive() NOT_CDS_RETURN_(false); // 2nd phase of -XX:CacheDataStore dumping 103 104 // dynamic_archive 105 static bool is_dumping_dynamic_archive() { return CDS_ONLY(_is_dumping_dynamic_archive) NOT_CDS(false); } 106 static void enable_dumping_dynamic_archive() { CDS_ONLY(_is_dumping_dynamic_archive = true); } 107 static void disable_dumping_dynamic_archive() { CDS_ONLY(_is_dumping_dynamic_archive = false); } 108 109 // Misc CDS features 110 static bool preserve_all_dumptime_verification_states(const InstanceKlass* ik); 111 static bool allow_only_single_java_thread() NOT_CDS_RETURN_(false); 112 113 // optimized_module_handling -- can we skip some expensive operations related to modules? 114 static bool is_using_optimized_module_handling() { return CDS_ONLY(_is_using_optimized_module_handling) NOT_CDS(false); } 115 static void stop_using_optimized_module_handling() NOT_CDS_RETURN; 116 117 static bool is_logging_lambda_form_invokers() NOT_CDS_RETURN_(false); 118 static bool is_dumping_regenerated_lambdaform_invokers() NOT_CDS_RETURN_(false); 119 120 static bool is_dumping_aot_linked_classes() NOT_CDS_JAVA_HEAP_RETURN_(false); 121 static bool is_using_aot_linked_classes() NOT_CDS_JAVA_HEAP_RETURN_(false); 122 static void set_has_aot_linked_classes(bool has_aot_linked_classes) NOT_CDS_JAVA_HEAP_RETURN; 123 124 // archive_path 125 126 // Points to the classes.jsa in $JAVA_HOME 127 static char* default_archive_path() NOT_CDS_RETURN_(nullptr); 128 // The actual static archive (if any) selected at runtime 129 static const char* static_archive_path() { return CDS_ONLY(_static_archive_path) NOT_CDS(nullptr); } 130 // The actual dynamic archive (if any) selected at runtime 131 static const char* dynamic_archive_path() { return CDS_ONLY(_dynamic_archive_path) NOT_CDS(nullptr); } 132 133 // --- Archived java objects 134 135 static bool is_dumping_heap() NOT_CDS_JAVA_HEAP_RETURN_(false); 136 static bool is_loading_heap() NOT_CDS_JAVA_HEAP_RETURN_(false); 137 static bool is_initing_classes_at_dump_time() NOT_CDS_JAVA_HEAP_RETURN_(false); 138 139 static bool is_dumping_invokedynamic() NOT_CDS_JAVA_HEAP_RETURN_(false); 140 static bool is_loading_invokedynamic() NOT_CDS_JAVA_HEAP_RETURN_(false); 141 static void set_has_archived_invokedynamic() { CDS_JAVA_HEAP_ONLY(_has_archived_invokedynamic = true); } 142 143 static bool is_dumping_packages() NOT_CDS_JAVA_HEAP_RETURN_(false); 144 static bool is_loading_packages() NOT_CDS_JAVA_HEAP_RETURN_(false); 145 static void set_is_loading_packages() { CDS_JAVA_HEAP_ONLY(_is_loading_packages = true); } 146 147 static bool is_dumping_protection_domains() NOT_CDS_JAVA_HEAP_RETURN_(false); 148 static bool is_loading_protection_domains() NOT_CDS_JAVA_HEAP_RETURN_(false); 149 static void set_is_loading_protection_domains() { CDS_JAVA_HEAP_ONLY(_is_loading_protection_domains = true); } 150 151 static bool is_dumping_reflection_data() NOT_CDS_JAVA_HEAP_RETURN_(false); 152 153 static bool is_dumping_dynamic_proxies() NOT_CDS_JAVA_HEAP_RETURN_(false); 154 static bool is_logging_dynamic_proxies() NOT_CDS_RETURN_(false); 155 156 // full_module_graph (requires optimized_module_handling) 157 static bool is_dumping_full_module_graph() { return CDS_ONLY(_is_dumping_full_module_graph) NOT_CDS(false); } 158 static bool is_using_full_module_graph() NOT_CDS_JAVA_HEAP_RETURN_(false); 159 static void stop_dumping_full_module_graph(const char* reason = nullptr) NOT_CDS_JAVA_HEAP_RETURN; 160 static void stop_using_full_module_graph(const char* reason = nullptr) NOT_CDS_JAVA_HEAP_RETURN; 161 162 // --- AOT compiler 163 164 static bool is_dumping_cached_code() NOT_CDS_RETURN_(false); 165 static void disable_dumping_cached_code() NOT_CDS_RETURN; 166 static void enable_dumping_cached_code() NOT_CDS_RETURN; 167 168 // Some CDS functions assume that they are called only within a single-threaded context. I.e., 169 // they are called from: 170 // - The VM thread (e.g., inside VM_PopulateDumpSharedSpace) 171 // - The thread that performs prepatory steps before switching to the VM thread 172 // Since these two threads never execute concurrently, we can avoid using locks in these CDS 173 // function. For safety, these functions should assert with CDSConfig::current_thread_is_vm_or_dumper(). 174 class DumperThreadMark { 175 public: 176 DumperThreadMark(JavaThread* current); 177 ~DumperThreadMark(); 178 }; 179 180 static bool current_thread_is_vm_or_dumper() NOT_CDS_RETURN_(false); 181 }; 182 183 #endif // SHARE_CDS_CDSCONFIG_HPP