CallLongMethod implementation added
[cacao.git] / threads / thread.h
index d64d3d992807ec3332f30cec49b5f32ba2bb7718..1c1eee4c6cbaeb25c93cfa95d732bc6e5b3c5bb6 100644 (file)
  * Written by Tim Wilkinson <tim@tjwassoc.demon.co.uk>, 1996.
  */
 
-#ifndef __thread_h
-#define __thread_h
+#ifndef _THREAD_H
+#define _THREAD_H
 
 #include "config.h"
 
+typedef struct {
+       int super_baseval, super_diffval, sub_baseval;
+} castinfo;
+
 #ifdef USE_THREADS
 
 #include "global.h"
 
-#define MAXTHREADS              256          /* schani */
-
-#define        THREADCLASS             "java/lang/Thread"
-#define        THREADGROUPCLASS        "java/lang/ThreadGroup"
-#define        THREADDEATHCLASS        "java/lang/ThreadDeath"
+#define        THREADCLASS         "java/lang/Thread"
+#define        THREADGROUPCLASS    "java/lang/ThreadGroup"
+#define        THREADDEATHCLASS    "java/lang/ThreadDeath"
 
 #define        MIN_THREAD_PRIO         1
 #define        NORM_THREAD_PRIO        5
 #define THREAD_FLAGS_USER_SUSPEND       2  /* Flag explicit suspend() call */
 #define        THREAD_FLAGS_KILLED             4
 
+#if !defined(NATIVE_THREADS)
+
+#define MAXTHREADS              256          /* schani */
+
+#if 1
+#define DBG(s)
+#define SDBG(s)
+#else
+#define DBG(s)                 s
+#define SDBG(s)                s
+#endif
+
 struct _thread;
 
+#if 0
 typedef struct _ctx
 {
     struct _thread    *thread;
@@ -54,10 +69,11 @@ typedef struct _ctx
     u1*                stackEnd;
     u1*                usedStackTop;
     s8                 time;
-    java_objectheader *exceptionptr;
+    java_objectheader *texceptionptr;
     struct _thread    *nextlive;
     u1                 flags;
 } ctx;
+#endif
 
 /*
 struct _stringClass;
@@ -66,37 +82,49 @@ struct _object;
 
 /* This structure mirrors java.lang.ThreadGroup.h */
 
-typedef struct _threadGroup
-{
-    java_objectheader    header;
-    struct _threadGroup* parent;
-    java_objectheader*   name;
-    s4                   maxPrio;
-    s4                   destroyed;
-    s4                   daemon;
-       s4                   vmAllowSuspension;
-    s4                   nthreads;
-    java_objectheader*   threads;
-    s4                   ngroups;
-    java_objectheader*   groups;
+typedef struct _threadGroup {
+   java_objectheader header;
+   struct _threadGroup* parent;
+   struct java_objectheader* name;
+   struct java_objectheader* threads;
+   struct java_objectheader* groups;
+   s4 daemon_flag;
+   s4 maxpri;
 } threadGroup;
 
+
+
+/* This structure mirrors java.lang.VMThread.h */
+typedef struct vmthread {
+   java_objectheader header;
+   struct _thread* thread;
+   s4 running;
+   s4 status;
+   s4 priority;
+   void* restorePoint;
+   void* stackMem;
+   void* stackBase;
+   void* stackEnd;
+   void* usedStackTop;
+   s8 time;
+   java_objectheader *texceptionptr;
+   struct _thread* nextlive;
+   struct _thread* next;
+   s4 flags;
+} vmthread;
+
 /* This structure mirrors java.lang.Thread.h */
-typedef struct _thread
-{
-    java_objectheader        header;
-    java_objectheader*       name;
-    s4                       priority;
-    struct _thread*          next;
-    s8                       PrivateInfo;
-    s4                       single_step;
-    s4                       daemon;
-    s4                       stillborn;
-    java_objectheader*       target;
-    threadGroup*             group;
-       java_objectheader*       contextClassLoader;
-       java_objectheader*       inheritedAccessControlContext;
-       java_objectheader*       values;
+typedef struct _thread {
+   java_objectheader header;
+   vmthread* vmThread;
+   threadGroup* group;
+   struct java_lang_Runnable* runnable;
+   struct java_lang_String* name;
+   s4 daemon;
+   s4 priority;
+   s8 stacksize;
+   struct java_lang_Throwable* stillborn;
+   struct java_lang_ClassLoader* contextClassLoader;
 } thread;
 
 void initThreads (u1 *stackbottom);
@@ -111,7 +139,7 @@ void killThread (thread*);
 void setPriorityThread (thread*, int);
 
 s8 currentTime (void);
-void sleepThread (s8);
+void sleepThread(s8 millis, s4 nanos);
 bool aliveThread (thread*);
 long framesThread (thread*);
 
@@ -123,7 +151,7 @@ extern int blockInts;
 extern bool needReschedule;
 extern thread *currentThread;
 extern thread *mainThread;
-extern ctx contexts[];
+/*extern ctx contexts[];*/
 extern int threadStackSize;
 
 extern thread *liveThreads;
@@ -131,24 +159,51 @@ extern thread *sleepThreads;
 
 extern thread *threadQhead[MAX_THREAD_PRIO + 1];
 
-#define CONTEXT(_t)                                                     \
-        (contexts[(_t)->PrivateInfo - 1])
 
-#if 1
+/*#define CONTEXT(_t)     (contexts[(_t)->PrivateInfo - 1])*/
+#define CONTEXT(_t)    (*(_t->vmThread))
+
 #define        intsDisable()   blockInts++
-#define        intsRestore()   if (blockInts == 1 && needReschedule) {         \
-                           reschedule();                               \
-                       }                                               \
-                       blockInts--
-#else
-#define        intsDisable()   do { blockInts++; fprintf(stderr, "++: %d (%s:%d)\n", blockInts, __FILE__, __LINE__); } while (0)
-#define        intsRestore()   do { \
-                            if (blockInts == 1 && needReschedule) {    \
-                               reschedule();                           \
-                           }                                           \
-                           blockInts--;                                \
-                            fprintf(stderr, "--: %d (%s:%d)\n", blockInts, __FILE__, __LINE__);     \
-                        } while (0)
+
+#define        intsRestore()   if (blockInts == 1 && needReschedule) { \
+                            reschedule(); \
+                        } \
+                        blockInts--
+
+
+/* access macros */
+
+#define        THREADSTACKSIZE         (32 * 1024)
+
+#define        THREADSWITCH(to, from) \
+    do { \
+       void *from1; \
+       void *from2; \
+        asm_perform_threadswitch((from?&(from)->restorePoint:&from1),\
+                                 &(to)->restorePoint, (from?&(from)->usedStackTop:&from2)); \
+    } while (0)
+
+
+#define THREADINIT(to, func) \
+    do { \
+        (to)->restorePoint = asm_initialize_thread_stack((u1*)(func), \
+                                                         (to)->stackEnd); \
+    } while (0)
+
+
+#define        THREADINFO(e) \
+    do { \
+        (e)->restorePoint = 0; \
+        (e)->flags = THREAD_FLAGS_NOSTACKALLOC; \
+    } while(0)
+
+
+/* function prototypes */
+void asm_perform_threadswitch(u1 **from, u1 **to, u1 **stackTop);
+u1*  asm_initialize_thread_stack(void *func, u1 *stack);
+
+#else // defined(NATIVE_THREADS)
+#include "nativethread.h"
 #endif
 
 #else
@@ -156,6 +211,7 @@ extern thread *threadQhead[MAX_THREAD_PRIO + 1];
 #define intsDisable()
 #define intsRestore()
 
-#endif
+#endif /* USE_THREADS */
+
+#endif /* _THREAD_H */
 
-#endif