LCOV - code coverage report
Current view: top level - vm - options.cpp (source / functions) Hit Total Coverage
Test: coverage.info Lines: 47 187 25.1 %
Date: 2017-07-14 10:03:36 Functions: 2 3 66.7 %

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

Generated by: LCOV version 1.11