1 /* src/vmcore/options.c - contains global options
3 Copyright (C) 1996-2005, 2006, 2007, 2008
4 CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
6 This file is part of CACAO.
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License as
10 published by the Free Software Foundation; either version 2, or (at
11 your option) any later version.
13 This program is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
34 #include "mm/memory.h"
36 #include "native/jni.h"
40 #include "vmcore/options.h"
41 #include "vmcore/system.h"
44 /* command line option ********************************************************/
46 s4 opt_index = 0; /* index of processed arguments */
47 char *opt_arg; /* this one exports the option argument */
49 bool opt_foo = false; /* option for development */
53 #if defined(ENABLE_JIT)
54 bool opt_jit = true; /* JIT mode execution (default) */
55 bool opt_intrp = false; /* interpreter mode execution */
57 bool opt_jit = false; /* JIT mode execution */
58 bool opt_intrp = true; /* interpreter mode execution (default) */
63 s4 opt_heapmaxsize = 0; /* maximum heap size */
64 s4 opt_heapstartsize = 0; /* initial heap size */
65 s4 opt_stacksize = 0; /* thread stack size */
67 bool opt_verbose = false;
68 bool opt_debugcolor = false; /* use ANSI terminal sequences */
69 bool compileall = false;
71 bool loadverbose = false;
72 bool initverbose = false;
74 bool opt_verboseclass = false;
75 bool opt_verbosegc = false;
76 bool opt_verbosejni = false;
77 bool opt_verbosecall = false; /* trace all method invocation */
79 bool showmethods = false;
80 bool showconstantpool = false;
83 char *opt_method = NULL;
84 char *opt_signature = NULL;
86 bool compileverbose = false; /* trace compiler actions */
87 bool showstack = false;
89 bool opt_showdisassemble = false; /* generate disassembler listing */
90 bool opt_shownops = false;
91 bool opt_showddatasegment = false; /* generate data segment listing */
92 bool opt_showintermediate = false; /* generate intermediate code listing */
94 bool checkbounds = true; /* check array bounds */
95 bool opt_noieee = false; /* don't implement ieee compliant floats */
96 bool checksync = true; /* do synchronization */
97 #if defined(ENABLE_LOOP)
98 bool opt_loops = false; /* optimize array accesses in loops */
101 bool makeinitializations = true;
103 #if defined(ENABLE_STATISTICS)
104 bool opt_stat = false;
105 bool opt_getloadingtime = false; /* to measure the runtime */
106 bool opt_getcompilingtime = false; /* compute compile time */
108 #if defined(ENABLE_VERIFIER)
109 bool opt_verify = true; /* true if classfiles should be verified */
112 #if defined(ENABLE_PROFILING)
113 bool opt_prof = false;
114 bool opt_prof_bb = false;
118 /* optimization options *******************************************************/
120 #if defined(ENABLE_IFCONV)
121 bool opt_ifconv = false;
124 #if defined(ENABLE_LSRA) || defined(ENABLE_SSA)
125 bool opt_lsra = false;
127 #if defined(ENABLE_SSA)
128 bool opt_ssa_dce = false; /* enable dead code elemination */
129 bool opt_ssa_cp = false; /* enable copy propagation */
133 /* interpreter options ********************************************************/
135 #if defined(ENABLE_INTRP)
136 bool opt_no_dynamic = false; /* suppress dynamic superinstructions */
137 bool opt_no_replication = false; /* don't use replication in intrp */
138 bool opt_no_quicksuper = false; /* instructions for quickening cannot be
139 part of dynamic superinstructions */
141 s4 opt_static_supers = 0x7fffffff;
142 bool vm_debug = false; /* XXX this should be called `opt_trace' */
145 #if defined(ENABLE_DEBUG_FILTER)
146 const char *opt_filter_verbosecall_include = 0;
147 const char *opt_filter_verbosecall_exclude = 0;
148 const char *opt_filter_show_method = 0;
152 /* -XX options ****************************************************************/
154 /* NOTE: For better readability keep these alpha-sorted. */
156 int opt_DebugExceptions = 0;
157 int opt_DebugFinalizer = 0;
158 int opt_DebugLocalReferences = 0;
159 int opt_DebugLocks = 0;
160 int opt_DebugPackage = 0;
161 int opt_DebugPatcher = 0;
162 int opt_DebugProperties = 0;
163 int opt_DebugStackFrameInfo = 0;
164 int opt_DebugStackTrace = 0;
165 int opt_DebugThreads = 0;
166 #if defined(ENABLE_DISASSEMBLER)
167 int opt_DisassembleStubs = 0;
169 #if defined(ENABLE_GC_CACAO)
170 int opt_GCDebugRootSet = 0;
171 int opt_GCStress = 0;
173 #if defined(ENABLE_INLINING)
175 #if defined(ENABLE_INLINING_DEBUG) || !defined(NDEBUG)
176 int opt_InlineAll = 0;
177 int opt_InlineCount = INT_MAX;
178 int opt_InlineMaxSize = INT_MAX;
179 int opt_InlineMinSize = 0;
182 int opt_MaxPermSize = 0;
183 int opt_PermSize = 0;
184 int opt_PrintConfig = 0;
185 int opt_ProfileGCMemoryUsage = 0;
186 int opt_ProfileMemoryUsage = 0;
187 FILE *opt_ProfileMemoryUsageGNUPlot = NULL;
188 #if defined(ENABLE_REPLACEMENT)
189 int opt_TestReplacement = 0;
191 int opt_ThreadStackSize = 0;
192 int opt_TraceCompilerCalls = 0;
193 int opt_TraceExceptions = 0;
194 #if defined(ENABLE_INLINING) && !defined(NDEBUG)
195 int opt_TraceInlining = 0;
197 int opt_TraceJavaCalls = 0;
198 int opt_TraceJNICalls = 0;
199 int opt_TraceJVMCalls = 0;
200 int opt_TraceJVMCallsVerbose = 0;
201 int opt_TraceLinkClass = 0;
202 #if defined(ENABLE_REPLACEMENT)
203 int opt_TraceReplacement = 0;
205 int opt_TraceSubsystemInitialization = 0;
216 OPT_DebugLocalReferences,
221 OPT_DebugStackFrameInfo,
224 OPT_DisassembleStubs,
235 OPT_ProfileGCMemoryUsage,
236 OPT_ProfileMemoryUsage,
237 OPT_ProfileMemoryUsageGNUPlot,
240 OPT_TraceCompilerCalls,
246 OPT_TraceJVMCallsVerbose,
248 OPT_TraceReplacement,
249 OPT_TraceSubsystemInitialization,
256 option_t options_XX[] = {
257 { "DebugExceptions", OPT_DebugExceptions, OPT_TYPE_BOOLEAN, "debug exceptions" },
258 { "DebugFinalizer", OPT_DebugFinalizer, OPT_TYPE_BOOLEAN, "debug finalizer thread" },
259 { "DebugLocalReferences", OPT_DebugLocalReferences, OPT_TYPE_BOOLEAN, "print debug information for local reference tables" },
260 { "DebugLocks", OPT_DebugLocks, OPT_TYPE_BOOLEAN, "print debug information for locks" },
261 { "DebugPackage", OPT_DebugPackage, OPT_TYPE_BOOLEAN, "debug Java boot-packages" },
262 { "DebugPatcher", OPT_DebugPatcher, OPT_TYPE_BOOLEAN, "debug JIT code patching" },
263 { "DebugProperties", OPT_DebugProperties, OPT_TYPE_BOOLEAN, "print debug information for properties" },
264 { "DebugStackFrameInfo", OPT_DebugStackFrameInfo, OPT_TYPE_BOOLEAN, "TODO" },
265 { "DebugStackTrace", OPT_DebugStackTrace, OPT_TYPE_BOOLEAN, "debug stacktrace creation" },
266 { "DebugThreads", OPT_DebugThreads, OPT_TYPE_BOOLEAN, "print debug information for threads" },
267 #if defined(ENABLE_DISASSEMBLER)
268 { "DisassembleStubs", OPT_DisassembleStubs, OPT_TYPE_BOOLEAN, "disassemble builtin and native stubs when generated" },
270 #if defined(ENABLE_GC_CACAO)
271 { "GCDebugRootSet", OPT_GCDebugRootSet, OPT_TYPE_BOOLEAN, "GC: print root-set at collection" },
272 { "GCStress", OPT_GCStress, OPT_TYPE_BOOLEAN, "GC: forced collection at every allocation" },
274 #if defined(ENABLE_INLINING)
275 { "Inline", OPT_Inline, OPT_TYPE_BOOLEAN, "enable method inlining" },
276 #if defined(ENABLE_INLINING_DEBUG) || !defined(NDEBUG)
277 { "InlineAll", OPT_InlineAll, OPT_TYPE_BOOLEAN, "use inlining in all compilations" },
278 { "InlineCount", OPT_InlineCount, OPT_TYPE_VALUE, "stop inlining after the given number of roots" },
279 { "InlineMaxSize", OPT_InlineMaxSize, OPT_TYPE_VALUE, "maximum size for inlined result" },
280 { "InlineMinSize", OPT_InlineMinSize, OPT_TYPE_VALUE, "minimum size for inlined result" },
283 { "MaxPermSize", OPT_MaxPermSize, OPT_TYPE_VALUE, "not implemented" },
284 { "PermSize", OPT_PermSize, OPT_TYPE_VALUE, "not implemented" },
285 { "PrintConfig", OPT_PrintConfig, OPT_TYPE_BOOLEAN, "print VM configuration" },
286 { "ProfileGCMemoryUsage", OPT_ProfileGCMemoryUsage, OPT_TYPE_VALUE, "profiles GC memory usage in the given interval, <value> is in seconds (default: 5)" },
287 { "ProfileMemoryUsage", OPT_ProfileMemoryUsage, OPT_TYPE_VALUE, "TODO" },
288 { "ProfileMemoryUsageGNUPlot", OPT_ProfileMemoryUsageGNUPlot, OPT_TYPE_VALUE, "TODO" },
289 #if defined(ENABLE_REPLACEMENT)
290 { "TestReplacement", OPT_TestReplacement, OPT_TYPE_BOOLEAN, "activate all replacement points during code generation" },
292 { "ThreadStackSize", OPT_ThreadStackSize, OPT_TYPE_VALUE, "TODO" },
293 { "TraceCompilerCalls", OPT_TraceCompilerCalls, OPT_TYPE_BOOLEAN, "trace JIT compiler calls" },
294 { "TraceExceptions", OPT_TraceExceptions, OPT_TYPE_BOOLEAN, "trace Exception throwing" },
295 #if defined(ENABLE_INLINING) && !defined(NDEBUG)
296 { "TraceInlining", OPT_TraceInlining, OPT_TYPE_BOOLEAN, "trace method inlining" },
298 #if !defined(ENABLE_VMLOG)
299 { "TraceJavaCalls", OPT_TraceJavaCalls, OPT_TYPE_BOOLEAN, "trace Java method calls" },
301 { "TraceJNICalls", OPT_TraceJNICalls, OPT_TYPE_BOOLEAN, "trace JNI method calls" },
302 { "TraceJVMCalls", OPT_TraceJVMCalls, OPT_TYPE_BOOLEAN, "trace JVM method calls but omit very frequent ones" },
303 { "TraceJVMCallsVerbose", OPT_TraceJVMCallsVerbose, OPT_TYPE_BOOLEAN, "trace all JVM method calls" },
304 { "TraceLinkClass", OPT_TraceLinkClass, OPT_TYPE_BOOLEAN, "trace class linking" },
305 #if defined(ENABLE_REPLACEMENT)
306 { "TraceReplacement", OPT_TraceReplacement, OPT_TYPE_VALUE, "trace on-stack replacement with the given verbosity level (default: 1)" },
308 { "TraceSubsystemInitialization", OPT_TraceSubsystemInitialization, OPT_TYPE_BOOLEAN, "trace initialization of subsystems" },
310 #if defined(ENABLE_VMLOG)
311 { "Vmlog", OPT_Vmlog, OPT_TYPE_VALUE, "prefix for vmlog trace files (enables vmlog)" },
312 { "VmlogStrings", OPT_VmlogStrings, OPT_TYPE_VALUE, "prefix of vmlog string file to load" },
313 { "VmlogIgnore", OPT_VmlogIgnore, OPT_TYPE_VALUE, "prefix of vmlog ignore file to load" },
318 { NULL, -1, -1, NULL }
322 /* options_get *****************************************************************
326 *******************************************************************************/
328 s4 options_get(opt_struct *opts, JavaVMInitArgs *vm_args)
333 if (opt_index >= vm_args->nOptions)
336 /* get the current option */
338 option = vm_args->options[opt_index].optionString;
340 if ((option == NULL) || (option[0] != '-'))
343 for (i = 0; opts[i].name; i++) {
345 /* boolean option found */
347 if (strcmp(option + 1, opts[i].name) == 0) {
349 return opts[i].value;
353 /* parameter option found */
355 /* with a space between */
357 if (strcmp(option + 1, opts[i].name) == 0) {
360 if (opt_index < vm_args->nOptions) {
361 opt_arg = system_strdup(vm_args->options[opt_index].optionString);
363 return opts[i].value;
369 /* parameter and option have no space between */
371 /* FIXME: this assumption is plain wrong, hits you if there is a
372 * parameter with no argument starting with same letter as param with argument
373 * but named after that one, ouch! */
375 size_t l = system_strlen(opts[i].name);
377 if (system_strlen(option + 1) > l) {
378 if (memcmp(option + 1, opts[i].name, l) == 0) {
380 opt_arg = system_strdup(option + 1 + l);
381 return opts[i].value;
392 /* options_xxusage *************************************************************
394 Print usage message for debugging options.
396 *******************************************************************************/
398 static void options_xxusage(void)
405 /* Prevent compiler warning. */
409 for (opt = options_XX; opt->name != NULL; opt++) {
413 case OPT_TYPE_BOOLEAN:
414 printf("+%s", opt->name);
415 length = system_strlen(" -XX:+") + system_strlen(opt->name);
419 printf("%s=<value>", opt->name);
420 length = system_strlen(" -XX:") + system_strlen(opt->name) +
421 system_strlen("=<value>");
425 vm_abort("options_xxusage: unkown option type %d", opt->type);
428 /* Check if the help fits into one 80-column line.
429 Documentation starts at column 29. */
431 if (length < (29 - 1)) {
432 /* Print missing spaces up to column 29. */
434 for (i = length; i < 29; i++)
439 printf(" "); /* 29 spaces */
442 /* Check documentation length. */
444 length = system_strlen(opt->doc);
446 if (length < (80 - 29)) {
447 printf("%s", opt->doc);
450 for (c = opt->doc, i = 29; *c != 0; c++, i++) {
451 /* If we are at the end of the line, break it. */
455 printf(" "); /* 29 spaces */
466 /* exit with error code */
472 /* options_xx ******************************************************************
476 *******************************************************************************/
478 void options_xx(JavaVMInitArgs *vm_args)
491 /* Iterate over all passed options. */
493 for (i = 0; i < vm_args->nOptions; i++) {
494 /* Get the current option. */
496 name = vm_args->options[i].optionString;
498 /* Check for help (-XX). */
500 if (strcmp(name, "-XX") == 0)
503 /* Check if the option start with -XX. */
505 start = strstr(name, "-XX:");
507 if ((start == NULL) || (start != name))
510 /* Check if the option is a boolean option. */
512 if (name[4] == '+') {
513 start = name + 4 + 1;
516 else if (name[4] == '-') {
517 start = name + 4 + 1;
525 /* Search for a '=' in the option name and get the option name
526 length and the value of the option. */
528 end = strchr(start, '=');
531 length = system_strlen(start);
535 length = end - start;
539 /* Search the option in the option array. */
541 for (opt = options_XX; opt->name != NULL; opt++) {
542 if (strncmp(opt->name, start, length) == 0) {
543 /* Check if the options passed fits to the type. */
546 case OPT_TYPE_BOOLEAN:
547 if ((enable == -1) || (value != NULL))
551 if ((enable != -1) || (value == NULL))
555 vm_abort("options_xx: unknown option type %d for option %s",
556 opt->type, opt->name);
563 /* Process the option. */
565 switch (opt->value) {
566 case OPT_DebugExceptions:
567 opt_DebugExceptions = enable;
570 case OPT_DebugFinalizer:
571 opt_DebugFinalizer = enable;
574 case OPT_DebugLocalReferences:
575 opt_DebugLocalReferences = enable;
579 opt_DebugLocks = enable;
582 case OPT_DebugPackage:
583 opt_DebugPackage = enable;
586 case OPT_DebugPatcher:
587 opt_DebugPatcher = enable;
590 case OPT_DebugProperties:
591 opt_DebugProperties = enable;
594 case OPT_DebugStackFrameInfo:
595 opt_DebugStackFrameInfo = enable;
598 case OPT_DebugStackTrace:
599 opt_DebugStackTrace = enable;
602 case OPT_DebugThreads:
603 opt_DebugThreads = enable;
606 #if defined(ENABLE_DISASSEMBLER)
607 case OPT_DisassembleStubs:
608 opt_DisassembleStubs = enable;
612 #if defined(ENABLE_GC_CACAO)
613 case OPT_GCDebugRootSet:
614 opt_GCDebugRootSet = enable;
618 opt_GCStress = enable;
622 #if defined(ENABLE_INLINING)
626 #if defined(ENABLE_INLINING_DEBUG) || !defined(NDEBUG)
628 opt_InlineAll = enable;
631 case OPT_InlineCount:
633 opt_InlineCount = atoi(value);
636 case OPT_InlineMaxSize:
638 opt_InlineMaxSize = atoi(value);
641 case OPT_InlineMinSize:
643 opt_InlineMinSize = atoi(value);
648 case OPT_MaxPermSize:
649 /* currently ignored */
653 /* currently ignored */
656 case OPT_PrintConfig:
657 opt_PrintConfig = enable;
660 case OPT_ProfileGCMemoryUsage:
662 opt_ProfileGCMemoryUsage = 5;
664 opt_ProfileGCMemoryUsage = atoi(value);
667 case OPT_ProfileMemoryUsage:
669 opt_ProfileMemoryUsage = 5;
671 opt_ProfileMemoryUsage = atoi(value);
673 # if defined(ENABLE_STATISTICS)
674 /* we also need statistics */
680 case OPT_ProfileMemoryUsageGNUPlot:
682 filename = "profile.dat";
686 file = fopen(filename, "w");
689 vm_abort("options_xx: fopen failed: %s", strerror(errno));
691 opt_ProfileMemoryUsageGNUPlot = file;
694 #if defined(ENABLE_REPLACEMENT)
695 case OPT_TestReplacement:
696 opt_TestReplacement = enable;
700 case OPT_ThreadStackSize:
701 /* currently ignored */
704 case OPT_TraceCompilerCalls:
705 opt_TraceCompilerCalls = enable;
708 case OPT_TraceExceptions:
709 opt_TraceExceptions = enable;
712 #if defined(ENABLE_INLINING) && !defined(NDEBUG)
713 case OPT_TraceInlining:
714 opt_TraceInlining = enable;
718 case OPT_TraceJavaCalls:
719 opt_verbosecall = enable;
720 opt_TraceJavaCalls = enable;
723 case OPT_TraceJNICalls:
724 opt_TraceJNICalls = enable;
727 case OPT_TraceJVMCalls:
728 opt_TraceJVMCalls = enable;
731 case OPT_TraceJVMCallsVerbose:
732 opt_TraceJVMCallsVerbose = enable;
735 case OPT_TraceLinkClass:
736 opt_TraceLinkClass = enable;
739 #if defined(ENABLE_REPLACEMENT)
740 case OPT_TraceReplacement:
742 opt_TraceReplacement = 1;
744 opt_TraceReplacement = atoi(value);
748 case OPT_TraceSubsystemInitialization:
749 opt_TraceSubsystemInitialization = enable;
752 #if defined(ENABLE_VMLOG)
755 vmlog_cacao_set_prefix("vmlog");
757 vmlog_cacao_set_prefix(value);
759 opt_TraceJavaCalls = 1;
762 case OPT_VmlogStrings:
764 vmlog_cacao_set_stringprefix(value);
767 case OPT_VmlogIgnore:
769 vmlog_cacao_set_ignoreprefix(value);
774 printf("Unknown -XX option: %s\n", name);
782 * These are local overrides for various environment variables in Emacs.
783 * Please do not remove this and leave it at the end of the file, where
784 * Emacs will automagically detect them.
785 * ---------------------------------------------------------------------
788 * indent-tabs-mode: t