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.hpp"
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 */
66 bool loadverbose = false;
67 bool initverbose = false;
69 bool opt_verboseclass = false;
70 bool opt_verbosegc = false;
71 bool opt_verbosejni = false;
72 bool opt_verbosecall = false; /* trace all method invocation */
74 bool showmethods = false;
75 bool showconstantpool = false;
78 bool compileverbose = false; /* trace compiler actions */
79 bool showstack = false;
81 bool opt_showdisassemble = false; /* generate disassembler listing */
82 bool opt_showddatasegment = false; /* generate data segment listing */
83 bool opt_showintermediate = false; /* generate intermediate code listing */
85 bool checkbounds = true; /* check array bounds */
86 bool checksync = true; /* do synchronization */
87 #if defined(ENABLE_LOOP)
88 bool opt_loops = false; /* optimize array accesses in loops */
91 bool makeinitializations = true;
93 #if defined(ENABLE_STATISTICS)
94 bool opt_stat = false;
95 bool opt_getloadingtime = false; /* to measure the runtime */
96 bool opt_getcompilingtime = false; /* compute compile time */
98 #if defined(ENABLE_VERIFIER)
99 bool opt_verify = true; /* true if classfiles should be verified */
102 #if defined(ENABLE_PROFILING)
103 bool opt_prof = false;
104 bool opt_prof_bb = false;
107 #if defined(ENABLE_OPAGENT)
108 bool opt_opagent = false;
111 /* optimization options *******************************************************/
113 #if defined(ENABLE_IFCONV)
114 bool opt_ifconv = false;
117 #if defined(ENABLE_LSRA) || defined(ENABLE_SSA)
118 bool opt_lsra = false;
120 #if defined(ENABLE_SSA)
121 bool opt_ssa_dce = false; /* enable dead code elemination */
122 bool opt_ssa_cp = false; /* enable copy propagation */
126 /* interpreter options ********************************************************/
128 #if defined(ENABLE_INTRP)
129 bool opt_no_dynamic = false; /* suppress dynamic superinstructions */
130 bool opt_no_replication = false; /* don't use replication in intrp */
131 bool opt_no_quicksuper = false; /* instructions for quickening cannot be
132 part of dynamic superinstructions */
134 s4 opt_static_supers = 0x7fffffff;
135 bool vm_debug = false; /* XXX this should be called `opt_trace' */
138 #if defined(ENABLE_DEBUG_FILTER)
139 const char *opt_filter_verbosecall_include = 0;
140 const char *opt_filter_verbosecall_exclude = 0;
141 const char *opt_filter_show_method = 0;
145 /* -XX options ****************************************************************/
147 /* NOTE: For better readability keep these alpha-sorted. */
149 /* Options which must always be available (production options in
152 int64_t opt_MaxDirectMemorySize = -1;
153 int opt_MaxPermSize = 0;
154 int opt_PermSize = 0;
155 int opt_ThreadStackSize = 0;
157 /* Debugging options which can be turned off. */
159 bool opt_AlwaysEmitLongBranches = false;
160 int opt_CompileAll = 0;
161 char* opt_CompileMethod = NULL;
162 char* opt_CompileSignature = NULL;
163 int opt_DebugExceptions = 0;
164 int opt_DebugFinalizer = 0;
165 int opt_DebugLocalReferences = 0;
166 int opt_DebugLocks = 0;
167 int opt_DebugPackage = 0;
168 int opt_DebugPatcher = 0;
169 int opt_DebugProperties = 0;
170 int opt_DebugStackFrameInfo = 0;
171 int opt_DebugStackTrace = 0;
172 int opt_DebugThreads = 0;
173 #if defined(ENABLE_DISASSEMBLER)
174 int opt_DisassembleStubs = 0;
176 #if defined(ENABLE_OPAGENT)
177 int opt_EnableOpagent = 0;
179 #if defined(ENABLE_GC_CACAO)
180 int opt_GCDebugRootSet = 0;
181 int opt_GCStress = 0;
183 #if defined(ENABLE_INLINING)
185 #if defined(ENABLE_INLINING_DEBUG) || !defined(NDEBUG)
186 int opt_InlineAll = 0;
187 int opt_InlineCount = INT_MAX;
188 int opt_InlineMaxSize = INT_MAX;
189 int opt_InlineMinSize = 0;
192 int opt_PrintConfig = 0;
193 int opt_PrintWarnings = 0;
194 int opt_ProfileGCMemoryUsage = 0;
195 int opt_ProfileMemoryUsage = 0;
196 FILE *opt_ProfileMemoryUsageGNUPlot = NULL;
197 int opt_RegallocSpillAll = 0;
198 #if defined(ENABLE_REPLACEMENT)
199 int opt_TestReplacement = 0;
201 int opt_TraceBuiltinCalls = 0;
202 int opt_TraceCompilerCalls = 0;
203 int opt_TraceExceptions = 0;
204 int opt_TraceHPI = 0;
205 #if defined(ENABLE_INLINING) && !defined(NDEBUG)
206 int opt_TraceInlining = 0;
208 int opt_TraceJavaCalls = 0;
209 int opt_TraceJNICalls = 0;
210 int opt_TraceJVMCalls = 0;
211 int opt_TraceJVMCallsVerbose = 0;
212 int opt_TraceLinkClass = 0;
213 #if defined(ENABLE_REPLACEMENT)
214 int opt_TraceReplacement = 0;
216 int opt_TraceSubsystemInitialization = 0;
217 int opt_TraceTraps = 0;
226 /* Options which must always be available (production options in
229 OPT_MaxDirectMemorySize,
234 /* Debugging options which can be turned off. */
236 OPT_AlwaysEmitLongBranches,
239 OPT_CompileSignature,
242 OPT_DebugLocalReferences,
247 OPT_DebugStackFrameInfo,
250 OPT_DisassembleStubs,
261 OPT_ProfileGCMemoryUsage,
262 OPT_ProfileMemoryUsage,
263 OPT_ProfileMemoryUsageGNUPlot,
264 OPT_RegallocSpillAll,
266 OPT_TraceBuiltinCalls,
267 OPT_TraceCompilerCalls,
274 OPT_TraceJVMCallsVerbose,
276 OPT_TraceReplacement,
277 OPT_TraceSubsystemInitialization,
285 option_t options_XX[] = {
286 /* Options which must always be available (production options in
289 { "MaxDirectMemorySize", OPT_MaxDirectMemorySize, OPT_TYPE_VALUE, "Maximum total size of NIO direct-buffer allocations" },
290 { "MaxPermSize", OPT_MaxPermSize, OPT_TYPE_VALUE, "not implemented" },
291 { "PermSize", OPT_PermSize, OPT_TYPE_VALUE, "not implemented" },
292 { "ThreadStackSize", OPT_ThreadStackSize, OPT_TYPE_VALUE, "TODO" },
294 /* Debugging options which can be turned off. */
296 { "AlwaysEmitLongBranches", OPT_AlwaysEmitLongBranches, OPT_TYPE_BOOLEAN, "Always emit long-branches." },
297 { "CompileAll", OPT_CompileAll, OPT_TYPE_BOOLEAN, "compile all methods, no execution" },
298 { "CompileMethod", OPT_CompileMethod, OPT_TYPE_VALUE, "compile only a specific method" },
299 { "CompileSignature", OPT_CompileSignature, OPT_TYPE_VALUE, "specify signature for a specific method" },
300 { "DebugExceptions", OPT_DebugExceptions, OPT_TYPE_BOOLEAN, "debug exceptions" },
301 { "DebugFinalizer", OPT_DebugFinalizer, OPT_TYPE_BOOLEAN, "debug finalizer thread" },
302 { "DebugLocalReferences", OPT_DebugLocalReferences, OPT_TYPE_BOOLEAN, "print debug information for local reference tables" },
303 { "DebugLocks", OPT_DebugLocks, OPT_TYPE_BOOLEAN, "print debug information for locks" },
304 { "DebugPackage", OPT_DebugPackage, OPT_TYPE_BOOLEAN, "debug Java boot-packages" },
305 { "DebugPatcher", OPT_DebugPatcher, OPT_TYPE_BOOLEAN, "debug JIT code patching" },
306 { "DebugProperties", OPT_DebugProperties, OPT_TYPE_BOOLEAN, "print debug information for properties" },
307 { "DebugStackFrameInfo", OPT_DebugStackFrameInfo, OPT_TYPE_BOOLEAN, "TODO" },
308 { "DebugStackTrace", OPT_DebugStackTrace, OPT_TYPE_BOOLEAN, "debug stacktrace creation" },
309 { "DebugThreads", OPT_DebugThreads, OPT_TYPE_BOOLEAN, "print debug information for threads" },
310 #if defined(ENABLE_DISASSEMBLER)
311 { "DisassembleStubs", OPT_DisassembleStubs, OPT_TYPE_BOOLEAN, "disassemble builtin and native stubs when generated" },
313 #if defined(ENABLE_OPAGENT)
314 { "EnableOpagent", OPT_EnableOpagent, OPT_TYPE_BOOLEAN, "enable providing JIT output to Oprofile" },
316 #if defined(ENABLE_GC_CACAO)
317 { "GCDebugRootSet", OPT_GCDebugRootSet, OPT_TYPE_BOOLEAN, "GC: print root-set at collection" },
318 { "GCStress", OPT_GCStress, OPT_TYPE_BOOLEAN, "GC: forced collection at every allocation" },
320 #if defined(ENABLE_INLINING)
321 { "Inline", OPT_Inline, OPT_TYPE_BOOLEAN, "enable method inlining" },
322 #if defined(ENABLE_INLINING_DEBUG) || !defined(NDEBUG)
323 { "InlineAll", OPT_InlineAll, OPT_TYPE_BOOLEAN, "use inlining in all compilations" },
324 { "InlineCount", OPT_InlineCount, OPT_TYPE_VALUE, "stop inlining after the given number of roots" },
325 { "InlineMaxSize", OPT_InlineMaxSize, OPT_TYPE_VALUE, "maximum size for inlined result" },
326 { "InlineMinSize", OPT_InlineMinSize, OPT_TYPE_VALUE, "minimum size for inlined result" },
329 { "PrintConfig", OPT_PrintConfig, OPT_TYPE_BOOLEAN, "print VM configuration" },
330 { "PrintWarnings", OPT_PrintWarnings, OPT_TYPE_BOOLEAN, "print warnings about suspicious behavior"},
331 { "ProfileGCMemoryUsage", OPT_ProfileGCMemoryUsage, OPT_TYPE_VALUE, "profiles GC memory usage in the given interval, <value> is in seconds (default: 5)" },
332 { "ProfileMemoryUsage", OPT_ProfileMemoryUsage, OPT_TYPE_VALUE, "TODO" },
333 { "ProfileMemoryUsageGNUPlot", OPT_ProfileMemoryUsageGNUPlot, OPT_TYPE_VALUE, "TODO" },
334 { "RegallocSpillAll", OPT_RegallocSpillAll, OPT_TYPE_BOOLEAN, "spill all variables to the stack" },
335 #if defined(ENABLE_REPLACEMENT)
336 { "TestReplacement", OPT_TestReplacement, OPT_TYPE_BOOLEAN, "activate all replacement points during code generation" },
338 { "TraceBuiltinCalls", OPT_TraceBuiltinCalls, OPT_TYPE_BOOLEAN, "trace calls to VM builtin functions" },
339 { "TraceCompilerCalls", OPT_TraceCompilerCalls, OPT_TYPE_BOOLEAN, "trace JIT compiler calls" },
340 { "TraceExceptions", OPT_TraceExceptions, OPT_TYPE_BOOLEAN, "trace Exception throwing" },
341 { "TraceHPI", OPT_TraceHPI, OPT_TYPE_BOOLEAN, "Trace Host Porting Interface (HPI)" },
342 #if defined(ENABLE_INLINING) && !defined(NDEBUG)
343 { "TraceInlining", OPT_TraceInlining, OPT_TYPE_VALUE, "trace method inlining with the given verbosity level (default: 1)" },
345 #if !defined(ENABLE_VMLOG)
346 { "TraceJavaCalls", OPT_TraceJavaCalls, OPT_TYPE_BOOLEAN, "trace Java method calls" },
348 { "TraceJNICalls", OPT_TraceJNICalls, OPT_TYPE_BOOLEAN, "trace JNI method calls" },
349 { "TraceJVMCalls", OPT_TraceJVMCalls, OPT_TYPE_BOOLEAN, "trace JVM method calls but omit very frequent ones" },
350 { "TraceJVMCallsVerbose", OPT_TraceJVMCallsVerbose, OPT_TYPE_BOOLEAN, "trace all JVM method calls" },
351 { "TraceLinkClass", OPT_TraceLinkClass, OPT_TYPE_BOOLEAN, "trace class linking" },
352 #if defined(ENABLE_REPLACEMENT)
353 { "TraceReplacement", OPT_TraceReplacement, OPT_TYPE_VALUE, "trace on-stack replacement with the given verbosity level (default: 1)" },
355 { "TraceSubsystemInitialization", OPT_TraceSubsystemInitialization, OPT_TYPE_BOOLEAN, "trace initialization of subsystems" },
356 { "TraceTraps", OPT_TraceTraps, OPT_TYPE_BOOLEAN, "trace traps generated by JIT code" },
357 #if defined(ENABLE_VMLOG)
358 { "Vmlog", OPT_Vmlog, OPT_TYPE_VALUE, "prefix for vmlog trace files (enables vmlog)" },
359 { "VmlogStrings", OPT_VmlogStrings, OPT_TYPE_VALUE, "prefix of vmlog string file to load" },
360 { "VmlogIgnore", OPT_VmlogIgnore, OPT_TYPE_VALUE, "prefix of vmlog ignore file to load" },
365 { NULL, -1, -1, NULL }
369 /* options_get *****************************************************************
373 *******************************************************************************/
375 int options_get(opt_struct *opts, JavaVMInitArgs *vm_args)
380 if (opt_index >= vm_args->nOptions)
383 /* get the current option */
385 option = vm_args->options[opt_index].optionString;
387 if ((option == NULL) || (option[0] != '-'))
390 for (i = 0; opts[i].name; i++) {
392 /* boolean option found */
394 if (strcmp(option + 1, opts[i].name) == 0) {
396 return opts[i].value;
400 /* parameter option found */
402 /* with a space between */
404 if (strcmp(option + 1, opts[i].name) == 0) {
407 if (opt_index < vm_args->nOptions) {
408 opt_arg = os_strdup(vm_args->options[opt_index].optionString);
410 return opts[i].value;
416 /* parameter and option have no space between */
418 /* FIXME: this assumption is plain wrong, hits you if there is a
419 * parameter with no argument starting with same letter as param with argument
420 * but named after that one, ouch! */
422 size_t l = os_strlen(opts[i].name);
424 if (os_strlen(option + 1) > l) {
425 if (memcmp(option + 1, opts[i].name, l) == 0) {
427 opt_arg = os_strdup(option + 1 + l);
428 return opts[i].value;
439 /* options_xxusage *************************************************************
441 Print usage message for debugging options.
443 *******************************************************************************/
445 static void options_xxusage(void)
452 /* Prevent compiler warning. */
456 for (opt = options_XX; opt->name != NULL; opt++) {
460 case OPT_TYPE_BOOLEAN:
461 printf("+%s", opt->name);
462 length = os_strlen(" -XX:+") + os_strlen(opt->name);
466 printf("%s=<value>", opt->name);
467 length = os_strlen(" -XX:") + os_strlen(opt->name) +
468 os_strlen("=<value>");
472 vm_abort("options_xxusage: unkown option type %d", opt->type);
475 /* Check if the help fits into one 80-column line.
476 Documentation starts at column 29. */
478 if (length < (29 - 1)) {
479 /* Print missing spaces up to column 29. */
481 for (i = length; i < 29; i++)
486 printf(" "); /* 29 spaces */
489 /* Check documentation length. */
491 length = os_strlen(opt->doc);
493 if (length < (80 - 29)) {
494 printf("%s", opt->doc);
497 for (c = opt->doc, i = 29; *c != 0; c++, i++) {
498 /* If we are at the end of the line, break it. */
502 printf(" "); /* 29 spaces */
513 /* exit with error code */
519 /* options_xx ******************************************************************
523 *******************************************************************************/
525 void options_xx(JavaVMInitArgs *vm_args)
538 /* Iterate over all passed options. */
540 for (i = 0; i < vm_args->nOptions; i++) {
541 /* Get the current option. */
543 name = vm_args->options[i].optionString;
545 /* Check for help (-XX). */
547 if (strcmp(name, "-XX") == 0)
550 /* Check if the option start with -XX. */
552 start = strstr(name, "-XX:");
554 if ((start == NULL) || (start != name))
557 /* Check if the option is a boolean option. */
559 if (name[4] == '+') {
560 start = name + 4 + 1;
563 else if (name[4] == '-') {
564 start = name + 4 + 1;
572 /* Search for a '=' in the option name and get the option name
573 length and the value of the option. */
575 end = strchr(start, '=');
578 length = os_strlen(start);
582 length = end - start;
586 /* Search the option in the option array. */
588 for (opt = options_XX; opt->name != NULL; opt++) {
589 if (strncmp(opt->name, start, length) == 0) {
590 /* Check if the options passed fits to the type. */
593 case OPT_TYPE_BOOLEAN:
594 if ((enable == -1) || (value != NULL))
598 if ((enable != -1) || (value == NULL))
602 vm_abort("options_xx: unknown option type %d for option %s",
603 opt->type, opt->name);
610 /* Process the option. */
612 switch (opt->value) {
614 /* Options which must always be available (production options
617 case OPT_MaxDirectMemorySize:
618 opt_MaxDirectMemorySize = os_atoi(value);
621 case OPT_MaxPermSize:
622 /* Currently ignored. */
626 /* Currently ignored. */
629 case OPT_ThreadStackSize:
630 /* currently ignored */
633 /* Debugging options which can be turned off. */
635 case OPT_AlwaysEmitLongBranches:
636 opt_AlwaysEmitLongBranches = enable;
640 opt_CompileAll = enable;
642 makeinitializations = false;
645 case OPT_CompileMethod:
646 opt_CompileMethod = value;
648 makeinitializations = false;
651 case OPT_CompileSignature:
652 opt_CompileSignature = value;
655 case OPT_DebugExceptions:
656 opt_DebugExceptions = enable;
659 case OPT_DebugFinalizer:
660 opt_DebugFinalizer = enable;
663 case OPT_DebugLocalReferences:
664 opt_DebugLocalReferences = enable;
668 opt_DebugLocks = enable;
671 case OPT_DebugPackage:
672 opt_DebugPackage = enable;
675 case OPT_DebugPatcher:
676 opt_DebugPatcher = enable;
679 case OPT_DebugProperties:
680 opt_DebugProperties = enable;
683 case OPT_DebugStackFrameInfo:
684 opt_DebugStackFrameInfo = enable;
687 case OPT_DebugStackTrace:
688 opt_DebugStackTrace = enable;
691 case OPT_DebugThreads:
692 opt_DebugThreads = enable;
695 #if defined(ENABLE_DISASSEMBLER)
696 case OPT_DisassembleStubs:
697 opt_DisassembleStubs = enable;
701 #if defined(ENABLE_OPAGENT)
702 case OPT_EnableOpagent:
703 opt_EnableOpagent = enable;
707 #if defined(ENABLE_GC_CACAO)
708 case OPT_GCDebugRootSet:
709 opt_GCDebugRootSet = enable;
713 opt_GCStress = enable;
717 #if defined(ENABLE_INLINING)
721 #if defined(ENABLE_INLINING_DEBUG) || !defined(NDEBUG)
723 opt_InlineAll = enable;
726 case OPT_InlineCount:
728 opt_InlineCount = os_atoi(value);
731 case OPT_InlineMaxSize:
733 opt_InlineMaxSize = os_atoi(value);
736 case OPT_InlineMinSize:
738 opt_InlineMinSize = os_atoi(value);
743 case OPT_PrintConfig:
744 opt_PrintConfig = enable;
747 case OPT_PrintWarnings:
748 opt_PrintWarnings = enable;
751 case OPT_ProfileGCMemoryUsage:
753 opt_ProfileGCMemoryUsage = 5;
755 opt_ProfileGCMemoryUsage = os_atoi(value);
758 case OPT_ProfileMemoryUsage:
760 opt_ProfileMemoryUsage = 5;
762 opt_ProfileMemoryUsage = os_atoi(value);
764 # if defined(ENABLE_STATISTICS)
765 /* we also need statistics */
771 case OPT_ProfileMemoryUsageGNUPlot:
773 filename = "profile.dat";
777 file = fopen(filename, "w");
780 #warning Use below method instead!
781 //os::abort_errno("options_xx: fopen failed");
782 vm_abort("options_xx: fopen failed");
784 opt_ProfileMemoryUsageGNUPlot = file;
787 case OPT_RegallocSpillAll:
788 opt_RegallocSpillAll = enable;
791 #if defined(ENABLE_REPLACEMENT)
792 case OPT_TestReplacement:
793 opt_TestReplacement = enable;
797 case OPT_TraceBuiltinCalls:
798 opt_TraceBuiltinCalls = enable;
801 case OPT_TraceCompilerCalls:
802 opt_TraceCompilerCalls = enable;
805 case OPT_TraceExceptions:
806 opt_TraceExceptions = enable;
810 opt_TraceHPI = enable;
813 #if defined(ENABLE_INLINING) && !defined(NDEBUG)
814 case OPT_TraceInlining:
816 opt_TraceInlining = 1;
818 opt_TraceInlining = os_atoi(value);
822 case OPT_TraceJavaCalls:
823 opt_verbosecall = enable;
824 opt_TraceJavaCalls = enable;
827 case OPT_TraceJNICalls:
828 opt_TraceJNICalls = enable;
831 case OPT_TraceJVMCalls:
832 opt_TraceJVMCalls = enable;
835 case OPT_TraceJVMCallsVerbose:
836 opt_TraceJVMCallsVerbose = enable;
839 case OPT_TraceLinkClass:
840 opt_TraceLinkClass = enable;
843 #if defined(ENABLE_REPLACEMENT)
844 case OPT_TraceReplacement:
846 opt_TraceReplacement = 1;
848 opt_TraceReplacement = os_atoi(value);
852 case OPT_TraceSubsystemInitialization:
853 opt_TraceSubsystemInitialization = enable;
857 opt_TraceTraps = enable;
860 #if defined(ENABLE_VMLOG)
863 vmlog_cacao_set_prefix("vmlog");
865 vmlog_cacao_set_prefix(value);
867 opt_TraceJavaCalls = 1;
870 case OPT_VmlogStrings:
872 vmlog_cacao_set_stringprefix(value);
875 case OPT_VmlogIgnore:
877 vmlog_cacao_set_ignoreprefix(value);
882 fprintf(stderr, "Unknown -XX option: %s\n", name);
890 * These are local overrides for various environment variables in Emacs.
891 * Please do not remove this and leave it at the end of the file, where
892 * Emacs will automagically detect them.
893 * ---------------------------------------------------------------------
896 * indent-tabs-mode: t