* Updated header: Added 2006. Changed address of FSF. Changed email
[cacao.git] / src / cacao / cacao.c
index 2d0867ecf4d0686c4f9370b42606092758ad2f27..183ba52a8707a5caaeeae4497a2ddf78d726a670 100644 (file)
@@ -1,9 +1,9 @@
 /* src/cacao/cacao.c - contains main() of cacao
 
-   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 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, 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.
+   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+   02110-1301, USA.
 
-   Contact: cacao@complang.tuwien.ac.at
+   Contact: cacao@cacaojvm.org
 
    Authors: Reinhard Grafl
 
      - Calling the class loader
      - Running the main method
 
-   $Id: cacao.c 3940 2005-12-11 01:06:16Z twisti $
+   $Id: cacao.c 4357 2006-01-22 23:33:38Z twisti $
 
 */
 
 
+#include "config.h"
+
 #include <assert.h>
 #include <stdlib.h>
 #include <string.h>
 
-#include "config.h"
+#include "vm/types.h"
+
 #include "cacao/cacao.h"
 #include "mm/boehm.h"
 #include "mm/memory.h"
@@ -69,6 +72,7 @@
 #include "vm/initialize.h"
 #include "vm/loader.h"
 #include "vm/options.h"
+#include "vm/properties.h"
 #include "vm/signallocal.h"
 #include "vm/statistics.h"
 #include "vm/stringlocal.h"
@@ -106,9 +110,6 @@ JNIEnv *env;                        /* pointer to native method interface     */
 JDK1_1InitArgs vm_args;             /* JDK 1.1 VM initialization arguments    */
 
 
-char *bootclasspath;                    /* contains the boot classpath        */
-char *classpath;                        /* contains the classpath             */
-
 char *mainstring;
 static classinfo *mainclass;
 
@@ -119,75 +120,85 @@ void **stackbottom = 0;
 
 /* define command line options ************************************************/
 
-#define OPT_CLASSPATH        2
-#define OPT_D                3
-#define OPT_MS               4
-#define OPT_MX               5
-#define OPT_VERBOSE1         6
-#define OPT_VERBOSE          7
-#define OPT_VERBOSESPECIFIC  8
-#define OPT_VERBOSECALL      9
-#define OPT_NOIEEE           10
-#define OPT_SOFTNULL         11
-#define OPT_TIME             12
-
-#if defined(STATISTICS)
-#define OPT_STAT             13
-#endif /* defined(STATISTICS) */
-
-#define OPT_LOG              14
-#define OPT_CHECK            15
-#define OPT_LOAD             16
-#define OPT_METHOD           17
-#define OPT_SIGNATURE        18
-#define OPT_SHOW             19
-#define OPT_ALL              20
-#define OPT_OLOOP            24
-#define OPT_INLINING        25
+enum {
+       OPT_CLASSPATH,
+       OPT_D,
+       OPT_MS,
+       OPT_MX,
+       OPT_VERBOSE1,
+       OPT_VERBOSE,
+       OPT_VERBOSESPECIFIC,
+       OPT_VERBOSECALL,
+       OPT_NOIEEE,
+       OPT_SOFTNULL,
+       OPT_TIME,
+
+#if defined(ENABLE_STATISTICS)
+       OPT_STAT,
+#endif
+
+       OPT_LOG,
+       OPT_CHECK,
+       OPT_LOAD,
+       OPT_METHOD,
+       OPT_SIGNATURE,
+       OPT_SHOW,
+       OPT_ALL,
+       OPT_OLOOP,
+       OPT_INLINING,
 
 #define STATIC_ANALYSIS
 #if defined(STATIC_ANALYSIS)
-# define OPT_RT              26
-# define OPT_XTA             27 
-# define OPT_VTA             28
-#endif /* defined(STATIC_ANALYSIS) */
+       OPT_RT,
+       OPT_XTA,
+       OPT_VTA,
+#endif
 
-#define OPT_VERBOSETC        29
-#define OPT_NOVERIFY         30
-#define OPT_LIBERALUTF       31
-#define OPT_VERBOSEEXCEPTION 32
-#define OPT_EAGER            33
+       OPT_VERBOSETC,
+       OPT_NOVERIFY,
+       OPT_LIBERALUTF,
+       OPT_VERBOSEEXCEPTION,
+       OPT_EAGER,
+
+#if defined(ENABLE_LSRA)
+       OPT_LSRA,
+#endif
 
-#if defined(LSRA)
-#define OPT_LSRA             34
-#endif /* defined(LSRA) */
+       OPT_JAR,
+       OPT_BOOTCLASSPATH,
+       OPT_BOOTCLASSPATH_A,
+       OPT_BOOTCLASSPATH_P,
+       OPT_VERSION,
+       OPT_SHOWVERSION,
+       OPT_FULLVERSION,
 
-#define OPT_JAR              35
-#define OPT_BOOTCLASSPATH    36
-#define OPT_BOOTCLASSPATH_A  37
-#define OPT_BOOTCLASSPATH_P  38
-#define OPT_VERSION          39
-#define OPT_SHOWVERSION      40
-#define OPT_FULLVERSION      41
+       OPT_HELP,
+       OPT_X,
 
-#define OPT_HELP             100
-#define OPT_X                101
+       OPT_JIT,
+       OPT_INTRP,
 
-#define OPT_JIT              102
-#define OPT_INTRP            103
+#if defined(ENABLE_INTRP)
+       /* interpreter options */
 
-#define OPT_STATIC_SUPERS    104
-#define OPT_TRACE            105
+       OPT_NO_DYNAMIC,
+       OPT_NO_REPLICATION,
+       OPT_NO_QUICKSUPER,
+       OPT_STATIC_SUPERS,
+       OPT_TRACE,
+#endif
 
-#define OPT_SS               106
+       OPT_SS,
 
 #ifdef ENABLE_JVMTI
-#define OPT_DEBUG            107
-#define OPT_AGENTLIB         108
-#define OPT_AGENTPATH        109
-#endif 
+       OPT_DEBUG,
+       OPT_AGENTLIB,
+       OPT_AGENTPATH,
+#endif
+
+       DUMMY
+};
 
-#define OPT_NO_DYNAMIC       110
 
 opt_struct opts[] = {
        { "classpath",         true,  OPT_CLASSPATH },
@@ -209,7 +220,7 @@ opt_struct opts[] = {
 #endif
        { "softnull",          false, OPT_SOFTNULL },
        { "time",              false, OPT_TIME },
-#if defined(STATISTICS)
+#if defined(ENABLE_STATISTICS)
        { "stat",              false, OPT_STAT },
 #endif
        { "log",               true,  OPT_LOG },
@@ -224,7 +235,7 @@ opt_struct opts[] = {
        { "xta",               false, OPT_XTA },
        { "vta",               false, OPT_VTA },
 #endif
-#ifdef LSRA
+#if defined(ENABLE_LSRA)
        { "lsra",              false, OPT_LSRA },
 #endif
        { "jar",               false, OPT_JAR },
@@ -234,11 +245,15 @@ opt_struct opts[] = {
        { "help",              false, OPT_HELP },
        { "?",                 false, OPT_HELP },
 
+#if defined(ENABLE_INTRP)
        /* interpreter options */
 
        { "trace",             false, OPT_TRACE },
        { "static-supers",     true,  OPT_STATIC_SUPERS },
        { "no-dynamic",        false, OPT_NO_DYNAMIC },
+       { "no-replication",    false, OPT_NO_REPLICATION },
+       { "no-quicksuper",     false, OPT_NO_QUICKSUPER },
+#endif
 
        /* JVMTI Agent Command Line Options */
 #ifdef ENABLE_JVMTI
@@ -319,7 +334,7 @@ static void usage(void)
        printf("    -liberalutf              don't warn about overlong UTF-8 sequences\n");
        printf("    -softnull                use software nullpointer check\n");
        printf("    -time                    measure the runtime\n");
-#if defined(STATISTICS)
+#if defined(ENABLE_STATISTICS)
        printf("    -stat                    detailed compiler statistics\n");
 #endif
        printf("    -log logfile             specify a name for the logfile\n");
@@ -349,7 +364,7 @@ static void usage(void)
        printf("    -xta                     use x type analysis\n");
        printf("    -vta                     use variable type analysis\n");
 #endif
-#ifdef LSRA
+#if defined(ENABLE_LSRA)
        printf("    -lsra                    use linear scan register allocation\n");
 #endif
 
@@ -397,10 +412,10 @@ static void version(void)
        printf("java version \""JAVA_VERSION"\"\n");
        printf("CACAO 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 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");
@@ -466,7 +481,7 @@ static void setup_debugger_process(char* transport) {
        if (!m)
                throw_main_exception_exit();
 
-       asm_calljavafunction(m, o, NULL, NULL, NULL);
+       ASM_CALLJAVAFUNCTION(m, o, NULL, NULL, NULL);
 
        /* configure(transport,NULL) */
        m = class_resolveclassmethod(
@@ -477,7 +492,9 @@ static void setup_debugger_process(char* transport) {
 
 
        s = javastring_new_char(transport);
-       asm_calljavafunction(m, o, s, NULL, NULL);
+
+       ASM_CALLJAVAFUNCTION(m, o, s, NULL, NULL);
+
        if (!m)
                throw_main_exception_exit();
 
@@ -491,7 +508,7 @@ static void setup_debugger_process(char* transport) {
        if (!m)
                throw_main_exception_exit();
 
-       asm_calljavafunction(m, o, NULL, NULL, NULL);
+       ASM_CALLJAVAFUNCTION(m, o, NULL, NULL, NULL);
 }
 #endif
 
@@ -533,7 +550,7 @@ static char *getmainclassnamefromjar(char *mainstring)
 
        s = javastring_new_char(mainstring);
 
-       asm_calljavafunction(m, o, s, NULL, NULL);
+       ASM_CALLJAVAFUNCTION(m, o, s, NULL, NULL);
 
        if (*exceptionptr)
                throw_main_exception_exit();
@@ -549,7 +566,7 @@ static char *getmainclassnamefromjar(char *mainstring)
        if (!m)
                throw_main_exception_exit();
 
-       o = asm_calljavafunction(m, o, NULL, NULL, NULL);
+       ASM_CALLJAVAFUNCTION_ADR(o, m, o, NULL, NULL, NULL);
 
        if (!o) {
                fprintf(stderr, "Could not get manifest from %s (invalid or corrupt jarfile?)\n", mainstring);
@@ -568,7 +585,7 @@ static char *getmainclassnamefromjar(char *mainstring)
        if (!m)
                throw_main_exception_exit();
 
-       o = asm_calljavafunction(m, o, NULL, NULL, NULL);
+       ASM_CALLJAVAFUNCTION_ADR(o, m, o, NULL, NULL, NULL);
 
        if (!o) {
                fprintf(stderr, "Could not get main attributes from %s (invalid or corrupt jarfile?)\n", mainstring);
@@ -589,7 +606,7 @@ static char *getmainclassnamefromjar(char *mainstring)
 
        s = javastring_new_char("Main-Class");
 
-       o = asm_calljavafunction(m, o, s, NULL, NULL);
+       ASM_CALLJAVAFUNCTION_ADR(o, m, o, s, NULL, NULL);
 
        if (!o)
                throw_main_exception_exit();
@@ -652,22 +669,20 @@ int main(int argc, char **argv)
        /* set the bootclasspath */
 
        cp = getenv("BOOTCLASSPATH");
+
        if (cp) {
                bootclasspath = MNEW(char, strlen(cp) + strlen("0"));
                strcpy(bootclasspath, cp);
 
        } else {
-               cplen = strlen(CACAO_INSTALL_PREFIX) + strlen(CACAO_VM_ZIP_PATH) +
+               cplen = strlen(CACAO_VM_ZIP_PATH) +
                        strlen(":") +
-                       strlen(CLASSPATH_INSTALL_DIR) +
                        strlen(CLASSPATH_GLIBJ_ZIP_PATH) +
                        strlen("0");
 
                bootclasspath = MNEW(char, cplen);
-               strcpy(bootclasspath, CACAO_INSTALL_PREFIX);
                strcat(bootclasspath, CACAO_VM_ZIP_PATH);
                strcat(bootclasspath, ":");
-               strcat(bootclasspath, CLASSPATH_INSTALL_DIR);
                strcat(bootclasspath, CLASSPATH_GLIBJ_ZIP_PATH);
        }
 
@@ -675,6 +690,7 @@ int main(int argc, char **argv)
        /* set the classpath */
 
        cp = getenv("CLASSPATH");
+
        if (cp) {
                classpath = MNEW(char, strlen(cp) + strlen("0"));
                strcat(classpath, cp);
@@ -694,6 +710,12 @@ int main(int argc, char **argv)
        heapstartsize = HEAP_STARTSIZE;
        opt_stacksize = STACK_SIZE;
 
+       /* initialize properties before commandline handling */
+
+       if (!properties_init())
+               throw_cacao_exception_exit(string_java_lang_InternalError,
+                                                                  "Unable to init properties");
+
        while ((i = get_opt(argc, argv, opts)) != OPT_DONE) {
                switch (i) {
                case OPT_IGNORE:
@@ -768,15 +790,17 @@ int main(int argc, char **argv)
                                for (j = 0; j < strlen(opt_arg); j++) {
                                        if (opt_arg[j] == '=') {
                                                opt_arg[j] = '\0';
-                                               create_property(opt_arg, opt_arg + j + 1);
+                                               properties_add(opt_arg, opt_arg + j + 1);
                                                goto didit;
                                        }
                                }
 
                                /* if no '=' is given, just create an empty property */
-                               create_property(opt_arg, "");
+
+                               properties_add(opt_arg, "");
                                        
-                       didit: ;
+                       didit:
+                               ;
                        }       
                        break;
 
@@ -876,7 +900,7 @@ int main(int argc, char **argv)
                        getloadingtime = true;
                        break;
                                        
-#if defined(STATISTICS)
+#if defined(ENABLE_STATISTICS)
                case OPT_STAT:
                        opt_stat = true;
                        break;
@@ -970,12 +994,7 @@ int main(int argc, char **argv)
                                switch (opt_arg[j]) {
                                case 'n':
                                     /* define in options.h; Used in main.c, jit.c & inline.c */
-#ifdef INAFTERMAIN
-                                       useinliningm = true;
-                                       useinlining = false;
-#else
-                                       useinlining = true;
-#endif
+                                       /* inlining is currently deactivated */
                                        break;
                                case 'v':
                                        inlinevirtuals = true;
@@ -1012,7 +1031,7 @@ int main(int argc, char **argv)
                        break;
 #endif
 
-#ifdef LSRA
+#if defined(ENABLE_LSRA)
                case OPT_LSRA:
                        opt_lsra = true;
                        break;
@@ -1044,6 +1063,7 @@ int main(int argc, char **argv)
 #endif
                        break;
 
+#if defined(ENABLE_INTRP)
                case OPT_STATIC_SUPERS:
                        opt_static_supers = atoi(opt_arg);
                        break;
@@ -1052,9 +1072,18 @@ int main(int argc, char **argv)
                        opt_no_dynamic = true;
                        break;
 
+               case OPT_NO_REPLICATION:
+                       opt_no_replication = true;
+                       break;
+
+               case OPT_NO_QUICKSUPER:
+                       opt_no_quicksuper = true;
+                       break;
+
                case OPT_TRACE:
                        vm_debug = true;
                        break;
+#endif
 
                default:
                        printf("Unknown option: %s\n", argv[opt_ind]);
@@ -1166,6 +1195,7 @@ int main(int argc, char **argv)
        if (!suck_init())
                throw_main_exception_exit();
 
+       suck_add_from_property("java.endorsed.dirs");
        suck_add(bootclasspath);
 
        /* initialize the memory subsystem (must be done _after_
@@ -1194,7 +1224,16 @@ int main(int argc, char **argv)
 
        /* machine dependent initialization */
 
-       md_init();
+#if defined(ENABLE_JIT)
+# if defined(ENABLE_INTRP)
+       if (opt_intrp)
+               intrp_md_init();
+       else
+# endif
+               md_init();
+#else
+       intrp_md_init();
+#endif
 
        /* initialize the loader subsystems (must be done _after_
        classcache_init) */
@@ -1365,9 +1404,10 @@ int main(int argc, char **argv)
 #endif
                /* here we go... */
 
-               asm_calljavafunction(m, a, NULL, NULL, NULL);
+               ASM_CALLJAVAFUNCTION(m, a, NULL, NULL, NULL);
 
                /* exception occurred? */
+
                if (*exceptionptr) {
                        throw_main_exception();
                        status = 1;
@@ -1551,7 +1591,7 @@ void cacao_exit(s4 status)
        /*   not sure if permanant or temp restriction          */
        if (inlinevirtuals) inlineoutsiders = false; 
 
-       asm_calljavafunction(m, (void *) (ptrint) status, NULL, NULL, NULL);
+       ASM_CALLJAVAFUNCTION(m, (void *) (ptrint) status, NULL, NULL, NULL);
 
        /* this should never happen */
 
@@ -1619,7 +1659,7 @@ void exit_handler(void)
        if (opt_verbose || getcompilingtime || opt_stat) {
                log_text("CACAO terminated");
 
-#if defined(STATISTICS)
+#if defined(ENABLE_STATISTICS)
                if (opt_stat) {
                        print_stats();
 #ifdef TYPECHECK_STATISTICS