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 JavaThread;
33
34 class CDSConfig : public AllStatic {
35 #if INCLUDE_CDS
36 static bool _is_dumping_static_archive;
37 static bool _is_dumping_preimage_static_archive;
38 static bool _is_dumping_final_static_archive;
39 static bool _is_dumping_dynamic_archive;
40 static bool _is_using_optimized_module_handling;
41 static bool _is_dumping_full_module_graph;
42 static bool _is_using_full_module_graph;
43 static bool _has_aot_linked_classes;
44 static bool _has_archived_invokedynamic;
45
46 static char* _default_archive_path;
47 static char* _static_archive_path;
48 static char* _dynamic_archive_path;
49
50 static bool _old_cds_flags_used;
51 static bool _new_aot_flags_used;
52 static bool _disable_heap_dumping;
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_aot_flags();
64 static void check_aotmode_off();
65 static void check_aotmode_auto_or_on();
66 static void check_aotmode_record();
67 static void check_aotmode_create();
68
69 public:
70 // Used by jdk.internal.misc.CDS.getCDSConfigStatus();
71 static const int IS_DUMPING_ARCHIVE = 1 << 0;
72 static const int IS_DUMPING_STATIC_ARCHIVE = 1 << 1;
73 static const int IS_LOGGING_LAMBDA_FORM_INVOKERS = 1 << 2;
74 static const int IS_USING_ARCHIVE = 1 << 3;
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 bool new_aot_flags_used() { return CDS_ONLY(_new_aot_flags_used) NOT_CDS(false); }
82 static void check_internal_module_property(const char* key, const char* value) NOT_CDS_RETURN;
83 static void check_incompatible_property(const char* key, const char* value) NOT_CDS_RETURN;
84 static void check_unsupported_dumping_module_options() NOT_CDS_RETURN;
85 static bool has_unsupported_runtime_module_options() NOT_CDS_RETURN_(false);
86 static bool check_vm_args_consistency(bool patch_mod_javabase, bool mode_flag_cmd_line) NOT_CDS_RETURN_(true);
87 static const char* type_of_archive_being_loaded();
88 static const char* type_of_archive_being_written();
89
90 // --- Basic CDS features
91
92 // archive(s) in general
93 static bool is_dumping_archive() { return is_dumping_static_archive() || is_dumping_dynamic_archive(); }
94 static bool is_using_archive() NOT_CDS_RETURN_(false);
95 static int num_archives(const char* archive_path) NOT_CDS_RETURN_(0);
96
97 // static_archive
98 static bool is_dumping_static_archive() { return CDS_ONLY(_is_dumping_static_archive) NOT_CDS(false); }
99 static void enable_dumping_static_archive() { CDS_ONLY(_is_dumping_static_archive = true); }
100
101 // A static CDS archive can be dumped in three modes:
102 //
103 // "classic" - This is the traditional CDS workflow of
104 // "java -Xshare:dump -XX:SharedClassListFile=file.txt".
105 //
106 // "preimage" - This happens when we execute the JEP 483 training run, e.g:
107 // "java -XX:AOTMode=record -XX:AOTConfiguration=app.aotconfig -cp app.jar App"
108 // The above command writes app.aotconfig as a "CDS preimage". This
109 // is a binary file that contains all the classes loaded during the
110 // training run, plus profiling data (e.g., the resolved constant pool entries).
111 //
112 // "final" - This happens when we execute the JEP 483 assembly phase, e.g:
113 // "java -XX:AOTMode=create -XX:AOTConfiguration=app.aotconfig -XX:AOTCache=app.aot -cp app.jar"
114 // The above command loads all classes from app.aotconfig, perform additional linking,
115 // and writes app.aot as a "CDS final image" file.
116 //
117 // The main structural difference between "preimage" and "final" is that the preimage
118 // - has a different magic number (0xcafea07c)
119 // - does not have any archived Java heap objects
120 // - does not have aot-linked classes
121 static bool is_dumping_classic_static_archive() NOT_CDS_RETURN_(false);
122 static bool is_dumping_preimage_static_archive() NOT_CDS_RETURN_(false);
123 static bool is_dumping_final_static_archive() NOT_CDS_RETURN_(false);
124
125 // dynamic_archive
126 static bool is_dumping_dynamic_archive() { return CDS_ONLY(_is_dumping_dynamic_archive) NOT_CDS(false); }
127 static void enable_dumping_dynamic_archive() { CDS_ONLY(_is_dumping_dynamic_archive = true); }
128 static void disable_dumping_dynamic_archive() { CDS_ONLY(_is_dumping_dynamic_archive = false); }
129
130 // Misc CDS features
131 static bool allow_only_single_java_thread() NOT_CDS_RETURN_(false);
132
133 // optimized_module_handling -- can we skip some expensive operations related to modules?
134 static bool is_using_optimized_module_handling() { return CDS_ONLY(_is_using_optimized_module_handling) NOT_CDS(false); }
135 static void stop_using_optimized_module_handling() NOT_CDS_RETURN;
136
137 static bool is_logging_lambda_form_invokers() NOT_CDS_RETURN_(false);
138
139 static bool is_dumping_aot_linked_classes() NOT_CDS_JAVA_HEAP_RETURN_(false);
140 static bool is_using_aot_linked_classes() NOT_CDS_JAVA_HEAP_RETURN_(false);
141 static void set_has_aot_linked_classes(bool has_aot_linked_classes) NOT_CDS_JAVA_HEAP_RETURN;
142
143 // archive_path
144
145 // Points to the classes.jsa in $JAVA_HOME
146 static char* default_archive_path() NOT_CDS_RETURN_(nullptr);
147 // The actual static archive (if any) selected at runtime
148 static const char* static_archive_path() { return CDS_ONLY(_static_archive_path) NOT_CDS(nullptr); }
149 // The actual dynamic archive (if any) selected at runtime
150 static const char* dynamic_archive_path() { return CDS_ONLY(_dynamic_archive_path) NOT_CDS(nullptr); }
151
152 // --- Archived java objects
153
154 static bool are_vm_options_incompatible_with_dumping_heap() NOT_CDS_JAVA_HEAP_RETURN_(true);
155 static void log_reasons_for_not_dumping_heap();
156
157 static void disable_heap_dumping() { CDS_ONLY(_disable_heap_dumping = true); }
158 static bool is_dumping_heap() NOT_CDS_JAVA_HEAP_RETURN_(false);
159 static bool is_loading_heap() NOT_CDS_JAVA_HEAP_RETURN_(false);
160 static bool is_initing_classes_at_dump_time() NOT_CDS_JAVA_HEAP_RETURN_(false);
161
162 static bool is_dumping_invokedynamic() NOT_CDS_JAVA_HEAP_RETURN_(false);
163 static bool is_loading_invokedynamic() NOT_CDS_JAVA_HEAP_RETURN_(false);
164 static void set_has_archived_invokedynamic() { CDS_JAVA_HEAP_ONLY(_has_archived_invokedynamic = true); }
165
166 // full_module_graph (requires optimized_module_handling)
167 static bool is_dumping_full_module_graph() { return CDS_ONLY(_is_dumping_full_module_graph) NOT_CDS(false); }
168 static bool is_using_full_module_graph() NOT_CDS_JAVA_HEAP_RETURN_(false);
169 static void stop_dumping_full_module_graph(const char* reason = nullptr) NOT_CDS_JAVA_HEAP_RETURN;
170 static void stop_using_full_module_graph(const char* reason = nullptr) NOT_CDS_JAVA_HEAP_RETURN;
171
172 // Some CDS functions assume that they are called only within a single-threaded context. I.e.,
173 // they are called from:
174 // - The VM thread (e.g., inside VM_PopulateDumpSharedSpace)
175 // - The thread that performs prepatory steps before switching to the VM thread
176 // Since these two threads never execute concurrently, we can avoid using locks in these CDS
177 // function. For safety, these functions should assert with CDSConfig::current_thread_is_vm_or_dumper().
178 class DumperThreadMark {
179 public:
180 DumperThreadMark(JavaThread* current);
181 ~DumperThreadMark();
182 };
183
184 static bool current_thread_is_vm_or_dumper() NOT_CDS_RETURN_(false);
185 };
186
187 #endif // SHARE_CDS_CDSCONFIG_HPP
|
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_preimage_static_archive;
39 static bool _is_dumping_final_static_archive;
40 static bool _is_dumping_dynamic_archive;
41 static bool _is_using_optimized_module_handling;
42 static bool _is_dumping_full_module_graph;
43 static bool _is_using_full_module_graph;
44 static bool _has_aot_linked_classes;
45 static bool _has_archived_invokedynamic;
46 static bool _is_loading_packages;
47 static bool _is_loading_protection_domains;
48 static bool _is_security_manager_allowed;
49
50 static char* _default_archive_path;
51 static char* _static_archive_path;
52 static char* _dynamic_archive_path;
53
54 static bool _old_cds_flags_used;
55 static bool _new_aot_flags_used;
56 static bool _disable_heap_dumping;
57
58 static JavaThread* _dumper_thread;
59 #endif
60
61 static void extract_shared_archive_paths(const char* archive_path,
62 char** base_archive_path,
63 char** top_archive_path);
64 static void init_shared_archive_paths();
65
66 static void check_flag_alias(bool alias_is_default, const char* alias_name);
67 static void check_aot_flags();
68 static void check_aotmode_off();
69 static void check_aotmode_auto_or_on();
70 static void check_aotmode_record();
71 static void check_aotmode_create();
72 static void setup_compiler_args();
73 static bool setup_experimental_leyden_workflow(bool xshare_auto_cmd_line); // Deprecated -- to be removed
74
75 public:
76 // Used by jdk.internal.misc.CDS.getCDSConfigStatus();
77 static const int IS_DUMPING_ARCHIVE = 1 << 0;
78 static const int IS_DUMPING_STATIC_ARCHIVE = 1 << 1;
79 static const int IS_LOGGING_LAMBDA_FORM_INVOKERS = 1 << 2;
80 static const int IS_USING_ARCHIVE = 1 << 3;
81 static const int IS_DUMPING_HEAP = 1 << 4;
82 static const int IS_LOGGING_DYNAMIC_PROXIES = 1 << 5;
83 static const int IS_DUMPING_PACKAGES = 1 << 6;
84 static const int IS_DUMPING_PROTECTION_DOMAINS = 1 << 7;
85 static int get_status() NOT_CDS_RETURN_(0);
86
87 // Initialization and command-line checking
88 static void initialize() NOT_CDS_RETURN;
89 static void set_old_cds_flags_used() { CDS_ONLY(_old_cds_flags_used = true); }
90 static bool old_cds_flags_used() { return CDS_ONLY(_old_cds_flags_used) NOT_CDS(false); }
91 static bool new_aot_flags_used() { return CDS_ONLY(_new_aot_flags_used) NOT_CDS(false); }
92 static void check_internal_module_property(const char* key, const char* value) NOT_CDS_RETURN;
93 static void check_incompatible_property(const char* key, const char* value) NOT_CDS_RETURN;
94 static void check_unsupported_dumping_module_options() NOT_CDS_RETURN;
95 static bool has_unsupported_runtime_module_options() NOT_CDS_RETURN_(false);
96 static bool check_vm_args_consistency(bool patch_mod_javabase, bool mode_flag_cmd_line, bool xshare_auto_cmd_line) NOT_CDS_RETURN_(true);
97 static const char* type_of_archive_being_loaded();
98 static const char* type_of_archive_being_written();
99
100 // --- Basic CDS features
101
102 // archive(s) in general
103 static bool is_dumping_archive() { return is_dumping_static_archive() || is_dumping_dynamic_archive(); }
104 static bool is_using_archive() NOT_CDS_RETURN_(false);
105 static int num_archives(const char* archive_path) NOT_CDS_RETURN_(0);
106
107 // static_archive
108 static bool is_dumping_static_archive() { return (CDS_ONLY(_is_dumping_static_archive) NOT_CDS(false))
109 || is_dumping_final_static_archive(); }
110 static void enable_dumping_static_archive() { CDS_ONLY(_is_dumping_static_archive = true); }
111
112
113 // A static CDS archive can be dumped in three modes:
114 //
115 // "classic" - This is the traditional CDS workflow of
116 // "java -Xshare:dump -XX:SharedClassListFile=file.txt".
117 //
118 // "preimage" - This happens when we execute the JEP 483 training run, e.g:
119 // "java -XX:AOTMode=record -XX:AOTConfiguration=app.aotconfig -cp app.jar App"
120 // The above command writes app.aotconfig as a "CDS preimage". This
121 // is a binary file that contains all the classes loaded during the
122 // training run, plus profiling data (e.g., the resolved constant pool entries).
123 //
124 // "final" - This happens when we execute the JEP 483 assembly phase, e.g:
125 // "java -XX:AOTMode=create -XX:AOTConfiguration=app.aotconfig -XX:AOTCache=app.aot -cp app.jar"
126 // The above command loads all classes from app.aotconfig, perform additional linking,
127 // and writes app.aot as a "CDS final image" file.
128 //
129 // The main structural difference between "preimage" and "final" is that the preimage
130 // - has a different magic number (0xcafea07c)
131 // - does not have any archived Java heap objects
132 // - does not have aot-linked classes
133 static bool is_dumping_classic_static_archive() NOT_CDS_RETURN_(false);
134 static bool is_dumping_preimage_static_archive() NOT_CDS_RETURN_(false);
135 static bool is_dumping_preimage_static_archive_with_triggers() NOT_CDS_RETURN_(false);
136 static bool is_dumping_final_static_archive() NOT_CDS_RETURN_(false);
137
138 // dynamic_archive
139 static bool is_dumping_dynamic_archive() { return CDS_ONLY(_is_dumping_dynamic_archive) NOT_CDS(false); }
140 static void enable_dumping_dynamic_archive() { CDS_ONLY(_is_dumping_dynamic_archive = true); }
141 static void disable_dumping_dynamic_archive() { CDS_ONLY(_is_dumping_dynamic_archive = false); }
142
143 // Misc CDS features
144 static bool preserve_all_dumptime_verification_states(const InstanceKlass* ik);
145 static bool allow_only_single_java_thread() NOT_CDS_RETURN_(false);
146
147 // optimized_module_handling -- can we skip some expensive operations related to modules?
148 static bool is_using_optimized_module_handling() { return CDS_ONLY(_is_using_optimized_module_handling) NOT_CDS(false); }
149 static void stop_using_optimized_module_handling() NOT_CDS_RETURN;
150
151 static bool is_logging_lambda_form_invokers() NOT_CDS_RETURN_(false);
152 static bool is_dumping_regenerated_lambdaform_invokers() NOT_CDS_RETURN_(false);
153
154 static bool is_dumping_aot_linked_classes() NOT_CDS_JAVA_HEAP_RETURN_(false);
155 static bool is_using_aot_linked_classes() NOT_CDS_JAVA_HEAP_RETURN_(false);
156 static void set_has_aot_linked_classes(bool has_aot_linked_classes) NOT_CDS_JAVA_HEAP_RETURN;
157
158 // archive_path
159
160 // Points to the classes.jsa in $JAVA_HOME
161 static char* default_archive_path() NOT_CDS_RETURN_(nullptr);
162 // The actual static archive (if any) selected at runtime
163 static const char* static_archive_path() { return CDS_ONLY(_static_archive_path) NOT_CDS(nullptr); }
164 // The actual dynamic archive (if any) selected at runtime
165 static const char* dynamic_archive_path() { return CDS_ONLY(_dynamic_archive_path) NOT_CDS(nullptr); }
166
167 // --- Archived java objects
168
169 static bool are_vm_options_incompatible_with_dumping_heap() NOT_CDS_JAVA_HEAP_RETURN_(true);
170 static void log_reasons_for_not_dumping_heap();
171
172 static void disable_heap_dumping() { CDS_ONLY(_disable_heap_dumping = true); }
173 static bool is_dumping_heap() NOT_CDS_JAVA_HEAP_RETURN_(false);
174 static bool is_loading_heap() NOT_CDS_JAVA_HEAP_RETURN_(false);
175 static bool is_initing_classes_at_dump_time() NOT_CDS_JAVA_HEAP_RETURN_(false);
176
177 static bool is_dumping_invokedynamic() NOT_CDS_JAVA_HEAP_RETURN_(false);
178 static bool is_loading_invokedynamic() NOT_CDS_JAVA_HEAP_RETURN_(false);
179 static void set_has_archived_invokedynamic() { CDS_JAVA_HEAP_ONLY(_has_archived_invokedynamic = true); }
180
181 static bool is_dumping_packages() NOT_CDS_JAVA_HEAP_RETURN_(false);
182 static bool is_loading_packages() NOT_CDS_JAVA_HEAP_RETURN_(false);
183 static void set_is_loading_packages() { CDS_JAVA_HEAP_ONLY(_is_loading_packages = true); }
184
185 static bool is_dumping_protection_domains() NOT_CDS_JAVA_HEAP_RETURN_(false);
186 static bool is_loading_protection_domains() NOT_CDS_JAVA_HEAP_RETURN_(false);
187 static void set_is_loading_protection_domains() { CDS_JAVA_HEAP_ONLY(_is_loading_protection_domains = true); }
188
189 static bool is_dumping_reflection_data() NOT_CDS_JAVA_HEAP_RETURN_(false);
190
191 static bool is_dumping_dynamic_proxies() NOT_CDS_JAVA_HEAP_RETURN_(false);
192 static bool is_logging_dynamic_proxies() NOT_CDS_RETURN_(false);
193
194 // full_module_graph (requires optimized_module_handling)
195 static bool is_dumping_full_module_graph() { return CDS_ONLY(_is_dumping_full_module_graph) NOT_CDS(false); }
196 static bool is_using_full_module_graph() NOT_CDS_JAVA_HEAP_RETURN_(false);
197 static void stop_dumping_full_module_graph(const char* reason = nullptr) NOT_CDS_JAVA_HEAP_RETURN;
198 static void stop_using_full_module_graph(const char* reason = nullptr) NOT_CDS_JAVA_HEAP_RETURN;
199
200 // --- AOT compiler
201
202 static bool is_dumping_cached_code() NOT_CDS_RETURN_(false);
203 static void disable_dumping_cached_code() NOT_CDS_RETURN;
204 static void enable_dumping_cached_code() NOT_CDS_RETURN;
205
206 static bool is_dumping_adapters() NOT_CDS_RETURN_(false);
207
208 // Are we using the (to be deprecated) -XX:CacheDataStore workflow?
209 static bool is_experimental_leyden_workflow() NOT_CDS_RETURN_(false);
210
211 // Some CDS functions assume that they are called only within a single-threaded context. I.e.,
212 // they are called from:
213 // - The VM thread (e.g., inside VM_PopulateDumpSharedSpace)
214 // - The thread that performs prepatory steps before switching to the VM thread
215 // Since these two threads never execute concurrently, we can avoid using locks in these CDS
216 // function. For safety, these functions should assert with CDSConfig::current_thread_is_vm_or_dumper().
217 class DumperThreadMark {
218 public:
219 DumperThreadMark(JavaThread* current);
220 ~DumperThreadMark();
221 };
222
223 static bool current_thread_is_vm_or_dumper() NOT_CDS_RETURN_(false);
224 };
225
226 #endif // SHARE_CDS_CDSCONFIG_HPP
|