fixed builtin problem on alpha
[cacao.git] / src / vm / jit / jit.c
index a72d201a7c097c1f84f55f12e44de70dc113a3d8..95bb7790a593b3684a0410718a13996e04ae907e 100644 (file)
@@ -27,7 +27,9 @@
    Authors: Andreas Krall
             Reinhard Grafl
 
-   $Id: jit.c 727 2003-12-11 10:52:40Z edwin $
+   Changes: Edwin Steiner
+
+   $Id: jit.c 789 2003-12-16 14:46:55Z edwin $
 
 */
 
 
 
 /* global switches ************************************************************/
-bool compileverbose =  false;
-bool showstack = false;
-bool showdisassemble = false; 
-bool showddatasegment = false; 
-bool showintermediate = false;
-int  optimizelevel = 0;
-
-bool useinlining = false;
-bool inlinevirtuals = false;
-bool inlineexceptions = false;
-bool inlineparamopt = false;
-bool inlineoutsiders = false;
-
-bool checkbounds = true;
-bool checknull = true;
-bool opt_noieee = false;
-bool checksync = true;
-bool opt_loops = false;
 
 bool getcompilingtime = false;
 long compilingtime = 0;
@@ -202,7 +186,14 @@ bool regs_ok;                   /* true if registers have been allocated      */
 chain *uninitializedclasses;
 
 int stackreq[256];
+
                                 
+#if defined(__I386__)
+/* these define if a method has ICMDs which use %edx or %ecx */
+bool method_uses_ecx;
+bool method_uses_edx;
+#endif
+
 
 int jcommandsize[256] = {
 
@@ -1306,7 +1297,8 @@ stdopdescriptor builtintable[] = {
 };
 
 #endif
-int builtintablelen; /* XXX make static again? */
+
+static int builtintablelen;
 
 #endif /* USEBUILTINTABLE */
 
@@ -1320,12 +1312,13 @@ int builtintablelen; /* XXX make static again? */
     The first part of the table (up to the 255-marker) lists the
     opcodes which are automatically replaced in stack.c.
 
-    The second part lists the builtin functions which are used for
-    BUILTIN* opcodes in parse.c and stack.c.
+    The second part lists the builtin functions which are "manually"
+    used for BUILTIN* opcodes in parse.c and stack.c.
 
 *****************************************************************************/
 
 builtin_descriptor builtin_desc[] = {
+#if defined(USEBUILTINTABLE)
        {ICMD_LCMP , BUILTIN_lcmp ,ICMD_BUILTIN2,TYPE_LONG  ,TYPE_LONG  ,TYPE_VOID ,TYPE_INT   ,
                     SUPPORT_LONG && SUPPORT_LONG_CMP,false,"lcmp"},
        
@@ -1368,11 +1361,19 @@ builtin_descriptor builtin_desc[] = {
                     SUPPORT_FLOAT && SUPPORT_FICVT,true ,"f2i"},
        {ICMD_D2I  , BUILTIN_d2i  ,ICMD_BUILTIN1,TYPE_DOUBLE,TYPE_VOID  ,TYPE_VOID ,TYPE_INT   ,
                     SUPPORT_DOUBLE && SUPPORT_FICVT,true ,"d2i"},
+#endif
 
        /* this record marks the end of the automatically replaced opcodes */
        {255       , NULL        ,0            ,0          ,0          ,0         ,0          ,
                     true                            ,false,"<INVALID>"},
 
+#if defined(__ALPHA__)
+       {255, BUILTIN_f2l  ,ICMD_BUILTIN1,TYPE_FLOAT ,TYPE_VOID  ,TYPE_VOID ,TYPE_LONG  ,0,0,"f2l"},
+       {255, BUILTIN_d2l  ,ICMD_BUILTIN1,TYPE_DOUBLE,TYPE_VOID  ,TYPE_VOID ,TYPE_LONG  ,0,0,"d2l"},
+       {255, BUILTIN_f2i  ,ICMD_BUILTIN1,TYPE_FLOAT ,TYPE_VOID  ,TYPE_VOID ,TYPE_INT   ,0,0,"f2i"},
+       {255, BUILTIN_d2i  ,ICMD_BUILTIN1,TYPE_DOUBLE,TYPE_VOID  ,TYPE_VOID ,TYPE_INT   ,0,0,"d2i"},
+#endif
+
        /* the following functions are not replaced automatically */
        {255,BUILTIN_instanceof      ,ICMD_BUILTIN2,TYPE_ADR   ,TYPE_ADR   ,TYPE_VOID  ,TYPE_INT   ,0,0,"instanceof"},
        {255,BUILTIN_arrayinstanceof ,ICMD_BUILTIN2,TYPE_ADR   ,TYPE_ADR   ,TYPE_VOID  ,TYPE_INT   ,0,0,"arrayinstanceof"},
@@ -1440,6 +1441,10 @@ methodptr jit_compile(methodinfo *m)
 
        count_methods++;
 
+#if defined(USE_THREADS) && defined(NATIVE_THREADS)
+       pthread_mutex_lock(&compiler_mutex);
+#endif
+
        intsDisable();      /* disable interrupts */
 
        regs_ok = false;
@@ -1462,7 +1467,7 @@ methodptr jit_compile(methodinfo *m)
                strcpy(logtext+strlen(logtext), ".");
                utf_sprint(logtext+strlen(logtext), m->name);
                utf_sprint(logtext+strlen(logtext), m->descriptor);
-               dolog(logtext);
+               log_text(logtext);
                intsRestore();                             /* enable interrupts again */
                return (methodptr) do_nothing_function;    /* return empty method     */
        }
@@ -1476,7 +1481,7 @@ methodptr jit_compile(methodinfo *m)
                strcpy(logtext+strlen(logtext), ".");
                utf_sprint(logtext+strlen(logtext), m->name);
                utf_sprint(logtext+strlen(logtext), m->descriptor);
-               dolog(logtext);
+               log_text(logtext);
        }
 
 
@@ -1509,17 +1514,22 @@ methodptr jit_compile(methodinfo *m)
 
        /* initialize class list with class the compiled method belongs to */
 
-       uninitializedclasses = chain_new(); 
+       uninitializedclasses = chain_new();
        compiler_addinitclass(m->class);
 
 
+#if defined(__I386__)
+       method_uses_ecx = true;
+       method_uses_edx = false;
+#endif
+
        /* call the compiler passes ***********************************************/
 
-       /* must be call before reg_init, because it can change maxlocals */
+       /* must be called before reg_init, because it can change maxlocals */
        if (useinlining)
                inlining_init(m);
 
-       reg_init(m);
+       reg_setup();
 
        codegen_init();
 
@@ -1536,7 +1546,7 @@ methodptr jit_compile(methodinfo *m)
                strcpy(logtext+strlen(logtext), ".");
                utf_sprint(logtext+strlen(logtext), m->name);
                utf_sprint(logtext+strlen(logtext), m->descriptor);
-               dolog(logtext);
+               log_text(logtext);
        }
 
        typecheck();
@@ -1578,7 +1588,7 @@ methodptr jit_compile(methodinfo *m)
 
        if (getcompilingtime) {
                stoptime = getcputime();
-               compilingtime += (stoptime-starttime); 
+               compilingtime += (stoptime - starttime);
        }
 
        /* initialize all used classes */
@@ -1597,6 +1607,10 @@ methodptr jit_compile(methodinfo *m)
 
        intsRestore();    /* enable interrupts again */
 
+#if defined(USE_THREADS) && defined(NATIVE_THREADS)
+       pthread_mutex_unlock(&compiler_mutex);
+#endif
+
        /* return pointer to the methods entry point */
        
        return m->entrypoint;
@@ -1790,7 +1804,8 @@ void jit_init()
        stackreq[JAVA_DUP_X2] = 4;
        stackreq[JAVA_DUP2_X1] = 3;
        stackreq[JAVA_DUP2_X2] = 4;
-       
+
+       reg_init();
        init_exceptions();
 }