1 /*
2 * Copyright (c) 1997, 2023, 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 *
74 void append_value(const char *value);
75
76 PathString(const char* value);
77 ~PathString();
78
79 // for JVM_ReadSystemPropertiesInfo
80 static int value_offset_in_bytes() { return (int)offset_of(PathString, _value); }
81 };
82
83 // ModulePatchPath records the module/path pair as specified to --patch-module.
84 class ModulePatchPath : public CHeapObj<mtInternal> {
85 private:
86 char* _module_name;
87 PathString* _path;
88 public:
89 ModulePatchPath(const char* module_name, const char* path);
90 ~ModulePatchPath();
91
92 inline const char* module_name() const { return _module_name; }
93 inline char* path_string() const { return _path->value(); }
94 };
95
96 // Element describing System and User (-Dkey=value flags) defined property.
97 //
98 // An internal SystemProperty is one that has been removed in
99 // jdk.internal.VM.saveAndRemoveProperties, like jdk.boot.class.path.append.
100 //
101 class SystemProperty : public PathString {
102 private:
103 char* _key;
104 SystemProperty* _next;
105 bool _internal;
106 bool _writeable;
107
108 public:
109 // Accessors
110 char* value() const { return PathString::value(); }
111 const char* key() const { return _key; }
112 bool internal() const { return _internal; }
113 SystemProperty* next() const { return _next; }
271 static void set_heap_size();
272
273 // Bytecode rewriting
274 static void set_bytecode_flags();
275
276 // Invocation API hooks
277 static abort_hook_t _abort_hook;
278 static exit_hook_t _exit_hook;
279 static vfprintf_hook_t _vfprintf_hook;
280
281 // System properties
282 static bool add_property(const char* prop, PropertyWriteable writeable=WriteableProperty,
283 PropertyInternal internal=ExternalProperty);
284
285 // Used for module system related properties: converted from command-line flags.
286 // Basic properties are writeable as they operate as "last one wins" and will get overwritten.
287 // Numbered properties are never writeable, and always internal.
288 static bool create_module_property(const char* prop_name, const char* prop_value, PropertyInternal internal);
289 static bool create_numbered_module_property(const char* prop_base_name, const char* prop_value, unsigned int count);
290
291 static int process_patch_mod_option(const char* patch_mod_tail, bool* patch_mod_javabase);
292
293 // Aggressive optimization flags.
294 static jint set_aggressive_opts_flags();
295
296 static jint set_aggressive_heap_flags();
297
298 // Argument parsing
299 static bool parse_argument(const char* arg, JVMFlagOrigin origin);
300 static bool process_argument(const char* arg, jboolean ignore_unrecognized, JVMFlagOrigin origin);
301 static void process_java_launcher_argument(const char*, void*);
302 static jint parse_options_environment_variable(const char* name, ScopedVMInitArgs* vm_args);
303 static jint parse_java_tool_options_environment_variable(ScopedVMInitArgs* vm_args);
304 static jint parse_java_options_environment_variable(ScopedVMInitArgs* vm_args);
305 static jint parse_vm_options_file(const char* file_name, ScopedVMInitArgs* vm_args);
306 static jint parse_options_buffer(const char* name, char* buffer, const size_t buf_len, ScopedVMInitArgs* vm_args);
307 static jint parse_xss(const JavaVMOption* option, const char* tail, intx* out_ThreadStackSize);
308 static jint insert_vm_options_file(const JavaVMInitArgs* args,
309 const char* vm_options_file,
310 const int vm_options_file_pos,
311 ScopedVMInitArgs* vm_options_file_args,
312 ScopedVMInitArgs* args_out);
313 static bool args_contains_vm_options_file_arg(const JavaVMInitArgs* args);
314 static jint expand_vm_options_as_needed(const JavaVMInitArgs* args_in,
315 ScopedVMInitArgs* mod_args,
316 JavaVMInitArgs** args_out);
317 static jint match_special_option_and_act(const JavaVMInitArgs* args,
318 ScopedVMInitArgs* args_out);
319
320 static bool handle_deprecated_print_gc_flags();
321
322 static jint parse_vm_init_args(const JavaVMInitArgs *vm_options_args,
323 const JavaVMInitArgs *java_tool_options_args,
324 const JavaVMInitArgs *java_options_args,
325 const JavaVMInitArgs *cmd_line_args);
326 static jint parse_each_vm_init_arg(const JavaVMInitArgs* args, bool* patch_mod_javabase, JVMFlagOrigin origin);
327 static jint finalize_vm_init_args(bool patch_mod_javabase);
328 static bool is_bad_option(const JavaVMOption* option, jboolean ignore, const char* option_type);
329
330 static bool is_bad_option(const JavaVMOption* option, jboolean ignore) {
331 return is_bad_option(option, ignore, nullptr);
332 }
333
334 static void describe_range_error(ArgsRange errcode);
335 static ArgsRange check_memory_size(julong size, julong min_size, julong max_size);
336 static ArgsRange parse_memory_size(const char* s, julong* long_arg,
337 julong min_size, julong max_size = max_uintx);
338
339 // methods to build strings from individual args
340 static void build_jvm_args(const char* arg);
341 static void build_jvm_flags(const char* arg);
342 static void add_string(char*** bldarray, int* count, const char* arg);
343 static const char* build_resource_string(char** args, int count);
344
345 // Returns true if the flag is obsolete (and not yet expired).
346 // In this case the 'version' buffer is filled in with
347 // the version number when the flag became obsolete.
453 static void PropertyList_add(SystemProperty** plist, const char* k, const char* v, bool writeable, bool internal);
454
455 static void PropertyList_unique_add(SystemProperty** plist, const char* k, const char* v,
456 PropertyAppendable append, PropertyWriteable writeable,
457 PropertyInternal internal);
458 static const char* PropertyList_get_value(SystemProperty* plist, const char* key);
459 static const char* PropertyList_get_readable_value(SystemProperty* plist, const char* key);
460 static int PropertyList_count(SystemProperty* pl);
461 static int PropertyList_readable_count(SystemProperty* pl);
462
463 static bool is_internal_module_property(const char* option);
464 static bool is_module_path_property(const char* key);
465
466 // Miscellaneous System property value getter and setters.
467 static void set_dll_dir(const char *value) { _sun_boot_library_path->set_value(value); }
468 static void set_java_home(const char *value) { _java_home->set_value(value); }
469 static void set_library_path(const char *value) { _java_library_path->set_value(value); }
470 static void set_ext_dirs(char *value) { _ext_dirs = os::strdup_check_oom(value); }
471
472 // Set up the underlying pieces of the boot class path
473 static void add_patch_mod_prefix(const char *module_name, const char *path, bool* patch_mod_javabase);
474 static void set_boot_class_path(const char *value, bool has_jimage) {
475 // During start up, set by os::set_boot_path()
476 assert(get_boot_class_path() == nullptr, "Boot class path previously set");
477 _boot_class_path->set_value(value);
478 _has_jimage = has_jimage;
479 }
480 static void append_sysclasspath(const char *value) {
481 _boot_class_path->append_value(value);
482 _jdk_boot_class_path_append->append_value(value);
483 }
484
485 static GrowableArray<ModulePatchPath*>* get_patch_mod_prefix() { return _patch_mod_prefix; }
486 static char* get_boot_class_path() { return _boot_class_path->value(); }
487 static bool has_jimage() { return _has_jimage; }
488
489 static char* get_java_home() { return _java_home->value(); }
490 static char* get_dll_dir() { return _sun_boot_library_path->value(); }
491 static char* get_appclasspath() { return _java_class_path->value(); }
492 static void fix_appclasspath();
493
|
1 /*
2 * Copyright (c) 1997, 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 *
74 void append_value(const char *value);
75
76 PathString(const char* value);
77 ~PathString();
78
79 // for JVM_ReadSystemPropertiesInfo
80 static int value_offset_in_bytes() { return (int)offset_of(PathString, _value); }
81 };
82
83 // ModulePatchPath records the module/path pair as specified to --patch-module.
84 class ModulePatchPath : public CHeapObj<mtInternal> {
85 private:
86 char* _module_name;
87 PathString* _path;
88 public:
89 ModulePatchPath(const char* module_name, const char* path);
90 ~ModulePatchPath();
91
92 inline const char* module_name() const { return _module_name; }
93 inline char* path_string() const { return _path->value(); }
94 inline void append_path(const char* path) { _path->append_value(path); }
95 };
96
97 // Element describing System and User (-Dkey=value flags) defined property.
98 //
99 // An internal SystemProperty is one that has been removed in
100 // jdk.internal.VM.saveAndRemoveProperties, like jdk.boot.class.path.append.
101 //
102 class SystemProperty : public PathString {
103 private:
104 char* _key;
105 SystemProperty* _next;
106 bool _internal;
107 bool _writeable;
108
109 public:
110 // Accessors
111 char* value() const { return PathString::value(); }
112 const char* key() const { return _key; }
113 bool internal() const { return _internal; }
114 SystemProperty* next() const { return _next; }
272 static void set_heap_size();
273
274 // Bytecode rewriting
275 static void set_bytecode_flags();
276
277 // Invocation API hooks
278 static abort_hook_t _abort_hook;
279 static exit_hook_t _exit_hook;
280 static vfprintf_hook_t _vfprintf_hook;
281
282 // System properties
283 static bool add_property(const char* prop, PropertyWriteable writeable=WriteableProperty,
284 PropertyInternal internal=ExternalProperty);
285
286 // Used for module system related properties: converted from command-line flags.
287 // Basic properties are writeable as they operate as "last one wins" and will get overwritten.
288 // Numbered properties are never writeable, and always internal.
289 static bool create_module_property(const char* prop_name, const char* prop_value, PropertyInternal internal);
290 static bool create_numbered_module_property(const char* prop_base_name, const char* prop_value, unsigned int count);
291
292 static int process_patch_mod_option(const char* patch_mod_tail);
293
294 // Aggressive optimization flags.
295 static jint set_aggressive_opts_flags();
296
297 static jint set_aggressive_heap_flags();
298
299 // Argument parsing
300 static bool parse_argument(const char* arg, JVMFlagOrigin origin);
301 static bool process_argument(const char* arg, jboolean ignore_unrecognized, JVMFlagOrigin origin);
302 static void process_java_launcher_argument(const char*, void*);
303 static jint parse_options_environment_variable(const char* name, ScopedVMInitArgs* vm_args);
304 static jint parse_java_tool_options_environment_variable(ScopedVMInitArgs* vm_args);
305 static jint parse_java_options_environment_variable(ScopedVMInitArgs* vm_args);
306 static jint parse_vm_options_file(const char* file_name, ScopedVMInitArgs* vm_args);
307 static jint parse_options_buffer(const char* name, char* buffer, const size_t buf_len, ScopedVMInitArgs* vm_args);
308 static jint parse_xss(const JavaVMOption* option, const char* tail, intx* out_ThreadStackSize);
309 static jint insert_vm_options_file(const JavaVMInitArgs* args,
310 const char* vm_options_file,
311 const int vm_options_file_pos,
312 ScopedVMInitArgs* vm_options_file_args,
313 ScopedVMInitArgs* args_out);
314 static bool args_contains_vm_options_file_arg(const JavaVMInitArgs* args);
315 static jint expand_vm_options_as_needed(const JavaVMInitArgs* args_in,
316 ScopedVMInitArgs* mod_args,
317 JavaVMInitArgs** args_out);
318 static jint match_special_option_and_act(const JavaVMInitArgs* args,
319 ScopedVMInitArgs* args_out);
320
321 static bool handle_deprecated_print_gc_flags();
322
323 static jint parse_vm_init_args(const JavaVMInitArgs *vm_options_args,
324 const JavaVMInitArgs *java_tool_options_args,
325 const JavaVMInitArgs *java_options_args,
326 const JavaVMInitArgs *cmd_line_args);
327 static jint parse_each_vm_init_arg(const JavaVMInitArgs* args, JVMFlagOrigin origin);
328 static jint finalize_vm_init_args();
329 static bool is_bad_option(const JavaVMOption* option, jboolean ignore, const char* option_type);
330
331 static bool is_bad_option(const JavaVMOption* option, jboolean ignore) {
332 return is_bad_option(option, ignore, nullptr);
333 }
334
335 static void describe_range_error(ArgsRange errcode);
336 static ArgsRange check_memory_size(julong size, julong min_size, julong max_size);
337 static ArgsRange parse_memory_size(const char* s, julong* long_arg,
338 julong min_size, julong max_size = max_uintx);
339
340 // methods to build strings from individual args
341 static void build_jvm_args(const char* arg);
342 static void build_jvm_flags(const char* arg);
343 static void add_string(char*** bldarray, int* count, const char* arg);
344 static const char* build_resource_string(char** args, int count);
345
346 // Returns true if the flag is obsolete (and not yet expired).
347 // In this case the 'version' buffer is filled in with
348 // the version number when the flag became obsolete.
454 static void PropertyList_add(SystemProperty** plist, const char* k, const char* v, bool writeable, bool internal);
455
456 static void PropertyList_unique_add(SystemProperty** plist, const char* k, const char* v,
457 PropertyAppendable append, PropertyWriteable writeable,
458 PropertyInternal internal);
459 static const char* PropertyList_get_value(SystemProperty* plist, const char* key);
460 static const char* PropertyList_get_readable_value(SystemProperty* plist, const char* key);
461 static int PropertyList_count(SystemProperty* pl);
462 static int PropertyList_readable_count(SystemProperty* pl);
463
464 static bool is_internal_module_property(const char* option);
465 static bool is_module_path_property(const char* key);
466
467 // Miscellaneous System property value getter and setters.
468 static void set_dll_dir(const char *value) { _sun_boot_library_path->set_value(value); }
469 static void set_java_home(const char *value) { _java_home->set_value(value); }
470 static void set_library_path(const char *value) { _java_library_path->set_value(value); }
471 static void set_ext_dirs(char *value) { _ext_dirs = os::strdup_check_oom(value); }
472
473 // Set up the underlying pieces of the boot class path
474 static void add_patch_mod_prefix(const char *module_name, const char *path, bool allow_append, bool allow_cds);
475 static int finalize_patch_module();
476 static void set_boot_class_path(const char *value, bool has_jimage) {
477 // During start up, set by os::set_boot_path()
478 assert(get_boot_class_path() == nullptr, "Boot class path previously set");
479 _boot_class_path->set_value(value);
480 _has_jimage = has_jimage;
481 }
482 static void append_sysclasspath(const char *value) {
483 _boot_class_path->append_value(value);
484 _jdk_boot_class_path_append->append_value(value);
485 }
486
487 static GrowableArray<ModulePatchPath*>* get_patch_mod_prefix() { return _patch_mod_prefix; }
488 static char* get_boot_class_path() { return _boot_class_path->value(); }
489 static bool has_jimage() { return _has_jimage; }
490
491 static char* get_java_home() { return _java_home->value(); }
492 static char* get_dll_dir() { return _sun_boot_library_path->value(); }
493 static char* get_appclasspath() { return _java_class_path->value(); }
494 static void fix_appclasspath();
495
|