Wed, 13 Jan 2010 23:05:52 -0800
6912065: final fields in objects need to support inlining optimizations for JSR 292
Reviewed-by: twisti, kvn
1 /*
2 * Copyright 1997-2009 Sun Microsystems, Inc. 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 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 */
25 // Arguments parses the command line and recognizes options
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 }
34 // Forward declarations
36 class SysClassPath;
38 // Element describing System and User (-Dkey=value flags) defined property.
40 class SystemProperty: public CHeapObj {
41 private:
42 char* _key;
43 char* _value;
44 SystemProperty* _next;
45 bool _writeable;
46 bool writeable() { return _writeable; }
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 }
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 }
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 };
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;
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; }
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 };
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; }
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 }
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");
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 }
191 AgentLibraryList() {
192 _first = NULL;
193 _last = NULL;
194 }
195 };
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 };
209 enum ArgsRange {
210 arg_unreadable = -3,
211 arg_too_small = -2,
212 arg_too_big = -1,
213 arg_in_range = 0
214 };
216 private:
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;
227 // Property list
228 static SystemProperty* _system_properties;
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;
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;
243 // java.vendor.url.bug, bug reporting URL for fatal errors.
244 static const char* _java_vendor_url_bug;
246 // sun.java.launcher, private property to provide information about
247 // java/gamma launcher
248 static const char* _sun_java_launcher;
250 // sun.java.launcher.pid, private property
251 static int _sun_java_launcher_pid;
253 // Option flags
254 static bool _has_profile;
255 static bool _has_alloc_profile;
256 static const char* _gc_log_filename;
257 static uintx _min_heap_size;
259 // -Xrun arguments
260 static AgentLibraryList _libraryList;
261 static void add_init_library(const char* name, char* options)
262 { _libraryList.add(new AgentLibrary(name, options, false, NULL)); }
264 // -agentlib and -agentpath arguments
265 static AgentLibraryList _agentList;
266 static void add_init_agent(const char* name, char* options, bool absolute_path)
267 { _agentList.add(new AgentLibrary(name, options, absolute_path, NULL)); }
269 // Late-binding agents not started via arguments
270 static void add_loaded_agent(const char* name, char* options, bool absolute_path, void* os_lib)
271 { _agentList.add(new AgentLibrary(name, options, absolute_path, os_lib)); }
273 // Operation modi
274 static Mode _mode;
275 static void set_mode_flags(Mode mode);
276 static bool _java_compiler;
277 static void set_java_compiler(bool arg) { _java_compiler = arg; }
278 static bool java_compiler() { return _java_compiler; }
280 // -Xdebug flag
281 static bool _xdebug_mode;
282 static void set_xdebug_mode(bool arg) { _xdebug_mode = arg; }
283 static bool xdebug_mode() { return _xdebug_mode; }
285 // Used to save default settings
286 static bool _AlwaysCompileLoopMethods;
287 static bool _UseOnStackReplacement;
288 static bool _BackgroundCompilation;
289 static bool _ClipInlining;
290 static bool _CIDynamicCompilePriority;
291 static intx _Tier2CompileThreshold;
293 // CMS/ParNew garbage collectors
294 static void set_parnew_gc_flags();
295 static void set_cms_and_parnew_gc_flags();
296 // UseParallel[Old]GC
297 static void set_parallel_gc_flags();
298 // Garbage-First (UseG1GC)
299 static void set_g1_gc_flags();
300 // GC ergonomics
301 static void set_ergonomics_flags();
302 // Setup heap size
303 static void set_heap_size();
304 // Based on automatic selection criteria, should the
305 // low pause collector be used.
306 static bool should_auto_select_low_pause_collector();
308 // Bytecode rewriting
309 static void set_bytecode_flags();
311 // Invocation API hooks
312 static abort_hook_t _abort_hook;
313 static exit_hook_t _exit_hook;
314 static vfprintf_hook_t _vfprintf_hook;
316 // System properties
317 static bool add_property(const char* prop);
319 // Aggressive optimization flags.
320 static void set_aggressive_opts_flags();
322 // Argument parsing
323 static void do_pd_flag_adjustments();
324 static bool parse_argument(const char* arg, FlagValueOrigin origin);
325 static bool process_argument(const char* arg, jboolean ignore_unrecognized, FlagValueOrigin origin);
326 static void process_java_launcher_argument(const char*, void*);
327 static void process_java_compiler_argument(char* arg);
328 static jint parse_options_environment_variable(const char* name, SysClassPath* scp_p, bool* scp_assembly_required_p);
329 static jint parse_java_tool_options_environment_variable(SysClassPath* scp_p, bool* scp_assembly_required_p);
330 static jint parse_java_options_environment_variable(SysClassPath* scp_p, bool* scp_assembly_required_p);
331 static jint parse_vm_init_args(const JavaVMInitArgs* args);
332 static jint parse_each_vm_init_arg(const JavaVMInitArgs* args, SysClassPath* scp_p, bool* scp_assembly_required_p, FlagValueOrigin origin);
333 static jint finalize_vm_init_args(SysClassPath* scp_p, bool scp_assembly_required);
334 static bool is_bad_option(const JavaVMOption* option, jboolean ignore,
335 const char* option_type);
336 static bool is_bad_option(const JavaVMOption* option, jboolean ignore) {
337 return is_bad_option(option, ignore, NULL);
338 }
339 static bool verify_percentage(uintx value, const char* name);
340 static void describe_range_error(ArgsRange errcode);
341 static ArgsRange check_memory_size(julong size, julong min_size);
342 static ArgsRange parse_memory_size(const char* s, julong* long_arg,
343 julong min_size);
345 // methods to build strings from individual args
346 static void build_jvm_args(const char* arg);
347 static void build_jvm_flags(const char* arg);
348 static void add_string(char*** bldarray, int* count, const char* arg);
349 static const char* build_resource_string(char** args, int count);
351 static bool methodExists(
352 char* className, char* methodName,
353 int classesNum, char** classes, bool* allMethods,
354 int methodsNum, char** methods, bool* allClasses
355 );
357 static void parseOnlyLine(
358 const char* line,
359 short* classesNum, short* classesMax, char*** classes, bool** allMethods,
360 short* methodsNum, short* methodsMax, char*** methods, bool** allClasses
361 );
363 // Returns true if the string s is in the list of flags that have recently
364 // been made obsolete. If we detect one of these flags on the command
365 // line, instead of failing we print a warning message and ignore the
366 // flag. This gives the user a release or so to stop using the flag.
367 static bool is_newly_obsolete(const char* s, JDK_Version* buffer);
369 static short CompileOnlyClassesNum;
370 static short CompileOnlyClassesMax;
371 static char** CompileOnlyClasses;
372 static bool* CompileOnlyAllMethods;
374 static short CompileOnlyMethodsNum;
375 static short CompileOnlyMethodsMax;
376 static char** CompileOnlyMethods;
377 static bool* CompileOnlyAllClasses;
379 static short InterpretOnlyClassesNum;
380 static short InterpretOnlyClassesMax;
381 static char** InterpretOnlyClasses;
382 static bool* InterpretOnlyAllMethods;
384 static bool CheckCompileOnly;
386 static char* SharedArchivePath;
388 public:
389 // Parses the arguments
390 static jint parse(const JavaVMInitArgs* args);
391 // Check for consistency in the selection of the garbage collector.
392 static bool check_gc_consistency();
393 // Check consistecy or otherwise of VM argument settings
394 static bool check_vm_args_consistency();
395 // Used by os_solaris
396 static bool process_settings_file(const char* file_name, bool should_exist, jboolean ignore_unrecognized);
398 // return a char* array containing all options
399 static char** jvm_flags_array() { return _jvm_flags_array; }
400 static char** jvm_args_array() { return _jvm_args_array; }
401 static int num_jvm_flags() { return _num_jvm_flags; }
402 static int num_jvm_args() { return _num_jvm_args; }
403 // return the arguments passed to the Java application
404 static const char* java_command() { return _java_command; }
406 // print jvm_flags, jvm_args and java_command
407 static void print_on(outputStream* st);
409 // convenient methods to obtain / print jvm_flags and jvm_args
410 static const char* jvm_flags() { return build_resource_string(_jvm_flags_array, _num_jvm_flags); }
411 static const char* jvm_args() { return build_resource_string(_jvm_args_array, _num_jvm_args); }
412 static void print_jvm_flags_on(outputStream* st);
413 static void print_jvm_args_on(outputStream* st);
415 // -Dkey=value flags
416 static SystemProperty* system_properties() { return _system_properties; }
417 static const char* get_property(const char* key);
419 // -Djava.vendor.url.bug
420 static const char* java_vendor_url_bug() { return _java_vendor_url_bug; }
422 // -Dsun.java.launcher
423 static const char* sun_java_launcher() { return _sun_java_launcher; }
424 // Was VM created by a Java launcher?
425 static bool created_by_java_launcher();
426 // -Dsun.java.launcher.pid
427 static int sun_java_launcher_pid() { return _sun_java_launcher_pid; }
429 // -Xloggc:<file>, if not specified will be NULL
430 static const char* gc_log_filename() { return _gc_log_filename; }
432 // -Xprof/-Xaprof
433 static bool has_profile() { return _has_profile; }
434 static bool has_alloc_profile() { return _has_alloc_profile; }
436 // -Xms, -Xmx
437 static uintx min_heap_size() { return _min_heap_size; }
438 static void set_min_heap_size(uintx v) { _min_heap_size = v; }
440 // -Xrun
441 static AgentLibrary* libraries() { return _libraryList.first(); }
442 static bool init_libraries_at_startup() { return !_libraryList.is_empty(); }
443 static void convert_library_to_agent(AgentLibrary* lib)
444 { _libraryList.remove(lib);
445 _agentList.add(lib); }
447 // -agentlib -agentpath
448 static AgentLibrary* agents() { return _agentList.first(); }
449 static bool init_agents_at_startup() { return !_agentList.is_empty(); }
451 // abort, exit, vfprintf hooks
452 static abort_hook_t abort_hook() { return _abort_hook; }
453 static exit_hook_t exit_hook() { return _exit_hook; }
454 static vfprintf_hook_t vfprintf_hook() { return _vfprintf_hook; }
456 static bool GetCheckCompileOnly () { return CheckCompileOnly; }
458 static const char* GetSharedArchivePath() { return SharedArchivePath; }
460 static bool CompileMethod(char* className, char* methodName) {
461 return
462 methodExists(
463 className, methodName,
464 CompileOnlyClassesNum, CompileOnlyClasses, CompileOnlyAllMethods,
465 CompileOnlyMethodsNum, CompileOnlyMethods, CompileOnlyAllClasses
466 );
467 }
469 // Java launcher properties
470 static void process_sun_java_launcher_properties(JavaVMInitArgs* args);
472 // System properties
473 static void init_system_properties();
475 // Property List manipulation
476 static void PropertyList_add(SystemProperty** plist, SystemProperty *element);
477 static void PropertyList_add(SystemProperty** plist, const char* k, char* v);
478 static void PropertyList_unique_add(SystemProperty** plist, const char* k, char* v) {
479 PropertyList_unique_add(plist, k, v, false);
480 }
481 static void PropertyList_unique_add(SystemProperty** plist, const char* k, char* v, jboolean append);
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);
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 }
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; }
507 // Operation modi
508 static Mode mode() { return _mode; }
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);
513 #ifdef KERNEL
514 // For java kernel vm, return property string for kernel properties.
515 static char *get_kernel_properties();
516 #endif // KERNEL
517 };