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