duke@435: /* mikael@4153: * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. duke@435: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. duke@435: * duke@435: * This code is free software; you can redistribute it and/or modify it duke@435: * under the terms of the GNU General Public License version 2 only, as duke@435: * published by the Free Software Foundation. duke@435: * duke@435: * This code is distributed in the hope that it will be useful, but WITHOUT duke@435: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or duke@435: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License duke@435: * version 2 for more details (a copy is included in the LICENSE file that duke@435: * accompanied this code). duke@435: * duke@435: * You should have received a copy of the GNU General Public License version duke@435: * 2 along with this work; if not, write to the Free Software Foundation, duke@435: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. duke@435: * trims@1907: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA trims@1907: * or visit www.oracle.com if you need additional information or have any trims@1907: * questions. duke@435: * duke@435: */ duke@435: stefank@2314: #ifndef SHARE_VM_RUNTIME_ARGUMENTS_HPP stefank@2314: #define SHARE_VM_RUNTIME_ARGUMENTS_HPP stefank@2314: stefank@2314: #include "runtime/java.hpp" stefank@2314: #include "runtime/perfData.hpp" stefank@2314: #include "utilities/top.hpp" stefank@2314: duke@435: // Arguments parses the command line and recognizes options duke@435: duke@435: // Invocation API hook typedefs (these should really be defined in jni.hpp) duke@435: extern "C" { duke@435: typedef void (JNICALL *abort_hook_t)(void); duke@435: typedef void (JNICALL *exit_hook_t)(jint code); duke@435: typedef jint (JNICALL *vfprintf_hook_t)(FILE *fp, const char *format, va_list args); duke@435: } duke@435: duke@435: // Forward declarations duke@435: duke@435: class SysClassPath; duke@435: duke@435: // Element describing System and User (-Dkey=value flags) defined property. duke@435: zgu@3900: class SystemProperty: public CHeapObj { duke@435: private: duke@435: char* _key; duke@435: char* _value; duke@435: SystemProperty* _next; duke@435: bool _writeable; duke@435: bool writeable() { return _writeable; } duke@435: duke@435: public: duke@435: // Accessors duke@435: const char* key() const { return _key; } duke@435: char* value() const { return _value; } duke@435: SystemProperty* next() const { return _next; } duke@435: void set_next(SystemProperty* next) { _next = next; } duke@435: bool set_value(char *value) { duke@435: if (writeable()) { duke@435: if (_value != NULL) { duke@435: FreeHeap(_value); duke@435: } zgu@3900: _value = AllocateHeap(strlen(value)+1, mtInternal); duke@435: if (_value != NULL) { duke@435: strcpy(_value, value); duke@435: } duke@435: return true; duke@435: } duke@435: return false; duke@435: } duke@435: duke@435: void append_value(const char *value) { duke@435: char *sp; duke@435: size_t len = 0; duke@435: if (value != NULL) { duke@435: len = strlen(value); duke@435: if (_value != NULL) { duke@435: len += strlen(_value); duke@435: } zgu@3900: sp = AllocateHeap(len+2, mtInternal); duke@435: if (sp != NULL) { duke@435: if (_value != NULL) { duke@435: strcpy(sp, _value); duke@435: strcat(sp, os::path_separator()); duke@435: strcat(sp, value); duke@435: FreeHeap(_value); duke@435: } else { duke@435: strcpy(sp, value); duke@435: } duke@435: _value = sp; duke@435: } duke@435: } duke@435: } duke@435: duke@435: // Constructor duke@435: SystemProperty(const char* key, const char* value, bool writeable) { duke@435: if (key == NULL) { duke@435: _key = NULL; duke@435: } else { zgu@3900: _key = AllocateHeap(strlen(key)+1, mtInternal); duke@435: strcpy(_key, key); duke@435: } duke@435: if (value == NULL) { duke@435: _value = NULL; duke@435: } else { zgu@3900: _value = AllocateHeap(strlen(value)+1, mtInternal); duke@435: strcpy(_value, value); duke@435: } duke@435: _next = NULL; duke@435: _writeable = writeable; duke@435: } duke@435: }; duke@435: duke@435: duke@435: // For use by -agentlib, -agentpath and -Xrun zgu@3900: class AgentLibrary : public CHeapObj { duke@435: friend class AgentLibraryList; duke@435: private: duke@435: char* _name; duke@435: char* _options; duke@435: void* _os_lib; duke@435: bool _is_absolute_path; duke@435: AgentLibrary* _next; duke@435: duke@435: public: duke@435: // Accessors duke@435: const char* name() const { return _name; } duke@435: char* options() const { return _options; } duke@435: bool is_absolute_path() const { return _is_absolute_path; } duke@435: void* os_lib() const { return _os_lib; } duke@435: void set_os_lib(void* os_lib) { _os_lib = os_lib; } duke@435: AgentLibrary* next() const { return _next; } duke@435: duke@435: // Constructor duke@435: AgentLibrary(const char* name, const char* options, bool is_absolute_path, void* os_lib) { zgu@3900: _name = AllocateHeap(strlen(name)+1, mtInternal); duke@435: strcpy(_name, name); duke@435: if (options == NULL) { duke@435: _options = NULL; duke@435: } else { zgu@3900: _options = AllocateHeap(strlen(options)+1, mtInternal); duke@435: strcpy(_options, options); duke@435: } duke@435: _is_absolute_path = is_absolute_path; duke@435: _os_lib = os_lib; duke@435: _next = NULL; duke@435: } duke@435: }; duke@435: duke@435: // maintain an order of entry list of AgentLibrary duke@435: class AgentLibraryList VALUE_OBJ_CLASS_SPEC { duke@435: private: duke@435: AgentLibrary* _first; duke@435: AgentLibrary* _last; duke@435: public: duke@435: bool is_empty() const { return _first == NULL; } duke@435: AgentLibrary* first() const { return _first; } duke@435: duke@435: // add to the end of the list duke@435: void add(AgentLibrary* lib) { duke@435: if (is_empty()) { duke@435: _first = _last = lib; duke@435: } else { duke@435: _last->_next = lib; duke@435: _last = lib; duke@435: } duke@435: lib->_next = NULL; duke@435: } duke@435: duke@435: // search for and remove a library known to be in the list duke@435: void remove(AgentLibrary* lib) { duke@435: AgentLibrary* curr; duke@435: AgentLibrary* prev = NULL; duke@435: for (curr = first(); curr != NULL; prev = curr, curr = curr->next()) { duke@435: if (curr == lib) { duke@435: break; duke@435: } duke@435: } duke@435: assert(curr != NULL, "always should be found"); duke@435: duke@435: if (curr != NULL) { duke@435: // it was found, by-pass this library duke@435: if (prev == NULL) { duke@435: _first = curr->_next; duke@435: } else { duke@435: prev->_next = curr->_next; duke@435: } duke@435: if (curr == _last) { duke@435: _last = prev; duke@435: } duke@435: curr->_next = NULL; duke@435: } duke@435: } duke@435: duke@435: AgentLibraryList() { duke@435: _first = NULL; duke@435: _last = NULL; duke@435: } duke@435: }; duke@435: duke@435: duke@435: class Arguments : AllStatic { duke@435: friend class VMStructs; duke@435: friend class JvmtiExport; duke@435: public: duke@435: // Operation modi duke@435: enum Mode { duke@435: _int, // corresponds to -Xint duke@435: _mixed, // corresponds to -Xmixed duke@435: _comp // corresponds to -Xcomp duke@435: }; duke@435: duke@435: enum ArgsRange { duke@435: arg_unreadable = -3, duke@435: arg_too_small = -2, duke@435: arg_too_big = -1, duke@435: arg_in_range = 0 duke@435: }; duke@435: duke@435: private: duke@435: duke@435: // an array containing all flags specified in the .hotspotrc file duke@435: static char** _jvm_flags_array; duke@435: static int _num_jvm_flags; duke@435: // an array containing all jvm arguments specified in the command line duke@435: static char** _jvm_args_array; duke@435: static int _num_jvm_args; duke@435: // string containing all java command (class/jarfile name and app args) duke@435: static char* _java_command; duke@435: duke@435: // Property list duke@435: static SystemProperty* _system_properties; duke@435: duke@435: // Quick accessor to System properties in the list: duke@435: static SystemProperty *_java_ext_dirs; duke@435: static SystemProperty *_java_endorsed_dirs; duke@435: static SystemProperty *_sun_boot_library_path; duke@435: static SystemProperty *_java_library_path; duke@435: static SystemProperty *_java_home; duke@435: static SystemProperty *_java_class_path; duke@435: static SystemProperty *_sun_boot_class_path; duke@435: duke@435: // Meta-index for knowing what packages are in the boot class path duke@435: static char* _meta_index_path; duke@435: static char* _meta_index_dir; duke@435: duke@435: // java.vendor.url.bug, bug reporting URL for fatal errors. duke@435: static const char* _java_vendor_url_bug; duke@435: duke@435: // sun.java.launcher, private property to provide information about duke@435: // java/gamma launcher duke@435: static const char* _sun_java_launcher; duke@435: duke@435: // sun.java.launcher.pid, private property duke@435: static int _sun_java_launcher_pid; duke@435: sla@2584: // was this VM created by the gamma launcher sla@2584: static bool _created_by_gamma_launcher; sla@2584: duke@435: // Option flags duke@435: static bool _has_profile; duke@435: static bool _has_alloc_profile; duke@435: static const char* _gc_log_filename; duke@435: static uintx _min_heap_size; duke@435: duke@435: // -Xrun arguments duke@435: static AgentLibraryList _libraryList; duke@435: static void add_init_library(const char* name, char* options) duke@435: { _libraryList.add(new AgentLibrary(name, options, false, NULL)); } duke@435: duke@435: // -agentlib and -agentpath arguments duke@435: static AgentLibraryList _agentList; duke@435: static void add_init_agent(const char* name, char* options, bool absolute_path) duke@435: { _agentList.add(new AgentLibrary(name, options, absolute_path, NULL)); } duke@435: duke@435: // Late-binding agents not started via arguments duke@435: static void add_loaded_agent(const char* name, char* options, bool absolute_path, void* os_lib) duke@435: { _agentList.add(new AgentLibrary(name, options, absolute_path, os_lib)); } duke@435: duke@435: // Operation modi duke@435: static Mode _mode; duke@435: static void set_mode_flags(Mode mode); duke@435: static bool _java_compiler; duke@435: static void set_java_compiler(bool arg) { _java_compiler = arg; } duke@435: static bool java_compiler() { return _java_compiler; } duke@435: duke@435: // -Xdebug flag duke@435: static bool _xdebug_mode; duke@435: static void set_xdebug_mode(bool arg) { _xdebug_mode = arg; } duke@435: static bool xdebug_mode() { return _xdebug_mode; } duke@435: duke@435: // Used to save default settings duke@435: static bool _AlwaysCompileLoopMethods; duke@435: static bool _UseOnStackReplacement; duke@435: static bool _BackgroundCompilation; duke@435: static bool _ClipInlining; duke@435: static bool _CIDynamicCompilePriority; duke@435: iveresov@2138: // Tiered iveresov@2138: static void set_tiered_flags(); duke@435: // CMS/ParNew garbage collectors duke@435: static void set_parnew_gc_flags(); duke@435: static void set_cms_and_parnew_gc_flags(); ysr@777: // UseParallel[Old]GC duke@435: static void set_parallel_gc_flags(); ysr@777: // Garbage-First (UseG1GC) ysr@777: static void set_g1_gc_flags(); duke@435: // GC ergonomics duke@435: static void set_ergonomics_flags(); jcoomes@2644: static void set_shared_spaces_flags(); phh@1499: // Setup heap size phh@1499: static void set_heap_size(); duke@435: // Based on automatic selection criteria, should the duke@435: // low pause collector be used. duke@435: static bool should_auto_select_low_pause_collector(); duke@435: duke@435: // Bytecode rewriting duke@435: static void set_bytecode_flags(); duke@435: duke@435: // Invocation API hooks duke@435: static abort_hook_t _abort_hook; duke@435: static exit_hook_t _exit_hook; duke@435: static vfprintf_hook_t _vfprintf_hook; duke@435: duke@435: // System properties duke@435: static bool add_property(const char* prop); duke@435: duke@435: // Aggressive optimization flags. duke@435: static void set_aggressive_opts_flags(); duke@435: duke@435: // Argument parsing duke@435: static void do_pd_flag_adjustments(); duke@435: static bool parse_argument(const char* arg, FlagValueOrigin origin); duke@435: static bool process_argument(const char* arg, jboolean ignore_unrecognized, FlagValueOrigin origin); duke@435: static void process_java_launcher_argument(const char*, void*); duke@435: static void process_java_compiler_argument(char* arg); duke@435: static jint parse_options_environment_variable(const char* name, SysClassPath* scp_p, bool* scp_assembly_required_p); duke@435: static jint parse_java_tool_options_environment_variable(SysClassPath* scp_p, bool* scp_assembly_required_p); duke@435: static jint parse_java_options_environment_variable(SysClassPath* scp_p, bool* scp_assembly_required_p); duke@435: static jint parse_vm_init_args(const JavaVMInitArgs* args); duke@435: static jint parse_each_vm_init_arg(const JavaVMInitArgs* args, SysClassPath* scp_p, bool* scp_assembly_required_p, FlagValueOrigin origin); duke@435: static jint finalize_vm_init_args(SysClassPath* scp_p, bool scp_assembly_required); duke@435: static bool is_bad_option(const JavaVMOption* option, jboolean ignore, duke@435: const char* option_type); duke@435: static bool is_bad_option(const JavaVMOption* option, jboolean ignore) { duke@435: return is_bad_option(option, ignore, NULL); duke@435: } johnc@1679: static bool verify_interval(uintx val, uintx min, johnc@1679: uintx max, const char* name); ptisnovs@2099: static bool verify_min_value(intx val, intx min, const char* name); duke@435: static bool verify_percentage(uintx value, const char* name); duke@435: static void describe_range_error(ArgsRange errcode); swamyv@924: static ArgsRange check_memory_size(julong size, julong min_size); swamyv@924: static ArgsRange parse_memory_size(const char* s, julong* long_arg, swamyv@924: julong min_size); jmasa@1719: // Parse a string for a unsigned integer. Returns true if value jmasa@1719: // is an unsigned integer greater than or equal to the minimum jmasa@1719: // parameter passed and returns the value in uintx_arg. Returns jmasa@1719: // false otherwise, with uintx_arg undefined. jmasa@1719: static bool parse_uintx(const char* value, uintx* uintx_arg, jmasa@1719: uintx min_size); duke@435: duke@435: // methods to build strings from individual args duke@435: static void build_jvm_args(const char* arg); duke@435: static void build_jvm_flags(const char* arg); duke@435: static void add_string(char*** bldarray, int* count, const char* arg); duke@435: static const char* build_resource_string(char** args, int count); duke@435: duke@435: static bool methodExists( duke@435: char* className, char* methodName, duke@435: int classesNum, char** classes, bool* allMethods, duke@435: int methodsNum, char** methods, bool* allClasses duke@435: ); duke@435: duke@435: static void parseOnlyLine( duke@435: const char* line, duke@435: short* classesNum, short* classesMax, char*** classes, bool** allMethods, duke@435: short* methodsNum, short* methodsMax, char*** methods, bool** allClasses duke@435: ); duke@435: kamg@677: // Returns true if the string s is in the list of flags that have recently kamg@677: // been made obsolete. If we detect one of these flags on the command kamg@677: // line, instead of failing we print a warning message and ignore the kamg@677: // flag. This gives the user a release or so to stop using the flag. kamg@677: static bool is_newly_obsolete(const char* s, JDK_Version* buffer); duke@435: duke@435: static short CompileOnlyClassesNum; duke@435: static short CompileOnlyClassesMax; duke@435: static char** CompileOnlyClasses; duke@435: static bool* CompileOnlyAllMethods; duke@435: duke@435: static short CompileOnlyMethodsNum; duke@435: static short CompileOnlyMethodsMax; duke@435: static char** CompileOnlyMethods; duke@435: static bool* CompileOnlyAllClasses; duke@435: duke@435: static short InterpretOnlyClassesNum; duke@435: static short InterpretOnlyClassesMax; duke@435: static char** InterpretOnlyClasses; duke@435: static bool* InterpretOnlyAllMethods; duke@435: duke@435: static bool CheckCompileOnly; duke@435: duke@435: static char* SharedArchivePath; duke@435: duke@435: public: duke@435: // Parses the arguments duke@435: static jint parse(const JavaVMInitArgs* args); brutisso@4296: // Adjusts the arguments after the OS have adjusted the arguments brutisso@4296: static jint adjust_after_os(); jmasa@445: // Check for consistency in the selection of the garbage collector. jmasa@445: static bool check_gc_consistency(); duke@435: // Check consistecy or otherwise of VM argument settings duke@435: static bool check_vm_args_consistency(); ptisnovs@2099: // Check stack pages settings ptisnovs@2099: static bool check_stack_pages(); duke@435: // Used by os_solaris duke@435: static bool process_settings_file(const char* file_name, bool should_exist, jboolean ignore_unrecognized); duke@435: duke@435: // return a char* array containing all options duke@435: static char** jvm_flags_array() { return _jvm_flags_array; } duke@435: static char** jvm_args_array() { return _jvm_args_array; } duke@435: static int num_jvm_flags() { return _num_jvm_flags; } duke@435: static int num_jvm_args() { return _num_jvm_args; } duke@435: // return the arguments passed to the Java application duke@435: static const char* java_command() { return _java_command; } duke@435: duke@435: // print jvm_flags, jvm_args and java_command duke@435: static void print_on(outputStream* st); duke@435: duke@435: // convenient methods to obtain / print jvm_flags and jvm_args duke@435: static const char* jvm_flags() { return build_resource_string(_jvm_flags_array, _num_jvm_flags); } duke@435: static const char* jvm_args() { return build_resource_string(_jvm_args_array, _num_jvm_args); } duke@435: static void print_jvm_flags_on(outputStream* st); duke@435: static void print_jvm_args_on(outputStream* st); duke@435: duke@435: // -Dkey=value flags duke@435: static SystemProperty* system_properties() { return _system_properties; } duke@435: static const char* get_property(const char* key); duke@435: duke@435: // -Djava.vendor.url.bug duke@435: static const char* java_vendor_url_bug() { return _java_vendor_url_bug; } duke@435: duke@435: // -Dsun.java.launcher duke@435: static const char* sun_java_launcher() { return _sun_java_launcher; } duke@435: // Was VM created by a Java launcher? duke@435: static bool created_by_java_launcher(); sla@2584: // Was VM created by the gamma Java launcher? sla@2584: static bool created_by_gamma_launcher(); duke@435: // -Dsun.java.launcher.pid duke@435: static int sun_java_launcher_pid() { return _sun_java_launcher_pid; } duke@435: duke@435: // -Xloggc:, if not specified will be NULL duke@435: static const char* gc_log_filename() { return _gc_log_filename; } duke@435: duke@435: // -Xprof/-Xaprof duke@435: static bool has_profile() { return _has_profile; } duke@435: static bool has_alloc_profile() { return _has_alloc_profile; } duke@435: phh@1499: // -Xms, -Xmx duke@435: static uintx min_heap_size() { return _min_heap_size; } duke@435: static void set_min_heap_size(uintx v) { _min_heap_size = v; } duke@435: duke@435: // -Xrun duke@435: static AgentLibrary* libraries() { return _libraryList.first(); } duke@435: static bool init_libraries_at_startup() { return !_libraryList.is_empty(); } duke@435: static void convert_library_to_agent(AgentLibrary* lib) duke@435: { _libraryList.remove(lib); duke@435: _agentList.add(lib); } duke@435: duke@435: // -agentlib -agentpath duke@435: static AgentLibrary* agents() { return _agentList.first(); } duke@435: static bool init_agents_at_startup() { return !_agentList.is_empty(); } duke@435: duke@435: // abort, exit, vfprintf hooks duke@435: static abort_hook_t abort_hook() { return _abort_hook; } duke@435: static exit_hook_t exit_hook() { return _exit_hook; } duke@435: static vfprintf_hook_t vfprintf_hook() { return _vfprintf_hook; } duke@435: duke@435: static bool GetCheckCompileOnly () { return CheckCompileOnly; } duke@435: duke@435: static const char* GetSharedArchivePath() { return SharedArchivePath; } duke@435: duke@435: static bool CompileMethod(char* className, char* methodName) { duke@435: return duke@435: methodExists( duke@435: className, methodName, duke@435: CompileOnlyClassesNum, CompileOnlyClasses, CompileOnlyAllMethods, duke@435: CompileOnlyMethodsNum, CompileOnlyMethods, CompileOnlyAllClasses duke@435: ); duke@435: } duke@435: duke@435: // Java launcher properties duke@435: static void process_sun_java_launcher_properties(JavaVMInitArgs* args); duke@435: duke@435: // System properties duke@435: static void init_system_properties(); duke@435: zgu@2219: // Update/Initialize System properties after JDK version number is known zgu@2219: static void init_version_specific_system_properties(); zgu@2219: phh@1126: // Property List manipulation duke@435: static void PropertyList_add(SystemProperty** plist, SystemProperty *element); duke@435: static void PropertyList_add(SystemProperty** plist, const char* k, char* v); phh@1126: static void PropertyList_unique_add(SystemProperty** plist, const char* k, char* v) { phh@1126: PropertyList_unique_add(plist, k, v, false); phh@1126: } phh@1126: static void PropertyList_unique_add(SystemProperty** plist, const char* k, char* v, jboolean append); duke@435: static const char* PropertyList_get_value(SystemProperty* plist, const char* key); duke@435: static int PropertyList_count(SystemProperty* pl); duke@435: static const char* PropertyList_get_key_at(SystemProperty* pl,int index); duke@435: static char* PropertyList_get_value_at(SystemProperty* pl,int index); duke@435: duke@435: // Miscellaneous System property value getter and setters. duke@435: static void set_dll_dir(char *value) { _sun_boot_library_path->set_value(value); } duke@435: static void set_java_home(char *value) { _java_home->set_value(value); } duke@435: static void set_library_path(char *value) { _java_library_path->set_value(value); } duke@435: static void set_ext_dirs(char *value) { _java_ext_dirs->set_value(value); } duke@435: static void set_endorsed_dirs(char *value) { _java_endorsed_dirs->set_value(value); } duke@435: static void set_sysclasspath(char *value) { _sun_boot_class_path->set_value(value); } duke@435: static void append_sysclasspath(const char *value) { _sun_boot_class_path->append_value(value); } duke@435: static void set_meta_index_path(char* meta_index_path, char* meta_index_dir) { duke@435: _meta_index_path = meta_index_path; duke@435: _meta_index_dir = meta_index_dir; duke@435: } duke@435: duke@435: static char *get_java_home() { return _java_home->value(); } duke@435: static char *get_dll_dir() { return _sun_boot_library_path->value(); } duke@435: static char *get_endorsed_dir() { return _java_endorsed_dirs->value(); } duke@435: static char *get_sysclasspath() { return _sun_boot_class_path->value(); } duke@435: static char* get_meta_index_path() { return _meta_index_path; } duke@435: static char* get_meta_index_dir() { return _meta_index_dir; } duke@435: duke@435: // Operation modi duke@435: static Mode mode() { return _mode; } duke@435: duke@435: // Utility: copies src into buf, replacing "%%" with "%" and "%p" with pid. duke@435: static bool copy_expand_pid(const char* src, size_t srclen, char* buf, size_t buflen); duke@435: duke@435: #ifdef KERNEL duke@435: // For java kernel vm, return property string for kernel properties. duke@435: static char *get_kernel_properties(); duke@435: #endif // KERNEL duke@435: }; stefank@2314: stefank@2314: #endif // SHARE_VM_RUNTIME_ARGUMENTS_HPP