* Removed all Id tags.
[cacao.git] / src / cacaoh / cacaoh.c
index a7858493b9473b7ccf8b58e7079a579ab8d21046..105030001449ae9d7cbccf1f207972ad3eebab29 100644 (file)
@@ -1,9 +1,9 @@
 /* src/cacaoh/cacaoh.c - main for header generation (cacaoh)
 
-   Copyright (C) 1996-2005 R. Grafl, A. Krall, C. Kruegel, C. Oates,
-   R. Obermaisser, M. Platter, M. Probst, S. Ring, E. Steiner,
-   C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich, J. Wenninger,
-   Institut f. Computersprachen - TU Wien
+   Copyright (C) 1996-2005, 2006, 2007 R. Grafl, A. Krall, C. Kruegel,
+   C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
+   E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
+   J. Wenninger, Institut f. Computersprachen - TU Wien
 
    This file is part of CACAO.
 
 
    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
-   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
-   02111-1307, USA.
-
-   Contact: cacao@complang.tuwien.ac.at
-
-   Authors: Reinhard Grafl
-
-   Changes: Mark Probst
-            Philipp Tomsich
-            Christian Thalinger
-
-   $Id: cacaoh.c 4226 2006-01-18 15:41:26Z twisti $
+   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+   02110-1301, USA.
 
 */
 
 #include "vm/types.h"
 
 #include "cacaoh/headers.h"
-#include "mm/boehm.h"
+
+#include "mm/gc-common.h"
 #include "mm/memory.h"
-#include "native/include/java_lang_Throwable.h"
-
-#if defined(USE_THREADS)
-# if defined(NATIVE_THREADS)
-#  include "threads/native/threads.h"
-# else
-#  include "threads/green/threads.h"
-# endif
-#endif
 
+#include "toolbox/hashtable.h"
 #include "toolbox/logging.h"
-#include "vm/classcache.h"
+
 #include "vm/exceptions.h"
 #include "vm/global.h"
-#include "vm/hashtable.h"
-#include "vm/loader.h"
-#include "vm/options.h"
-#include "vm/statistics.h"
 #include "vm/stringlocal.h"
-#include "vm/suck.h"
-
-
-/* define heap sizes **********************************************************/
+#include "vm/vm.h"
 
-#define HEAP_MAXSIZE      2 * 1024 * 1024   /* default 2MB                    */
-#define HEAP_STARTSIZE    100 * 1024        /* default 100kB                  */
+#include "vmcore/classcache.h"
+#include "vmcore/loader.h"
+#include "vmcore/options.h"
+#include "vmcore/statistics.h"
+#include "vmcore/suck.h"
 
 
 /* define cacaoh options ******************************************************/
@@ -105,7 +84,7 @@ opt_struct opts[] = {
 
 *******************************************************************************/
 
-static void usage(void)
+void usage(void)
 {
        printf("Usage: cacaoh [options] <classes>\n"
                   "\n"
@@ -132,10 +111,10 @@ static void usage(void)
 static void version(void)
 {
        printf("cacaoh version "VERSION"\n");
-       printf("Copyright (C) 1996-2005 R. Grafl, A. Krall, C. Kruegel, C. Oates,\n");
-       printf("R. Obermaisser, M. Platter, M. Probst, S. Ring, E. Steiner,\n");
-       printf("C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich, J. Wenninger,\n");
-       printf("Institut f. Computersprachen - TU Wien\n\n");
+       printf("Copyright (C) 1996-2005, 2006, 2007 R. Grafl, A. Krall, C. Kruegel,\n");
+       printf("C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,\n");
+       printf("E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,\n");
+       printf("J. Wenninger, Institut f. Computersprachen - TU Wien\n\n");
 
        printf("This program is free software; you can redistribute it and/or\n");
        printf("modify it under the terms of the GNU General Public License as\n");
@@ -151,6 +130,11 @@ static void version(void)
 }
 
 
+/* forward declarations *******************************************************/
+
+static JavaVMInitArgs *cacaoh_options_prepare(int argc, char **argv);
+
+
 /* main ************************************************************************
 
    Main program.
@@ -159,10 +143,11 @@ static void version(void)
 
 int main(int argc, char **argv)
 {
-       s4 i, a;
+       JavaVMInitArgs *vm_args;
+       s4 i, j;
+       s4 opt;
        classinfo *c;
        char *opt_directory;
-       void *dummy;
 
        /********** internal (only used by main) *****************************/
    
@@ -170,17 +155,10 @@ int main(int argc, char **argv)
        char *classpath;
        char *cp;
        s4    cplen;
-       u4    heapmaxsize;
-       u4    heapstartsize;
 
        if (argc < 2)
                usage();
 
-
-#if defined(DISABLE_GC)
-       nogc_init(HEAP_MAXSIZE, HEAP_STARTSIZE);
-#endif
-
        /* set the bootclasspath */
 
        cp = getenv("BOOTCLASSPATH");
@@ -188,17 +166,22 @@ int main(int argc, char **argv)
        if (cp) {
                bootclasspath = MNEW(char, strlen(cp) + strlen("0"));
                strcpy(bootclasspath, cp);
-
-       } else {
-               cplen = strlen(CACAO_VM_ZIP_PATH) +
+       }
+       else {
+               cplen =
+#if defined(WITH_CLASSPATH_GNU)
+                       strlen(CACAO_VM_ZIP) +
                        strlen(":") +
-                       strlen(CLASSPATH_GLIBJ_ZIP_PATH) +
+#endif
+                       strlen(CLASSPATH_CLASSES) +
                        strlen("0");
 
                bootclasspath = MNEW(char, cplen);
-               strcat(bootclasspath, CACAO_VM_ZIP_PATH);
+#if defined(WITH_CLASSPATH_GNU)
+               strcat(bootclasspath, CACAO_VM_ZIP);
                strcat(bootclasspath, ":");
-               strcat(bootclasspath, CLASSPATH_GLIBJ_ZIP_PATH);
+#endif
+               strcat(bootclasspath, CLASSPATH_CLASSES);
        }
 
 
@@ -206,11 +189,11 @@ int main(int argc, char **argv)
 
        cp = getenv("CLASSPATH");
 
-       if (cp) {
+       if (cp != NULL) {
                classpath = MNEW(char, strlen(cp) + strlen("0"));
                strcat(classpath, cp);
-
-       else {
+       }
+       else {
                classpath = MNEW(char, strlen(".") + strlen("0"));
                strcpy(classpath, ".");
        }
@@ -221,11 +204,13 @@ int main(int argc, char **argv)
        opt_verbose = false;
        opt_directory = NULL;
 
-       heapmaxsize = HEAP_MAXSIZE;
-       heapstartsize = HEAP_STARTSIZE;
 
-       while ((i = get_opt(argc, argv, opts)) != OPT_DONE) {
-               switch (i) {
+       /* parse the options ******************************************************/
+
+       vm_args = cacaoh_options_prepare(argc, argv);
+
+       while ((opt = options_get(opts, vm_args)) != OPT_DONE) {
+               switch (opt) {
                case OPT_IGNORE:
                        break;
 
@@ -242,8 +227,8 @@ int main(int argc, char **argv)
                        break;
 
                case OPT_BOOTCLASSPATH:
-                       /* Forget default bootclasspath and set the argument as new boot  */
-                       /* classpath.                                                     */
+                       /* Forget default bootclasspath and set the argument as
+                          new boot classpath. */
                        MFREE(bootclasspath, char, strlen(bootclasspath));
 
                        bootclasspath = MNEW(char, strlen(opt_arg) + strlen("0"));
@@ -274,78 +259,66 @@ int main(int argc, char **argv)
 
        if (opt_verbose) {
                log_init(NULL);
-               log_text("Java - header-generator started"); 
+               log_println("Java - header-generator started"); 
        }
-       
-       /* initialize the garbage collector */
-
-       gc_init(heapmaxsize, heapstartsize);
-
-#if defined(USE_THREADS)
-#if defined(NATIVE_THREADS)
-       threads_preinit();
-#endif
-       initLocks();
-#endif
 
        /* initialize the utf8 hashtable stuff: lock, often used utf8 strings
           (must be done _after_ threads_preinit) */
 
        if (!utf8_init())
-               throw_main_exception_exit();
+               vm_abort("utf8_init failed\n");
 
        /* initialize the classcache hashtable stuff: lock, hashtable
           (must be done _after_ threads_preinit) */
 
        if (!classcache_init())
-               throw_main_exception_exit();
+               vm_abort("classcache_init failed\n");
 
        /* initialize the loader with bootclasspath (must be done _after_
           thread_preinit) */
 
-       suck_init();
+       if (!suck_init())
+               vm_abort("suck_init failed\n");
 
        suck_add(bootclasspath);
 
-       /* Also add the normal classpath, so the bootstrap class loader can find  */
-       /* the files.                                                             */
+       /* Also add the normal classpath, so the bootstrap class loader
+          can find the files. */
 
        suck_add(classpath);
 
        /* initialize the loader subsystems (must be done _after_
        classcache_init) */
 
-       if (!loader_init((u1 *) &dummy))
-               throw_main_exception_exit();
+       if (!loader_init())
+               vm_abort("loader_init failed\n");
 
 
-       /*********************** Load JAVA classes  **************************/
+       /* load Java classes ******************************************************/
        
-       nativemethod_chain = chain_new();
-       nativeclass_chain = chain_new();
-       
-       for (a = opt_ind; a < argc; a++) {
-               cp = argv[a];
+       for (i = opt_index; i < vm_args->nOptions; i++) {
+               cp = vm_args->options[i].optionString;
 
                /* convert classname */
 
-               for (i = strlen(cp) - 1; i >= 0; i--) {
-                       switch (cp[i]) {
-                       case '.': cp[i] = '/';
+               for (j = strlen(cp) - 1; j >= 0; j--) {
+                       switch (cp[j]) {
+                       case '.':
+                               cp[j] = '/';
+                               break;
+                       case '_':
+                               cp[j] = '$';
                                break;
-                       case '_': cp[i] = '$';
                        }
                }
        
                /* exceptions are catched with new_exception call */
 
                if (!(c = load_class_bootstrap(utf_new_char(cp))))
-                       throw_cacao_exception_exit(string_java_lang_NoClassDefFoundError,
-                                                                          cp);
+                       vm_abort("java.lang.NoClassDefFoundError: %s\n", cp);
 
                if (!link_class(c))
-                       throw_cacao_exception_exit(string_java_lang_LinkageError,
-                                                                          cp);
+                       vm_abort("java.lang.LinkageError: %s\n", cp);
 
                headerfile_generate(c, opt_directory);
        }
@@ -355,9 +328,9 @@ int main(int argc, char **argv)
        loader_close();
 
        if (opt_verbose) {
-               log_text("Java - header-generator stopped");
+               log_println("Java - header-generator stopped");
 #if defined(ENABLE_STATISTICS)
-               mem_usagelog(true);
+               statistics_print_memory_usage();
 #endif
        }
        
@@ -365,6 +338,29 @@ int main(int argc, char **argv)
 }
 
 
+/* cacaoh_options_prepare ******************************************************
+
+   Prepare the JavaVMInitArgs.
+
+*******************************************************************************/
+
+static JavaVMInitArgs *cacaoh_options_prepare(int argc, char **argv)
+{
+       JavaVMInitArgs *vm_args;
+       s4              i;
+
+       vm_args = NEW(JavaVMInitArgs);
+
+       vm_args->nOptions = argc - 1;
+       vm_args->options  = MNEW(JavaVMOption, argc);
+
+       for (i = 1; i < argc; i++)
+               vm_args->options[i - 1].optionString = argv[i];
+
+       return vm_args;
+}
+
+
 /*
  * 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