Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/runtime/arguments.hpp
32285 views
/*1* Copyright (c) 1997, 2018, 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_VM_RUNTIME_ARGUMENTS_HPP25#define SHARE_VM_RUNTIME_ARGUMENTS_HPP2627#include "runtime/java.hpp"28#include "runtime/perfData.hpp"29#include "utilities/debug.hpp"30#include "utilities/top.hpp"3132// Arguments parses the command line and recognizes options3334// Invocation API hook typedefs (these should really be defined in jni.hpp)35extern "C" {36typedef void (JNICALL *abort_hook_t)(void);37typedef void (JNICALL *exit_hook_t)(jint code);38typedef jint (JNICALL *vfprintf_hook_t)(FILE *fp, const char *format, va_list args) ATTRIBUTE_PRINTF(2, 0);39}4041// Forward declarations4243class SysClassPath;4445// Element describing System and User (-Dkey=value flags) defined property.4647class SystemProperty: public CHeapObj<mtInternal> {48private:49char* _key;50char* _value;51SystemProperty* _next;52bool _writeable;53bool writeable() { return _writeable; }5455public:56// Accessors57const char* key() const { return _key; }58char* value() const { return _value; }59SystemProperty* next() const { return _next; }60void set_next(SystemProperty* next) { _next = next; }61bool set_value(char *value) {62if (writeable()) {63if (_value != NULL) {64FreeHeap(_value);65}66_value = AllocateHeap(strlen(value)+1, mtInternal);67if (_value != NULL) {68strcpy(_value, value);69}70return true;71}72return false;73}7475void append_value(const char *value) {76char *sp;77size_t len = 0;78if (value != NULL) {79len = strlen(value);80if (_value != NULL) {81len += strlen(_value);82}83sp = AllocateHeap(len+2, mtInternal);84if (sp != NULL) {85if (_value != NULL) {86strcpy(sp, _value);87strcat(sp, os::path_separator());88strcat(sp, value);89FreeHeap(_value);90} else {91strcpy(sp, value);92}93_value = sp;94}95}96}9798// Constructor99SystemProperty(const char* key, const char* value, bool writeable) {100if (key == NULL) {101_key = NULL;102} else {103_key = AllocateHeap(strlen(key)+1, mtInternal);104strcpy(_key, key);105}106if (value == NULL) {107_value = NULL;108} else {109_value = AllocateHeap(strlen(value)+1, mtInternal);110strcpy(_value, value);111}112_next = NULL;113_writeable = writeable;114}115};116117118// For use by -agentlib, -agentpath and -Xrun119class AgentLibrary : public CHeapObj<mtInternal> {120friend class AgentLibraryList;121public:122// Is this library valid or not. Don't rely on os_lib == NULL as statically123// linked lib could have handle of RTLD_DEFAULT which == 0 on some platforms124enum AgentState {125agent_invalid = 0,126agent_valid = 1127};128129private:130char* _name;131char* _options;132void* _os_lib;133bool _is_absolute_path;134bool _is_static_lib;135AgentState _state;136AgentLibrary* _next;137138public:139// Accessors140const char* name() const { return _name; }141char* options() const { return _options; }142bool is_absolute_path() const { return _is_absolute_path; }143void* os_lib() const { return _os_lib; }144void set_os_lib(void* os_lib) { _os_lib = os_lib; }145AgentLibrary* next() const { return _next; }146bool is_static_lib() const { return _is_static_lib; }147void set_static_lib(bool is_static_lib) { _is_static_lib = is_static_lib; }148bool valid() { return (_state == agent_valid); }149void set_valid() { _state = agent_valid; }150void set_invalid() { _state = agent_invalid; }151152// Constructor153AgentLibrary(const char* name, const char* options, bool is_absolute_path, void* os_lib) {154_name = AllocateHeap(strlen(name)+1, mtInternal);155strcpy(_name, name);156if (options == NULL) {157_options = NULL;158} else {159_options = AllocateHeap(strlen(options)+1, mtInternal);160strcpy(_options, options);161}162_is_absolute_path = is_absolute_path;163_os_lib = os_lib;164_next = NULL;165_state = agent_invalid;166_is_static_lib = false;167}168};169170// maintain an order of entry list of AgentLibrary171class AgentLibraryList VALUE_OBJ_CLASS_SPEC {172private:173AgentLibrary* _first;174AgentLibrary* _last;175public:176bool is_empty() const { return _first == NULL; }177AgentLibrary* first() const { return _first; }178179// add to the end of the list180void add(AgentLibrary* lib) {181if (is_empty()) {182_first = _last = lib;183} else {184_last->_next = lib;185_last = lib;186}187lib->_next = NULL;188}189190// search for and remove a library known to be in the list191void remove(AgentLibrary* lib) {192AgentLibrary* curr;193AgentLibrary* prev = NULL;194for (curr = first(); curr != NULL; prev = curr, curr = curr->next()) {195if (curr == lib) {196break;197}198}199assert(curr != NULL, "always should be found");200201if (curr != NULL) {202// it was found, by-pass this library203if (prev == NULL) {204_first = curr->_next;205} else {206prev->_next = curr->_next;207}208if (curr == _last) {209_last = prev;210}211curr->_next = NULL;212}213}214215AgentLibraryList() {216_first = NULL;217_last = NULL;218}219};220221222class Arguments : AllStatic {223friend class VMStructs;224friend class JvmtiExport;225public:226// Operation modi227enum Mode {228_int, // corresponds to -Xint229_mixed, // corresponds to -Xmixed230_comp // corresponds to -Xcomp231};232233enum ArgsRange {234arg_unreadable = -3,235arg_too_small = -2,236arg_too_big = -1,237arg_in_range = 0238};239240private:241242// an array containing all flags specified in the .hotspotrc file243static char** _jvm_flags_array;244static int _num_jvm_flags;245// an array containing all jvm arguments specified in the command line246static char** _jvm_args_array;247static int _num_jvm_args;248// string containing all java command (class/jarfile name and app args)249static char* _java_command;250251// Property list252static SystemProperty* _system_properties;253254// Quick accessor to System properties in the list:255static SystemProperty *_java_ext_dirs;256static SystemProperty *_java_endorsed_dirs;257static SystemProperty *_sun_boot_library_path;258static SystemProperty *_java_library_path;259static SystemProperty *_java_home;260static SystemProperty *_java_class_path;261static SystemProperty *_sun_boot_class_path;262263// Meta-index for knowing what packages are in the boot class path264static char* _meta_index_path;265static char* _meta_index_dir;266267// java.vendor.url.bug, bug reporting URL for fatal errors.268static const char* _java_vendor_url_bug;269270// sun.java.launcher, private property to provide information about271// java/gamma launcher272static const char* _sun_java_launcher;273274// sun.java.launcher.pid, private property275static int _sun_java_launcher_pid;276277// was this VM created by the gamma launcher278static bool _created_by_gamma_launcher;279280// Option flags281static bool _has_profile;282static const char* _gc_log_filename;283// Value of the conservative maximum heap alignment needed284static size_t _conservative_max_heap_alignment;285286static uintx _min_heap_size;287288// Used to store original flag values289static uintx _min_heap_free_ratio;290static uintx _max_heap_free_ratio;291292// -Xrun arguments293static AgentLibraryList _libraryList;294static void add_init_library(const char* name, char* options)295{ _libraryList.add(new AgentLibrary(name, options, false, NULL)); }296297// -agentlib and -agentpath arguments298static AgentLibraryList _agentList;299static void add_init_agent(const char* name, char* options, bool absolute_path)300{ _agentList.add(new AgentLibrary(name, options, absolute_path, NULL)); }301302// Late-binding agents not started via arguments303static void add_loaded_agent(AgentLibrary *agentLib)304{ _agentList.add(agentLib); }305static void add_loaded_agent(const char* name, char* options, bool absolute_path, void* os_lib)306{ _agentList.add(new AgentLibrary(name, options, absolute_path, os_lib)); }307308// Operation modi309static Mode _mode;310static void set_mode_flags(Mode mode);311static bool _java_compiler;312static void set_java_compiler(bool arg) { _java_compiler = arg; }313static bool java_compiler() { return _java_compiler; }314315// -Xdebug flag316static bool _xdebug_mode;317static void set_xdebug_mode(bool arg) { _xdebug_mode = arg; }318static bool xdebug_mode() { return _xdebug_mode; }319320// Used to save default settings321static bool _AlwaysCompileLoopMethods;322static bool _UseOnStackReplacement;323static bool _BackgroundCompilation;324static bool _ClipInlining;325static bool _CIDynamicCompilePriority;326327// Tiered328static void set_tiered_flags();329static int get_min_number_of_compiler_threads();330// CMS/ParNew garbage collectors331static void set_parnew_gc_flags();332static void set_cms_and_parnew_gc_flags();333// UseParallel[Old]GC334static void set_parallel_gc_flags();335// Garbage-First (UseG1GC)336static void set_g1_gc_flags();337// Shenandoah GC (UseShenandoahGC)338static void set_shenandoah_gc_flags();339// GC ergonomics340static void set_conservative_max_heap_alignment();341static void set_use_compressed_oops();342static void set_use_compressed_klass_ptrs();343static void select_gc();344static void set_ergonomics_flags();345static void set_shared_spaces_flags();346// limits the given memory size by the maximum amount of memory this process is347// currently allowed to allocate or reserve.348static julong limit_by_allocatable_memory(julong size);349// Setup heap size350static void set_heap_size();351// Based on automatic selection criteria, should the352// low pause collector be used.353static bool should_auto_select_low_pause_collector();354355// Bytecode rewriting356static void set_bytecode_flags();357358// Invocation API hooks359static abort_hook_t _abort_hook;360static exit_hook_t _exit_hook;361static vfprintf_hook_t _vfprintf_hook;362363// System properties364static bool add_property(const char* prop);365366// Aggressive optimization flags.367static void set_aggressive_opts_flags();368369static jint set_aggressive_heap_flags();370371// Argument parsing372static void do_pd_flag_adjustments();373static bool parse_argument(const char* arg, Flag::Flags origin);374static bool process_argument(const char* arg, jboolean ignore_unrecognized, Flag::Flags origin);375static void process_java_launcher_argument(const char*, void*);376static void process_java_compiler_argument(char* arg);377static jint parse_options_environment_variable(const char* name, SysClassPath* scp_p, bool* scp_assembly_required_p);378static jint parse_java_tool_options_environment_variable(SysClassPath* scp_p, bool* scp_assembly_required_p);379static jint parse_java_options_environment_variable(SysClassPath* scp_p, bool* scp_assembly_required_p);380static jint parse_vm_init_args(const JavaVMInitArgs* args);381static jint parse_each_vm_init_arg(const JavaVMInitArgs* args, SysClassPath* scp_p, bool* scp_assembly_required_p, Flag::Flags origin);382static jint finalize_vm_init_args(SysClassPath* scp_p, bool scp_assembly_required);383static bool is_bad_option(const JavaVMOption* option, jboolean ignore, const char* option_type);384385static bool is_bad_option(const JavaVMOption* option, jboolean ignore) {386return is_bad_option(option, ignore, NULL);387}388389static bool is_percentage(uintx val) {390return val <= 100;391}392393static bool verify_interval(uintx val, uintx min,394uintx max, const char* name);395static bool verify_min_value(intx val, intx min, const char* name);396static bool verify_percentage(uintx value, const char* name);397static void describe_range_error(ArgsRange errcode);398static ArgsRange check_memory_size(julong size, julong min_size);399static ArgsRange parse_memory_size(const char* s, julong* long_arg,400julong min_size);401// Parse a string for a unsigned integer. Returns true if value402// is an unsigned integer greater than or equal to the minimum403// parameter passed and returns the value in uintx_arg. Returns404// false otherwise, with uintx_arg undefined.405static bool parse_uintx(const char* value, uintx* uintx_arg,406uintx min_size);407408// methods to build strings from individual args409static void build_jvm_args(const char* arg);410static void build_jvm_flags(const char* arg);411static void add_string(char*** bldarray, int* count, const char* arg);412static const char* build_resource_string(char** args, int count);413414static bool methodExists(415char* className, char* methodName,416int classesNum, char** classes, bool* allMethods,417int methodsNum, char** methods, bool* allClasses418);419420static void parseOnlyLine(421const char* line,422short* classesNum, short* classesMax, char*** classes, bool** allMethods,423short* methodsNum, short* methodsMax, char*** methods, bool** allClasses424);425426// Returns true if the string s is in the list of flags that have recently427// been made obsolete. If we detect one of these flags on the command428// line, instead of failing we print a warning message and ignore the429// flag. This gives the user a release or so to stop using the flag.430static bool is_newly_obsolete(const char* s, JDK_Version* buffer);431432static short CompileOnlyClassesNum;433static short CompileOnlyClassesMax;434static char** CompileOnlyClasses;435static bool* CompileOnlyAllMethods;436437static short CompileOnlyMethodsNum;438static short CompileOnlyMethodsMax;439static char** CompileOnlyMethods;440static bool* CompileOnlyAllClasses;441442static short InterpretOnlyClassesNum;443static short InterpretOnlyClassesMax;444static char** InterpretOnlyClasses;445static bool* InterpretOnlyAllMethods;446447static bool CheckCompileOnly;448449static char* SharedArchivePath;450451public:452// Parses the arguments, first phase453static jint parse(const JavaVMInitArgs* args);454// Apply ergonomics455static jint apply_ergo();456// Adjusts the arguments after the OS have adjusted the arguments457static jint adjust_after_os();458459static void set_gc_specific_flags();460static inline bool gc_selected(); // whether a gc has been selected461static void select_gc_ergonomically();462463// Verifies that the given value will fit as a MinHeapFreeRatio. If not, an error464// message is returned in the provided buffer.465static bool verify_MinHeapFreeRatio(FormatBuffer<80>& err_msg, uintx min_heap_free_ratio);466467// Verifies that the given value will fit as a MaxHeapFreeRatio. If not, an error468// message is returned in the provided buffer.469static bool verify_MaxHeapFreeRatio(FormatBuffer<80>& err_msg, uintx max_heap_free_ratio);470471// Check for consistency in the selection of the garbage collector.472static bool check_gc_consistency(); // Check user-selected gc473static void check_deprecated_gcs();474static void check_deprecated_gc_flags();475// Check consistecy or otherwise of VM argument settings476static bool check_vm_args_consistency();477// Check stack pages settings478static bool check_stack_pages();479// Used by os_solaris480static bool process_settings_file(const char* file_name, bool should_exist, jboolean ignore_unrecognized);481482static size_t conservative_max_heap_alignment() { return _conservative_max_heap_alignment; }483// Return the maximum size a heap with compressed oops can take484static size_t max_heap_for_compressed_oops();485486// return a char* array containing all options487static char** jvm_flags_array() { return _jvm_flags_array; }488static char** jvm_args_array() { return _jvm_args_array; }489static int num_jvm_flags() { return _num_jvm_flags; }490static int num_jvm_args() { return _num_jvm_args; }491// return the arguments passed to the Java application492static const char* java_command() { return _java_command; }493494// print jvm_flags, jvm_args and java_command495static void print_on(outputStream* st);496497// convenient methods to obtain / print jvm_flags and jvm_args498static const char* jvm_flags() { return build_resource_string(_jvm_flags_array, _num_jvm_flags); }499static const char* jvm_args() { return build_resource_string(_jvm_args_array, _num_jvm_args); }500static void print_jvm_flags_on(outputStream* st);501static void print_jvm_args_on(outputStream* st);502503// -Dkey=value flags504static SystemProperty* system_properties() { return _system_properties; }505static const char* get_property(const char* key);506507// -Djava.vendor.url.bug508static const char* java_vendor_url_bug() { return _java_vendor_url_bug; }509510// -Dsun.java.launcher511static const char* sun_java_launcher() { return _sun_java_launcher; }512// Was VM created by a Java launcher?513static bool created_by_java_launcher();514// Was VM created by the gamma Java launcher?515static bool created_by_gamma_launcher();516// -Dsun.java.launcher.pid517static int sun_java_launcher_pid() { return _sun_java_launcher_pid; }518519// -Xloggc:<file>, if not specified will be NULL520static const char* gc_log_filename() { return _gc_log_filename; }521522// -Xprof523static bool has_profile() { return _has_profile; }524525// -Xms, -Xmx526static uintx min_heap_size() { return _min_heap_size; }527static void set_min_heap_size(uintx v) { _min_heap_size = v; }528529// Returns the original values of -XX:MinHeapFreeRatio and -XX:MaxHeapFreeRatio530static uintx min_heap_free_ratio() { return _min_heap_free_ratio; }531static uintx max_heap_free_ratio() { return _max_heap_free_ratio; }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 bool GetCheckCompileOnly () { return CheckCompileOnly; }550551static const char* GetSharedArchivePath() { return SharedArchivePath; }552553static bool CompileMethod(char* className, char* methodName) {554return555methodExists(556className, methodName,557CompileOnlyClassesNum, CompileOnlyClasses, CompileOnlyAllMethods,558CompileOnlyMethodsNum, CompileOnlyMethods, CompileOnlyAllClasses559);560}561562// Java launcher properties563static void process_sun_java_launcher_properties(JavaVMInitArgs* args);564565// System properties566static void init_system_properties();567568// Update/Initialize System properties after JDK version number is known569static void init_version_specific_system_properties();570571// Property List manipulation572static void PropertyList_add(SystemProperty** plist, SystemProperty *element);573static void PropertyList_add(SystemProperty** plist, const char* k, char* v);574static void PropertyList_unique_add(SystemProperty** plist, const char* k, char* v) {575PropertyList_unique_add(plist, k, v, false);576}577static void PropertyList_unique_add(SystemProperty** plist, const char* k, char* v, jboolean append);578static const char* PropertyList_get_value(SystemProperty* plist, const char* key);579static int PropertyList_count(SystemProperty* pl);580static const char* PropertyList_get_key_at(SystemProperty* pl,int index);581static char* PropertyList_get_value_at(SystemProperty* pl,int index);582583// Miscellaneous System property value getter and setters.584static void set_dll_dir(char *value) { _sun_boot_library_path->set_value(value); }585static void set_java_home(char *value) { _java_home->set_value(value); }586static void set_library_path(char *value) { _java_library_path->set_value(value); }587static void set_ext_dirs(char *value) { _java_ext_dirs->set_value(value); }588static void set_endorsed_dirs(char *value) { _java_endorsed_dirs->set_value(value); }589static void set_sysclasspath(char *value) { _sun_boot_class_path->set_value(value); }590static void append_sysclasspath(const char *value) { _sun_boot_class_path->append_value(value); }591static void set_meta_index_path(char* meta_index_path, char* meta_index_dir) {592_meta_index_path = meta_index_path;593_meta_index_dir = meta_index_dir;594}595596static char* get_java_home() { return _java_home->value(); }597static char* get_dll_dir() { return _sun_boot_library_path->value(); }598static char* get_endorsed_dir() { return _java_endorsed_dirs->value(); }599static char* get_sysclasspath() { return _sun_boot_class_path->value(); }600static char* get_meta_index_path() { return _meta_index_path; }601static char* get_meta_index_dir() { return _meta_index_dir; }602static char* get_ext_dirs() { return _java_ext_dirs->value(); }603static char* get_appclasspath() { return _java_class_path->value(); }604static void fix_appclasspath();605606// Operation modi607static Mode mode() { return _mode; }608static bool is_interpreter_only() { return mode() == _int; }609610611// Utility: copies src into buf, replacing "%%" with "%" and "%p" with pid.612static bool copy_expand_pid(const char* src, size_t srclen, char* buf, size_t buflen);613};614615bool Arguments::gc_selected() {616return UseConcMarkSweepGC || UseG1GC || UseParallelGC || UseParallelOldGC ||617UseParNewGC || UseSerialGC || UseShenandoahGC;618}619620#endif // SHARE_VM_RUNTIME_ARGUMENTS_HPP621622623