This is the mail archive of the java-patches@sourceware.cygnus.com mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Patch: gij command-line, plus bug fix


I'm checking in the appended patch.  It actually is two separate
patches, but I'm being lazy and checking them in together.

Part 1 is a bug fix related to some stuff I checked in earlier.
Without this libgcj won't compile with --enable-interpreter.  Sigh.

Part 2 adds command-line processing to `gij'.  gij now accepts `-D',
`--help', `--version', `-ms', and `-mx'.  This part of the change also
fixes up some declarations, and extends the GC interface to allow
setting of the initial and maximum heap sizes.

If you get this change you need to get the corresponding jvgenmain
patch which I'm checking in to gcc.

1999-10-22  Tom Tromey  <tromey@cygnus.com>

	* Makefile.in: Rebuilt.
	* Makefile.am (java/lang/ClassLoader.h): New target.
	* java/lang/natClassLoader.cc (_Jv_FindClass): Removed reference
	to `redirect'.

	* include/java-props.h (_Jv_Compiler_Properties): Changed
	declaration.
	* gcj/array.h (JvRunMain, _Jv_RunMain): Don't declare.
	* include/jvm.h (_Jv_GCSetInitialHeapSize,
	_Jv_GCSetMaximumHeapSize): Declare.
	(JvRunMain, _Jv_RunMain): Declare.
	(_Jv_SetMaximumHeapSize, _Jv_SetInitialHeapSize): Declare.
	* nogc.cc (_Jv_GCSetInitialHeapSize): New function.
	(_Jv_GCSetMaximumHeapSize): Likewise.
	* boehm.cc (_Jv_GCSetInitialHeapSize): New function.
	(_Jv_GCSetMaximumHeapSize): Likewise.
	* prims.cc (parse_heap_size): New function.
	(_Jv_SetInitialHeapSize): Likewise.
	(_Jv_SetMaximumHeapSize): Likewise.
	(_Jv_Compiler_Properties): New global.
	* gij.cc (help): New function.
	(version): Likewise.
	(heap_size): Likewise.
	(heap_max_size): Likewise.
	(main): Parse arguments.  Set _Jv_Compiler_Properties.
	Include <config.h>, <java-props.h>.
	(_Jv_Compiler_Properties): Removed.

Tom

Index: Makefile.am
===================================================================
RCS file: /cvs/java/libgcj/libjava/Makefile.am,v
retrieving revision 1.35
diff -u -r1.35 Makefile.am
--- Makefile.am	1999/10/06 23:13:37	1.35
+++ Makefile.am	1999/10/22 19:23:53
@@ -203,6 +203,11 @@
 
 $(nat_headers): libgcj.zip
 
+java/lang/ClassLoader.h: java/lang/ClassLoader.class libgcj.zip
+	$(GCJH) -classpath $(top_builddir) \
+		-friend 'jclass _Jv_FindClass (_Jv_Utf8Const *name, java::lang::ClassLoader *loader);' \
+		$(basename $<)
+
 ## Our internal main program needs to be able to create a FirstThread.
 java/lang/FirstThread.h: java/lang/FirstThread.class libgcj.zip
 	$(GCJH) -classpath $(top_builddir) \
Index: boehm.cc
===================================================================
RCS file: /cvs/java/libgcj/libjava/boehm.cc,v
retrieving revision 1.7
diff -u -r1.7 boehm.cc
--- boehm.cc	1999/09/10 22:03:05	1.7
+++ boehm.cc	1999/10/22 19:24:05
@@ -393,6 +393,20 @@
 }
 
 void
+_Jv_GCSetInitialHeapSize (size_t size)
+{
+  size_t current = GC_get_heap_size ();
+  if (size > current)
+    GC_expand_hp (current - size);
+}
+
+void
+_Jv_GCSetMaximumHeapSize (size_t size)
+{
+  GC_set_max_heap_size ((GC_word) size);
+}
+
+void
 _Jv_InitGC (void)
 {
   int proc;
Index: gij.cc
===================================================================
RCS file: /cvs/java/libgcj/libjava/gij.cc,v
retrieving revision 1.4
diff -u -r1.4 gij.cc
--- gij.cc	1999/10/15 16:53:40	1.4
+++ gij.cc	1999/10/22 19:24:05
@@ -8,27 +8,120 @@
 
 /* Author: Kresten Krab Thorup <krab@gnu.org>  */
 
+#include <config.h>
+
 #include <jvm.h>
 #include <gcj/cni.h>
+#include <java-props.h>
+
 #include <stdio.h>
+#include <string.h>
 
 #include <java/lang/System.h>
 #include <java/util/Properties.h>
+
+static void
+help ()
+{
+  printf ("Usage: gij [OPTION] ... CLASS [ARGS] ...\n\n");
+  printf ("Interpret Java bytecodes\n\n");
+  printf ("  -DVAR=VAL         define property VAR with value VAL\n");
+  printf ("  --help            print this help, then exit\n");
+  printf ("  --ms=NUMBER       set initial heap size\n");
+  printf ("  --mx=NUMBER       set maximum heap size\n");
+  printf ("  --version         print version number, then exit\n");
+  printf ("\nSee http://sourceware.cygnus.com/java/ for information on reporting bugs\n");
+  exit (0);
+}
 
-// This is used to initialize the compiled-in system properties.
-const char *_Jv_Compiler_Properties[] =
+static void
+version ()
 {
-  NULL
-};
+  printf ("gij (GNU libgcj) version %s\n\n", VERSION);
+  printf ("Copyright (C) 1999 Cygnus Solutions.\n");
+  printf ("This is free software; see the source for copying conditions.  There is NO\n");
+  printf ("warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n");
+  exit (0);
+}
 
 int
 main (int argc, const char **argv)
 {
-  if (argc < 2)
+  /* We rearrange ARGV so that all the -D options appear near the
+     beginning.  */
+  int last_D_option = 0;
+
+  int i;
+  for (i = 1; i < argc; ++i)
+    {
+      const char *arg = argv[i];
+
+      /* A non-option stops processing.  */
+      if (arg[0] != '-')
+	break;
+      /* A "--" stops processing.  */
+      if (! strcmp (arg, "--"))
+	{
+	  ++i;
+	  break;
+	}
+
+      if (! strncmp (arg, "-D", 2))
+	{
+	  argv[last_D_option++] = arg + 2;
+	  continue;
+	}
+
+      /* Allow both single or double hyphen for all remaining
+	 options.  */
+      if (arg[1] == '-')
+	++arg;
+
+      if (! strcmp (arg, "-help"))
+	help ();
+      else if (! strcmp (arg, "-version"))
+	version ();
+      /* FIXME: use getopt and avoid the ugliness here.
+	 We at least need to handle the argument in a better way.  */
+      else if (! strncmp (arg, "-ms=", 4))
+	_Jv_SetInitialHeapSize (arg + 4);
+      else if (! strcmp (arg, "-ms"))
+	{
+	  if (i >= argc - 1)
+	    {
+	    no_argument:
+	      fprintf (stderr, "gij: option requires an argument -- `%s'\n",
+		       argv[i]);
+	      fprintf (stderr, "Try `gij --help' for more information.\n");
+	      exit (1);
+	    }
+	  _Jv_SetInitialHeapSize (argv[++i]);
+	}
+      else if (! strncmp (arg, "-mx=", 4))
+	_Jv_SetMaximumHeapSize (arg + 4);
+      else if (! strcmp (arg, "-mx"))
+	{
+	  if (i >= argc - 1)
+	    goto no_argument;
+	  _Jv_SetMaximumHeapSize (argv[++i]);
+	}
+      else
+	{
+	  fprintf (stderr, "gij: unrecognized option -- `%s'\n", argv[i]);
+	  fprintf (stderr, "Try `gij --help' for more information.\n");
+	  exit (1);
+	}
+    }
+
+  argv[last_D_option] = NULL;
+  _Jv_Compiler_Properties = argv;
+
+  if (argc - i < 1)
     {
-      printf ("usage: %s CLASS [ARGS]...\n", argv[0]);
+      fprintf (stderr, "Usage: gij [OPTION] ... CLASS [ARGS] ...\n");
+      fprintf (stderr, "Try `gij --help' for more information.\n");
       exit (1);
     }
 
-  _Jv_RunMain (argv[1], argc - 1, argv + 1);
+  _Jv_RunMain (argv[i], argc - i, argv + i);
 }
Index: nogc.cc
===================================================================
RCS file: /cvs/java/libgcj/libjava/nogc.cc,v
retrieving revision 1.2
diff -u -r1.2 nogc.cc
--- nogc.cc	1999/09/10 22:03:05	1.2
+++ nogc.cc	1999/10/22 19:24:05
@@ -76,6 +76,16 @@
 }
 
 void
+_Jv_GCSetInitialHeapSize (size_t size)
+{
+}
+
+void
+_Jv_GCSetMaximumHeapSize (size_t size)
+{
+}
+
+void
 _Jv_InitGC (void)
 {
 }
Index: prims.cc
===================================================================
RCS file: /cvs/java/libgcj/libjava/prims.cc,v
retrieving revision 1.11
diff -u -r1.11 prims.cc
--- prims.cc	1999/10/15 06:07:41	1.11
+++ prims.cc	1999/10/22 19:24:14
@@ -63,6 +63,9 @@
 // Largest representable size_t.
 #define SIZE_T_MAX ((size_t) (~ (size_t) 0))
 
+// Properties set at compile time.
+const char **_Jv_Compiler_Properties;
+
 #ifndef DISABLE_GETENV_PROPERTIES
 // Property key/value pairs.
 property_pair *_Jv_Environment_Properties;
@@ -811,7 +814,39 @@
   java::lang::Runtime::getRuntime ()->exit (0);
 }
 
+
+
+// Parse a string and return a heap size.
+static size_t
+parse_heap_size (const char *spec)
+{
+  char *end;
+  unsigned long val = strtoul (spec, &end, 10);
+  if (*spec == 'k' || *spec == 'K')
+    val *= 1000;
+  else if (*spec == 'm' || *spec == 'M')
+    val *= 1000000;
+  return (size_t) val;
+}
+
+// Set the initial heap size.  This might be ignored by the GC layer.
+// This must be called before _Jv_RunMain.
+void
+_Jv_SetInitialHeapSize (const char *arg)
+{
+  size_t size = parse_heap_size (arg);
+  _Jv_GCSetInitialHeapSize (size);
+}
 
+// Set the maximum heap size.  This might be ignored by the GC layer.
+// This must be called before _Jv_RunMain.
+void
+_Jv_SetMaximumHeapSize (const char *arg)
+{
+  size_t size = parse_heap_size (arg);
+  _Jv_GCSetMaximumHeapSize (size);
+}
+
 
 
 void *
@@ -885,10 +920,3 @@
 
   return dividend % divisor;
 }
-
-
-
-
-
-
-
Index: gcj/array.h
===================================================================
RCS file: /cvs/java/libgcj/libjava/gcj/array.h,v
retrieving revision 1.1
diff -u -r1.1 array.h
--- array.h	1999/09/10 22:03:06	1.1
+++ array.h	1999/10/22 19:24:14
@@ -69,8 +69,6 @@
 { return _Jv_NewObjectArray (length, cls, init); }
 
 extern "C" jstringArray JvConvertArgv(int argc, const char **argv);
-extern "C" void JvRunMain (jclass klass, int argc, const char **argv);
-void _Jv_RunMain (const char* name, int argc, const char **argv);
 
 inline jsize JvGetArrayLength (jarray array) { return array->length; }
 
Index: include/java-props.h
===================================================================
RCS file: /cvs/java/libgcj/libjava/include/java-props.h,v
retrieving revision 1.3
diff -u -r1.3 java-props.h
--- java-props.h	1999/10/15 16:53:41	1.3
+++ java-props.h	1999/10/22 19:24:18
@@ -19,8 +19,8 @@
   size_t      value_length;
 } property_pair;
 
-// The compiler generates this declaration.
-extern char *_Jv_Compiler_Properties[];
+// Set to NULL-terminated list of properties set at compile time.
+extern const char **_Jv_Compiler_Properties;
 
 // Properties taken from the user's environment.
 extern property_pair *_Jv_Environment_Properties;
Index: include/jvm.h
===================================================================
RCS file: /cvs/java/libgcj/libjava/include/jvm.h,v
retrieving revision 1.5
diff -u -r1.5 jvm.h
--- jvm.h	1999/09/10 22:03:06	1.5
+++ jvm.h	1999/10/22 19:24:18
@@ -83,8 +83,29 @@
 /* Return approximation of total free memory.  */
 long _Jv_GCFreeMemory (void);
 
+/* Set initial heap size.  If SIZE==0, ignore.  Should be run before
+   _Jv_InitGC.  Not required to have any actual effect.  */
+void _Jv_GCSetInitialHeapSize (size_t size);
+
+/* Set maximum heap size.  If SIZE==0, unbounded.  Should be run
+   before _Jv_InitGC.  Not required to have any actual effect.  */
+void _Jv_GCSetMaximumHeapSize (size_t size);
+
+/* External interface to setting the heap size.  Parses ARG (a number
+   which can optionally have "k" or "m" appended and calls
+   _Jv_GCSetInitialHeapSize.  */
+void _Jv_SetInitialHeapSize (const char *arg);
+
+/* External interface to setting the maximum heap size.  Parses ARG (a
+   number which can optionally have "k" or "m" appended and calls
+   _Jv_GCSetMaximumHeapSize.  */
+void _Jv_SetMaximumHeapSize (const char *arg);
+
 /* Allocate some unscanned bytes.  Throw exception if out of memory.  */
 void *_Jv_AllocBytesChecked (jsize size);
+
+extern "C" void JvRunMain (jclass klass, int argc, const char **argv);
+void _Jv_RunMain (const char* name, int argc, const char **argv);
 
 // This function is used to determine the hash code of an object.
 inline jint
Index: java/lang/natClassLoader.cc
===================================================================
RCS file: /cvs/java/libgcj/libjava/java/lang/natClassLoader.cc,v
retrieving revision 1.11
diff -u -r1.11 natClassLoader.cc
--- natClassLoader.cc	1999/10/18 22:57:07	1.11
+++ natClassLoader.cc	1999/10/22 19:24:27
@@ -447,20 +447,19 @@
 	}
       else 
 	{
-	  if (redirect == NULL)
+	  java::lang::ClassLoader *sys = java::lang::ClassLoader::system;
+	  if (sys == NULL)
 	    {
 	      _Jv_InitClass (&ClassLoaderClass);
-	      java::lang::ClassLoader::getSystemClassLoader ();
+	      sys = java::lang::ClassLoader::getSystemClassLoader ();
 	    }
 
-	  // Load using the bootstrap loader jmspec 5.3.1
-	  klass = redirect -> loadClass (sname, false); 
+	  // Load using the bootstrap loader jmspec 5.3.1.
+	  klass = sys->loadClass (sname, false); 
 
-	  // register that we're an initiating loader
+	  // Register that we're an initiating loader.
 	  if (klass)
-	    {
-	      _Jv_RegisterInitiatingLoader (klass, 0);
-	    }
+	    _Jv_RegisterInitiatingLoader (klass, 0);
 	}
     }
   else

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]