* Updated header: Added 2006. Changed address of FSF. Changed email
[cacao.git] / src / threads / native / threads.h
index f53f22d67de852976115da97ad47eb3e3a380f5c..0b41d448aa1af9ef683a89940d6e326e59359503 100644 (file)
@@ -1,9 +1,9 @@
 /* src/threads/native/threads.h - native threads header
 
-   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, 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: Stefan Ring
 
    Changes: Christian Thalinger
 
-   $Id: threads.h 2739 2005-06-20 09:53:53Z twisti $
+   $Id: threads.h 4357 2006-01-22 23:33:38Z twisti $
 
 */
 
 
 #include <pthread.h>
 #include <semaphore.h>
+#include <ucontext.h>
+
+#include "config.h"
+#include "vm/types.h"
+
+#include "config.h"
+#include "vm/types.h"
 
 #include "mm/memory.h"
 #include "native/jni.h"
 #include "native/include/java_lang_Object.h" /* required by java/lang/VMThread*/
 #include "native/include/java_lang_Thread.h"
 #include "native/include/java_lang_VMThread.h"
+#include "vm/global.h"
 
 #if defined(__DARWIN__)
 #include <mach/mach.h>
@@ -100,9 +108,11 @@ struct nativethread {
        threadobject      *next;
        threadobject      *prev;
        java_objectheader *_exceptionptr;
-       u1                 _dontfillinexceptionstacktrace;
-       methodinfo        *_threadrootmethod;
        void              *_stackframeinfo;
+       localref_table    *_localref_table; /* JNI local references               */
+#if defined(ENABLE_INTRP)
+       void              *_global_sp;
+#endif
        pthread_t          tid;
 #if defined(__DARWIN__)
        mach_port_t        mach_thread;
@@ -114,15 +124,16 @@ struct nativethread {
 
 /* threadobject ****************************************************************
 
-   DOCUMENT ME!
+   Every java.lang.VMThread object is actually an instance of this structure.
 
 *******************************************************************************/
 
 struct threadobject {
        java_lang_VMThread  o;
-       nativethread        info;
-       ExecEnvironment     ee;
+       nativethread        info;           /* some general pthreads stuff        */
+       ExecEnvironment     ee;             /* contains our lock record pool      */
 
+       /* these are used for the wait/notify implementation                      */
        pthread_mutex_t     waitLock;
        pthread_cond_t      waitCond;
        bool                interrupted;
@@ -132,13 +143,19 @@ struct threadobject {
        dumpinfo            dumpinfo;       /* dump memory info structure         */
 };
 
+/* monitorLockRecord ***********************************************************
+
+   This is the really interesting stuff.
+   See handbook for a detailed description.
+
+*******************************************************************************/
 
 struct monitorLockRecord {
        threadobject      *ownerThread;
        java_objectheader *o;
-       int                lockCount;
+       s4                 lockCount;
        monitorLockRecord *nextFree;
-       int                queuers;
+       s4                 queuers;
        monitorLockRecord *waiter;
        monitorLockRecord *incharge;
        bool               waiting;
@@ -148,7 +165,6 @@ struct monitorLockRecord {
 };
 
 
-
 struct lockRecordPoolHeader {
        lockRecordPool *next;
        int             size;
@@ -164,17 +180,23 @@ monitorLockRecord *monitorEnter(threadobject *, java_objectheader *);
 bool monitorExit(threadobject *, java_objectheader *);
 
 bool threadHoldsLock(threadobject *t, java_objectheader *o);
-void signal_cond_for_object (java_objectheader *obj);
-void broadcast_cond_for_object (java_objectheader *obj);
-void wait_cond_for_object (java_objectheader *obj, s8 time, s4 nanos);
+void signal_cond_for_object(java_objectheader *obj);
+void broadcast_cond_for_object(java_objectheader *obj);
+void wait_cond_for_object(java_objectheader *obj, s8 time, s4 nanos);
+
+void *thread_getself(void);
+
+void threads_preinit(void);
+bool threads_init(u1 *stackbottom);
 
-void initThreadsEarly();
-void initThreads(u1 *stackbottom);
 void initObjectLock(java_objectheader *);
 monitorLockRecord *get_dummyLR(void);
 void initLocks();
 void initThread(java_lang_VMThread *);
-void startThread(thread *t);
+
+/* start a thread */
+void threads_start_thread(thread *t, functionptr function);
+
 void joinAllThreads();
 
 void sleepThread(s8 millis, s4 nanos);
@@ -197,12 +219,20 @@ void thread_registercritical(threadcritnode *);
 u1 *thread_checkcritical(u1*);
 
 extern volatile int stopworldwhere;
+extern threadobject *mainthreadobj;
+
+extern pthread_mutex_t pool_lock;
+extern lockRecordPool *global_pool;
+
 
 void cast_stopworld();
 void cast_startworld();
 
 /* dumps all threads */
-void thread_dump(void);
+void threads_dump(void);
+
+/* this is a machine dependent functions (src/vm/jit/$(ARCH_DIR)/md.c) */
+void thread_restartcriticalsection(ucontext_t *);
 
 #endif /* _THREADS_H */