- replaced proto_ exception with dynamic ones
[cacao.git] / builtin.h
index 51b2900def2d30a95334f8e1245756d8a8f30998..34cbf55b514e395fa5721d88d4b146ff818d7086 100644 (file)
--- a/builtin.h
+++ b/builtin.h
@@ -26,7 +26,9 @@
 
    Authors: Reinhard Grafl
 
-   $Id: builtin.h 727 2003-12-11 10:52:40Z edwin $
+   Changes: Edwin Steiner
+
+   $Id: builtin.h 930 2004-03-02 21:18:23Z jowenn $
 
 */
 
@@ -34,6 +36,9 @@
 #ifndef _BUILTIN_H
 #define _BUILTIN_H
 
+#include "config.h"
+#include "toolbox/loging.h"
+
 
 /* define infinity for floating point numbers */
 
 #define DBL_POSINF  0x7ff0000000000000LL
 #define DBL_NEGINF  0xfff0000000000000LL
 
-/* XXX delete */
-#if 0
-typedef struct builtin_descriptor {
-       functionptr bptr;
-       char        *name;
-       } builtin_descriptor;
-#endif
 
+/* float versions are not defined in gnu classpath's fdlibm */
+
+#define copysignf    copysign
+#define finitef      finite
+#define fmodf        fmod
+#define isnanf       isnan
+
+
+/**********************************************************************/
+/* BUILTIN FUNCTIONS TABLE                                            */
+/**********************************************************************/
+
+/* IMPORTANT:
+ * For each builtin function which is used in a BUILTIN* opcode there
+ * must be an entry in the builtin_desc table in jit/jit.c.
+ */
 typedef struct builtin_descriptor builtin_descriptor;
 
+/* There is a builtin_descriptor in builtin_desc for every builtin
+ * function used in BUILTIN* opcodes.
+ */
 struct builtin_descriptor {
-       int         opcode;
-       functionptr builtin;
-       int         icmd;
-       u1          type_s1;
-       u1          type_s2;
-       u1          type_s3;
-       u1          type_d;
-       bool        supported;
-       bool        isfloat;
-       char        *name;
+       int         opcode;   /* opcode which is replaced by this builtin */
+                             /* (255 means no automatic replacement,     */
+                             /*    0 means end of list.)                 */
+       functionptr builtin;  /* the builtin function (specify BUILTIN_...*/
+                             /* macro)                                   */
+       int         icmd;     /* the BUILTIN* opcode to use (# of args)   */
+       u1          type_s1;  /* type of 1st argument                     */
+       u1          type_s2;  /* type of 2nd argument, or TYPE_VOID       */
+       u1          type_s3;  /* type of 3rd argument, or TYPE_VOID       */
+       u1          type_d;   /* type of result (may be TYPE_VOID)        */
+       bool        supported;/* is <opcode> supported without builtin?   */
+       bool        isfloat;  /* is this a floating point operation?      */
+       char        *name;    /* display name of the builtin function     */
 };
 
 extern builtin_descriptor builtin_desc[];
-extern int builtintablelen;
 
-extern java_objectheader* exceptionptr;
+/**********************************************************************/
+/* GLOBAL VARIABLES                                                   */
+/**********************************************************************/
+
+#define THREADSPECIFIC
+#define exceptionptr (&_exceptionptr)
+#define threadrootmethod (&_threadrootmethod)
+
+#if defined(USE_THREADS) && defined(NATIVE_THREADS)
+#ifdef HAVE___THREAD
+
+#undef THREADSPECIFIC
+#define THREADSPECIFIC __thread
+
+#else
+
+#undef exceptionptr
+#undef threadrootmethod
+#define exceptionptr builtin_get_exceptionptrptr()
+#define threadrootmethod  builtin_get_threadrootmethod()
+#endif
+#endif
+
+extern THREADSPECIFIC java_objectheader* _exceptionptr;
+extern THREADSPECIFIC methodinfo* _threadrootmethod;
+extern THREADSPECIFIC native_stackframeinfo* _threadnativestackframeinfo;
 
 
 /**********************************************************************/
@@ -91,7 +136,7 @@ extern java_objectheader* exceptionptr;
  *
  * IMPORTANT:
  * For each builtin function which is used in a BUILTIN* opcode there
- * must be an entry in the builtin_desc table in builtin.c!
+ * must be an entry in the builtin_desc table in jit/jit.c.
  *
  * Below each prototype is either the BUILTIN_ macro definition or a
  * comment specifiying that this function is not used in BUILTIN*
@@ -125,11 +170,17 @@ s4 asm_builtin_checkarraycast(java_objectheader *obj, vftbl *target);
 
 java_objectheader *builtin_throw_exception(java_objectheader *exception);
 /* NOT AN OP */
-java_objectheader *builtin_trace_exception(java_objectheader *exceptionptr,
+java_objectheader *builtin_trace_exception(java_objectheader *_exceptionptr,
                                                                                   methodinfo *method, 
                                                                                   int *pos, int noindent);
 /* NOT AN OP */
 
+static inline java_objectheader **builtin_get_exceptionptrptr();
+static inline methodinfo **builtin_get_threadrootmethod();
+/* NOT AN OP */
+void builtin_reset_exceptionptr();
+/* NOT AN OP */
+
 java_objectheader *builtin_new(classinfo *c);
 #define BUILTIN_new (functionptr) builtin_new
 
@@ -178,12 +229,12 @@ void builtin_trace_args(s8 a0, s8 a1, s8 a2, s8 a3, s8 a4, s8 a5, s8 a6, s8 a7,
 /* NOT AN OP */
 #endif
 #endif
-void builtin_displaymethodstart(methodinfo *method); /* XXX? */
+void builtin_displaymethodstart(methodinfo *method);
 /* NOT AN OP */
 void builtin_displaymethodstop(methodinfo *method, s8 l, double d, float f);
 /* NOT AN OP */
-/* void builtin_displaymethodstop(methodinfo *method); */ /* XXX? */
-void builtin_displaymethodexception(methodinfo *method); /* XXX? */
+/* void builtin_displaymethodstop(methodinfo *method); */
+void builtin_displaymethodexception(methodinfo *method);
 /* NOT AN OP */
 
 void builtin_monitorenter(java_objectheader *o);
@@ -235,36 +286,36 @@ s8 builtin_lneg(s8 a);
 s4 builtin_lcmp(s8 a, s8 b);
 #define BUILTIN_lcmp (functionptr) builtin_lcmp
 
-float builtin_fadd(float a, float b); /* XXX? */
+float builtin_fadd(float a, float b);
 /* NOT AN OP */
-float builtin_fsub(float a, float b); /* XXX? */
+float builtin_fsub(float a, float b);
 /* NOT AN OP */
-float builtin_fmul(float a, float b); /* XXX? */
+float builtin_fmul(float a, float b);
 /* NOT AN OP */
-float builtin_fdiv(float a, float b); /* XXX? */
+float builtin_fdiv(float a, float b);
 /* NOT AN OP */
-float builtin_fneg(float a);          /* XXX? */
+float builtin_fneg(float a);         
 /* NOT AN OP */
-s4 builtin_fcmpl(float a, float b);   /* XXX? */
+s4 builtin_fcmpl(float a, float b);  
 /* NOT AN OP */
-s4 builtin_fcmpg(float a, float b);   /* XXX? */
+s4 builtin_fcmpg(float a, float b);  
 /* NOT AN OP */
 float builtin_frem(float a, float b);
 #define BUILTIN_frem (functionptr) builtin_frem
 
-double builtin_dadd(double a, double b); /* XXX? */
+double builtin_dadd(double a, double b);
 /* NOT AN OP */
-double builtin_dsub(double a, double b); /* XXX? */
+double builtin_dsub(double a, double b);
 /* NOT AN OP */
-double builtin_dmul(double a, double b); /* XXX? */
+double builtin_dmul(double a, double b);
 /* NOT AN OP */
-double builtin_ddiv(double a, double b); /* XXX? */
+double builtin_ddiv(double a, double b);
 /* NOT AN OP */
-double builtin_dneg(double a);           /* XXX? */ 
+double builtin_dneg(double a);          
 /* NOT AN OP */
-s4 builtin_dcmpl(double a, double b);    /* XXX? */
+s4 builtin_dcmpl(double a, double b);   
 /* NOT AN OP */
-s4 builtin_dcmpg(double a, double b);    /* XXX? */
+s4 builtin_dcmpg(double a, double b);   
 /* NOT AN OP */
 double builtin_drem(double a, double b);
 #define BUILTIN_drem (functionptr) builtin_drem
@@ -291,7 +342,7 @@ s8       builtin_f2l(float a);
 s8       asm_builtin_f2l(float a);
 /* NOT AN OP */
 
-double   builtin_f2d(float a);     /* XXX? */
+double   builtin_f2d(float a);
 /* NOT AN OP */
 
 s4       builtin_d2i(double a);
@@ -303,17 +354,60 @@ s8       builtin_d2l(double a);
 s8       asm_builtin_d2l(double a);
 /* NOT AN OP */
 
-float    builtin_d2f(double a);    /* XXX? */
+float    builtin_d2f(double a);
 /* NOT AN OP */
 
 java_arrayheader *builtin_clone_array(void *env, java_arrayheader *o);
 /* NOT AN OP */
 
+/* builtin_dummy just panics if it is executed. */
+s4 builtin_dummy();
+/* NOT AN OP */
+
 /* conversion helper functions */
 
 inline float intBitsToFloat(s4 i);
 inline float longBitsToDouble(s8 l);
 
+
+static inline java_objectheader **builtin_get_exceptionptrptr()
+{
+#if defined(USE_THREADS) && defined(NATIVE_THREADS)
+#ifdef HAVE___THREAD
+    return &_exceptionptr;
+#else
+    return &((nativethread*) pthread_getspecific(tkey_exceptionptr))->_exceptionptr;
+#endif
+#else
+    panic("builtin_get_exceptionptrptr should not be used in this configuration");
+    return NULL;
+#endif
+}
+
+static inline methodinfo **builtin_get_threadrootmethod()
+{
+#if defined(USE_THREADS) && defined(NATIVE_THREADS)
+#ifdef HAVE___THREAD
+    return &_threadrootmethod;
+#else
+    return &((nativethread*) pthread_getspecific(tkey_threadrootmethod))->_threadrootmethod;
+#endif
+#else
+    panic("builting_get_threadrootmethod should not be used in this configuration");
+    return NULL;
+#endif
+}
+
+/* returns the root method of a thread. this is used in asmpart.S and delivers the abort condition
+   for the stack unwinding for getClassContext and getClassLoader. For the main thread this is the main function.
+   Otherwhise it is the thread's run method (at least that's how I see it) (jowenn) */
+methodinfo *builtin_asm_get_threadrootmethod();
+
+/* adds an element to the stack frame info list (needed for unwinding across native functions) */
+native_stackframeinfo **builtin_asm_new_stackframeinfo();
+
+/* returns the current top element of the stack frame info list (needed for unwinding across native functions) */
+native_stackframeinfo *builtin_asm_get_stackframeinfo();
 #endif /* _BUILTIN_H */