Path: blob/master/src/hotspot/share/runtime/arguments.hpp
40951 views
/*1* Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#ifndef SHARE_RUNTIME_ARGUMENTS_HPP25#define SHARE_RUNTIME_ARGUMENTS_HPP2627#include "logging/logLevel.hpp"28#include "logging/logTag.hpp"29#include "memory/allocation.hpp"30#include "runtime/globals.hpp"31#include "runtime/java.hpp"32#include "runtime/os.hpp"33#include "utilities/debug.hpp"34#include "utilities/vmEnums.hpp"3536// Arguments parses the command line and recognizes options3738// Invocation API hook typedefs (these should really be defined in jni.h)39extern "C" {40typedef void (JNICALL *abort_hook_t)(void);41typedef void (JNICALL *exit_hook_t)(jint code);42typedef jint (JNICALL *vfprintf_hook_t)(FILE *fp, const char *format, va_list args) ATTRIBUTE_PRINTF(2, 0);43}4445// Obsolete or deprecated -XX flag.46struct SpecialFlag {47const char* name;48JDK_Version deprecated_in; // When the deprecation warning started (or "undefined").49JDK_Version obsolete_in; // When the obsolete warning started (or "undefined").50JDK_Version expired_in; // When the option expires (or "undefined").51};5253// PathString is used as:54// - the underlying value for a SystemProperty55// - the path portion of an --patch-module module/path pair56// - the string that represents the system boot class path, Arguments::_system_boot_class_path.57class PathString : public CHeapObj<mtArguments> {58protected:59char* _value;60public:61char* value() const { return _value; }6263bool set_value(const char *value);64void append_value(const char *value);6566PathString(const char* value);67~PathString();68};6970// ModulePatchPath records the module/path pair as specified to --patch-module.71class ModulePatchPath : public CHeapObj<mtInternal> {72private:73char* _module_name;74PathString* _path;75public:76ModulePatchPath(const char* module_name, const char* path);77~ModulePatchPath();7879inline void set_path(const char* path) { _path->set_value(path); }80inline const char* module_name() const { return _module_name; }81inline char* path_string() const { return _path->value(); }82};8384// Element describing System and User (-Dkey=value flags) defined property.85//86// An internal SystemProperty is one that has been removed in87// jdk.internal.VM.saveAndRemoveProperties, like jdk.boot.class.path.append.88//89class SystemProperty : public PathString {90private:91char* _key;92SystemProperty* _next;93bool _internal;94bool _writeable;95bool writeable() { return _writeable; }9697public:98// Accessors99char* value() const { return PathString::value(); }100const char* key() const { return _key; }101bool internal() const { return _internal; }102SystemProperty* next() const { return _next; }103void set_next(SystemProperty* next) { _next = next; }104105bool is_readable() const {106return !_internal || strcmp(_key, "jdk.boot.class.path.append") == 0;107}108109// A system property should only have its value set110// via an external interface if it is a writeable property.111// The internal, non-writeable property jdk.boot.class.path.append112// is the only exception to this rule. It can be set externally113// via -Xbootclasspath/a or JVMTI OnLoad phase call to AddToBootstrapClassLoaderSearch.114// In those cases for jdk.boot.class.path.append, the base class115// set_value and append_value methods are called directly.116bool set_writeable_value(const char *value) {117if (writeable()) {118return set_value(value);119}120return false;121}122void append_writeable_value(const char *value) {123if (writeable()) {124append_value(value);125}126}127128// Constructor129SystemProperty(const char* key, const char* value, bool writeable, bool internal = false);130};131132133// For use by -agentlib, -agentpath and -Xrun134class AgentLibrary : public CHeapObj<mtArguments> {135friend class AgentLibraryList;136public:137// Is this library valid or not. Don't rely on os_lib == NULL as statically138// linked lib could have handle of RTLD_DEFAULT which == 0 on some platforms139enum AgentState {140agent_invalid = 0,141agent_valid = 1142};143144private:145char* _name;146char* _options;147void* _os_lib;148bool _is_absolute_path;149bool _is_static_lib;150bool _is_instrument_lib;151AgentState _state;152AgentLibrary* _next;153154public:155// Accessors156const char* name() const { return _name; }157char* options() const { return _options; }158bool is_absolute_path() const { return _is_absolute_path; }159void* os_lib() const { return _os_lib; }160void set_os_lib(void* os_lib) { _os_lib = os_lib; }161AgentLibrary* next() const { return _next; }162bool is_static_lib() const { return _is_static_lib; }163bool is_instrument_lib() const { return _is_instrument_lib; }164void set_static_lib(bool is_static_lib) { _is_static_lib = is_static_lib; }165bool valid() { return (_state == agent_valid); }166void set_valid() { _state = agent_valid; }167void set_invalid() { _state = agent_invalid; }168169// Constructor170AgentLibrary(const char* name, const char* options, bool is_absolute_path,171void* os_lib, bool instrument_lib=false);172};173174// maintain an order of entry list of AgentLibrary175class AgentLibraryList {176private:177AgentLibrary* _first;178AgentLibrary* _last;179public:180bool is_empty() const { return _first == NULL; }181AgentLibrary* first() const { return _first; }182183// add to the end of the list184void add(AgentLibrary* lib) {185if (is_empty()) {186_first = _last = lib;187} else {188_last->_next = lib;189_last = lib;190}191lib->_next = NULL;192}193194// search for and remove a library known to be in the list195void remove(AgentLibrary* lib) {196AgentLibrary* curr;197AgentLibrary* prev = NULL;198for (curr = first(); curr != NULL; prev = curr, curr = curr->next()) {199if (curr == lib) {200break;201}202}203assert(curr != NULL, "always should be found");204205if (curr != NULL) {206// it was found, by-pass this library207if (prev == NULL) {208_first = curr->_next;209} else {210prev->_next = curr->_next;211}212if (curr == _last) {213_last = prev;214}215curr->_next = NULL;216}217}218219AgentLibraryList() {220_first = NULL;221_last = NULL;222}223};224225// Helper class for controlling the lifetime of JavaVMInitArgs objects.226class ScopedVMInitArgs;227228class Arguments : AllStatic {229friend class VMStructs;230friend class JvmtiExport;231friend class CodeCacheExtensions;232friend class ArgumentsTest;233public:234// Operation modi235enum Mode {236_int, // corresponds to -Xint237_mixed, // corresponds to -Xmixed238_comp // corresponds to -Xcomp239};240241enum ArgsRange {242arg_unreadable = -3,243arg_too_small = -2,244arg_too_big = -1,245arg_in_range = 0246};247248enum PropertyAppendable {249AppendProperty,250AddProperty251};252253enum PropertyWriteable {254WriteableProperty,255UnwriteableProperty256};257258enum PropertyInternal {259InternalProperty,260ExternalProperty261};262263private:264265// a pointer to the flags file name if it is specified266static char* _jvm_flags_file;267// an array containing all flags specified in the .hotspotrc file268static char** _jvm_flags_array;269static int _num_jvm_flags;270// an array containing all jvm arguments specified in the command line271static char** _jvm_args_array;272static int _num_jvm_args;273// string containing all java command (class/jarfile name and app args)274static char* _java_command;275276// Property list277static SystemProperty* _system_properties;278279// Quick accessor to System properties in the list:280static SystemProperty *_sun_boot_library_path;281static SystemProperty *_java_library_path;282static SystemProperty *_java_home;283static SystemProperty *_java_class_path;284static SystemProperty *_jdk_boot_class_path_append;285static SystemProperty *_vm_info;286287// --patch-module=module=<file>(<pathsep><file>)*288// Each element contains the associated module name, path289// string pair as specified to --patch-module.290static GrowableArray<ModulePatchPath*>* _patch_mod_prefix;291292// The constructed value of the system class path after293// argument processing and JVMTI OnLoad additions via294// calls to AddToBootstrapClassLoaderSearch. This is the295// final form before ClassLoader::setup_bootstrap_search().296// Note: since --patch-module is a module name/path pair, the297// system boot class path string no longer contains the "prefix"298// to the boot class path base piece as it did when299// -Xbootclasspath/p was supported.300static PathString *_system_boot_class_path;301302// Set if a modular java runtime image is present vs. a build with exploded modules303static bool _has_jimage;304305// temporary: to emit warning if the default ext dirs are not empty.306// remove this variable when the warning is no longer needed.307static char* _ext_dirs;308309// java.vendor.url.bug, bug reporting URL for fatal errors.310static const char* _java_vendor_url_bug;311312// sun.java.launcher, private property to provide information about313// java launcher314static const char* _sun_java_launcher;315316// was this VM created via the -XXaltjvm=<path> option317static bool _sun_java_launcher_is_altjvm;318319// Option flags320static const char* _gc_log_filename;321// Value of the conservative maximum heap alignment needed322static size_t _conservative_max_heap_alignment;323324// -Xrun arguments325static AgentLibraryList _libraryList;326static void add_init_library(const char* name, char* options);327328// -agentlib and -agentpath arguments329static AgentLibraryList _agentList;330static void add_init_agent(const char* name, char* options, bool absolute_path);331static void add_instrument_agent(const char* name, char* options, bool absolute_path);332333// Late-binding agents not started via arguments334static void add_loaded_agent(AgentLibrary *agentLib);335336// Operation modi337static Mode _mode;338static void set_mode_flags(Mode mode);339static bool _java_compiler;340static void set_java_compiler(bool arg) { _java_compiler = arg; }341static bool java_compiler() { return _java_compiler; }342343// -Xdebug flag344static bool _xdebug_mode;345static void set_xdebug_mode(bool arg) { _xdebug_mode = arg; }346static bool xdebug_mode() { return _xdebug_mode; }347348// preview features349static bool _enable_preview;350351// Used to save default settings352static bool _AlwaysCompileLoopMethods;353static bool _UseOnStackReplacement;354static bool _BackgroundCompilation;355static bool _ClipInlining;356357// GC ergonomics358static void set_conservative_max_heap_alignment();359static void set_use_compressed_oops();360static void set_use_compressed_klass_ptrs();361static jint set_ergonomics_flags();362static jint set_shared_spaces_flags_and_archive_paths();363// Limits the given heap size by the maximum amount of virtual364// memory this process is currently allowed to use. It also takes365// the virtual-to-physical ratio of the current GC into account.366static size_t limit_heap_by_allocatable_memory(size_t size);367// Setup heap size368static void set_heap_size();369370// Bytecode rewriting371static void set_bytecode_flags();372373// Invocation API hooks374static abort_hook_t _abort_hook;375static exit_hook_t _exit_hook;376static vfprintf_hook_t _vfprintf_hook;377378// System properties379static bool add_property(const char* prop, PropertyWriteable writeable=WriteableProperty,380PropertyInternal internal=ExternalProperty);381382// Used for module system related properties: converted from command-line flags.383// Basic properties are writeable as they operate as "last one wins" and will get overwritten.384// Numbered properties are never writeable, and always internal.385static bool create_module_property(const char* prop_name, const char* prop_value, PropertyInternal internal);386static bool create_numbered_module_property(const char* prop_base_name, const char* prop_value, unsigned int count);387388static int process_patch_mod_option(const char* patch_mod_tail, bool* patch_mod_javabase);389390// Aggressive optimization flags.391static jint set_aggressive_opts_flags();392393static jint set_aggressive_heap_flags();394395// Argument parsing396static bool parse_argument(const char* arg, JVMFlagOrigin origin);397static bool process_argument(const char* arg, jboolean ignore_unrecognized, JVMFlagOrigin origin);398static void process_java_launcher_argument(const char*, void*);399static void process_java_compiler_argument(const char* arg);400static jint parse_options_environment_variable(const char* name, ScopedVMInitArgs* vm_args);401static jint parse_java_tool_options_environment_variable(ScopedVMInitArgs* vm_args);402static jint parse_java_options_environment_variable(ScopedVMInitArgs* vm_args);403static jint parse_vm_options_file(const char* file_name, ScopedVMInitArgs* vm_args);404static jint parse_options_buffer(const char* name, char* buffer, const size_t buf_len, ScopedVMInitArgs* vm_args);405static jint parse_xss(const JavaVMOption* option, const char* tail, intx* out_ThreadStackSize);406static jint insert_vm_options_file(const JavaVMInitArgs* args,407const char* vm_options_file,408const int vm_options_file_pos,409ScopedVMInitArgs* vm_options_file_args,410ScopedVMInitArgs* args_out);411static bool args_contains_vm_options_file_arg(const JavaVMInitArgs* args);412static jint expand_vm_options_as_needed(const JavaVMInitArgs* args_in,413ScopedVMInitArgs* mod_args,414JavaVMInitArgs** args_out);415static jint match_special_option_and_act(const JavaVMInitArgs* args,416ScopedVMInitArgs* args_out);417418static bool handle_deprecated_print_gc_flags();419420static jint parse_vm_init_args(const JavaVMInitArgs *vm_options_args,421const JavaVMInitArgs *java_tool_options_args,422const JavaVMInitArgs *java_options_args,423const JavaVMInitArgs *cmd_line_args);424static jint parse_each_vm_init_arg(const JavaVMInitArgs* args, bool* patch_mod_javabase, JVMFlagOrigin origin);425static jint finalize_vm_init_args(bool patch_mod_javabase);426static bool is_bad_option(const JavaVMOption* option, jboolean ignore, const char* option_type);427428static bool is_bad_option(const JavaVMOption* option, jboolean ignore) {429return is_bad_option(option, ignore, NULL);430}431432static void describe_range_error(ArgsRange errcode);433static ArgsRange check_memory_size(julong size, julong min_size, julong max_size);434static ArgsRange parse_memory_size(const char* s, julong* long_arg,435julong min_size, julong max_size = max_uintx);436437// methods to build strings from individual args438static void build_jvm_args(const char* arg);439static void build_jvm_flags(const char* arg);440static void add_string(char*** bldarray, int* count, const char* arg);441static const char* build_resource_string(char** args, int count);442443// Returns true if the flag is obsolete (and not yet expired).444// In this case the 'version' buffer is filled in with445// the version number when the flag became obsolete.446static bool is_obsolete_flag(const char* flag_name, JDK_Version* version);447448// Returns 1 if the flag is deprecated (and not yet obsolete or expired).449// In this case the 'version' buffer is filled in with the version number when450// the flag became deprecated.451// Returns -1 if the flag is expired or obsolete.452// Returns 0 otherwise.453static int is_deprecated_flag(const char* flag_name, JDK_Version* version);454455// Return the real name for the flag passed on the command line (either an alias name or "flag_name").456static const char* real_flag_name(const char *flag_name);457458// Return the "real" name for option arg if arg is an alias, and print a warning if arg is deprecated.459// Return NULL if the arg has expired.460static const char* handle_aliases_and_deprecation(const char* arg, bool warn);461462static char* SharedArchivePath;463static char* SharedDynamicArchivePath;464static size_t _default_SharedBaseAddress; // The default value specified in globals.hpp465static int num_archives(const char* archive_path) NOT_CDS_RETURN_(0);466static void extract_shared_archive_paths(const char* archive_path,467char** base_archive_path,468char** top_archive_path) NOT_CDS_RETURN;469470public:471// Parses the arguments, first phase472static jint parse(const JavaVMInitArgs* args);473// Parse a string for a unsigned integer. Returns true if value474// is an unsigned integer greater than or equal to the minimum475// parameter passed and returns the value in uintx_arg. Returns476// false otherwise, with uintx_arg undefined.477static bool parse_uintx(const char* value, uintx* uintx_arg,478uintx min_size);479// Apply ergonomics480static jint apply_ergo();481// Adjusts the arguments after the OS have adjusted the arguments482static jint adjust_after_os();483484// Check consistency or otherwise of VM argument settings485static bool check_vm_args_consistency();486// Used by os_solaris487static bool process_settings_file(const char* file_name, bool should_exist, jboolean ignore_unrecognized);488489static size_t conservative_max_heap_alignment() { return _conservative_max_heap_alignment; }490// Return the maximum size a heap with compressed oops can take491static size_t max_heap_for_compressed_oops();492493// return a char* array containing all options494static char** jvm_flags_array() { return _jvm_flags_array; }495static char** jvm_args_array() { return _jvm_args_array; }496static int num_jvm_flags() { return _num_jvm_flags; }497static int num_jvm_args() { return _num_jvm_args; }498// return the arguments passed to the Java application499static const char* java_command() { return _java_command; }500501// print jvm_flags, jvm_args and java_command502static void print_on(outputStream* st);503static void print_summary_on(outputStream* st);504505// convenient methods to get and set jvm_flags_file506static const char* get_jvm_flags_file() { return _jvm_flags_file; }507static void set_jvm_flags_file(const char *value) {508if (_jvm_flags_file != NULL) {509os::free(_jvm_flags_file);510}511_jvm_flags_file = os::strdup_check_oom(value);512}513// convenient methods to obtain / print jvm_flags and jvm_args514static const char* jvm_flags() { return build_resource_string(_jvm_flags_array, _num_jvm_flags); }515static const char* jvm_args() { return build_resource_string(_jvm_args_array, _num_jvm_args); }516static void print_jvm_flags_on(outputStream* st);517static void print_jvm_args_on(outputStream* st);518519// -Dkey=value flags520static SystemProperty* system_properties() { return _system_properties; }521static const char* get_property(const char* key);522523// -Djava.vendor.url.bug524static const char* java_vendor_url_bug() { return _java_vendor_url_bug; }525526// -Dsun.java.launcher527static const char* sun_java_launcher() { return _sun_java_launcher; }528// Was VM created by a Java launcher?529static bool created_by_java_launcher();530// -Dsun.java.launcher.is_altjvm531static bool sun_java_launcher_is_altjvm();532533// -Xrun534static AgentLibrary* libraries() { return _libraryList.first(); }535static bool init_libraries_at_startup() { return !_libraryList.is_empty(); }536static void convert_library_to_agent(AgentLibrary* lib)537{ _libraryList.remove(lib);538_agentList.add(lib); }539540// -agentlib -agentpath541static AgentLibrary* agents() { return _agentList.first(); }542static bool init_agents_at_startup() { return !_agentList.is_empty(); }543544// abort, exit, vfprintf hooks545static abort_hook_t abort_hook() { return _abort_hook; }546static exit_hook_t exit_hook() { return _exit_hook; }547static vfprintf_hook_t vfprintf_hook() { return _vfprintf_hook; }548549static const char* GetSharedArchivePath() { return SharedArchivePath; }550static const char* GetSharedDynamicArchivePath() { return SharedDynamicArchivePath; }551static size_t default_SharedBaseAddress() { return _default_SharedBaseAddress; }552// Java launcher properties553static void process_sun_java_launcher_properties(JavaVMInitArgs* args);554555// System properties556static void init_system_properties();557558// Update/Initialize System properties after JDK version number is known559static void init_version_specific_system_properties();560561// Update VM info property - called after argument parsing562static void update_vm_info_property(const char* vm_info) {563_vm_info->set_value(vm_info);564}565566// Property List manipulation567static void PropertyList_add(SystemProperty *element);568static void PropertyList_add(SystemProperty** plist, SystemProperty *element);569static void PropertyList_add(SystemProperty** plist, const char* k, const char* v, bool writeable, bool internal);570571static void PropertyList_unique_add(SystemProperty** plist, const char* k, const char* v,572PropertyAppendable append, PropertyWriteable writeable,573PropertyInternal internal);574static const char* PropertyList_get_value(SystemProperty* plist, const char* key);575static const char* PropertyList_get_readable_value(SystemProperty* plist, const char* key);576static int PropertyList_count(SystemProperty* pl);577static int PropertyList_readable_count(SystemProperty* pl);578static const char* PropertyList_get_key_at(SystemProperty* pl,int index);579static char* PropertyList_get_value_at(SystemProperty* pl,int index);580581static bool is_internal_module_property(const char* option);582583// Miscellaneous System property value getter and setters.584static void set_dll_dir(const char *value) { _sun_boot_library_path->set_value(value); }585static void set_java_home(const char *value) { _java_home->set_value(value); }586static void set_library_path(const char *value) { _java_library_path->set_value(value); }587static void set_ext_dirs(char *value) { _ext_dirs = os::strdup_check_oom(value); }588589// Set up the underlying pieces of the system boot class path590static void add_patch_mod_prefix(const char *module_name, const char *path, bool* patch_mod_javabase);591static void set_sysclasspath(const char *value, bool has_jimage) {592// During start up, set by os::set_boot_path()593assert(get_sysclasspath() == NULL, "System boot class path previously set");594_system_boot_class_path->set_value(value);595_has_jimage = has_jimage;596}597static void append_sysclasspath(const char *value) {598_system_boot_class_path->append_value(value);599_jdk_boot_class_path_append->append_value(value);600}601602static GrowableArray<ModulePatchPath*>* get_patch_mod_prefix() { return _patch_mod_prefix; }603static char* get_sysclasspath() { return _system_boot_class_path->value(); }604static char* get_jdk_boot_class_path_append() { return _jdk_boot_class_path_append->value(); }605static bool has_jimage() { return _has_jimage; }606607static char* get_java_home() { return _java_home->value(); }608static char* get_dll_dir() { return _sun_boot_library_path->value(); }609static char* get_ext_dirs() { return _ext_dirs; }610static char* get_appclasspath() { return _java_class_path->value(); }611static void fix_appclasspath();612613static char* get_default_shared_archive_path() NOT_CDS_RETURN_(NULL);614static bool init_shared_archive_paths() NOT_CDS_RETURN_(false);615616// Operation modi617static Mode mode() { return _mode; }618static bool is_interpreter_only() { return mode() == _int; }619static bool is_compiler_only() { return mode() == _comp; }620621622// preview features623static void set_enable_preview() { _enable_preview = true; }624static bool enable_preview() { return _enable_preview; }625626// Utility: copies src into buf, replacing "%%" with "%" and "%p" with pid.627static bool copy_expand_pid(const char* src, size_t srclen, char* buf, size_t buflen);628629static void check_unsupported_dumping_properties() NOT_CDS_RETURN;630631static bool check_unsupported_cds_runtime_properties() NOT_CDS_RETURN0;632633static bool atojulong(const char *s, julong* result);634635static bool has_jfr_option() NOT_JFR_RETURN_(false);636637static bool is_dumping_archive() { return DumpSharedSpaces || DynamicDumpSharedSpaces; }638639static void assert_is_dumping_archive() {640assert(Arguments::is_dumping_archive(), "dump time only");641}642643DEBUG_ONLY(static bool verify_special_jvm_flags(bool check_globals);)644};645646// Disable options not supported in this release, with a warning if they647// were explicitly requested on the command-line648#define UNSUPPORTED_OPTION(opt) \649do { \650if (opt) { \651if (FLAG_IS_CMDLINE(opt)) { \652warning("-XX:+" #opt " not supported in this VM"); \653} \654FLAG_SET_DEFAULT(opt, false); \655} \656} while(0)657658// similar to UNSUPPORTED_OPTION but sets flag to NULL659#define UNSUPPORTED_OPTION_NULL(opt) \660do { \661if (opt) { \662if (FLAG_IS_CMDLINE(opt)) { \663warning("-XX flag " #opt " not supported in this VM"); \664} \665FLAG_SET_DEFAULT(opt, NULL); \666} \667} while(0)668669// Initialize options not supported in this release, with a warning670// if they were explicitly requested on the command-line671#define UNSUPPORTED_OPTION_INIT(opt, value) \672do { \673if (FLAG_IS_CMDLINE(opt)) { \674warning("-XX flag " #opt " not supported in this VM"); \675} \676FLAG_SET_DEFAULT(opt, value); \677} while(0)678679#endif // SHARE_RUNTIME_ARGUMENTS_HPP680681682