From b8c3c4f0146f82c900a995c8e98b83a2147115fd Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Fri, 22 Oct 1999 19:43:41 +0000 Subject: [PATCH] Makefile.in: Rebuilt. * 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 , . (_Jv_Compiler_Properties): Removed. From-SVN: r30133 --- libjava/ChangeLog | 30 ++++++++ libjava/Makefile.am | 5 ++ libjava/Makefile.in | 5 ++ libjava/boehm.cc | 14 ++++ libjava/gcj/array.h | 2 - libjava/gij.cc | 107 ++++++++++++++++++++++++++-- libjava/include/java-props.h | 4 +- libjava/include/jvm.h | 21 ++++++ libjava/java/lang/natClassLoader.cc | 15 ++-- libjava/nogc.cc | 10 +++ libjava/prims.cc | 42 +++++++++-- 11 files changed, 229 insertions(+), 26 deletions(-) diff --git a/libjava/ChangeLog b/libjava/ChangeLog index cff9145a83c..0d5c0302984 100644 --- a/libjava/ChangeLog +++ b/libjava/ChangeLog @@ -1,3 +1,33 @@ +1999-10-22 Tom Tromey + + * 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 , . + (_Jv_Compiler_Properties): Removed. + 1999-10-18 Tom Tromey * gnu/gcj/runtime/VMClassLoader.java (getVMClassLoader): New diff --git a/libjava/Makefile.am b/libjava/Makefile.am index 721cd4e0cd9..e8641980985 100644 --- a/libjava/Makefile.am +++ b/libjava/Makefile.am @@ -203,6 +203,11 @@ nat_headers = $(ordinary_java_source_files:.java=.h) \ $(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) \ diff --git a/libjava/Makefile.in b/libjava/Makefile.in index 6611a087381..402feba9dbe 100644 --- a/libjava/Makefile.in +++ b/libjava/Makefile.in @@ -1433,6 +1433,11 @@ $(javao_files): %.lo: %.java $(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 $<) + java/lang/FirstThread.h: java/lang/FirstThread.class libgcj.zip $(GCJH) -classpath $(top_builddir) \ -friend 'void JvRunMain (jclass, int, const char **);' \ diff --git a/libjava/boehm.cc b/libjava/boehm.cc index b300c37c860..fb11a112873 100644 --- a/libjava/boehm.cc +++ b/libjava/boehm.cc @@ -392,6 +392,20 @@ _Jv_GCFreeMemory (void) return sum; } +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) { diff --git a/libjava/gcj/array.h b/libjava/gcj/array.h index cd419d708f0..f3733595e76 100644 --- a/libjava/gcj/array.h +++ b/libjava/gcj/array.h @@ -69,8 +69,6 @@ inline jobjectArray JvNewObjectArray (jsize length, jclass cls, jobject init) { 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; } diff --git a/libjava/gij.cc b/libjava/gij.cc index b851b77dcd8..f07c4956a43 100644 --- a/libjava/gij.cc +++ b/libjava/gij.cc @@ -8,27 +8,120 @@ details. */ /* Author: Kresten Krab Thorup */ +#include + #include #include +#include + #include +#include #include #include -// This is used to initialize the compiled-in system properties. -const char *_Jv_Compiler_Properties[] = +static void +help () { - NULL -}; + 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); +} + +static void +version () +{ + 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) { - printf ("usage: %s CLASS [ARGS]...\n", argv[0]); + 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) + { + 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); } diff --git a/libjava/include/java-props.h b/libjava/include/java-props.h index 65130da8814..81bdd7ff4ff 100644 --- a/libjava/include/java-props.h +++ b/libjava/include/java-props.h @@ -19,8 +19,8 @@ typedef struct 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; diff --git a/libjava/include/jvm.h b/libjava/include/jvm.h index 7b0b476a2ed..d917a4f70f7 100644 --- a/libjava/include/jvm.h +++ b/libjava/include/jvm.h @@ -83,9 +83,30 @@ long _Jv_GCTotalMemory (void); /* 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 _Jv_HashCode (jobject obj) diff --git a/libjava/java/lang/natClassLoader.cc b/libjava/java/lang/natClassLoader.cc index ee5f2e78e85..2a73ba69053 100644 --- a/libjava/java/lang/natClassLoader.cc +++ b/libjava/java/lang/natClassLoader.cc @@ -447,20 +447,19 @@ jclass _Jv_FindClass (_Jv_Utf8Const *name, } 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 diff --git a/libjava/nogc.cc b/libjava/nogc.cc index 3a31092ab66..241fa19bfe7 100644 --- a/libjava/nogc.cc +++ b/libjava/nogc.cc @@ -75,6 +75,16 @@ _Jv_GCFreeMemory (void) return 0; } +void +_Jv_GCSetInitialHeapSize (size_t size) +{ +} + +void +_Jv_GCSetMaximumHeapSize (size_t size) +{ +} + void _Jv_InitGC (void) { diff --git a/libjava/prims.cc b/libjava/prims.cc index e694e136ddd..6e6c6339923 100644 --- a/libjava/prims.cc +++ b/libjava/prims.cc @@ -63,6 +63,9 @@ static java::lang::OutOfMemoryError *no_memory; // 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,6 +814,38 @@ _Jv_RunMain (const char *class_name, int argc, const char **argv) 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); +} @@ -885,10 +920,3 @@ _Jv_remJ (jlong dividend, jlong divisor) return dividend % divisor; } - - - - - - -