This is the mail archive of the
java@gcc.gnu.org
mailing list for the Java project.
Re: -X options?
>>>>> "Tom" == Tom Tromey <tromey@redhat.com> writes:
>>>>> "Casey" == Casey Marshall <csm@gnu.org> writes:
Casey> At least four times now I've had to look up the property name
Casey> 'gnu.gcj.precompiled.db.path', which is really verbose.
Casey> Why aren't these properties (also, say, the gcj-jit properties)
Casey> handled as '-X' options? That way, it would be easier to set
Casey> them, and would allow the supported options to be listed with
Casey> 'gij -X'.
Tom> I think we just didn't think of it.
Tom> It sounds like a good idea to me.
I had written a little patch to do this (only in gij, though) but I
also saw open patches that change the argument parsing, and realized
that -X parsing probably shouldn't be in gij.cc.
$ gij -X
-Xdb:PATH set path to precompiled gcjdb file
-Xjit:PATH set path to 'gcj' compiler for JIT compliation
-Xjitcache:PATH set path for storing cached JIT compilations
-Xjitopts:OPTS specify options to pass to JIT compiler
-Xms:SIZE set initial heap size
-Xmx:SIZE set maximum heap size
The -X options are non-standard and subject to change without notice.
--
Casey Marshall || csm@gnu.org
Index: libjava/gij.cc
===================================================================
RCS file: /cvsroot/gcc/gcc/libjava/gij.cc,v
retrieving revision 1.25
diff -u -b -B -r1.25 gij.cc
--- libjava/gij.cc 18 Feb 2005 20:52:14 -0000 1.25
+++ libjava/gij.cc 2 Mar 2005 22:14:22 -0000
@@ -21,6 +21,13 @@
#include <java/lang/System.h>
#include <java/util/Properties.h>
+#define XOPTION_DB "db"
+#define XOPTION_JIT "jit"
+#define XOPTION_JITOPTS "jitopts"
+#define XOPTION_JITCACHE "jitcache"
+#define XOPTION_MAXMEM "mx"
+#define XOPTION_INITMEM "ms"
+
static void
help ()
{
@@ -36,6 +43,7 @@
printf (" --ms=NUMBER set initial heap size\n");
printf (" --mx=NUMBER set maximum heap size\n");
printf (" --verbose[:class] print information about class loading\n");
+ printf (" --verbose:gc enable verbose GC output\n");
printf (" --showversion print version number, then keep going\n");
printf (" --version print version number, then exit\n");
printf ("\nOptions can be specified with `-' or `--'.\n");
@@ -44,6 +52,18 @@
}
static void
+xhelp ()
+{
+ printf (" -Xdb:PATH set path to precompiled gcjdb file\n");
+ printf (" -Xjit:PATH set path to 'gcj' compiler for JIT compliation\n");
+ printf (" -Xjitcache:PATH set path for storing cached JIT compilations\n");
+ printf (" -Xjitopts:OPTS specify options to pass to JIT compiler\n");
+ printf (" -Xms:SIZE set initial heap size\n");
+ printf (" -Xmx:SIZE set maximum heap size\n");
+ printf ("\nThe -X options are non-standard and subject to change without notice.\n");
+}
+
+static void
version ()
{
printf ("gij (GNU libgcj) version %s\n\n", __VERSION__);
@@ -52,6 +72,102 @@
printf ("warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n");
}
+
+static char db_path[1024];
+static char jit_path[1024];
+static char jit_opts[1024];
+static char jit_cache[1024];
+
+/**
+ * Check if INCOMING is well-formed VM option XOPT that takes an
+ * argument.
+ *
+ * Only returns on success; prints an error and exits on failure.
+ *
+ * @param xopt The option being checked.
+ * @param incoming The option specified on the command line.
+ */
+static void
+checkarg (const char *xopt, const char *incoming)
+{
+ int i = strlen (xopt);
+ if (incoming[i] == '\0' || incoming[i+1] == '\0')
+ {
+ fprintf (stderr, "gij: VM option '%s' requires an argument\n", xopt);
+ exit (1);
+ }
+ if (incoming[i] != ':')
+ {
+ fprintf (stderr, "gij: unrecognized VM option: %s\n", incoming);
+ exit (1);
+ }
+}
+
+static char *
+parse_xoption (const char *xopt)
+{
+ /* FIXME using static, fixed-size buffers is stupid. Can I get away with
+ a malloc() here? I don't want to allocate a lot of stuff just to
+ support translating -X options to properties. */
+ if (strncmp (xopt, XOPTION_DB, strlen (XOPTION_DB)) == 0)
+ {
+ checkarg (XOPTION_DB, xopt);
+ snprintf (db_path, sizeof (db_path), "gnu.gcj.precompiled.db.path=%s",
+ xopt + strlen (XOPTION_DB) + 1);
+ return db_path;
+ }
+ else if (strncmp (xopt, XOPTION_JITOPTS, strlen (XOPTION_JITOPTS)) == 0)
+ {
+ checkarg (XOPTION_JITOPTS, xopt);
+ snprintf (jit_opts, sizeof (jit_opts), "gnu.gcj.jit.options=%s",
+ xopt + strlen (XOPTION_JITOPTS) + 1);
+ return jit_opts;
+ }
+ else if (strncmp (xopt, XOPTION_JITCACHE, strlen (XOPTION_JITCACHE)) == 0)
+ {
+ checkarg (XOPTION_JITCACHE, xopt);
+ snprintf (jit_cache, sizeof (jit_cache), "gnu.gcj.jit.cachedir=%s",
+ xopt + strlen (XOPTION_JITCACHE) + 1);
+ return jit_cache;
+ }
+ else if (strncmp (xopt, XOPTION_JIT, strlen (XOPTION_JIT)) == 0)
+ {
+ checkarg (XOPTION_JIT, xopt);
+ snprintf (jit_path, sizeof (jit_path), "gnu.gcj.jit.compiler=%s",
+ xopt + strlen (XOPTION_JIT) + 1);
+ return jit_path;
+ }
+ else if (strncmp (xopt, XOPTION_MAXMEM, strlen (XOPTION_MAXMEM)) == 0)
+ {
+ char *s = (char *) xopt + 2;
+ if (*s == ':')
+ s++;
+ if (*s == '\0')
+ {
+ fprintf (stderr, "gij: VM option 'mx' requires an argument\n");
+ exit (1);
+ }
+ _Jv_SetMaximumHeapSize (s);
+ return NULL;
+ }
+ else if (strncmp (xopt, XOPTION_INITMEM, strlen (XOPTION_INITMEM)) == 0)
+ {
+ char *s = (char *) xopt + 2;
+ if (*s == ':')
+ s++;
+ if (*s == '\0')
+ {
+ fprintf (stderr, "gij: VM option 'ms' requires an argument\n");
+ exit (1);
+ }
+ _Jv_SetInitialHeapSize (s);
+ return NULL;
+ }
+
+ fprintf (stderr, "gij: unrecognized VM option: %s\n", xopt);
+ exit (1);
+}
+
int
main (int argc, const char **argv)
{
@@ -136,14 +252,20 @@
}
else if (! strcmp (arg, "-verbose") || ! strcmp (arg, "-verbose:class"))
gcj::verbose_class_flag = true;
+ else if (! strcmp (arg, "-verbose:gc"))
+ setenv ("GC_PRINT_STATS", "1", 1);
else if (arg[1] == 'X')
{
+ char *xprop = NULL;
if (arg[2] == '\0')
{
- printf ("gij: currently no -X options are recognized\n");
+ xhelp ();
exit (0);
}
- /* Ignore other -X options. */
+
+ xprop = parse_xoption (arg + 2);
+ if (xprop != NULL)
+ argv[last_D_option++] = xprop;
}
else
{