1 /* src/vmcore/options.c - contains global options
3 Copyright (C) 1996-2005, 2006, 2007 R. Grafl, A. Krall, C. Kruegel,
4 C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
5 E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
6 J. Wenninger, Institut f. Computersprachen - TU Wien
8 This file is part of CACAO.
10 This program is free software; you can redistribute it and/or
11 modify it under the terms of the GNU General Public License as
12 published by the Free Software Foundation; either version 2, or (at
13 your option) any later version.
15 This program is distributed in the hope that it will be useful, but
16 WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
35 #if defined(HAVE_STRING_H)
41 #include "mm/memory.h"
43 #include "native/jni.h"
47 #include "vmcore/options.h"
50 /* command line option ********************************************************/
52 s4 opt_index = 0; /* index of processed arguments */
53 char *opt_arg; /* this one exports the option argument */
55 bool opt_foo = false; /* option for development */
59 #if defined(ENABLE_JIT)
60 bool opt_jit = true; /* JIT mode execution (default) */
61 bool opt_intrp = false; /* interpreter mode execution */
63 bool opt_jit = false; /* JIT mode execution */
64 bool opt_intrp = true; /* interpreter mode execution (default) */
69 s4 opt_heapmaxsize = 0; /* maximum heap size */
70 s4 opt_heapstartsize = 0; /* initial heap size */
71 s4 opt_stacksize = 0; /* thread stack size */
73 bool opt_verbose = false;
74 bool opt_debugcolor = false; /* use ANSI terminal sequences */
75 bool compileall = false;
77 bool loadverbose = false;
78 bool initverbose = false;
80 bool opt_verboseclass = false;
81 bool opt_verbosegc = false;
82 bool opt_verbosejni = false;
83 bool opt_verbosecall = false; /* trace all method invocation */
85 bool showmethods = false;
86 bool showconstantpool = false;
89 char *opt_method = NULL;
90 char *opt_signature = NULL;
92 bool compileverbose = false; /* trace compiler actions */
93 bool showstack = false;
95 bool opt_showdisassemble = false; /* generate disassembler listing */
96 bool opt_shownops = false;
97 bool opt_showddatasegment = false; /* generate data segment listing */
98 bool opt_showintermediate = false; /* generate intermediate code listing */
100 bool checkbounds = true; /* check array bounds */
101 bool opt_noieee = false; /* don't implement ieee compliant floats */
102 bool checksync = true; /* do synchronization */
103 #if defined(ENABLE_LOOP)
104 bool opt_loops = false; /* optimize array accesses in loops */
107 bool makeinitializations = true;
109 #if defined(ENABLE_STATISTICS)
110 bool opt_stat = false;
111 bool opt_getloadingtime = false; /* to measure the runtime */
112 bool opt_getcompilingtime = false; /* compute compile time */
114 #if defined(ENABLE_VERIFIER)
115 bool opt_verify = true; /* true if classfiles should be verified */
118 #if defined(ENABLE_PROFILING)
119 bool opt_prof = false;
120 bool opt_prof_bb = false;
124 /* inlining options ***********************************************************/
126 #if defined(ENABLE_INLINING)
127 bool opt_inlining = false;
128 #if defined(ENABLE_INLINING_DEBUG) || !defined(NDEBUG)
129 s4 opt_inline_debug_min_size = 0;
130 s4 opt_inline_debug_max_size = INT_MAX;
131 s4 opt_inline_debug_end_counter = INT_MAX;
132 bool opt_inline_debug_all = false;
133 #endif /* defined(ENABLE_INLINING_DEBUG) || !defined(NDEBUG) */
135 bool opt_inline_debug_log = false;
136 #endif /* !defined(NDEBUG) */
137 #endif /* defined(ENABLE_INLINING) */
140 /* optimization options *******************************************************/
142 #if defined(ENABLE_IFCONV)
143 bool opt_ifconv = false;
146 #if defined(ENABLE_LSRA) || defined(ENABLE_SSA)
147 bool opt_lsra = false;
151 /* interpreter options ********************************************************/
153 #if defined(ENABLE_INTRP)
154 bool opt_no_dynamic = false; /* suppress dynamic superinstructions */
155 bool opt_no_replication = false; /* don't use replication in intrp */
156 bool opt_no_quicksuper = false; /* instructions for quickening cannot be
157 part of dynamic superinstructions */
159 s4 opt_static_supers = 0x7fffffff;
160 bool vm_debug = false; /* XXX this should be called `opt_trace' */
163 #if defined(ENABLE_DEBUG_FILTER)
164 const char *opt_filter_verbosecall_include = 0;
165 const char *opt_filter_verbosecall_exclude = 0;
166 const char *opt_filter_show_method = 0;
170 /* -XX options ****************************************************************/
172 /* NOTE: For better readability keep these alpha-sorted. */
174 int opt_DebugExceptions = 0;
175 int opt_DebugFinalizer = 0;
176 int opt_DebugLocalReferences = 0;
177 int opt_DebugLocks = 0;
178 int opt_DebugPackage = 0;
179 int opt_DebugPatcher = 0;
180 int opt_DebugProperties = 0;
181 int32_t opt_DebugStackFrameInfo = 0;
182 int opt_DebugStackTrace = 0;
183 int opt_DebugThreads = 0;
184 #if defined(ENABLE_DISASSEMBLER)
185 int opt_DisassembleStubs = 0;
187 #if defined(ENABLE_GC_CACAO)
188 int32_t opt_GCDebugRootSet = 0;
189 int32_t opt_GCStress = 0;
191 int32_t opt_MaxPermSize = 0;
192 int32_t opt_PermSize = 0;
193 int opt_PrintConfig = 0;
194 int32_t opt_ProfileGCMemoryUsage = 0;
195 int32_t opt_ProfileMemoryUsage = 0;
196 FILE *opt_ProfileMemoryUsageGNUPlot = NULL;
197 #if defined(ENABLE_REPLACEMENT)
198 int opt_TestReplacement = 0;
200 int32_t opt_ThreadStackSize = 0;
201 int opt_TraceCompilerCalls = 0;
202 int32_t opt_TraceExceptions = 0;
203 int32_t opt_TraceJavaCalls = 0;
204 int32_t opt_TraceJNICalls = 0;
205 int32_t opt_TraceJVMCalls = 0;
206 int32_t opt_TraceJVMCallsVerbose = 0;
207 int32_t opt_TraceLinkClass = 0;
208 #if defined(ENABLE_REPLACEMENT)
209 int32_t opt_TraceReplacement = 0;
221 OPT_DebugLocalReferences,
226 OPT_DebugStackFrameInfo,
229 OPT_DisassembleStubs,
235 OPT_ProfileGCMemoryUsage,
236 OPT_ProfileMemoryUsage,
237 OPT_ProfileMemoryUsageGNUPlot,
240 OPT_TraceCompilerCalls,
245 OPT_TraceJVMCallsVerbose,
251 option_t options_XX[] = {
252 { "DebugExceptions", OPT_DebugExceptions, OPT_TYPE_BOOLEAN, "debug exceptions" },
253 { "DebugFinalizer", OPT_DebugFinalizer, OPT_TYPE_BOOLEAN, "debug finalizer thread" },
254 { "DebugLocalReferences", OPT_DebugLocalReferences, OPT_TYPE_BOOLEAN, "print debug information for local reference tables" },
255 { "DebugLocks", OPT_DebugLocks, OPT_TYPE_BOOLEAN, "print debug information for locks" },
256 { "DebugPackage", OPT_DebugPackage, OPT_TYPE_BOOLEAN, "debug Java boot-packages" },
257 { "DebugPatcher", OPT_DebugPatcher, OPT_TYPE_BOOLEAN, "debug JIT code patching" },
258 { "DebugProperties", OPT_DebugProperties, OPT_TYPE_BOOLEAN, "print debug information for properties" },
259 { "DebugStackFrameInfo", OPT_DebugStackFrameInfo, OPT_TYPE_BOOLEAN, "TODO" },
260 { "DebugStackTrace", OPT_DebugStackTrace, OPT_TYPE_BOOLEAN, "debug stacktrace creation" },
261 { "DebugThreads", OPT_DebugThreads, OPT_TYPE_BOOLEAN, "print debug information for threads" },
262 #if defined(ENABLE_DISASSEMBLER)
263 { "DisassembleStubs", OPT_DisassembleStubs, OPT_TYPE_BOOLEAN, "disassemble builtin and native stubs when generated" },
265 #if defined(ENABLE_GC_CACAO)
266 { "GCDebugRootSet", OPT_GCDebugRootSet, OPT_TYPE_BOOLEAN, "GC: print root-set at collection" },
267 { "GCStress", OPT_GCStress, OPT_TYPE_BOOLEAN, "GC: forced collection at every allocation" },
269 { "MaxPermSize", OPT_MaxPermSize, OPT_TYPE_VALUE, "not implemented" },
270 { "PermSize", OPT_PermSize, OPT_TYPE_VALUE, "not implemented" },
271 { "PrintConfig", OPT_PrintConfig, OPT_TYPE_BOOLEAN, "print VM configuration" },
272 { "ProfileGCMemoryUsage", OPT_ProfileGCMemoryUsage, OPT_TYPE_VALUE, "profiles GC memory usage in the given interval, <value> is in seconds (default: 5)" },
273 { "ProfileMemoryUsage", OPT_ProfileMemoryUsage, OPT_TYPE_VALUE, "TODO" },
274 { "ProfileMemoryUsageGNUPlot", OPT_ProfileMemoryUsageGNUPlot, OPT_TYPE_VALUE, "TODO" },
275 #if defined(ENABLE_REPLACEMENT)
276 { "TestReplacement" , OPT_TestReplacement, OPT_TYPE_BOOLEAN, "activate all replacement points during code generation" },
278 { "ThreadStackSize", OPT_ThreadStackSize, OPT_TYPE_VALUE, "TODO" },
279 { "TraceCompilerCalls", OPT_TraceCompilerCalls, OPT_TYPE_BOOLEAN, "trace JIT compiler calls" },
280 { "TraceExceptions", OPT_TraceExceptions, OPT_TYPE_BOOLEAN, "trace Exception throwing" },
281 { "TraceJavaCalls", OPT_TraceJavaCalls, OPT_TYPE_BOOLEAN, "trace Java method calls" },
282 { "TraceJNICalls", OPT_TraceJNICalls, OPT_TYPE_BOOLEAN, "trace JNI method calls" },
283 { "TraceJVMCalls", OPT_TraceJVMCalls, OPT_TYPE_BOOLEAN, "trace JVM method calls but omit very frequent ones" },
284 { "TraceJVMCallsVerbose", OPT_TraceJVMCallsVerbose, OPT_TYPE_BOOLEAN, "trace all JVM method calls" },
285 { "TraceLinkClass", OPT_TraceLinkClass, OPT_TYPE_BOOLEAN, "trace class linking" },
286 #if defined(ENABLE_REPLACEMENT)
287 { "TraceReplacement", OPT_TraceReplacement, OPT_TYPE_VALUE, "trace on-stack replacement with the given verbosity level (default: 1)" },
292 { NULL, -1, -1, NULL }
296 /* options_get *****************************************************************
300 *******************************************************************************/
302 s4 options_get(opt_struct *opts, JavaVMInitArgs *vm_args)
307 if (opt_index >= vm_args->nOptions)
310 /* get the current option */
312 option = vm_args->options[opt_index].optionString;
314 if ((option == NULL) || (option[0] != '-'))
317 for (i = 0; opts[i].name; i++) {
319 /* boolean option found */
321 if (strcmp(option + 1, opts[i].name) == 0) {
323 return opts[i].value;
327 /* parameter option found */
329 /* with a space between */
331 if (strcmp(option + 1, opts[i].name) == 0) {
334 if (opt_index < vm_args->nOptions) {
336 #if defined(HAVE_STRDUP)
337 opt_arg = strdup(vm_args->options[opt_index].optionString);
343 return opts[i].value;
349 /* parameter and option have no space between */
351 /* FIXME: this assumption is plain wrong, hits you if there is a
352 * parameter with no argument starting with same letter as param with argument
353 * but named after that one, ouch! */
355 size_t l = strlen(opts[i].name);
357 if (strlen(option + 1) > l) {
358 if (memcmp(option + 1, opts[i].name, l) == 0) {
361 #if defined(HAVE_STRDUP)
362 opt_arg = strdup(option + 1 + l);
367 return opts[i].value;
378 /* options_xxusage *************************************************************
380 Print usage message for debugging options.
382 *******************************************************************************/
384 static void options_xxusage(void)
391 for (opt = options_XX; opt->name != NULL; opt++) {
395 case OPT_TYPE_BOOLEAN:
396 printf("+%s", opt->name);
397 length = strlen(" -XX:+") + strlen(opt->name);
400 printf("%s=<value>", opt->name);
401 length = strlen(" -XX:") + strlen(opt->name) + strlen("=<value>");
405 /* Check if the help fits into one 80-column line.
406 Documentation starts at column 29. */
408 if (length < (29 - 1)) {
409 /* Print missing spaces up to column 29. */
411 for (i = length; i < 29; i++)
416 printf(" "); /* 29 spaces */
419 /* Check documentation length. */
421 length = strlen(opt->doc);
423 if (length < (80 - 29)) {
424 printf("%s", opt->doc);
427 for (c = opt->doc, i = 29; *c != 0; c++, i++) {
428 /* If we are at the end of the line, break it. */
432 printf(" "); /* 29 spaces */
443 /* exit with error code */
449 /* options_xx ******************************************************************
453 *******************************************************************************/
455 void options_xx(JavaVMInitArgs *vm_args)
468 /* Iterate over all passed options. */
470 for (i = 0; i < vm_args->nOptions; i++) {
471 /* Get the current option. */
473 name = vm_args->options[i].optionString;
475 /* Check for help (-XX). */
477 if (strcmp(name, "-XX") == 0)
480 /* Check if the option start with -XX. */
482 start = strstr(name, "-XX:");
484 if ((start == NULL) || (start != name))
487 /* Check if the option is a boolean option. */
489 if (name[4] == '+') {
490 start = name + 4 + 1;
493 else if (name[4] == '-') {
494 start = name + 4 + 1;
502 /* Search for a '=' in the option name and get the option name
503 length and the value of the option. */
505 end = strchr(start, '=');
508 length = strlen(start);
512 length = end - start;
516 /* Search the option in the option array. */
518 for (opt = options_XX; opt->name != NULL; opt++) {
519 if (strncmp(opt->name, start, length) == 0) {
520 /* Check if the options passed fits to the type. */
523 case OPT_TYPE_BOOLEAN:
524 if ((enable == -1) || (value != NULL))
528 if ((enable != -1) || (value == NULL))
532 vm_abort("options_xx: unknown option type %d for option %s",
533 opt->type, opt->name);
540 /* Process the option. */
542 switch (opt->value) {
543 case OPT_DebugExceptions:
544 opt_DebugExceptions = enable;
547 case OPT_DebugFinalizer:
548 opt_DebugFinalizer = enable;
551 case OPT_DebugLocalReferences:
552 opt_DebugLocalReferences = enable;
556 opt_DebugLocks = enable;
559 case OPT_DebugPackage:
560 opt_DebugPackage = enable;
563 case OPT_DebugPatcher:
564 opt_DebugPatcher = enable;
567 case OPT_DebugProperties:
568 opt_DebugProperties = enable;
571 case OPT_DebugStackFrameInfo:
572 opt_DebugStackFrameInfo = enable;
575 case OPT_DebugStackTrace:
576 opt_DebugStackTrace = enable;
579 case OPT_DebugThreads:
580 opt_DebugThreads = enable;
583 #if defined(ENABLE_DISASSEMBLER)
584 case OPT_DisassembleStubs:
585 opt_DisassembleStubs = enable;
589 #if defined(ENABLE_GC_CACAO)
590 case OPT_GCDebugRootSet:
591 opt_GCDebugRootSet = enable;
595 opt_GCStress = enable;
599 case OPT_MaxPermSize:
600 /* currently ignored */
604 /* currently ignored */
607 case OPT_PrintConfig:
608 opt_PrintConfig = enable;
611 case OPT_ProfileGCMemoryUsage:
613 opt_ProfileGCMemoryUsage = 5;
615 opt_ProfileGCMemoryUsage = atoi(value);
618 case OPT_ProfileMemoryUsage:
620 opt_ProfileMemoryUsage = 5;
622 opt_ProfileMemoryUsage = atoi(value);
624 # if defined(ENABLE_STATISTICS)
625 /* we also need statistics */
631 case OPT_ProfileMemoryUsageGNUPlot:
633 filename = "profile.dat";
637 file = fopen(filename, "w");
640 vm_abort("options_xx: fopen failed: %s", strerror(errno));
642 opt_ProfileMemoryUsageGNUPlot = file;
645 #if defined(ENABLE_REPLACEMENT)
646 case OPT_TestReplacement:
647 opt_TestReplacement = enable;
651 case OPT_ThreadStackSize:
652 /* currently ignored */
655 case OPT_TraceCompilerCalls:
656 opt_TraceCompilerCalls = enable;
659 case OPT_TraceExceptions:
660 opt_TraceExceptions = enable;
663 case OPT_TraceJavaCalls:
664 opt_verbosecall = enable;
665 opt_TraceJavaCalls = enable;
668 case OPT_TraceJNICalls:
669 opt_TraceJNICalls = enable;
672 case OPT_TraceJVMCalls:
673 opt_TraceJVMCalls = enable;
676 case OPT_TraceJVMCallsVerbose:
677 opt_TraceJVMCallsVerbose = enable;
680 case OPT_TraceLinkClass:
681 opt_TraceLinkClass = enable;
684 #if defined(ENABLE_REPLACEMENT)
685 case OPT_TraceReplacement:
687 opt_TraceReplacement = 1;
689 opt_TraceReplacement = atoi(value);
694 printf("Unknown -XX option: %s\n", name);
702 * These are local overrides for various environment variables in Emacs.
703 * Please do not remove this and leave it at the end of the file, where
704 * Emacs will automagically detect them.
705 * ---------------------------------------------------------------------
708 * indent-tabs-mode: t