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 "native/jni.h"
37 #include "vm/options.h"
42 /* command line option ********************************************************/
44 s4 opt_index = 0; /* index of processed arguments */
45 char *opt_arg; /* this one exports the option argument */
47 bool opt_foo = false; /* option for development */
51 #if defined(ENABLE_JIT)
52 bool opt_jit = true; /* JIT mode execution (default) */
53 bool opt_intrp = false; /* interpreter mode execution */
55 bool opt_jit = false; /* JIT mode execution */
56 bool opt_intrp = true; /* interpreter mode execution (default) */
61 s4 opt_heapmaxsize = 0; /* maximum heap size */
62 s4 opt_heapstartsize = 0; /* initial heap size */
63 s4 opt_stacksize = 0; /* thread stack size */
65 bool opt_verbose = false;
66 bool opt_debugcolor = false; /* use ANSI terminal sequences */
67 bool compileall = false;
69 bool loadverbose = false;
70 bool initverbose = false;
72 bool opt_verboseclass = false;
73 bool opt_verbosegc = false;
74 bool opt_verbosejni = false;
75 bool opt_verbosecall = false; /* trace all method invocation */
77 bool showmethods = false;
78 bool showconstantpool = false;
81 char *opt_method = NULL;
82 char *opt_signature = NULL;
84 bool compileverbose = false; /* trace compiler actions */
85 bool showstack = false;
87 bool opt_showdisassemble = false; /* generate disassembler listing */
88 bool opt_shownops = false;
89 bool opt_showddatasegment = false; /* generate data segment listing */
90 bool opt_showintermediate = false; /* generate intermediate code listing */
92 bool checkbounds = true; /* check array bounds */
93 bool opt_noieee = false; /* don't implement ieee compliant floats */
94 bool checksync = true; /* do synchronization */
95 #if defined(ENABLE_LOOP)
96 bool opt_loops = false; /* optimize array accesses in loops */
99 bool makeinitializations = true;
101 #if defined(ENABLE_STATISTICS)
102 bool opt_stat = false;
103 bool opt_getloadingtime = false; /* to measure the runtime */
104 bool opt_getcompilingtime = false; /* compute compile time */
106 #if defined(ENABLE_VERIFIER)
107 bool opt_verify = true; /* true if classfiles should be verified */
110 #if defined(ENABLE_PROFILING)
111 bool opt_prof = false;
112 bool opt_prof_bb = false;
115 #if defined(ENABLE_OPAGENT)
116 bool opt_opagent = false;
119 /* optimization options *******************************************************/
121 #if defined(ENABLE_IFCONV)
122 bool opt_ifconv = false;
125 #if defined(ENABLE_LSRA) || defined(ENABLE_SSA)
126 bool opt_lsra = false;
128 #if defined(ENABLE_SSA)
129 bool opt_ssa_dce = false; /* enable dead code elemination */
130 bool opt_ssa_cp = false; /* enable copy propagation */
134 /* interpreter options ********************************************************/
136 #if defined(ENABLE_INTRP)
137 bool opt_no_dynamic = false; /* suppress dynamic superinstructions */
138 bool opt_no_replication = false; /* don't use replication in intrp */
139 bool opt_no_quicksuper = false; /* instructions for quickening cannot be
140 part of dynamic superinstructions */
142 s4 opt_static_supers = 0x7fffffff;
143 bool vm_debug = false; /* XXX this should be called `opt_trace' */
146 #if defined(ENABLE_DEBUG_FILTER)
147 const char *opt_filter_verbosecall_include = 0;
148 const char *opt_filter_verbosecall_exclude = 0;
149 const char *opt_filter_show_method = 0;
153 /* -XX options ****************************************************************/
155 /* NOTE: For better readability keep these alpha-sorted. */
157 /* Options which must always be available (production options in
160 int64_t opt_MaxDirectMemorySize = -1;
161 int opt_MaxPermSize = 0;
162 int opt_PermSize = 0;
163 int opt_ThreadStackSize = 0;
165 /* Debugging options which can be turned off. */
167 int opt_DebugExceptions = 0;
168 int opt_DebugFinalizer = 0;
169 #if defined(ENABLE_JITCACHE)
170 int opt_DebugJitCache = 0;
172 int opt_DebugLocalReferences = 0;
173 int opt_DebugLocks = 0;
174 int opt_DebugPackage = 0;
175 int opt_DebugPatcher = 0;
176 int opt_DebugProperties = 0;
177 int opt_DebugStackFrameInfo = 0;
178 int opt_DebugStackTrace = 0;
179 int opt_DebugThreads = 0;
180 #if defined(ENABLE_DISASSEMBLER)
181 int opt_DisassembleStubs = 0;
183 #if defined(ENABLE_OPAGENT)
184 int opt_EnableOpagent = 0;
186 #if defined(ENABLE_GC_CACAO)
187 int opt_GCDebugRootSet = 0;
188 int opt_GCStress = 0;
190 #if defined(ENABLE_INLINING)
192 #if defined(ENABLE_INLINING_DEBUG) || !defined(NDEBUG)
193 int opt_InlineAll = 0;
194 int opt_InlineCount = INT_MAX;
195 int opt_InlineMaxSize = INT_MAX;
196 int opt_InlineMinSize = 0;
199 int opt_PrintConfig = 0;
200 int opt_ProfileGCMemoryUsage = 0;
201 int opt_ProfileMemoryUsage = 0;
202 FILE *opt_ProfileMemoryUsageGNUPlot = NULL;
203 #if defined(ENABLE_REPLACEMENT)
204 int opt_TestReplacement = 0;
206 int opt_TraceCompilerCalls = 0;
207 int opt_TraceExceptions = 0;
208 int opt_TraceHPI = 0;
209 #if defined(ENABLE_INLINING) && !defined(NDEBUG)
210 int opt_TraceInlining = 0;
212 int opt_TraceJavaCalls = 0;
213 int opt_TraceJNICalls = 0;
214 int opt_TraceJVMCalls = 0;
215 int opt_TraceJVMCallsVerbose = 0;
216 int opt_TraceLinkClass = 0;
217 #if defined(ENABLE_REPLACEMENT)
218 int opt_TraceReplacement = 0;
220 int opt_TraceSubsystemInitialization = 0;
221 int opt_TraceTraps = 0;
230 /* Options which must always be available (production options in
233 OPT_MaxDirectMemorySize,
238 /* Debugging options which can be turned off. */
243 OPT_DebugLocalReferences,
248 OPT_DebugStackFrameInfo,
251 OPT_DisassembleStubs,
261 OPT_ProfileGCMemoryUsage,
262 OPT_ProfileMemoryUsage,
263 OPT_ProfileMemoryUsageGNUPlot,
265 OPT_TraceCompilerCalls,
272 OPT_TraceJVMCallsVerbose,
274 OPT_TraceReplacement,
275 OPT_TraceSubsystemInitialization,
283 option_t options_XX[] = {
284 /* Options which must always be available (production options in
287 { "MaxDirectMemorySize", OPT_MaxDirectMemorySize, OPT_TYPE_VALUE, "Maximum total size of NIO direct-buffer allocations" },
288 { "MaxPermSize", OPT_MaxPermSize, OPT_TYPE_VALUE, "not implemented" },
289 { "PermSize", OPT_PermSize, OPT_TYPE_VALUE, "not implemented" },
290 { "ThreadStackSize", OPT_ThreadStackSize, OPT_TYPE_VALUE, "TODO" },
292 /* Debugging options which can be turned off. */
294 { "DebugExceptions", OPT_DebugExceptions, OPT_TYPE_BOOLEAN, "debug exceptions" },
295 { "DebugFinalizer", OPT_DebugFinalizer, OPT_TYPE_BOOLEAN, "debug finalizer thread" },
296 #if defined (ENABLE_JITCACHE)
297 { "DebugJitCache", OPT_DebugJitCache, OPT_TYPE_BOOLEAN, "debug JIT cache actions" },
299 { "DebugLocalReferences", OPT_DebugLocalReferences, OPT_TYPE_BOOLEAN, "print debug information for local reference tables" },
300 { "DebugLocks", OPT_DebugLocks, OPT_TYPE_BOOLEAN, "print debug information for locks" },
301 { "DebugPackage", OPT_DebugPackage, OPT_TYPE_BOOLEAN, "debug Java boot-packages" },
302 { "DebugPatcher", OPT_DebugPatcher, OPT_TYPE_BOOLEAN, "debug JIT code patching" },
303 { "DebugProperties", OPT_DebugProperties, OPT_TYPE_BOOLEAN, "print debug information for properties" },
304 { "DebugStackFrameInfo", OPT_DebugStackFrameInfo, OPT_TYPE_BOOLEAN, "TODO" },
305 { "DebugStackTrace", OPT_DebugStackTrace, OPT_TYPE_BOOLEAN, "debug stacktrace creation" },
306 { "DebugThreads", OPT_DebugThreads, OPT_TYPE_BOOLEAN, "print debug information for threads" },
307 #if defined(ENABLE_DISASSEMBLER)
308 { "DisassembleStubs", OPT_DisassembleStubs, OPT_TYPE_BOOLEAN, "disassemble builtin and native stubs when generated" },
310 #if defined(ENABLE_OPAGENT)
311 { "EnableOpagent", OPT_EnableOpagent, OPT_TYPE_BOOLEAN, "enable providing JIT output to Oprofile" },
313 #if defined(ENABLE_GC_CACAO)
314 { "GCDebugRootSet", OPT_GCDebugRootSet, OPT_TYPE_BOOLEAN, "GC: print root-set at collection" },
315 { "GCStress", OPT_GCStress, OPT_TYPE_BOOLEAN, "GC: forced collection at every allocation" },
317 #if defined(ENABLE_INLINING)
318 { "Inline", OPT_Inline, OPT_TYPE_BOOLEAN, "enable method inlining" },
319 #if defined(ENABLE_INLINING_DEBUG) || !defined(NDEBUG)
320 { "InlineAll", OPT_InlineAll, OPT_TYPE_BOOLEAN, "use inlining in all compilations" },
321 { "InlineCount", OPT_InlineCount, OPT_TYPE_VALUE, "stop inlining after the given number of roots" },
322 { "InlineMaxSize", OPT_InlineMaxSize, OPT_TYPE_VALUE, "maximum size for inlined result" },
323 { "InlineMinSize", OPT_InlineMinSize, OPT_TYPE_VALUE, "minimum size for inlined result" },
326 { "PrintConfig", OPT_PrintConfig, OPT_TYPE_BOOLEAN, "print VM configuration" },
327 { "ProfileGCMemoryUsage", OPT_ProfileGCMemoryUsage, OPT_TYPE_VALUE, "profiles GC memory usage in the given interval, <value> is in seconds (default: 5)" },
328 { "ProfileMemoryUsage", OPT_ProfileMemoryUsage, OPT_TYPE_VALUE, "TODO" },
329 { "ProfileMemoryUsageGNUPlot", OPT_ProfileMemoryUsageGNUPlot, OPT_TYPE_VALUE, "TODO" },
330 #if defined(ENABLE_REPLACEMENT)
331 { "TestReplacement", OPT_TestReplacement, OPT_TYPE_BOOLEAN, "activate all replacement points during code generation" },
333 { "TraceCompilerCalls", OPT_TraceCompilerCalls, OPT_TYPE_BOOLEAN, "trace JIT compiler calls" },
334 { "TraceExceptions", OPT_TraceExceptions, OPT_TYPE_BOOLEAN, "trace Exception throwing" },
335 { "TraceHPI", OPT_TraceHPI, OPT_TYPE_BOOLEAN, "Trace Host Porting Interface (HPI)" },
336 #if defined(ENABLE_INLINING) && !defined(NDEBUG)
337 { "TraceInlining", OPT_TraceInlining, OPT_TYPE_VALUE, "trace method inlining with the given verbosity level (default: 1)" },
339 #if !defined(ENABLE_VMLOG)
340 { "TraceJavaCalls", OPT_TraceJavaCalls, OPT_TYPE_BOOLEAN, "trace Java method calls" },
342 { "TraceJNICalls", OPT_TraceJNICalls, OPT_TYPE_BOOLEAN, "trace JNI method calls" },
343 { "TraceJVMCalls", OPT_TraceJVMCalls, OPT_TYPE_BOOLEAN, "trace JVM method calls but omit very frequent ones" },
344 { "TraceJVMCallsVerbose", OPT_TraceJVMCallsVerbose, OPT_TYPE_BOOLEAN, "trace all JVM method calls" },
345 { "TraceLinkClass", OPT_TraceLinkClass, OPT_TYPE_BOOLEAN, "trace class linking" },
346 #if defined(ENABLE_REPLACEMENT)
347 { "TraceReplacement", OPT_TraceReplacement, OPT_TYPE_VALUE, "trace on-stack replacement with the given verbosity level (default: 1)" },
349 { "TraceSubsystemInitialization", OPT_TraceSubsystemInitialization, OPT_TYPE_BOOLEAN, "trace initialization of subsystems" },
350 { "TraceTraps", OPT_TraceTraps, OPT_TYPE_BOOLEAN, "trace traps generated by JIT code" },
351 #if defined(ENABLE_VMLOG)
352 { "Vmlog", OPT_Vmlog, OPT_TYPE_VALUE, "prefix for vmlog trace files (enables vmlog)" },
353 { "VmlogStrings", OPT_VmlogStrings, OPT_TYPE_VALUE, "prefix of vmlog string file to load" },
354 { "VmlogIgnore", OPT_VmlogIgnore, OPT_TYPE_VALUE, "prefix of vmlog ignore file to load" },
359 { NULL, -1, -1, NULL }
363 /* options_get *****************************************************************
367 *******************************************************************************/
369 int options_get(opt_struct *opts, JavaVMInitArgs *vm_args)
374 if (opt_index >= vm_args->nOptions)
377 /* get the current option */
379 option = vm_args->options[opt_index].optionString;
381 if ((option == NULL) || (option[0] != '-'))
384 for (i = 0; opts[i].name; i++) {
386 /* boolean option found */
388 if (strcmp(option + 1, opts[i].name) == 0) {
390 return opts[i].value;
394 /* parameter option found */
396 /* with a space between */
398 if (strcmp(option + 1, opts[i].name) == 0) {
401 if (opt_index < vm_args->nOptions) {
402 opt_arg = os_strdup(vm_args->options[opt_index].optionString);
404 return opts[i].value;
410 /* parameter and option have no space between */
412 /* FIXME: this assumption is plain wrong, hits you if there is a
413 * parameter with no argument starting with same letter as param with argument
414 * but named after that one, ouch! */
416 size_t l = os_strlen(opts[i].name);
418 if (os_strlen(option + 1) > l) {
419 if (memcmp(option + 1, opts[i].name, l) == 0) {
421 opt_arg = os_strdup(option + 1 + l);
422 return opts[i].value;
433 /* options_xxusage *************************************************************
435 Print usage message for debugging options.
437 *******************************************************************************/
439 static void options_xxusage(void)
446 /* Prevent compiler warning. */
450 for (opt = options_XX; opt->name != NULL; opt++) {
454 case OPT_TYPE_BOOLEAN:
455 printf("+%s", opt->name);
456 length = os_strlen(" -XX:+") + os_strlen(opt->name);
460 printf("%s=<value>", opt->name);
461 length = os_strlen(" -XX:") + os_strlen(opt->name) +
462 os_strlen("=<value>");
466 vm_abort("options_xxusage: unkown option type %d", opt->type);
469 /* Check if the help fits into one 80-column line.
470 Documentation starts at column 29. */
472 if (length < (29 - 1)) {
473 /* Print missing spaces up to column 29. */
475 for (i = length; i < 29; i++)
480 printf(" "); /* 29 spaces */
483 /* Check documentation length. */
485 length = os_strlen(opt->doc);
487 if (length < (80 - 29)) {
488 printf("%s", opt->doc);
491 for (c = opt->doc, i = 29; *c != 0; c++, i++) {
492 /* If we are at the end of the line, break it. */
496 printf(" "); /* 29 spaces */
507 /* exit with error code */
513 /* options_xx ******************************************************************
517 *******************************************************************************/
519 void options_xx(JavaVMInitArgs *vm_args)
532 /* Iterate over all passed options. */
534 for (i = 0; i < vm_args->nOptions; i++) {
535 /* Get the current option. */
537 name = vm_args->options[i].optionString;
539 /* Check for help (-XX). */
541 if (strcmp(name, "-XX") == 0)
544 /* Check if the option start with -XX. */
546 start = strstr(name, "-XX:");
548 if ((start == NULL) || (start != name))
551 /* Check if the option is a boolean option. */
553 if (name[4] == '+') {
554 start = name + 4 + 1;
557 else if (name[4] == '-') {
558 start = name + 4 + 1;
566 /* Search for a '=' in the option name and get the option name
567 length and the value of the option. */
569 end = strchr(start, '=');
572 length = os_strlen(start);
576 length = end - start;
580 /* Search the option in the option array. */
582 for (opt = options_XX; opt->name != NULL; opt++) {
583 if (strncmp(opt->name, start, length) == 0) {
584 /* Check if the options passed fits to the type. */
587 case OPT_TYPE_BOOLEAN:
588 if ((enable == -1) || (value != NULL))
592 if ((enable != -1) || (value == NULL))
596 vm_abort("options_xx: unknown option type %d for option %s",
597 opt->type, opt->name);
604 /* Process the option. */
606 switch (opt->value) {
608 /* Options which must always be available (production options
611 case OPT_MaxDirectMemorySize:
612 opt_MaxDirectMemorySize = os_atoi(value);
615 case OPT_MaxPermSize:
616 /* Currently ignored. */
620 /* Currently ignored. */
623 case OPT_ThreadStackSize:
624 /* currently ignored */
627 /* Debugging options which can be turned off. */
629 case OPT_DebugExceptions:
630 opt_DebugExceptions = enable;
633 case OPT_DebugFinalizer:
634 opt_DebugFinalizer = enable;
637 #if defined(ENABLE_JITCACHE)
638 case OPT_DebugJitCache:
639 opt_DebugJitCache = enable;
643 case OPT_DebugLocalReferences:
644 opt_DebugLocalReferences = enable;
648 opt_DebugLocks = enable;
651 case OPT_DebugPackage:
652 opt_DebugPackage = enable;
655 case OPT_DebugPatcher:
656 opt_DebugPatcher = enable;
659 case OPT_DebugProperties:
660 opt_DebugProperties = enable;
663 case OPT_DebugStackFrameInfo:
664 opt_DebugStackFrameInfo = enable;
667 case OPT_DebugStackTrace:
668 opt_DebugStackTrace = enable;
671 case OPT_DebugThreads:
672 opt_DebugThreads = enable;
675 #if defined(ENABLE_DISASSEMBLER)
676 case OPT_DisassembleStubs:
677 opt_DisassembleStubs = enable;
681 #if defined(ENABLE_OPAGENT)
682 case OPT_EnableOpagent:
683 opt_EnableOpagent = enable;
687 #if defined(ENABLE_GC_CACAO)
688 case OPT_GCDebugRootSet:
689 opt_GCDebugRootSet = enable;
693 opt_GCStress = enable;
697 #if defined(ENABLE_INLINING)
701 #if defined(ENABLE_INLINING_DEBUG) || !defined(NDEBUG)
703 opt_InlineAll = enable;
706 case OPT_InlineCount:
708 opt_InlineCount = os_atoi(value);
711 case OPT_InlineMaxSize:
713 opt_InlineMaxSize = os_atoi(value);
716 case OPT_InlineMinSize:
718 opt_InlineMinSize = os_atoi(value);
723 case OPT_PrintConfig:
724 opt_PrintConfig = enable;
727 case OPT_ProfileGCMemoryUsage:
729 opt_ProfileGCMemoryUsage = 5;
731 opt_ProfileGCMemoryUsage = os_atoi(value);
734 case OPT_ProfileMemoryUsage:
736 opt_ProfileMemoryUsage = 5;
738 opt_ProfileMemoryUsage = os_atoi(value);
740 # if defined(ENABLE_STATISTICS)
741 /* we also need statistics */
747 case OPT_ProfileMemoryUsageGNUPlot:
749 filename = "profile.dat";
753 file = fopen(filename, "w");
756 vm_abort_errno("options_xx: fopen failed");
758 opt_ProfileMemoryUsageGNUPlot = file;
761 #if defined(ENABLE_REPLACEMENT)
762 case OPT_TestReplacement:
763 opt_TestReplacement = enable;
767 case OPT_TraceCompilerCalls:
768 opt_TraceCompilerCalls = enable;
771 case OPT_TraceExceptions:
772 opt_TraceExceptions = enable;
776 opt_TraceHPI = enable;
779 #if defined(ENABLE_INLINING) && !defined(NDEBUG)
780 case OPT_TraceInlining:
782 opt_TraceInlining = 1;
784 opt_TraceInlining = os_atoi(value);
788 case OPT_TraceJavaCalls:
789 opt_verbosecall = enable;
790 opt_TraceJavaCalls = enable;
793 case OPT_TraceJNICalls:
794 opt_TraceJNICalls = enable;
797 case OPT_TraceJVMCalls:
798 opt_TraceJVMCalls = enable;
801 case OPT_TraceJVMCallsVerbose:
802 opt_TraceJVMCallsVerbose = enable;
805 case OPT_TraceLinkClass:
806 opt_TraceLinkClass = enable;
809 #if defined(ENABLE_REPLACEMENT)
810 case OPT_TraceReplacement:
812 opt_TraceReplacement = 1;
814 opt_TraceReplacement = os_atoi(value);
818 case OPT_TraceSubsystemInitialization:
819 opt_TraceSubsystemInitialization = enable;
823 opt_TraceTraps = enable;
826 #if defined(ENABLE_VMLOG)
829 vmlog_cacao_set_prefix("vmlog");
831 vmlog_cacao_set_prefix(value);
833 opt_TraceJavaCalls = 1;
836 case OPT_VmlogStrings:
838 vmlog_cacao_set_stringprefix(value);
841 case OPT_VmlogIgnore:
843 vmlog_cacao_set_ignoreprefix(value);
848 printf("Unknown -XX option: %s\n", name);
856 * These are local overrides for various environment variables in Emacs.
857 * Please do not remove this and leave it at the end of the file, where
858 * Emacs will automagically detect them.
859 * ---------------------------------------------------------------------
862 * indent-tabs-mode: t