1 /* src/vm/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
33 #include "mm/memory.h"
35 #include "vm/options.h"
40 /* command line option ********************************************************/
42 s4 opt_index = 0; /* index of processed arguments */
43 char *opt_arg; /* this one exports the option argument */
45 bool opt_foo = false; /* option for development */
49 #if defined(ENABLE_JIT)
50 bool opt_jit = true; /* JIT mode execution (default) */
51 bool opt_intrp = false; /* interpreter mode execution */
53 bool opt_jit = false; /* JIT mode execution */
54 bool opt_intrp = true; /* interpreter mode execution (default) */
59 s4 opt_heapmaxsize = 0; /* maximum heap size */
60 s4 opt_heapstartsize = 0; /* initial heap size */
61 s4 opt_stacksize = 0; /* thread stack size */
63 bool opt_verbose = false;
64 bool opt_debugcolor = false; /* use ANSI terminal sequences */
65 bool compileall = false;
67 bool loadverbose = false;
68 bool initverbose = false;
70 bool opt_verboseclass = false;
71 bool opt_verbosegc = false;
72 bool opt_verbosejni = false;
73 bool opt_verbosecall = false; /* trace all method invocation */
75 bool showmethods = false;
76 bool showconstantpool = false;
79 char *opt_method = NULL;
80 char *opt_signature = NULL;
82 bool compileverbose = false; /* trace compiler actions */
83 bool showstack = false;
85 bool opt_showdisassemble = false; /* generate disassembler listing */
86 bool opt_showddatasegment = false; /* generate data segment listing */
87 bool opt_showintermediate = false; /* generate intermediate code listing */
89 bool checkbounds = true; /* check array bounds */
90 bool opt_noieee = false; /* don't implement ieee compliant floats */
91 bool checksync = true; /* do synchronization */
92 #if defined(ENABLE_LOOP)
93 bool opt_loops = false; /* optimize array accesses in loops */
96 bool makeinitializations = true;
98 #if defined(ENABLE_STATISTICS)
99 bool opt_stat = false;
100 bool opt_getloadingtime = false; /* to measure the runtime */
101 bool opt_getcompilingtime = false; /* compute compile time */
103 #if defined(ENABLE_VERIFIER)
104 bool opt_verify = true; /* true if classfiles should be verified */
107 #if defined(ENABLE_PROFILING)
108 bool opt_prof = false;
109 bool opt_prof_bb = false;
112 #if defined(ENABLE_OPAGENT)
113 bool opt_opagent = false;
116 /* optimization options *******************************************************/
118 #if defined(ENABLE_IFCONV)
119 bool opt_ifconv = false;
122 #if defined(ENABLE_LSRA) || defined(ENABLE_SSA)
123 bool opt_lsra = false;
125 #if defined(ENABLE_SSA)
126 bool opt_ssa_dce = false; /* enable dead code elemination */
127 bool opt_ssa_cp = false; /* enable copy propagation */
131 /* interpreter options ********************************************************/
133 #if defined(ENABLE_INTRP)
134 bool opt_no_dynamic = false; /* suppress dynamic superinstructions */
135 bool opt_no_replication = false; /* don't use replication in intrp */
136 bool opt_no_quicksuper = false; /* instructions for quickening cannot be
137 part of dynamic superinstructions */
139 s4 opt_static_supers = 0x7fffffff;
140 bool vm_debug = false; /* XXX this should be called `opt_trace' */
143 #if defined(ENABLE_DEBUG_FILTER)
144 const char *opt_filter_verbosecall_include = 0;
145 const char *opt_filter_verbosecall_exclude = 0;
146 const char *opt_filter_show_method = 0;
150 /* -XX options ****************************************************************/
152 /* NOTE: For better readability keep these alpha-sorted. */
154 /* Options which must always be available (production options in
157 int64_t opt_MaxDirectMemorySize = -1;
158 int opt_MaxPermSize = 0;
159 int opt_PermSize = 0;
160 int opt_ThreadStackSize = 0;
162 /* Debugging options which can be turned off. */
164 int opt_DebugExceptions = 0;
165 int opt_DebugFinalizer = 0;
166 int opt_DebugLocalReferences = 0;
167 int opt_DebugLocks = 0;
168 int opt_DebugPackage = 0;
169 int opt_DebugPatcher = 0;
170 int opt_DebugProperties = 0;
171 int opt_DebugStackFrameInfo = 0;
172 int opt_DebugStackTrace = 0;
173 int opt_DebugThreads = 0;
174 #if defined(ENABLE_DISASSEMBLER)
175 int opt_DisassembleStubs = 0;
177 #if defined(ENABLE_OPAGENT)
178 int opt_EnableOpagent = 0;
180 #if defined(ENABLE_GC_CACAO)
181 int opt_GCDebugRootSet = 0;
182 int opt_GCStress = 0;
184 #if defined(ENABLE_INLINING)
186 #if defined(ENABLE_INLINING_DEBUG) || !defined(NDEBUG)
187 int opt_InlineAll = 0;
188 int opt_InlineCount = INT_MAX;
189 int opt_InlineMaxSize = INT_MAX;
190 int opt_InlineMinSize = 0;
193 int opt_PrintConfig = 0;
194 int opt_ProfileGCMemoryUsage = 0;
195 int opt_ProfileMemoryUsage = 0;
196 FILE *opt_ProfileMemoryUsageGNUPlot = NULL;
197 #if defined(ENABLE_REPLACEMENT)
198 int opt_TestReplacement = 0;
200 int opt_TraceCompilerCalls = 0;
201 int opt_TraceExceptions = 0;
202 int opt_TraceHPI = 0;
203 #if defined(ENABLE_INLINING) && !defined(NDEBUG)
204 int opt_TraceInlining = 0;
206 int opt_TraceJavaCalls = 0;
207 int opt_TraceJNICalls = 0;
208 int opt_TraceJVMCalls = 0;
209 int opt_TraceJVMCallsVerbose = 0;
210 int opt_TraceLinkClass = 0;
211 #if defined(ENABLE_REPLACEMENT)
212 int opt_TraceReplacement = 0;
214 int opt_TraceSubsystemInitialization = 0;
215 int opt_TraceTraps = 0;
224 /* Options which must always be available (production options in
227 OPT_MaxDirectMemorySize,
232 /* Debugging options which can be turned off. */
236 OPT_DebugLocalReferences,
241 OPT_DebugStackFrameInfo,
244 OPT_DisassembleStubs,
254 OPT_ProfileGCMemoryUsage,
255 OPT_ProfileMemoryUsage,
256 OPT_ProfileMemoryUsageGNUPlot,
258 OPT_TraceCompilerCalls,
265 OPT_TraceJVMCallsVerbose,
267 OPT_TraceReplacement,
268 OPT_TraceSubsystemInitialization,
276 option_t options_XX[] = {
277 /* Options which must always be available (production options in
280 { "MaxDirectMemorySize", OPT_MaxDirectMemorySize, OPT_TYPE_VALUE, "Maximum total size of NIO direct-buffer allocations" },
281 { "MaxPermSize", OPT_MaxPermSize, OPT_TYPE_VALUE, "not implemented" },
282 { "PermSize", OPT_PermSize, OPT_TYPE_VALUE, "not implemented" },
283 { "ThreadStackSize", OPT_ThreadStackSize, OPT_TYPE_VALUE, "TODO" },
285 /* Debugging options which can be turned off. */
287 { "DebugExceptions", OPT_DebugExceptions, OPT_TYPE_BOOLEAN, "debug exceptions" },
288 { "DebugFinalizer", OPT_DebugFinalizer, OPT_TYPE_BOOLEAN, "debug finalizer thread" },
289 { "DebugLocalReferences", OPT_DebugLocalReferences, OPT_TYPE_BOOLEAN, "print debug information for local reference tables" },
290 { "DebugLocks", OPT_DebugLocks, OPT_TYPE_BOOLEAN, "print debug information for locks" },
291 { "DebugPackage", OPT_DebugPackage, OPT_TYPE_BOOLEAN, "debug Java boot-packages" },
292 { "DebugPatcher", OPT_DebugPatcher, OPT_TYPE_BOOLEAN, "debug JIT code patching" },
293 { "DebugProperties", OPT_DebugProperties, OPT_TYPE_BOOLEAN, "print debug information for properties" },
294 { "DebugStackFrameInfo", OPT_DebugStackFrameInfo, OPT_TYPE_BOOLEAN, "TODO" },
295 { "DebugStackTrace", OPT_DebugStackTrace, OPT_TYPE_BOOLEAN, "debug stacktrace creation" },
296 { "DebugThreads", OPT_DebugThreads, OPT_TYPE_BOOLEAN, "print debug information for threads" },
297 #if defined(ENABLE_DISASSEMBLER)
298 { "DisassembleStubs", OPT_DisassembleStubs, OPT_TYPE_BOOLEAN, "disassemble builtin and native stubs when generated" },
300 #if defined(ENABLE_OPAGENT)
301 { "EnableOpagent", OPT_EnableOpagent, OPT_TYPE_BOOLEAN, "enable providing JIT output to Oprofile" },
303 #if defined(ENABLE_GC_CACAO)
304 { "GCDebugRootSet", OPT_GCDebugRootSet, OPT_TYPE_BOOLEAN, "GC: print root-set at collection" },
305 { "GCStress", OPT_GCStress, OPT_TYPE_BOOLEAN, "GC: forced collection at every allocation" },
307 #if defined(ENABLE_INLINING)
308 { "Inline", OPT_Inline, OPT_TYPE_BOOLEAN, "enable method inlining" },
309 #if defined(ENABLE_INLINING_DEBUG) || !defined(NDEBUG)
310 { "InlineAll", OPT_InlineAll, OPT_TYPE_BOOLEAN, "use inlining in all compilations" },
311 { "InlineCount", OPT_InlineCount, OPT_TYPE_VALUE, "stop inlining after the given number of roots" },
312 { "InlineMaxSize", OPT_InlineMaxSize, OPT_TYPE_VALUE, "maximum size for inlined result" },
313 { "InlineMinSize", OPT_InlineMinSize, OPT_TYPE_VALUE, "minimum size for inlined result" },
316 { "PrintConfig", OPT_PrintConfig, OPT_TYPE_BOOLEAN, "print VM configuration" },
317 { "ProfileGCMemoryUsage", OPT_ProfileGCMemoryUsage, OPT_TYPE_VALUE, "profiles GC memory usage in the given interval, <value> is in seconds (default: 5)" },
318 { "ProfileMemoryUsage", OPT_ProfileMemoryUsage, OPT_TYPE_VALUE, "TODO" },
319 { "ProfileMemoryUsageGNUPlot", OPT_ProfileMemoryUsageGNUPlot, OPT_TYPE_VALUE, "TODO" },
320 #if defined(ENABLE_REPLACEMENT)
321 { "TestReplacement", OPT_TestReplacement, OPT_TYPE_BOOLEAN, "activate all replacement points during code generation" },
323 { "TraceCompilerCalls", OPT_TraceCompilerCalls, OPT_TYPE_BOOLEAN, "trace JIT compiler calls" },
324 { "TraceExceptions", OPT_TraceExceptions, OPT_TYPE_BOOLEAN, "trace Exception throwing" },
325 { "TraceHPI", OPT_TraceHPI, OPT_TYPE_BOOLEAN, "Trace Host Porting Interface (HPI)" },
326 #if defined(ENABLE_INLINING) && !defined(NDEBUG)
327 { "TraceInlining", OPT_TraceInlining, OPT_TYPE_VALUE, "trace method inlining with the given verbosity level (default: 1)" },
329 #if !defined(ENABLE_VMLOG)
330 { "TraceJavaCalls", OPT_TraceJavaCalls, OPT_TYPE_BOOLEAN, "trace Java method calls" },
332 { "TraceJNICalls", OPT_TraceJNICalls, OPT_TYPE_BOOLEAN, "trace JNI method calls" },
333 { "TraceJVMCalls", OPT_TraceJVMCalls, OPT_TYPE_BOOLEAN, "trace JVM method calls but omit very frequent ones" },
334 { "TraceJVMCallsVerbose", OPT_TraceJVMCallsVerbose, OPT_TYPE_BOOLEAN, "trace all JVM method calls" },
335 { "TraceLinkClass", OPT_TraceLinkClass, OPT_TYPE_BOOLEAN, "trace class linking" },
336 #if defined(ENABLE_REPLACEMENT)
337 { "TraceReplacement", OPT_TraceReplacement, OPT_TYPE_VALUE, "trace on-stack replacement with the given verbosity level (default: 1)" },
339 { "TraceSubsystemInitialization", OPT_TraceSubsystemInitialization, OPT_TYPE_BOOLEAN, "trace initialization of subsystems" },
340 { "TraceTraps", OPT_TraceTraps, OPT_TYPE_BOOLEAN, "trace traps generated by JIT code" },
341 #if defined(ENABLE_VMLOG)
342 { "Vmlog", OPT_Vmlog, OPT_TYPE_VALUE, "prefix for vmlog trace files (enables vmlog)" },
343 { "VmlogStrings", OPT_VmlogStrings, OPT_TYPE_VALUE, "prefix of vmlog string file to load" },
344 { "VmlogIgnore", OPT_VmlogIgnore, OPT_TYPE_VALUE, "prefix of vmlog ignore file to load" },
349 { NULL, -1, -1, NULL }
353 /* options_get *****************************************************************
357 *******************************************************************************/
359 int options_get(opt_struct *opts, JavaVMInitArgs *vm_args)
364 if (opt_index >= vm_args->nOptions)
367 /* get the current option */
369 option = vm_args->options[opt_index].optionString;
371 if ((option == NULL) || (option[0] != '-'))
374 for (i = 0; opts[i].name; i++) {
376 /* boolean option found */
378 if (strcmp(option + 1, opts[i].name) == 0) {
380 return opts[i].value;
384 /* parameter option found */
386 /* with a space between */
388 if (strcmp(option + 1, opts[i].name) == 0) {
391 if (opt_index < vm_args->nOptions) {
392 opt_arg = os_strdup(vm_args->options[opt_index].optionString);
394 return opts[i].value;
400 /* parameter and option have no space between */
402 /* FIXME: this assumption is plain wrong, hits you if there is a
403 * parameter with no argument starting with same letter as param with argument
404 * but named after that one, ouch! */
406 size_t l = os_strlen(opts[i].name);
408 if (os_strlen(option + 1) > l) {
409 if (memcmp(option + 1, opts[i].name, l) == 0) {
411 opt_arg = os_strdup(option + 1 + l);
412 return opts[i].value;
423 /* options_xxusage *************************************************************
425 Print usage message for debugging options.
427 *******************************************************************************/
429 static void options_xxusage(void)
436 /* Prevent compiler warning. */
440 for (opt = options_XX; opt->name != NULL; opt++) {
444 case OPT_TYPE_BOOLEAN:
445 printf("+%s", opt->name);
446 length = os_strlen(" -XX:+") + os_strlen(opt->name);
450 printf("%s=<value>", opt->name);
451 length = os_strlen(" -XX:") + os_strlen(opt->name) +
452 os_strlen("=<value>");
456 vm_abort("options_xxusage: unkown option type %d", opt->type);
459 /* Check if the help fits into one 80-column line.
460 Documentation starts at column 29. */
462 if (length < (29 - 1)) {
463 /* Print missing spaces up to column 29. */
465 for (i = length; i < 29; i++)
470 printf(" "); /* 29 spaces */
473 /* Check documentation length. */
475 length = os_strlen(opt->doc);
477 if (length < (80 - 29)) {
478 printf("%s", opt->doc);
481 for (c = opt->doc, i = 29; *c != 0; c++, i++) {
482 /* If we are at the end of the line, break it. */
486 printf(" "); /* 29 spaces */
497 /* exit with error code */
503 /* options_xx ******************************************************************
507 *******************************************************************************/
509 void options_xx(JavaVMInitArgs *vm_args)
522 /* Iterate over all passed options. */
524 for (i = 0; i < vm_args->nOptions; i++) {
525 /* Get the current option. */
527 name = vm_args->options[i].optionString;
529 /* Check for help (-XX). */
531 if (strcmp(name, "-XX") == 0)
534 /* Check if the option start with -XX. */
536 start = strstr(name, "-XX:");
538 if ((start == NULL) || (start != name))
541 /* Check if the option is a boolean option. */
543 if (name[4] == '+') {
544 start = name + 4 + 1;
547 else if (name[4] == '-') {
548 start = name + 4 + 1;
556 /* Search for a '=' in the option name and get the option name
557 length and the value of the option. */
559 end = strchr(start, '=');
562 length = os_strlen(start);
566 length = end - start;
570 /* Search the option in the option array. */
572 for (opt = options_XX; opt->name != NULL; opt++) {
573 if (strncmp(opt->name, start, length) == 0) {
574 /* Check if the options passed fits to the type. */
577 case OPT_TYPE_BOOLEAN:
578 if ((enable == -1) || (value != NULL))
582 if ((enable != -1) || (value == NULL))
586 vm_abort("options_xx: unknown option type %d for option %s",
587 opt->type, opt->name);
594 /* Process the option. */
596 switch (opt->value) {
598 /* Options which must always be available (production options
601 case OPT_MaxDirectMemorySize:
602 opt_MaxDirectMemorySize = os_atoi(value);
605 case OPT_MaxPermSize:
606 /* Currently ignored. */
610 /* Currently ignored. */
613 case OPT_ThreadStackSize:
614 /* currently ignored */
617 /* Debugging options which can be turned off. */
619 case OPT_DebugExceptions:
620 opt_DebugExceptions = enable;
623 case OPT_DebugFinalizer:
624 opt_DebugFinalizer = enable;
627 case OPT_DebugLocalReferences:
628 opt_DebugLocalReferences = enable;
632 opt_DebugLocks = enable;
635 case OPT_DebugPackage:
636 opt_DebugPackage = enable;
639 case OPT_DebugPatcher:
640 opt_DebugPatcher = enable;
643 case OPT_DebugProperties:
644 opt_DebugProperties = enable;
647 case OPT_DebugStackFrameInfo:
648 opt_DebugStackFrameInfo = enable;
651 case OPT_DebugStackTrace:
652 opt_DebugStackTrace = enable;
655 case OPT_DebugThreads:
656 opt_DebugThreads = enable;
659 #if defined(ENABLE_DISASSEMBLER)
660 case OPT_DisassembleStubs:
661 opt_DisassembleStubs = enable;
665 #if defined(ENABLE_OPAGENT)
666 case OPT_EnableOpagent:
667 opt_EnableOpagent = enable;
671 #if defined(ENABLE_GC_CACAO)
672 case OPT_GCDebugRootSet:
673 opt_GCDebugRootSet = enable;
677 opt_GCStress = enable;
681 #if defined(ENABLE_INLINING)
685 #if defined(ENABLE_INLINING_DEBUG) || !defined(NDEBUG)
687 opt_InlineAll = enable;
690 case OPT_InlineCount:
692 opt_InlineCount = os_atoi(value);
695 case OPT_InlineMaxSize:
697 opt_InlineMaxSize = os_atoi(value);
700 case OPT_InlineMinSize:
702 opt_InlineMinSize = os_atoi(value);
707 case OPT_PrintConfig:
708 opt_PrintConfig = enable;
711 case OPT_ProfileGCMemoryUsage:
713 opt_ProfileGCMemoryUsage = 5;
715 opt_ProfileGCMemoryUsage = os_atoi(value);
718 case OPT_ProfileMemoryUsage:
720 opt_ProfileMemoryUsage = 5;
722 opt_ProfileMemoryUsage = os_atoi(value);
724 # if defined(ENABLE_STATISTICS)
725 /* we also need statistics */
731 case OPT_ProfileMemoryUsageGNUPlot:
733 filename = "profile.dat";
737 file = fopen(filename, "w");
740 vm_abort_errno("options_xx: fopen failed");
742 opt_ProfileMemoryUsageGNUPlot = file;
745 #if defined(ENABLE_REPLACEMENT)
746 case OPT_TestReplacement:
747 opt_TestReplacement = enable;
751 case OPT_TraceCompilerCalls:
752 opt_TraceCompilerCalls = enable;
755 case OPT_TraceExceptions:
756 opt_TraceExceptions = enable;
760 opt_TraceHPI = enable;
763 #if defined(ENABLE_INLINING) && !defined(NDEBUG)
764 case OPT_TraceInlining:
766 opt_TraceInlining = 1;
768 opt_TraceInlining = os_atoi(value);
772 case OPT_TraceJavaCalls:
773 opt_verbosecall = enable;
774 opt_TraceJavaCalls = enable;
777 case OPT_TraceJNICalls:
778 opt_TraceJNICalls = enable;
781 case OPT_TraceJVMCalls:
782 opt_TraceJVMCalls = enable;
785 case OPT_TraceJVMCallsVerbose:
786 opt_TraceJVMCallsVerbose = enable;
789 case OPT_TraceLinkClass:
790 opt_TraceLinkClass = enable;
793 #if defined(ENABLE_REPLACEMENT)
794 case OPT_TraceReplacement:
796 opt_TraceReplacement = 1;
798 opt_TraceReplacement = os_atoi(value);
802 case OPT_TraceSubsystemInitialization:
803 opt_TraceSubsystemInitialization = enable;
807 opt_TraceTraps = enable;
810 #if defined(ENABLE_VMLOG)
813 vmlog_cacao_set_prefix("vmlog");
815 vmlog_cacao_set_prefix(value);
817 opt_TraceJavaCalls = 1;
820 case OPT_VmlogStrings:
822 vmlog_cacao_set_stringprefix(value);
825 case OPT_VmlogIgnore:
827 vmlog_cacao_set_ignoreprefix(value);
832 printf("Unknown -XX option: %s\n", name);
840 * These are local overrides for various environment variables in Emacs.
841 * Please do not remove this and leave it at the end of the file, where
842 * Emacs will automagically detect them.
843 * ---------------------------------------------------------------------
846 * indent-tabs-mode: t