src/share/vm/runtime/arguments.hpp

Fri, 25 Jan 2013 10:04:08 -0500

author
zgu
date
Fri, 25 Jan 2013 10:04:08 -0500
changeset 4492
8b46b0196eb0
parent 4388
e0ab18eafbde
child 4734
209f8ba5020b
permissions
-rw-r--r--

8000692: Remove old KERNEL code
Summary: Removed depreciated kernel VM source code from hotspot VM
Reviewed-by: dholmes, acorn

     1 /*
     2  * Copyright (c) 1997, 2013, 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  *
    23  */
    25 #ifndef SHARE_VM_RUNTIME_ARGUMENTS_HPP
    26 #define SHARE_VM_RUNTIME_ARGUMENTS_HPP
    28 #include "runtime/java.hpp"
    29 #include "runtime/perfData.hpp"
    30 #include "utilities/top.hpp"
    32 // Arguments parses the command line and recognizes options
    34 // Invocation API hook typedefs (these should really be defined in jni.hpp)
    35 extern "C" {
    36   typedef void (JNICALL *abort_hook_t)(void);
    37   typedef void (JNICALL *exit_hook_t)(jint code);
    38   typedef jint (JNICALL *vfprintf_hook_t)(FILE *fp, const char *format, va_list args);
    39 }
    41 // Forward declarations
    43 class SysClassPath;
    45 // Element describing System and User (-Dkey=value flags) defined property.
    47 class SystemProperty: public CHeapObj<mtInternal> {
    48  private:
    49   char*           _key;
    50   char*           _value;
    51   SystemProperty* _next;
    52   bool            _writeable;
    53   bool writeable()   { return _writeable; }
    55  public:
    56   // Accessors
    57   const char* key() const                   { return _key; }
    58   char* value() const                       { return _value; }
    59   SystemProperty* next() const              { return _next; }
    60   void set_next(SystemProperty* next)       { _next = next; }
    61   bool set_value(char *value) {
    62     if (writeable()) {
    63       if (_value != NULL) {
    64         FreeHeap(_value);
    65       }
    66       _value = AllocateHeap(strlen(value)+1, mtInternal);
    67       if (_value != NULL) {
    68         strcpy(_value, value);
    69       }
    70       return true;
    71     }
    72     return false;
    73   }
    75   void append_value(const char *value) {
    76     char *sp;
    77     size_t len = 0;
    78     if (value != NULL) {
    79       len = strlen(value);
    80       if (_value != NULL) {
    81         len += strlen(_value);
    82       }
    83       sp = AllocateHeap(len+2, mtInternal);
    84       if (sp != NULL) {
    85         if (_value != NULL) {
    86           strcpy(sp, _value);
    87           strcat(sp, os::path_separator());
    88           strcat(sp, value);
    89           FreeHeap(_value);
    90         } else {
    91           strcpy(sp, value);
    92         }
    93         _value = sp;
    94       }
    95     }
    96   }
    98   // Constructor
    99   SystemProperty(const char* key, const char* value, bool writeable) {
   100     if (key == NULL) {
   101       _key = NULL;
   102     } else {
   103       _key = AllocateHeap(strlen(key)+1, mtInternal);
   104       strcpy(_key, key);
   105     }
   106     if (value == NULL) {
   107       _value = NULL;
   108     } else {
   109       _value = AllocateHeap(strlen(value)+1, mtInternal);
   110       strcpy(_value, value);
   111     }
   112     _next = NULL;
   113     _writeable = writeable;
   114   }
   115 };
   118 // For use by -agentlib, -agentpath and -Xrun
   119 class AgentLibrary : public CHeapObj<mtInternal> {
   120   friend class AgentLibraryList;
   121  private:
   122   char*           _name;
   123   char*           _options;
   124   void*           _os_lib;
   125   bool            _is_absolute_path;
   126   AgentLibrary*   _next;
   128  public:
   129   // Accessors
   130   const char* name() const                  { return _name; }
   131   char* options() const                     { return _options; }
   132   bool is_absolute_path() const             { return _is_absolute_path; }
   133   void* os_lib() const                      { return _os_lib; }
   134   void set_os_lib(void* os_lib)             { _os_lib = os_lib; }
   135   AgentLibrary* next() const                { return _next; }
   137   // Constructor
   138   AgentLibrary(const char* name, const char* options, bool is_absolute_path, void* os_lib) {
   139     _name = AllocateHeap(strlen(name)+1, mtInternal);
   140     strcpy(_name, name);
   141     if (options == NULL) {
   142       _options = NULL;
   143     } else {
   144       _options = AllocateHeap(strlen(options)+1, mtInternal);
   145       strcpy(_options, options);
   146     }
   147     _is_absolute_path = is_absolute_path;
   148     _os_lib = os_lib;
   149     _next = NULL;
   150   }
   151 };
   153 // maintain an order of entry list of AgentLibrary
   154 class AgentLibraryList VALUE_OBJ_CLASS_SPEC {
   155  private:
   156   AgentLibrary*   _first;
   157   AgentLibrary*   _last;
   158  public:
   159   bool is_empty() const                     { return _first == NULL; }
   160   AgentLibrary* first() const               { return _first; }
   162   // add to the end of the list
   163   void add(AgentLibrary* lib) {
   164     if (is_empty()) {
   165       _first = _last = lib;
   166     } else {
   167       _last->_next = lib;
   168       _last = lib;
   169     }
   170     lib->_next = NULL;
   171   }
   173   // search for and remove a library known to be in the list
   174   void remove(AgentLibrary* lib) {
   175     AgentLibrary* curr;
   176     AgentLibrary* prev = NULL;
   177     for (curr = first(); curr != NULL; prev = curr, curr = curr->next()) {
   178       if (curr == lib) {
   179         break;
   180       }
   181     }
   182     assert(curr != NULL, "always should be found");
   184     if (curr != NULL) {
   185       // it was found, by-pass this library
   186       if (prev == NULL) {
   187         _first = curr->_next;
   188       } else {
   189         prev->_next = curr->_next;
   190       }
   191       if (curr == _last) {
   192         _last = prev;
   193       }
   194       curr->_next = NULL;
   195     }
   196   }
   198   AgentLibraryList() {
   199     _first = NULL;
   200     _last = NULL;
   201   }
   202 };
   205 class Arguments : AllStatic {
   206   friend class VMStructs;
   207   friend class JvmtiExport;
   208  public:
   209   // Operation modi
   210   enum Mode {
   211     _int,       // corresponds to -Xint
   212     _mixed,     // corresponds to -Xmixed
   213     _comp       // corresponds to -Xcomp
   214   };
   216   enum ArgsRange {
   217     arg_unreadable = -3,
   218     arg_too_small  = -2,
   219     arg_too_big    = -1,
   220     arg_in_range   = 0
   221   };
   223  private:
   225   // an array containing all flags specified in the .hotspotrc file
   226   static char** _jvm_flags_array;
   227   static int    _num_jvm_flags;
   228   // an array containing all jvm arguments specified in the command line
   229   static char** _jvm_args_array;
   230   static int    _num_jvm_args;
   231   // string containing all java command (class/jarfile name and app args)
   232   static char* _java_command;
   234   // Property list
   235   static SystemProperty* _system_properties;
   237   // Quick accessor to System properties in the list:
   238   static SystemProperty *_java_ext_dirs;
   239   static SystemProperty *_java_endorsed_dirs;
   240   static SystemProperty *_sun_boot_library_path;
   241   static SystemProperty *_java_library_path;
   242   static SystemProperty *_java_home;
   243   static SystemProperty *_java_class_path;
   244   static SystemProperty *_sun_boot_class_path;
   246   // Meta-index for knowing what packages are in the boot class path
   247   static char* _meta_index_path;
   248   static char* _meta_index_dir;
   250   // java.vendor.url.bug, bug reporting URL for fatal errors.
   251   static const char* _java_vendor_url_bug;
   253   // sun.java.launcher, private property to provide information about
   254   // java/gamma launcher
   255   static const char* _sun_java_launcher;
   257   // sun.java.launcher.pid, private property
   258   static int    _sun_java_launcher_pid;
   260   // was this VM created by the gamma launcher
   261   static bool   _created_by_gamma_launcher;
   263   // Option flags
   264   static bool   _has_profile;
   265   static bool   _has_alloc_profile;
   266   static const char*  _gc_log_filename;
   267   static uintx  _min_heap_size;
   269   // -Xrun arguments
   270   static AgentLibraryList _libraryList;
   271   static void add_init_library(const char* name, char* options)
   272     { _libraryList.add(new AgentLibrary(name, options, false, NULL)); }
   274   // -agentlib and -agentpath arguments
   275   static AgentLibraryList _agentList;
   276   static void add_init_agent(const char* name, char* options, bool absolute_path)
   277     { _agentList.add(new AgentLibrary(name, options, absolute_path, NULL)); }
   279   // Late-binding agents not started via arguments
   280   static void add_loaded_agent(const char* name, char* options, bool absolute_path, void* os_lib)
   281     { _agentList.add(new AgentLibrary(name, options, absolute_path, os_lib)); }
   283   // Operation modi
   284   static Mode _mode;
   285   static void set_mode_flags(Mode mode);
   286   static bool _java_compiler;
   287   static void set_java_compiler(bool arg) { _java_compiler = arg; }
   288   static bool java_compiler()   { return _java_compiler; }
   290   // -Xdebug flag
   291   static bool _xdebug_mode;
   292   static void set_xdebug_mode(bool arg) { _xdebug_mode = arg; }
   293   static bool xdebug_mode()             { return _xdebug_mode; }
   295   // Used to save default settings
   296   static bool _AlwaysCompileLoopMethods;
   297   static bool _UseOnStackReplacement;
   298   static bool _BackgroundCompilation;
   299   static bool _ClipInlining;
   300   static bool _CIDynamicCompilePriority;
   302   // Tiered
   303   static void set_tiered_flags();
   304   // CMS/ParNew garbage collectors
   305   static void set_parnew_gc_flags();
   306   static void set_cms_and_parnew_gc_flags();
   307   // UseParallel[Old]GC
   308   static void set_parallel_gc_flags();
   309   // Garbage-First (UseG1GC)
   310   static void set_g1_gc_flags();
   311   // GC ergonomics
   312   static void set_ergonomics_flags();
   313   static void set_shared_spaces_flags();
   314   // Setup heap size
   315   static void set_heap_size();
   316   // Based on automatic selection criteria, should the
   317   // low pause collector be used.
   318   static bool should_auto_select_low_pause_collector();
   320   // Bytecode rewriting
   321   static void set_bytecode_flags();
   323   // Invocation API hooks
   324   static abort_hook_t     _abort_hook;
   325   static exit_hook_t      _exit_hook;
   326   static vfprintf_hook_t  _vfprintf_hook;
   328   // System properties
   329   static bool add_property(const char* prop);
   331   // Aggressive optimization flags.
   332   static void set_aggressive_opts_flags();
   334   // Argument parsing
   335   static void do_pd_flag_adjustments();
   336   static bool parse_argument(const char* arg, FlagValueOrigin origin);
   337   static bool process_argument(const char* arg, jboolean ignore_unrecognized, FlagValueOrigin origin);
   338   static void process_java_launcher_argument(const char*, void*);
   339   static void process_java_compiler_argument(char* arg);
   340   static jint parse_options_environment_variable(const char* name, SysClassPath* scp_p, bool* scp_assembly_required_p);
   341   static jint parse_java_tool_options_environment_variable(SysClassPath* scp_p, bool* scp_assembly_required_p);
   342   static jint parse_java_options_environment_variable(SysClassPath* scp_p, bool* scp_assembly_required_p);
   343   static jint parse_vm_init_args(const JavaVMInitArgs* args);
   344   static jint parse_each_vm_init_arg(const JavaVMInitArgs* args, SysClassPath* scp_p, bool* scp_assembly_required_p, FlagValueOrigin origin);
   345   static jint finalize_vm_init_args(SysClassPath* scp_p, bool scp_assembly_required);
   346   static bool is_bad_option(const JavaVMOption* option, jboolean ignore,
   347     const char* option_type);
   348   static bool is_bad_option(const JavaVMOption* option, jboolean ignore) {
   349     return is_bad_option(option, ignore, NULL);
   350   }
   351   static bool verify_interval(uintx val, uintx min,
   352                               uintx max, const char* name);
   353   static bool verify_min_value(intx val, intx min, const char* name);
   354   static bool verify_percentage(uintx value, const char* name);
   355   static void describe_range_error(ArgsRange errcode);
   356   static ArgsRange check_memory_size(julong size, julong min_size);
   357   static ArgsRange parse_memory_size(const char* s, julong* long_arg,
   358                                      julong min_size);
   359   // Parse a string for a unsigned integer.  Returns true if value
   360   // is an unsigned integer greater than or equal to the minimum
   361   // parameter passed and returns the value in uintx_arg.  Returns
   362   // false otherwise, with uintx_arg undefined.
   363   static bool parse_uintx(const char* value, uintx* uintx_arg,
   364                           uintx min_size);
   366   // methods to build strings from individual args
   367   static void build_jvm_args(const char* arg);
   368   static void build_jvm_flags(const char* arg);
   369   static void add_string(char*** bldarray, int* count, const char* arg);
   370   static const char* build_resource_string(char** args, int count);
   372   static bool methodExists(
   373     char* className, char* methodName,
   374     int classesNum, char** classes, bool* allMethods,
   375     int methodsNum, char** methods, bool* allClasses
   376   );
   378   static void parseOnlyLine(
   379     const char* line,
   380     short* classesNum, short* classesMax, char*** classes, bool** allMethods,
   381     short* methodsNum, short* methodsMax, char*** methods, bool** allClasses
   382   );
   384   // Returns true if the string s is in the list of flags that have recently
   385   // been made obsolete.  If we detect one of these flags on the command
   386   // line, instead of failing we print a warning message and ignore the
   387   // flag.  This gives the user a release or so to stop using the flag.
   388   static bool is_newly_obsolete(const char* s, JDK_Version* buffer);
   390   static short  CompileOnlyClassesNum;
   391   static short  CompileOnlyClassesMax;
   392   static char** CompileOnlyClasses;
   393   static bool*  CompileOnlyAllMethods;
   395   static short  CompileOnlyMethodsNum;
   396   static short  CompileOnlyMethodsMax;
   397   static char** CompileOnlyMethods;
   398   static bool*  CompileOnlyAllClasses;
   400   static short  InterpretOnlyClassesNum;
   401   static short  InterpretOnlyClassesMax;
   402   static char** InterpretOnlyClasses;
   403   static bool*  InterpretOnlyAllMethods;
   405   static bool   CheckCompileOnly;
   407   static char*  SharedArchivePath;
   409  public:
   410   // Parses the arguments
   411   static jint parse(const JavaVMInitArgs* args);
   412   // Adjusts the arguments after the OS have adjusted the arguments
   413   static jint adjust_after_os();
   414   // Check for consistency in the selection of the garbage collector.
   415   static bool check_gc_consistency();
   416   static void check_deprecated_gcs();
   417   // Check consistecy or otherwise of VM argument settings
   418   static bool check_vm_args_consistency();
   419   // Check stack pages settings
   420   static bool check_stack_pages();
   421   // Used by os_solaris
   422   static bool process_settings_file(const char* file_name, bool should_exist, jboolean ignore_unrecognized);
   424   // return a char* array containing all options
   425   static char** jvm_flags_array()          { return _jvm_flags_array; }
   426   static char** jvm_args_array()           { return _jvm_args_array; }
   427   static int num_jvm_flags()               { return _num_jvm_flags; }
   428   static int num_jvm_args()                { return _num_jvm_args; }
   429   // return the arguments passed to the Java application
   430   static const char* java_command()        { return _java_command; }
   432   // print jvm_flags, jvm_args and java_command
   433   static void print_on(outputStream* st);
   435   // convenient methods to obtain / print jvm_flags and jvm_args
   436   static const char* jvm_flags()           { return build_resource_string(_jvm_flags_array, _num_jvm_flags); }
   437   static const char* jvm_args()            { return build_resource_string(_jvm_args_array, _num_jvm_args); }
   438   static void print_jvm_flags_on(outputStream* st);
   439   static void print_jvm_args_on(outputStream* st);
   441   // -Dkey=value flags
   442   static SystemProperty*  system_properties()   { return _system_properties; }
   443   static const char*    get_property(const char* key);
   445   // -Djava.vendor.url.bug
   446   static const char* java_vendor_url_bug()  { return _java_vendor_url_bug; }
   448   // -Dsun.java.launcher
   449   static const char* sun_java_launcher()    { return _sun_java_launcher; }
   450   // Was VM created by a Java launcher?
   451   static bool created_by_java_launcher();
   452   // Was VM created by the gamma Java launcher?
   453   static bool created_by_gamma_launcher();
   454   // -Dsun.java.launcher.pid
   455   static int sun_java_launcher_pid()        { return _sun_java_launcher_pid; }
   457   // -Xloggc:<file>, if not specified will be NULL
   458   static const char* gc_log_filename()      { return _gc_log_filename; }
   460   // -Xprof/-Xaprof
   461   static bool has_profile()                 { return _has_profile; }
   462   static bool has_alloc_profile()           { return _has_alloc_profile; }
   464   // -Xms, -Xmx
   465   static uintx min_heap_size()              { return _min_heap_size; }
   466   static void  set_min_heap_size(uintx v)   { _min_heap_size = v;  }
   468   // -Xrun
   469   static AgentLibrary* libraries()          { return _libraryList.first(); }
   470   static bool init_libraries_at_startup()   { return !_libraryList.is_empty(); }
   471   static void convert_library_to_agent(AgentLibrary* lib)
   472                                             { _libraryList.remove(lib);
   473                                               _agentList.add(lib); }
   475   // -agentlib -agentpath
   476   static AgentLibrary* agents()             { return _agentList.first(); }
   477   static bool init_agents_at_startup()      { return !_agentList.is_empty(); }
   479   // abort, exit, vfprintf hooks
   480   static abort_hook_t    abort_hook()       { return _abort_hook; }
   481   static exit_hook_t     exit_hook()        { return _exit_hook; }
   482   static vfprintf_hook_t vfprintf_hook()    { return _vfprintf_hook; }
   484   static bool GetCheckCompileOnly ()        { return CheckCompileOnly; }
   486   static const char* GetSharedArchivePath() { return SharedArchivePath; }
   488   static bool CompileMethod(char* className, char* methodName) {
   489     return
   490       methodExists(
   491         className, methodName,
   492         CompileOnlyClassesNum, CompileOnlyClasses, CompileOnlyAllMethods,
   493         CompileOnlyMethodsNum, CompileOnlyMethods, CompileOnlyAllClasses
   494       );
   495   }
   497   // Java launcher properties
   498   static void process_sun_java_launcher_properties(JavaVMInitArgs* args);
   500   // System properties
   501   static void init_system_properties();
   503   // Update/Initialize System properties after JDK version number is known
   504   static void init_version_specific_system_properties();
   506   // Property List manipulation
   507   static void PropertyList_add(SystemProperty** plist, SystemProperty *element);
   508   static void PropertyList_add(SystemProperty** plist, const char* k, char* v);
   509   static void PropertyList_unique_add(SystemProperty** plist, const char* k, char* v) {
   510     PropertyList_unique_add(plist, k, v, false);
   511   }
   512   static void PropertyList_unique_add(SystemProperty** plist, const char* k, char* v, jboolean append);
   513   static const char* PropertyList_get_value(SystemProperty* plist, const char* key);
   514   static int  PropertyList_count(SystemProperty* pl);
   515   static const char* PropertyList_get_key_at(SystemProperty* pl,int index);
   516   static char* PropertyList_get_value_at(SystemProperty* pl,int index);
   518   // Miscellaneous System property value getter and setters.
   519   static void set_dll_dir(char *value) { _sun_boot_library_path->set_value(value); }
   520   static void set_java_home(char *value) { _java_home->set_value(value); }
   521   static void set_library_path(char *value) { _java_library_path->set_value(value); }
   522   static void set_ext_dirs(char *value) { _java_ext_dirs->set_value(value); }
   523   static void set_endorsed_dirs(char *value) { _java_endorsed_dirs->set_value(value); }
   524   static void set_sysclasspath(char *value) { _sun_boot_class_path->set_value(value); }
   525   static void append_sysclasspath(const char *value) { _sun_boot_class_path->append_value(value); }
   526   static void set_meta_index_path(char* meta_index_path, char* meta_index_dir) {
   527     _meta_index_path = meta_index_path;
   528     _meta_index_dir  = meta_index_dir;
   529   }
   531   static char *get_java_home() { return _java_home->value(); }
   532   static char *get_dll_dir() { return _sun_boot_library_path->value(); }
   533   static char *get_endorsed_dir() { return _java_endorsed_dirs->value(); }
   534   static char *get_sysclasspath() { return _sun_boot_class_path->value(); }
   535   static char* get_meta_index_path() { return _meta_index_path; }
   536   static char* get_meta_index_dir()  { return _meta_index_dir;  }
   538   // Operation modi
   539   static Mode mode()                        { return _mode; }
   541   // Utility: copies src into buf, replacing "%%" with "%" and "%p" with pid.
   542   static bool copy_expand_pid(const char* src, size_t srclen, char* buf, size_t buflen);
   543 };
   545 #endif // SHARE_VM_RUNTIME_ARGUMENTS_HPP

mercurial