* Removed all Id tags.
[cacao.git] / src / vmcore / options.c
index 1bc4a9b9190b6a580ae7fdad614b3831aa9dafac..8fc1216d387bc6443c65e0d09c8a66fcbd6be283 100644 (file)
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
    02110-1301, USA.
 
-   $Id: options.c 7450 2007-03-04 19:13:29Z edwin $
-
 */
 
 
 #include "config.h"
 
-#include <string.h>
-#include <limits.h>
+#include <errno.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#if defined(HAVE_STRING_H)
+# include <string.h>
+#endif
 
-#include "vm/types.h"
+#include <limits.h>
 
 #include "mm/memory.h"
+
 #include "native/jni.h"
+
+#include "vm/vm.h"
+
 #include "vmcore/options.h"
 
 
@@ -74,8 +82,7 @@ bool opt_verboseclass     = false;
 bool opt_verbosegc        = false;
 bool opt_verbosejni       = false;
 bool opt_verbosecall      = false;      /* trace all method invocation        */
-bool opt_verboseexception = false;
-bool opt_verbosememory    = false;
+bool opt_verbosethreads   = false;
 
 bool showmethods = false;
 bool showconstantpool = false;
@@ -95,7 +102,6 @@ bool opt_showexceptionstubs = false;
 bool opt_shownativestub     = false;
 
 bool checkbounds = true;       /* check array bounds                         */
-bool checknull = true;         /* check null pointers                        */
 bool opt_noieee = false;       /* don't implement ieee compliant floats      */
 bool checksync = true;         /* do synchronization                         */
 #if defined(ENABLE_LOOP)
@@ -112,7 +118,6 @@ bool opt_getcompilingtime = false; /* compute compile time                   */
 #if defined(ENABLE_VERIFIER)
 bool opt_verify  = true;       /* true if classfiles should be verified      */
 #endif
-bool opt_eager   = false;
 
 #if defined(ENABLE_PROFILING)
 bool opt_prof    = false;
@@ -125,7 +130,6 @@ bool opt_prof_bb = false;
 #if defined(ENABLE_INLINING)
 bool opt_inlining = false;
 #if defined(ENABLE_INLINING_DEBUG) || !defined(NDEBUG)
-s4 opt_replace_verbose = 0;
 s4 opt_inline_debug_min_size = 0;
 s4 opt_inline_debug_max_size = INT_MAX;
 s4 opt_inline_debug_end_counter = INT_MAX;
@@ -160,6 +164,81 @@ s4   opt_static_supers = 0x7fffffff;
 bool vm_debug = false;          /* XXX this should be called `opt_trace'      */
 #endif
 
+#if defined(ENABLE_DEBUG_FILTER)
+const char *opt_filter_verbosecall_include = 0;
+const char *opt_filter_verbosecall_exclude = 0;
+const char *opt_filter_show_method = 0;
+#endif
+
+
+/* -XX options ****************************************************************/
+
+/* NOTE: For better readability keep these alpha-sorted. */
+
+int32_t  opt_DebugStackFrameInfo       = 0;
+int32_t  opt_DebugStackTrace           = 0;
+int32_t  opt_MaxPermSize               = 0;
+int32_t  opt_PermSize                  = 0;
+int      opt_PrintConfig               = 0;
+int32_t  opt_ProfileGCMemoryUsage      = 0;
+int32_t  opt_ProfileMemoryUsage        = 0;
+FILE    *opt_ProfileMemoryUsageGNUPlot = NULL;
+int32_t  opt_ThreadStackSize           = 0;
+int32_t  opt_TraceExceptions           = 0;
+int32_t  opt_TraceJavaCalls            = 0;
+int32_t  opt_TraceJNICalls             = 0;
+int32_t  opt_TraceJVMCalls             = 0;
+#if defined(ENABLE_REPLACEMENT)
+int32_t  opt_TraceReplacement          = 0;
+#endif
+
+
+enum {
+       OPT_TYPE_BOOLEAN,
+       OPT_TYPE_VALUE
+};
+
+enum {
+       OPT_DebugStackFrameInfo,
+       OPT_DebugStackTrace,
+       OPT_MaxPermSize,
+       OPT_PermSize,
+       OPT_PrintConfig,
+       OPT_ProfileGCMemoryUsage,
+       OPT_ProfileMemoryUsage,
+       OPT_ProfileMemoryUsageGNUPlot,
+       OPT_ThreadStackSize,
+       OPT_TraceExceptions,
+       OPT_TraceJavaCalls,
+       OPT_TraceJNICalls,
+       OPT_TraceJVMCalls,
+       OPT_TraceReplacement
+};
+
+
+option_t options_XX[] = {
+       { "DebugStackFrameInfo",       OPT_DebugStackFrameInfo,       OPT_TYPE_BOOLEAN, "TODO" },
+       { "DebugStackTrace",           OPT_DebugStackTrace,           OPT_TYPE_BOOLEAN, "TODO" },
+       { "MaxPermSize",               OPT_MaxPermSize,               OPT_TYPE_VALUE,   "not implemented" },
+       { "PermSize",                  OPT_PermSize,                  OPT_TYPE_VALUE,   "not implemented" },
+       { "PrintConfig",               OPT_PrintConfig,               OPT_TYPE_BOOLEAN, "print VM configuration" },
+       { "ProfileGCMemoryUsage",      OPT_ProfileGCMemoryUsage,      OPT_TYPE_VALUE,   "profiles GC memory usage in the given interval, <value> is in seconds (default: 5)" },
+       { "ProfileMemoryUsage",        OPT_ProfileMemoryUsage,        OPT_TYPE_VALUE,   "TODO" },
+       { "ProfileMemoryUsageGNUPlot", OPT_ProfileMemoryUsageGNUPlot, OPT_TYPE_VALUE,   "TODO" },
+       { "ThreadStackSize",           OPT_ThreadStackSize,           OPT_TYPE_VALUE,   "TODO" },
+       { "TraceExceptions",           OPT_TraceExceptions,           OPT_TYPE_BOOLEAN, "TODO" },
+       { "TraceJavaCalls",            OPT_TraceJavaCalls,            OPT_TYPE_BOOLEAN, "trace Java method calls" },
+       { "TraceJNICalls",             OPT_TraceJNICalls,             OPT_TYPE_BOOLEAN, "trace JNI method calls" },
+       { "TraceJVMCalls",             OPT_TraceJVMCalls,             OPT_TYPE_BOOLEAN, "TODO" },
+#if defined(ENABLE_REPLACEMENT)
+       { "TraceReplacement",          OPT_TraceReplacement,          OPT_TYPE_VALUE,   "trace on-stack replacement with the given verbosity level (default: 1)" },
+#endif
+
+       /* end marker */
+
+       { NULL,                        -1,                            -1, NULL }
+};
+
 
 /* options_get *****************************************************************
 
@@ -200,7 +279,13 @@ s4 options_get(opt_struct *opts, JavaVMInitArgs *vm_args)
                                opt_index++;
 
                                if (opt_index < vm_args->nOptions) {
+
+#if defined(HAVE_STRDUP)
                                        opt_arg = strdup(vm_args->options[opt_index].optionString);
+#else
+# error !HAVE_STRDUP
+#endif
+
                                        opt_index++;
                                        return opts[i].value;
                                }
@@ -219,7 +304,13 @@ s4 options_get(opt_struct *opts, JavaVMInitArgs *vm_args)
                                if (strlen(option + 1) > l) {
                                        if (memcmp(option + 1, opts[i].name, l) == 0) {
                                                opt_index++;
+
+#if defined(HAVE_STRDUP)
                                                opt_arg = strdup(option + 1 + l);
+#else
+# error !HAVE_STRDUP
+#endif
+
                                                return opts[i].value;
                                        }
                                }
@@ -231,6 +322,246 @@ s4 options_get(opt_struct *opts, JavaVMInitArgs *vm_args)
 }
 
 
+/* options_xxusage *************************************************************
+
+   Print usage message for debugging options.
+
+*******************************************************************************/
+
+static void options_xxusage(void)
+{
+       option_t *opt;
+       int       length;
+       int       i;
+       char     *c;
+
+       for (opt = options_XX; opt->name != NULL; opt++) {
+               printf("    -XX:");
+
+               switch (opt->type) {
+               case OPT_TYPE_BOOLEAN:
+                       printf("+%s", opt->name);
+                       length = strlen("    -XX:+") + strlen(opt->name);
+                       break;
+               case OPT_TYPE_VALUE:
+                       printf("%s=<value>", opt->name);
+                       length = strlen("    -XX:") + strlen(opt->name) + strlen("=<value>");
+                       break;
+               }
+
+               /* Check if the help fits into one 80-column line.
+                  Documentation starts at column 29. */
+
+               if (length < (29 - 1)) {
+                       /* Print missing spaces up to column 29. */
+
+                       for (i = length; i < 29; i++)
+                               printf(" ");
+               }
+               else {
+                       printf("\n");
+                       printf("                             "); /* 29 spaces */
+               }
+
+               /* Check documentation length. */
+
+               length = strlen(opt->doc);
+
+               if (length < (80 - 29)) {
+                       printf("%s", opt->doc);
+               }
+               else {
+                       for (c = opt->doc, i = 29; *c != 0; c++, i++) {
+                               /* If we are at the end of the line, break it. */
+
+                               if (i == 80) {
+                                       printf("\n");
+                                       printf("                             "); /* 29 spaces */
+                                       i = 29;
+                               }
+
+                               printf("%c", *c);
+                       }
+               }
+
+               printf("\n");
+       }
+
+       /* exit with error code */
+
+       exit(1);
+}
+
+
+/* options_xx ******************************************************************
+
+   Handle -XX: options.
+
+*******************************************************************************/
+
+void options_xx(const char *name)
+{
+       const char *start;
+       char       *end;
+       int         length;
+       int         enable;
+       char       *value;
+       option_t   *opt;
+       char       *filename;
+       FILE       *file;
+
+       /* Check for help (-XX), in this case name is NULL. */
+
+       if (name == NULL)
+               options_xxusage();
+
+       /* Check if the option is a boolean option. */
+
+       if (name[0] == '+') {
+               start  = name + 1;
+               enable = 1;
+       }
+       else if (name[0] == '-') {
+               start  = name + 1;
+               enable = 0;
+       }
+       else {
+               start  = name;
+               enable = -1;
+       }
+
+       /* Search for a '=' in the option name and get the option name
+          length and the value of the option. */
+
+       end = strchr(start, '=');
+
+       if (end == NULL) {
+               length = strlen(start);
+               value  = NULL;
+       }
+       else {
+               length = end - start;
+               value  = end + 1;
+       }
+
+       /* search the option in the option array */
+
+       for (opt = options_XX; opt->name != NULL; opt++) {
+               if (strncmp(opt->name, start, length) == 0) {
+                       /* Check if the options passed fits to the type. */
+
+                       switch (opt->type) {
+                       case OPT_TYPE_BOOLEAN:
+                               if ((enable == -1) || (value != NULL))
+                                       options_xxusage();
+                               break;
+                       case OPT_TYPE_VALUE:
+                               if ((enable != -1) || (value == NULL))
+                                       options_xxusage();
+                               break;
+                       default:
+                               vm_abort("options_xx: unknown option type %d for option %s",
+                                                opt->type, opt->name);
+                       }
+
+                       break;
+               }
+       }
+
+       /* process the option */
+
+       switch (opt->value) {
+       case OPT_DebugStackFrameInfo:
+               opt_DebugStackFrameInfo = enable;
+               break;
+
+       case OPT_DebugStackTrace:
+               opt_DebugStackTrace = enable;
+               break;
+
+       case OPT_MaxPermSize:
+               /* currently ignored */
+               break;
+
+       case OPT_PermSize:
+               /* currently ignored */
+               break;
+
+       case OPT_PrintConfig:
+               vm_printconfig();
+               break;
+
+       case OPT_ProfileGCMemoryUsage:
+               if (value == NULL)
+                       opt_ProfileGCMemoryUsage = 5;
+               else
+                       opt_ProfileGCMemoryUsage = atoi(value);
+               break;
+
+       case OPT_ProfileMemoryUsage:
+               if (value == NULL)
+                       opt_ProfileMemoryUsage = 5;
+               else
+                       opt_ProfileMemoryUsage = atoi(value);
+
+# if defined(ENABLE_STATISTICS)
+               /* we also need statistics */
+
+               opt_stat = true;
+# endif
+               break;
+
+       case OPT_ProfileMemoryUsageGNUPlot:
+               if (value == NULL)
+                       filename = "profile.dat";
+               else
+                       filename = value;
+
+               file = fopen(filename, "w");
+
+               if (file == NULL)
+                       vm_abort("options_xx: fopen failed: %s", strerror(errno));
+
+               opt_ProfileMemoryUsageGNUPlot = file;
+               break;
+
+       case OPT_ThreadStackSize:
+               /* currently ignored */
+               break;
+
+       case OPT_TraceExceptions:
+               opt_TraceExceptions = enable;
+               break;
+
+       case OPT_TraceJavaCalls:
+               opt_verbosecall = enable;
+               opt_TraceJavaCalls = enable;
+               break;
+
+       case OPT_TraceJNICalls:
+               opt_TraceJNICalls = enable;
+               break;
+
+       case OPT_TraceJVMCalls:
+               opt_TraceJVMCalls = enable;
+               break;
+
+#if defined(ENABLE_REPLACEMENT)
+       case OPT_TraceReplacement:
+               if (value == NULL)
+                       opt_TraceReplacement = 1;
+               else
+                       opt_TraceReplacement = atoi(value);
+               break;
+#endif
+
+       default:
+               printf("Unknown -XX option: %s\n", name);
+               break;
+       }
+}
+
+
 /*
  * These are local overrides for various environment variables in Emacs.
  * Please do not remove this and leave it at the end of the file, where