* src/threads/posix/thread-posix.cpp: Eliminated some easy-to-fix or pointless compil...
[cacao.git] / src / vm / options.c
1 /* src/vm/options.c - contains global options
2
3    Copyright (C) 1996-2005, 2006, 2007, 2008, 2010
4    CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
5
6    This file is part of CACAO.
7
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.
12
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.
17
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
21    02110-1301, USA.
22
23 */
24
25
26 #include "config.h"
27
28 #include <limits.h>
29 #include <stdint.h>
30 #include <stdio.h>
31 #include <stdlib.h>
32
33 #include "mm/memory.hpp"
34
35 #include "vm/options.h"
36 #include "vm/os.hpp"
37 #include "vm/vm.hpp"
38
39
40 /* command line option ********************************************************/
41
42 s4    opt_index = 0;            /* index of processed arguments               */
43 char *opt_arg;                  /* this one exports the option argument       */
44
45 bool opt_foo = false;           /* option for development                     */
46
47 bool opt_jar = false;
48
49 #if defined(ENABLE_JIT)
50 bool opt_jit = true;            /* JIT mode execution (default)               */
51 bool opt_intrp = false;         /* interpreter mode execution                 */
52 #else
53 bool opt_jit = false;           /* JIT mode execution                         */
54 bool opt_intrp = true;          /* interpreter mode execution (default)       */
55 #endif
56
57 bool opt_run = true;
58
59 s4   opt_heapmaxsize   = 0;     /* maximum heap size                          */
60 s4   opt_heapstartsize = 0;     /* initial heap size                          */
61 s4   opt_stacksize     = 0;     /* thread stack size                          */
62
63 bool opt_verbose = false;
64 bool opt_debugcolor = false;    /* use ANSI terminal sequences                */
65
66 bool loadverbose = false;
67 bool initverbose = false;
68
69 bool opt_verboseclass     = false;
70 bool opt_verbosegc        = false;
71 bool opt_verbosejni       = false;
72 bool opt_verbosecall      = false;      /* trace all method invocation        */
73
74 bool showmethods = false;
75 bool showconstantpool = false;
76 bool showutf = false;
77
78 bool compileverbose =  false;           /* trace compiler actions             */
79 bool showstack = false;
80
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 */
84
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           */
89 #endif
90
91 bool makeinitializations = true;
92
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                   */
97 #endif
98 #if defined(ENABLE_VERIFIER)
99 bool opt_verify  = true;       /* true if classfiles should be verified      */
100 #endif
101
102 #if defined(ENABLE_PROFILING)
103 bool opt_prof    = false;
104 bool opt_prof_bb = false;
105 #endif
106
107 #if defined(ENABLE_OPAGENT)
108 bool opt_opagent = false;
109 #endif
110
111 /* optimization options *******************************************************/
112
113 #if defined(ENABLE_IFCONV)
114 bool opt_ifconv = false;
115 #endif
116
117 #if defined(ENABLE_LSRA) || defined(ENABLE_SSA)
118 bool opt_lsra = false;
119 #endif
120 #if defined(ENABLE_SSA)
121 bool opt_ssa_dce = false;          /* enable dead code elemination */
122 bool opt_ssa_cp = false;           /* enable copy propagation      */
123 #endif
124
125
126 /* interpreter options ********************************************************/
127
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 */
133
134 s4   opt_static_supers = 0x7fffffff;
135 bool vm_debug = false;          /* XXX this should be called `opt_trace'      */
136 #endif
137
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;
142 #endif
143
144
145 /* -XX options ****************************************************************/
146
147 /* NOTE: For better readability keep these alpha-sorted. */
148
149 /* Options which must always be available (production options in
150    HotSpot). */
151
152 int64_t  opt_MaxDirectMemorySize          = -1;
153 int      opt_MaxPermSize                  = 0;
154 int      opt_PermSize                     = 0;
155 int      opt_ThreadStackSize              = 0;
156
157 /* Debugging options which can be turned off. */
158
159 bool     opt_AlwaysEmitLongBranches       = false;
160 bool     opt_AlwaysMmapFirstPage          = false;
161 int      opt_CompileAll                   = 0;
162 char*    opt_CompileMethod                = NULL;
163 char*    opt_CompileSignature             = NULL;
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;
176 #endif
177 #if defined(ENABLE_OPAGENT)
178 int      opt_EnableOpagent                = 0;
179 #endif
180 #if defined(ENABLE_GC_CACAO)
181 int      opt_GCDebugRootSet               = 0;
182 int      opt_GCStress                     = 0;
183 #endif
184 #if defined(ENABLE_INLINING)
185 int      opt_Inline                       = 0;
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;
191 #endif
192 #endif
193 int      opt_PrintConfig                  = 0;
194 int      opt_PrintWarnings                = 0;
195 int      opt_ProfileGCMemoryUsage         = 0;
196 int      opt_ProfileMemoryUsage           = 0;
197 FILE    *opt_ProfileMemoryUsageGNUPlot    = NULL;
198 int      opt_RegallocSpillAll             = 0;
199 #if defined(ENABLE_REPLACEMENT)
200 int      opt_TestReplacement              = 0;
201 #endif
202 int      opt_TraceBuiltinCalls            = 0;
203 int      opt_TraceCompilerCalls           = 0;
204 int      opt_TraceExceptions              = 0;
205 int      opt_TraceHPI                     = 0;
206 #if defined(ENABLE_INLINING) && !defined(NDEBUG)
207 int      opt_TraceInlining                = 0;
208 #endif
209 int      opt_TraceJavaCalls               = 0;
210 bool     opt_TraceJMMCalls                = false;
211 int      opt_TraceJNICalls                = 0;
212 int      opt_TraceJVMCalls                = 0;
213 int      opt_TraceJVMCallsVerbose         = 0;
214 #if defined(ENABLE_JVMTI)
215 int      opt_TraceJVMTICalls              = 0;
216 #endif
217 int      opt_TraceLinkClass               = 0;
218 #if defined(ENABLE_REPLACEMENT)
219 int      opt_TraceReplacement             = 0;
220 #endif
221 int      opt_TraceSubsystemInitialization = 0;
222 int      opt_TraceTraps                   = 0;
223
224
225 enum {
226         OPT_TYPE_BOOLEAN,
227         OPT_TYPE_VALUE
228 };
229
230 enum {
231         /* Options which must always be available (production options in
232            HotSpot). */
233
234         OPT_MaxDirectMemorySize,
235         OPT_MaxPermSize,
236         OPT_PermSize,
237         OPT_ThreadStackSize,
238
239         /* Debugging options which can be turned off. */
240
241         OPT_AlwaysEmitLongBranches,
242         OPT_AlwaysMmapFirstPage,
243         OPT_CompileAll,
244         OPT_CompileMethod,
245         OPT_CompileSignature,
246         OPT_DebugExceptions,
247         OPT_DebugFinalizer,
248         OPT_DebugLocalReferences,
249         OPT_DebugLocks,
250         OPT_DebugPackage,
251         OPT_DebugPatcher,
252         OPT_DebugProperties,
253         OPT_DebugStackFrameInfo,
254         OPT_DebugStackTrace,
255         OPT_DebugThreads,
256         OPT_DisassembleStubs,
257         OPT_EnableOpagent,
258         OPT_GCDebugRootSet,
259         OPT_GCStress,
260         OPT_Inline,
261         OPT_InlineAll,
262         OPT_InlineCount,
263         OPT_InlineMaxSize,
264         OPT_InlineMinSize,
265         OPT_PrintConfig,
266         OPT_PrintWarnings,
267         OPT_ProfileGCMemoryUsage,
268         OPT_ProfileMemoryUsage,
269         OPT_ProfileMemoryUsageGNUPlot,
270         OPT_RegallocSpillAll,
271         OPT_TestReplacement,
272         OPT_TraceBuiltinCalls,
273         OPT_TraceCompilerCalls,
274         OPT_TraceExceptions,
275         OPT_TraceHPI,
276         OPT_TraceInlining,
277         OPT_TraceJavaCalls,
278         OPT_TraceJMMCalls,
279         OPT_TraceJNICalls,
280         OPT_TraceJVMCalls,
281         OPT_TraceJVMCallsVerbose,
282         OPT_TraceJVMTICalls,
283         OPT_TraceLinkClass,
284         OPT_TraceReplacement,
285         OPT_TraceSubsystemInitialization,
286         OPT_TraceTraps,
287         OPT_Vmlog,
288         OPT_VmlogStrings,
289         OPT_VmlogIgnore
290 };
291
292
293 option_t options_XX[] = {
294         /* Options which must always be available (production options in
295            HotSpot). */
296
297         { "MaxDirectMemorySize",          OPT_MaxDirectMemorySize,          OPT_TYPE_VALUE,   "Maximum total size of NIO direct-buffer allocations" },
298         { "MaxPermSize",                  OPT_MaxPermSize,                  OPT_TYPE_VALUE,   "not implemented" },
299         { "PermSize",                     OPT_PermSize,                     OPT_TYPE_VALUE,   "not implemented" },
300         { "ThreadStackSize",              OPT_ThreadStackSize,              OPT_TYPE_VALUE,   "TODO" },
301
302         /* Debugging options which can be turned off. */
303
304         { "AlwaysEmitLongBranches",       OPT_AlwaysEmitLongBranches,       OPT_TYPE_BOOLEAN, "Always emit long-branches." },
305         { "AlwaysMmapFirstPage",          OPT_AlwaysMmapFirstPage,          OPT_TYPE_BOOLEAN, "Always mmap memory page at address 0x0." },
306         { "CompileAll",                   OPT_CompileAll,                   OPT_TYPE_BOOLEAN, "compile all methods, no execution" },
307         { "CompileMethod",                OPT_CompileMethod,                OPT_TYPE_VALUE,   "compile only a specific method" },
308         { "CompileSignature",             OPT_CompileSignature,             OPT_TYPE_VALUE,   "specify signature for a specific method" },
309         { "DebugExceptions",              OPT_DebugExceptions,              OPT_TYPE_BOOLEAN, "debug exceptions" },
310         { "DebugFinalizer",               OPT_DebugFinalizer,               OPT_TYPE_BOOLEAN, "debug finalizer thread" },
311         { "DebugLocalReferences",         OPT_DebugLocalReferences,         OPT_TYPE_BOOLEAN, "print debug information for local reference tables" },
312         { "DebugLocks",                   OPT_DebugLocks,                   OPT_TYPE_BOOLEAN, "print debug information for locks" },
313         { "DebugPackage",                 OPT_DebugPackage,                 OPT_TYPE_BOOLEAN, "debug Java boot-packages" },
314         { "DebugPatcher",                 OPT_DebugPatcher,                 OPT_TYPE_BOOLEAN, "debug JIT code patching" },
315         { "DebugProperties",              OPT_DebugProperties,              OPT_TYPE_BOOLEAN, "print debug information for properties" },
316         { "DebugStackFrameInfo",          OPT_DebugStackFrameInfo,          OPT_TYPE_BOOLEAN, "TODO" },
317         { "DebugStackTrace",              OPT_DebugStackTrace,              OPT_TYPE_BOOLEAN, "debug stacktrace creation" },
318         { "DebugThreads",                 OPT_DebugThreads,                 OPT_TYPE_BOOLEAN, "print debug information for threads" },
319 #if defined(ENABLE_DISASSEMBLER)
320         { "DisassembleStubs",             OPT_DisassembleStubs,             OPT_TYPE_BOOLEAN, "disassemble builtin and native stubs when generated" },
321 #endif
322 #if defined(ENABLE_OPAGENT)
323         { "EnableOpagent",                OPT_EnableOpagent,                OPT_TYPE_BOOLEAN, "enable providing JIT output to Oprofile" },
324 #endif
325 #if defined(ENABLE_GC_CACAO)
326         { "GCDebugRootSet",               OPT_GCDebugRootSet,               OPT_TYPE_BOOLEAN, "GC: print root-set at collection" },
327         { "GCStress",                     OPT_GCStress,                     OPT_TYPE_BOOLEAN, "GC: forced collection at every allocation" },
328 #endif
329 #if defined(ENABLE_INLINING)
330         { "Inline",                       OPT_Inline,                       OPT_TYPE_BOOLEAN, "enable method inlining" },
331 #if defined(ENABLE_INLINING_DEBUG) || !defined(NDEBUG)
332         { "InlineAll",                    OPT_InlineAll,                    OPT_TYPE_BOOLEAN, "use inlining in all compilations" },
333         { "InlineCount",                  OPT_InlineCount,                  OPT_TYPE_VALUE,   "stop inlining after the given number of roots" },
334         { "InlineMaxSize",                OPT_InlineMaxSize,                OPT_TYPE_VALUE,   "maximum size for inlined result" },
335         { "InlineMinSize",                OPT_InlineMinSize,                OPT_TYPE_VALUE,   "minimum size for inlined result" },
336 #endif
337 #endif
338         { "PrintConfig",                  OPT_PrintConfig,                  OPT_TYPE_BOOLEAN, "print VM configuration" },
339         { "PrintWarnings",                OPT_PrintWarnings,                OPT_TYPE_BOOLEAN, "print warnings about suspicious behavior"},
340         { "ProfileGCMemoryUsage",         OPT_ProfileGCMemoryUsage,         OPT_TYPE_VALUE,   "profiles GC memory usage in the given interval, <value> is in seconds (default: 5)" },
341         { "ProfileMemoryUsage",           OPT_ProfileMemoryUsage,           OPT_TYPE_VALUE,   "TODO" },
342         { "ProfileMemoryUsageGNUPlot",    OPT_ProfileMemoryUsageGNUPlot,    OPT_TYPE_VALUE,   "TODO" },
343         { "RegallocSpillAll",             OPT_RegallocSpillAll,             OPT_TYPE_BOOLEAN, "spill all variables to the stack" },
344 #if defined(ENABLE_REPLACEMENT)
345         { "TestReplacement",              OPT_TestReplacement,              OPT_TYPE_BOOLEAN, "activate all replacement points during code generation" },
346 #endif
347         { "TraceBuiltinCalls",            OPT_TraceBuiltinCalls,            OPT_TYPE_BOOLEAN, "trace calls to VM builtin functions" },
348         { "TraceCompilerCalls",           OPT_TraceCompilerCalls,           OPT_TYPE_BOOLEAN, "trace JIT compiler calls" },
349         { "TraceExceptions",              OPT_TraceExceptions,              OPT_TYPE_BOOLEAN, "trace Exception throwing" },
350         { "TraceHPI",                     OPT_TraceHPI,                     OPT_TYPE_BOOLEAN, "Trace Host Porting Interface (HPI)" },
351 #if defined(ENABLE_INLINING) && !defined(NDEBUG)
352         { "TraceInlining",                OPT_TraceInlining,                OPT_TYPE_VALUE,   "trace method inlining with the given verbosity level (default: 1)" },
353 #endif
354 #if !defined(ENABLE_VMLOG)
355         { "TraceJavaCalls",               OPT_TraceJavaCalls,               OPT_TYPE_BOOLEAN, "trace Java method calls" },
356 #endif
357         { "TraceJMMCalls",                OPT_TraceJMMCalls,                OPT_TYPE_BOOLEAN, "trace JMM method calls" },
358         { "TraceJNICalls",                OPT_TraceJNICalls,                OPT_TYPE_BOOLEAN, "trace JNI method calls" },
359         { "TraceJVMCalls",                OPT_TraceJVMCalls,                OPT_TYPE_BOOLEAN, "trace JVM method calls but omit very frequent ones" },
360         { "TraceJVMCallsVerbose",         OPT_TraceJVMCallsVerbose,         OPT_TYPE_BOOLEAN, "trace all JVM method calls" },
361 #if defined(ENABLE_JVMTI)
362         { "TraceJVMTICalls",              OPT_TraceJVMTICalls,              OPT_TYPE_BOOLEAN, "trace JVMTI method calls" },
363 #endif
364         { "TraceLinkClass",               OPT_TraceLinkClass,               OPT_TYPE_BOOLEAN, "trace class linking" },
365 #if defined(ENABLE_REPLACEMENT)
366         { "TraceReplacement",             OPT_TraceReplacement,             OPT_TYPE_VALUE,   "trace on-stack replacement with the given verbosity level (default: 1)" },
367 #endif
368         { "TraceSubsystemInitialization", OPT_TraceSubsystemInitialization, OPT_TYPE_BOOLEAN, "trace initialization of subsystems" },
369         { "TraceTraps",                   OPT_TraceTraps,                   OPT_TYPE_BOOLEAN, "trace traps generated by JIT code" },
370 #if defined(ENABLE_VMLOG)
371         { "Vmlog",                        OPT_Vmlog,                        OPT_TYPE_VALUE,   "prefix for vmlog trace files (enables vmlog)" },
372         { "VmlogStrings",                 OPT_VmlogStrings,                 OPT_TYPE_VALUE,   "prefix of vmlog string file to load" },
373         { "VmlogIgnore",                  OPT_VmlogIgnore,                  OPT_TYPE_VALUE,   "prefix of vmlog ignore file to load" },
374 #endif
375
376         /* end marker */
377
378         { NULL,                           -1,                               -1,               NULL }
379 };
380
381
382 /* options_get *****************************************************************
383
384    DOCUMENT ME!!!
385
386 *******************************************************************************/
387
388 int options_get(opt_struct *opts, JavaVMInitArgs *vm_args)
389 {
390         char *option;
391         int   i;
392
393         if (opt_index >= vm_args->nOptions)
394                 return OPT_DONE;
395
396         /* get the current option */
397
398         option = vm_args->options[opt_index].optionString;
399
400         if ((option == NULL) || (option[0] != '-'))
401                 return OPT_DONE;
402
403         for (i = 0; opts[i].name; i++) {
404                 if (!opts[i].arg) {
405                         /* boolean option found */
406
407                         if (strcmp(option + 1, opts[i].name) == 0) {
408                                 opt_index++;
409                                 return opts[i].value;
410                         }
411
412                 } else {
413                         /* parameter option found */
414
415                         /* with a space between */
416
417                         if (strcmp(option + 1, opts[i].name) == 0) {
418                                 opt_index++;
419
420                                 if (opt_index < vm_args->nOptions) {
421                                         opt_arg = os_strdup(vm_args->options[opt_index].optionString);
422                                         opt_index++;
423                                         return opts[i].value;
424                                 }
425
426                                 return OPT_ERROR;
427
428                         } else {
429                                 /* parameter and option have no space between */
430
431                                 /* FIXME: this assumption is plain wrong, hits you if there is a
432                                  * parameter with no argument starting with same letter as param with argument
433                                  * but named after that one, ouch! */
434
435                                 size_t l = os_strlen(opts[i].name);
436
437                                 if (os_strlen(option + 1) > l) {
438                                         if (memcmp(option + 1, opts[i].name, l) == 0) {
439                                                 opt_index++;
440                                                 opt_arg = os_strdup(option + 1 + l);
441                                                 return opts[i].value;
442                                         }
443                                 }
444                         }
445                 }
446         }
447
448         return OPT_ERROR;
449 }
450
451
452 /* options_xxusage *************************************************************
453
454    Print usage message for debugging options.
455
456 *******************************************************************************/
457
458 static void options_xxusage(void)
459 {
460         option_t   *opt;
461         int         length;
462         int         i;
463         const char *c;
464
465         /* Prevent compiler warning. */
466
467         length = 0;
468
469         for (opt = options_XX; opt->name != NULL; opt++) {
470                 printf("    -XX:");
471
472                 switch (opt->type) {
473                 case OPT_TYPE_BOOLEAN:
474                         printf("+%s", opt->name);
475                         length = os_strlen("    -XX:+") + os_strlen(opt->name);
476                         break;
477
478                 case OPT_TYPE_VALUE:
479                         printf("%s=<value>", opt->name);
480                         length = os_strlen("    -XX:") + os_strlen(opt->name) +
481                                 os_strlen("=<value>");
482                         break;
483
484                 default:
485                         vm_abort("options_xxusage: unkown option type %d", opt->type);
486                 }
487
488                 /* Check if the help fits into one 80-column line.
489                    Documentation starts at column 29. */
490
491                 if (length < (29 - 1)) {
492                         /* Print missing spaces up to column 29. */
493
494                         for (i = length; i < 29; i++)
495                                 printf(" ");
496                 }
497                 else {
498                         printf("\n");
499                         printf("                             "); /* 29 spaces */
500                 }
501
502                 /* Check documentation length. */
503
504                 length = os_strlen(opt->doc);
505
506                 if (length < (80 - 29)) {
507                         printf("%s", opt->doc);
508                 }
509                 else {
510                         for (c = opt->doc, i = 29; *c != 0; c++, i++) {
511                                 /* If we are at the end of the line, break it. */
512
513                                 if (i == 80) {
514                                         printf("\n");
515                                         printf("                             "); /* 29 spaces */
516                                         i = 29;
517                                 }
518
519                                 printf("%c", *c);
520                         }
521                 }
522
523                 printf("\n");
524         }
525
526         /* exit with error code */
527
528         exit(1);
529 }
530
531
532 /* options_xx ******************************************************************
533
534    Handle -XX: options.
535
536 *******************************************************************************/
537
538 void options_xx(JavaVMInitArgs *vm_args)
539 {
540         const char *name;
541         const char *start;
542         char       *end;
543         int         length;
544         int         enable;
545         char       *value;
546         option_t   *opt;
547         char       *filename;
548         FILE       *file;
549         int         i;
550
551         /* Iterate over all passed options. */
552
553         for (i = 0; i < vm_args->nOptions; i++) {
554                 /* Get the current option. */
555
556                 name = vm_args->options[i].optionString;
557
558                 /* Check for help (-XX). */
559
560                 if (strcmp(name, "-XX") == 0)
561                         options_xxusage();
562
563                 /* Check if the option start with -XX. */
564
565                 start = strstr(name, "-XX:");
566
567                 if ((start == NULL) || (start != name))
568                         continue;
569
570                 /* Check if the option is a boolean option. */
571
572                 if (name[4] == '+') {
573                         start  = name + 4 + 1;
574                         enable = 1;
575                 }
576                 else if (name[4] == '-') {
577                         start  = name + 4 + 1;
578                         enable = 0;
579                 }
580                 else {
581                         start  = name + 4;
582                         enable = -1;
583                 }
584
585                 /* Search for a '=' in the option name and get the option name
586                    length and the value of the option. */
587
588                 end = strchr(start, '=');
589
590                 if (end == NULL) {
591                         length = os_strlen(start);
592                         value  = NULL;
593                 }
594                 else {
595                         length = end - start;
596                         value  = end + 1;
597                 }
598
599                 /* Search the option in the option array. */
600
601                 for (opt = options_XX; opt->name != NULL; opt++) {
602                         if (strncmp(opt->name, start, length) == 0) {
603                                 /* Check if the options passed fits to the type. */
604
605                                 switch (opt->type) {
606                                 case OPT_TYPE_BOOLEAN:
607                                         if ((enable == -1) || (value != NULL))
608                                                 options_xxusage();
609                                         break;
610                                 case OPT_TYPE_VALUE:
611                                         if ((enable != -1) || (value == NULL))
612                                                 options_xxusage();
613                                         break;
614                                 default:
615                                         vm_abort("options_xx: unknown option type %d for option %s",
616                                                          opt->type, opt->name);
617                                 }
618
619                                 break;
620                         }
621                 }
622
623                 /* Process the option. */
624
625                 switch (opt->value) {
626
627                 /* Options which must always be available (production options
628                    in HotSpot). */
629
630                 case OPT_MaxDirectMemorySize:
631                         opt_MaxDirectMemorySize = os_atoi(value);
632                         break;
633
634                 case OPT_MaxPermSize:
635                         /* Currently ignored. */
636                         break;
637
638                 case OPT_PermSize:
639                         /* Currently ignored. */
640                         break;
641
642                 case OPT_ThreadStackSize:
643                         /* currently ignored */
644                         break;
645
646                 /* Debugging options which can be turned off. */
647
648                 case OPT_AlwaysEmitLongBranches:
649                         opt_AlwaysEmitLongBranches = enable;
650                         break;
651
652                 case OPT_AlwaysMmapFirstPage:
653                         opt_AlwaysMmapFirstPage = enable;
654                         break;
655
656                 case OPT_CompileAll:
657                         opt_CompileAll = enable;
658                         opt_run = false;
659                         makeinitializations = false;
660                         break;
661
662                 case OPT_CompileMethod:
663                         opt_CompileMethod = value;
664                         opt_run = false;
665                         makeinitializations = false;
666                         break;
667
668                 case OPT_CompileSignature:
669                         opt_CompileSignature = value;
670                         break;
671
672                 case OPT_DebugExceptions:
673                         opt_DebugExceptions = enable;
674                         break;
675
676                 case OPT_DebugFinalizer:
677                         opt_DebugFinalizer = enable;
678                         break;
679
680                 case OPT_DebugLocalReferences:
681                         opt_DebugLocalReferences = enable;
682                         break;
683
684                 case OPT_DebugLocks:
685                         opt_DebugLocks = enable;
686                         break;
687
688                 case OPT_DebugPackage:
689                         opt_DebugPackage = enable;
690                         break;
691
692                 case OPT_DebugPatcher:
693                         opt_DebugPatcher = enable;
694                         break;
695
696                 case OPT_DebugProperties:
697                         opt_DebugProperties = enable;
698                         break;
699
700                 case OPT_DebugStackFrameInfo:
701                         opt_DebugStackFrameInfo = enable;
702                         break;
703
704                 case OPT_DebugStackTrace:
705                         opt_DebugStackTrace = enable;
706                         break;
707
708                 case OPT_DebugThreads:
709                         opt_DebugThreads = enable;
710                         break;
711
712 #if defined(ENABLE_DISASSEMBLER)
713                 case OPT_DisassembleStubs:
714                         opt_DisassembleStubs = enable;
715                         break;
716 #endif
717
718 #if defined(ENABLE_OPAGENT)
719                 case OPT_EnableOpagent:
720                         opt_EnableOpagent = enable;
721                         break;
722 #endif
723
724 #if defined(ENABLE_GC_CACAO)
725                 case OPT_GCDebugRootSet:
726                         opt_GCDebugRootSet = enable;
727                         break;
728
729                 case OPT_GCStress:
730                         opt_GCStress = enable;
731                         break;
732 #endif
733
734 #if defined(ENABLE_INLINING)
735                 case OPT_Inline:
736                         opt_Inline = enable;
737                         break;
738 #if defined(ENABLE_INLINING_DEBUG) || !defined(NDEBUG)
739                 case OPT_InlineAll:
740                         opt_InlineAll = enable;
741                         break;
742
743                 case OPT_InlineCount:
744                         if (value != NULL)
745                                 opt_InlineCount = os_atoi(value);
746                         break;
747
748                 case OPT_InlineMaxSize:
749                         if (value != NULL)
750                                 opt_InlineMaxSize = os_atoi(value);
751                         break;
752
753                 case OPT_InlineMinSize:
754                         if (value != NULL)
755                                 opt_InlineMinSize = os_atoi(value);
756                         break;
757 #endif
758 #endif
759
760                 case OPT_PrintConfig:
761                         opt_PrintConfig = enable;
762                         break;
763
764                 case OPT_PrintWarnings:
765                         opt_PrintWarnings = enable;
766                         break;
767
768                 case OPT_ProfileGCMemoryUsage:
769                         if (value == NULL)
770                                 opt_ProfileGCMemoryUsage = 5;
771                         else
772                                 opt_ProfileGCMemoryUsage = os_atoi(value);
773                         break;
774
775                 case OPT_ProfileMemoryUsage:
776                         if (value == NULL)
777                                 opt_ProfileMemoryUsage = 5;
778                         else
779                                 opt_ProfileMemoryUsage = os_atoi(value);
780
781 # if defined(ENABLE_STATISTICS)
782                         /* we also need statistics */
783
784                         opt_stat = true;
785 # endif
786                         break;
787
788                 case OPT_ProfileMemoryUsageGNUPlot:
789                         if (value == NULL)
790                                 filename = "profile.dat";
791                         else
792                                 filename = value;
793
794                         file = fopen(filename, "w");
795
796                         if (file == NULL)
797                                 /* FIXME Use below method instead! */
798                                 //os::abort_errno("options_xx: fopen failed");
799                                 vm_abort("options_xx: fopen failed");
800
801                         opt_ProfileMemoryUsageGNUPlot = file;
802                         break;
803
804                 case OPT_RegallocSpillAll:
805                         opt_RegallocSpillAll = enable;
806                         break;
807
808 #if defined(ENABLE_REPLACEMENT)
809                 case OPT_TestReplacement:
810                         opt_TestReplacement = enable;
811                         break;
812 #endif
813
814                 case OPT_TraceBuiltinCalls:
815                         opt_TraceBuiltinCalls = enable;
816                         break;
817
818                 case OPT_TraceCompilerCalls:
819                         opt_TraceCompilerCalls = enable;
820                         break;
821
822                 case OPT_TraceExceptions:
823                         opt_TraceExceptions = enable;
824                         break;
825
826                 case OPT_TraceHPI:
827                         opt_TraceHPI = enable;
828                         break;
829
830 #if defined(ENABLE_INLINING) && !defined(NDEBUG)
831                 case OPT_TraceInlining:
832                         if (value == NULL)
833                                 opt_TraceInlining = 1;
834                         else
835                                 opt_TraceInlining = os_atoi(value);
836                         break;
837 #endif
838
839                 case OPT_TraceJavaCalls:
840                         opt_verbosecall = enable;
841                         opt_TraceJavaCalls = enable;
842                         break;
843
844                 case OPT_TraceJMMCalls:
845                         opt_TraceJMMCalls = enable;
846                         break;
847
848                 case OPT_TraceJNICalls:
849                         opt_TraceJNICalls = enable;
850                         break;
851
852                 case OPT_TraceJVMCalls:
853                         opt_TraceJVMCalls = enable;
854                         break;
855
856                 case OPT_TraceJVMCallsVerbose:
857                         opt_TraceJVMCallsVerbose = enable;
858                         break;
859
860 #if defined(ENABLE_JVMTI)
861                 case OPT_TraceJVMTICalls:
862                         opt_TraceJVMTICalls = enable;
863                         break;
864 #endif
865
866                 case OPT_TraceLinkClass:
867                         opt_TraceLinkClass = enable;
868                         break;
869
870 #if defined(ENABLE_REPLACEMENT)
871                 case OPT_TraceReplacement:
872                         if (value == NULL)
873                                 opt_TraceReplacement = 1;
874                         else
875                                 opt_TraceReplacement = os_atoi(value);
876                         break;
877 #endif
878
879                 case OPT_TraceSubsystemInitialization:
880                         opt_TraceSubsystemInitialization = enable;
881                         break;
882
883                 case OPT_TraceTraps:
884                         opt_TraceTraps = enable;
885                         break;
886
887 #if defined(ENABLE_VMLOG)
888                 case OPT_Vmlog:
889                         if (value == NULL)
890                                 vmlog_cacao_set_prefix("vmlog");
891                         else
892                                 vmlog_cacao_set_prefix(value);
893                         opt_verbosecall = 1;
894                         opt_TraceJavaCalls = 1;
895                         break;
896
897                 case OPT_VmlogStrings:
898                         if (value != NULL)
899                                 vmlog_cacao_set_stringprefix(value);
900                         break;
901
902                 case OPT_VmlogIgnore:
903                         if (value != NULL)
904                                 vmlog_cacao_set_ignoreprefix(value);
905                         break;
906 #endif
907
908                 default:
909                         fprintf(stderr, "Unknown -XX option: %s\n", name);
910                         break;
911                 }
912         }
913 }
914
915
916 /*
917  * These are local overrides for various environment variables in Emacs.
918  * Please do not remove this and leave it at the end of the file, where
919  * Emacs will automagically detect them.
920  * ---------------------------------------------------------------------
921  * Local variables:
922  * mode: c
923  * indent-tabs-mode: t
924  * c-basic-offset: 4
925  * tab-width: 4
926  * End:
927  */