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