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 linkverbose = false;
79 bool initverbose = false;
81 bool opt_verboseclass = false;
82 bool opt_verbosegc = false;
83 bool opt_verbosejni = false;
84 bool opt_verbosecall = false; /* trace all method invocation */
85 bool opt_verbosethreads = false;
87 bool showmethods = false;
88 bool showconstantpool = false;
91 char *opt_method = NULL;
92 char *opt_signature = NULL;
94 bool compileverbose = false; /* trace compiler actions */
95 bool showstack = false;
97 bool opt_showdisassemble = false; /* generate disassembler listing */
98 bool opt_shownops = false;
99 bool opt_showddatasegment = false; /* generate data segment listing */
100 bool opt_showintermediate = false; /* generate intermediate code listing */
101 bool opt_showexceptionstubs = false;
102 bool opt_shownativestub = false;
104 bool checkbounds = true; /* check array bounds */
105 bool opt_noieee = false; /* don't implement ieee compliant floats */
106 bool checksync = true; /* do synchronization */
107 #if defined(ENABLE_LOOP)
108 bool opt_loops = false; /* optimize array accesses in loops */
111 bool makeinitializations = true;
113 #if defined(ENABLE_STATISTICS)
114 bool opt_stat = false;
115 bool opt_getloadingtime = false; /* to measure the runtime */
116 bool opt_getcompilingtime = false; /* compute compile time */
118 #if defined(ENABLE_VERIFIER)
119 bool opt_verify = true; /* true if classfiles should be verified */
122 #if defined(ENABLE_PROFILING)
123 bool opt_prof = false;
124 bool opt_prof_bb = false;
128 /* inlining options ***********************************************************/
130 #if defined(ENABLE_INLINING)
131 bool opt_inlining = false;
132 #if defined(ENABLE_INLINING_DEBUG) || !defined(NDEBUG)
133 s4 opt_inline_debug_min_size = 0;
134 s4 opt_inline_debug_max_size = INT_MAX;
135 s4 opt_inline_debug_end_counter = INT_MAX;
136 bool opt_inline_debug_all = false;
137 #endif /* defined(ENABLE_INLINING_DEBUG) || !defined(NDEBUG) */
139 bool opt_inline_debug_log = false;
140 #endif /* !defined(NDEBUG) */
141 #endif /* defined(ENABLE_INLINING) */
144 /* optimization options *******************************************************/
146 #if defined(ENABLE_IFCONV)
147 bool opt_ifconv = false;
150 #if defined(ENABLE_LSRA) || defined(ENABLE_SSA)
151 bool opt_lsra = false;
155 /* interpreter options ********************************************************/
157 #if defined(ENABLE_INTRP)
158 bool opt_no_dynamic = false; /* suppress dynamic superinstructions */
159 bool opt_no_replication = false; /* don't use replication in intrp */
160 bool opt_no_quicksuper = false; /* instructions for quickening cannot be
161 part of dynamic superinstructions */
163 s4 opt_static_supers = 0x7fffffff;
164 bool vm_debug = false; /* XXX this should be called `opt_trace' */
167 #if defined(ENABLE_DEBUG_FILTER)
168 const char *opt_filter_verbosecall_include = 0;
169 const char *opt_filter_verbosecall_exclude = 0;
170 const char *opt_filter_show_method = 0;
174 /* -XX options ****************************************************************/
176 /* NOTE: For better readability keep these alpha-sorted. */
178 int32_t opt_DebugStackFrameInfo = 0;
179 int32_t opt_DebugStackTrace = 0;
180 int32_t opt_MaxPermSize = 0;
181 int32_t opt_PermSize = 0;
182 int opt_PrintConfig = 0;
183 int32_t opt_ProfileGCMemoryUsage = 0;
184 int32_t opt_ProfileMemoryUsage = 0;
185 FILE *opt_ProfileMemoryUsageGNUPlot = NULL;
186 int32_t opt_ThreadStackSize = 0;
187 int32_t opt_TraceExceptions = 0;
188 int32_t opt_TraceJavaCalls = 0;
189 int32_t opt_TraceJNICalls = 0;
190 int32_t opt_TraceJVMCalls = 0;
191 #if defined(ENABLE_REPLACEMENT)
192 int32_t opt_TraceReplacement = 0;
202 OPT_DebugStackFrameInfo,
207 OPT_ProfileGCMemoryUsage,
208 OPT_ProfileMemoryUsage,
209 OPT_ProfileMemoryUsageGNUPlot,
219 option_t options_XX[] = {
220 { "DebugStackFrameInfo", OPT_DebugStackFrameInfo, OPT_TYPE_BOOLEAN, "TODO" },
221 { "DebugStackTrace", OPT_DebugStackTrace, OPT_TYPE_BOOLEAN, "TODO" },
222 { "MaxPermSize", OPT_MaxPermSize, OPT_TYPE_VALUE, "not implemented" },
223 { "PermSize", OPT_PermSize, OPT_TYPE_VALUE, "not implemented" },
224 { "PrintConfig", OPT_PrintConfig, OPT_TYPE_BOOLEAN, "print VM configuration" },
225 { "ProfileGCMemoryUsage", OPT_ProfileGCMemoryUsage, OPT_TYPE_VALUE, "profiles GC memory usage in the given interval, <value> is in seconds (default: 5)" },
226 { "ProfileMemoryUsage", OPT_ProfileMemoryUsage, OPT_TYPE_VALUE, "TODO" },
227 { "ProfileMemoryUsageGNUPlot", OPT_ProfileMemoryUsageGNUPlot, OPT_TYPE_VALUE, "TODO" },
228 { "ThreadStackSize", OPT_ThreadStackSize, OPT_TYPE_VALUE, "TODO" },
229 { "TraceExceptions", OPT_TraceExceptions, OPT_TYPE_BOOLEAN, "TODO" },
230 { "TraceJavaCalls", OPT_TraceJavaCalls, OPT_TYPE_BOOLEAN, "trace Java method calls" },
231 { "TraceJNICalls", OPT_TraceJNICalls, OPT_TYPE_BOOLEAN, "trace JNI method calls" },
232 { "TraceJVMCalls", OPT_TraceJVMCalls, OPT_TYPE_BOOLEAN, "TODO" },
233 #if defined(ENABLE_REPLACEMENT)
234 { "TraceReplacement", OPT_TraceReplacement, OPT_TYPE_VALUE, "trace on-stack replacement with the given verbosity level (default: 1)" },
239 { NULL, -1, -1, NULL }
243 /* options_get *****************************************************************
247 *******************************************************************************/
249 s4 options_get(opt_struct *opts, JavaVMInitArgs *vm_args)
254 if (opt_index >= vm_args->nOptions)
257 /* get the current option */
259 option = vm_args->options[opt_index].optionString;
261 if ((option == NULL) || (option[0] != '-'))
264 for (i = 0; opts[i].name; i++) {
266 /* boolean option found */
268 if (strcmp(option + 1, opts[i].name) == 0) {
270 return opts[i].value;
274 /* parameter option found */
276 /* with a space between */
278 if (strcmp(option + 1, opts[i].name) == 0) {
281 if (opt_index < vm_args->nOptions) {
283 #if defined(HAVE_STRDUP)
284 opt_arg = strdup(vm_args->options[opt_index].optionString);
290 return opts[i].value;
296 /* parameter and option have no space between */
298 /* FIXME: this assumption is plain wrong, hits you if there is a
299 * parameter with no argument starting with same letter as param with argument
300 * but named after that one, ouch! */
302 size_t l = strlen(opts[i].name);
304 if (strlen(option + 1) > l) {
305 if (memcmp(option + 1, opts[i].name, l) == 0) {
308 #if defined(HAVE_STRDUP)
309 opt_arg = strdup(option + 1 + l);
314 return opts[i].value;
325 /* options_xxusage *************************************************************
327 Print usage message for debugging options.
329 *******************************************************************************/
331 static void options_xxusage(void)
338 for (opt = options_XX; opt->name != NULL; opt++) {
342 case OPT_TYPE_BOOLEAN:
343 printf("+%s", opt->name);
344 length = strlen(" -XX:+") + strlen(opt->name);
347 printf("%s=<value>", opt->name);
348 length = strlen(" -XX:") + strlen(opt->name) + strlen("=<value>");
352 /* Check if the help fits into one 80-column line.
353 Documentation starts at column 29. */
355 if (length < (29 - 1)) {
356 /* Print missing spaces up to column 29. */
358 for (i = length; i < 29; i++)
363 printf(" "); /* 29 spaces */
366 /* Check documentation length. */
368 length = strlen(opt->doc);
370 if (length < (80 - 29)) {
371 printf("%s", opt->doc);
374 for (c = opt->doc, i = 29; *c != 0; c++, i++) {
375 /* If we are at the end of the line, break it. */
379 printf(" "); /* 29 spaces */
390 /* exit with error code */
396 /* options_xx ******************************************************************
400 *******************************************************************************/
402 void options_xx(const char *name)
413 /* Check for help (-XX), in this case name is NULL. */
418 /* Check if the option is a boolean option. */
420 if (name[0] == '+') {
424 else if (name[0] == '-') {
433 /* Search for a '=' in the option name and get the option name
434 length and the value of the option. */
436 end = strchr(start, '=');
439 length = strlen(start);
443 length = end - start;
447 /* search the option in the option array */
449 for (opt = options_XX; opt->name != NULL; opt++) {
450 if (strncmp(opt->name, start, length) == 0) {
451 /* Check if the options passed fits to the type. */
454 case OPT_TYPE_BOOLEAN:
455 if ((enable == -1) || (value != NULL))
459 if ((enable != -1) || (value == NULL))
463 vm_abort("options_xx: unknown option type %d for option %s",
464 opt->type, opt->name);
471 /* process the option */
473 switch (opt->value) {
474 case OPT_DebugStackFrameInfo:
475 opt_DebugStackFrameInfo = enable;
478 case OPT_DebugStackTrace:
479 opt_DebugStackTrace = enable;
482 case OPT_MaxPermSize:
483 /* currently ignored */
487 /* currently ignored */
490 case OPT_PrintConfig:
494 case OPT_ProfileGCMemoryUsage:
496 opt_ProfileGCMemoryUsage = 5;
498 opt_ProfileGCMemoryUsage = atoi(value);
501 case OPT_ProfileMemoryUsage:
503 opt_ProfileMemoryUsage = 5;
505 opt_ProfileMemoryUsage = atoi(value);
507 # if defined(ENABLE_STATISTICS)
508 /* we also need statistics */
514 case OPT_ProfileMemoryUsageGNUPlot:
516 filename = "profile.dat";
520 file = fopen(filename, "w");
523 vm_abort("options_xx: fopen failed: %s", strerror(errno));
525 opt_ProfileMemoryUsageGNUPlot = file;
528 case OPT_ThreadStackSize:
529 /* currently ignored */
532 case OPT_TraceExceptions:
533 opt_TraceExceptions = enable;
536 case OPT_TraceJavaCalls:
537 opt_verbosecall = enable;
538 opt_TraceJavaCalls = enable;
541 case OPT_TraceJNICalls:
542 opt_TraceJNICalls = enable;
545 case OPT_TraceJVMCalls:
546 opt_TraceJVMCalls = enable;
549 #if defined(ENABLE_REPLACEMENT)
550 case OPT_TraceReplacement:
552 opt_TraceReplacement = 1;
554 opt_TraceReplacement = atoi(value);
559 printf("Unknown -XX option: %s\n", name);
566 * These are local overrides for various environment variables in Emacs.
567 * Please do not remove this and leave it at the end of the file, where
568 * Emacs will automagically detect them.
569 * ---------------------------------------------------------------------
572 * indent-tabs-mode: t