CACAO
threadobject.hpp
Go to the documentation of this file.
1 /* src/threads/threadobject.hpp - Thread data structure
2 
3  Copyright (C) 1996-2013
4  CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
5 
6  This file is part of CACAO.
7 
8  This program is free software; you can redistribute it and/or
9  modify it under the terms of the GNU General Public License as
10  published by the Free Software Foundation; either version 2, or (at
11  your option) any later version.
12 
13  This program is distributed in the hope that it will be useful, but
14  WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with this program; if not, write to the Free Software
20  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21  02110-1301, USA.
22 
23 */
24 
25 
26 #ifndef THREADOBJECT_HPP_
27 #define THREADOBJECT_HPP_ 1
28 
29 #ifndef THREAD_HPP_
30 # error "Do not directly include this header, include threads/thread.hpp instead"
31 #endif
32 
33 #include "config.h"
34 #include "vm/types.hpp"
35 
36 #if defined(ENABLE_TLH)
37 # include "mm/tlh.hpp"
38 #endif
39 
40 #include "threads/condition.hpp"
41 #include "threads/mutex.hpp"
42 
43 #if defined(ENABLE_THREADS)
44 # include "threads/posix/threadobject-posix.hpp"
45 #else
46 # include "threads/none/threadobject-none.hpp"
47 #endif
48 
49 /* forward declarations */
50 class DumpMemory;
51 
52 /* threadobject ****************************************************************
53 
54  Struct holding thread local variables.
55 
56 *******************************************************************************/
57 
58 struct threadobject {
59  detail::threadobject impl; // platform specific thread data
60 
61  java_object_t *object; /* link to java.lang.Thread object */
62 
63  ptrint thinlock; /* pre-computed thin lock value */
64 
65  s4 index; /* thread index, starting with 1 */
66  u4 flags; /* flag field */
67  ThreadState state; /* state field */
68  bool is_in_active_list; /* for debugging only */
69 
70  /* for the sable tasuki lock extension */
71  bool flc_bit;
72  struct threadobject *flc_list; /* FLC list head for this thread */
73  struct threadobject *flc_tail; /* tail pointer for FLC list */
74  struct threadobject *flc_next; /* next pointer for FLC list */
76  Mutex* flc_lock; /* controlling access to these fields */
78 
79  /* these are used for the wait/notify implementation */
82 
83  Mutex* suspendmutex; /* lock before suspending this thread */
84  Condition* suspendcond; /* notify to resume this thread */
85 
86  bool interrupted;
87  bool signaled;
88  bool park_permit;
89 
90  bool suspended; /* is this thread suspended? */
91  SuspendReason suspend_reason; /* reason for suspending */
92 
93  u1 *pc; /* current PC (used for profiling) */
94 
95  java_object_t *_exceptionptr; /* current exception */
96  struct stackframeinfo_t *_stackframeinfo; /* current native stackframeinfo */
97  struct localref_table *_localref_table; /* JNI local references */
98 
99 #if defined(ENABLE_INTRP)
100  Cell *_global_sp; /* stack pointer for interpreter */
101 #endif
102 
103 #if defined(ENABLE_GC_CACAO)
104  bool gc_critical; /* indicates a critical section */
105 
106  sourcestate_t *ss;
107  executionstate_t *es;
108 #endif
109 
110  DumpMemory* _dumpmemory; ///< Dump memory structure.
111 
112 #if defined(ENABLE_DEBUG_FILTER)
113  u2 filterverbosecallctr[2]; /* counters for verbose call filter */
114 #endif
115 
116 #if !defined(NDEBUG)
119 #endif
120 
121 #if defined(ENABLE_TLH)
122  tlh_t tlh;
123 #endif
124 
125 #if defined(ENABLE_ESCAPE_REASON)
126  void *escape_reasons;
127 #endif
128 };
129 
130 
131 /* current threadobject *******************************************************/
132 
133 #if defined(HAVE___THREAD)
134 
135 #define THREADOBJECT thread_current
136 
137 extern __thread threadobject *thread_current;
138 
139 #else /* defined(HAVE___THREAD) */
140 
141 #define THREADOBJECT \
142  ((threadobject *) pthread_getspecific(thread_current_key))
143 
144 extern pthread_key_t thread_current_key;
145 
146 #endif /* defined(HAVE___THREAD) */
147 
148 
149 /* native-world flags *********************************************************/
150 
151 #if defined(ENABLE_GC_CACAO)
152 # define THREAD_NATIVEWORLD_ENTER THREADOBJECT->flags |= THREAD_FLAG_IN_NATIVE
153 # define THREAD_NATIVEWORLD_EXIT THREADOBJECT->flags &= ~THREAD_FLAG_IN_NATIVE
154 #else
155 # define THREAD_NATIVEWORLD_ENTER /*nop*/
156 # define THREAD_NATIVEWORLD_EXIT /*nop*/
157 #endif
158 
159 
160 /* counter for verbose call filter ********************************************/
161 
162 #if defined(ENABLE_DEBUG_FILTER)
163 # define FILTERVERBOSECALLCTR (THREADOBJECT->filterverbosecallctr)
164 #endif
165 
166 /* state for trace java call **************************************************/
167 
168 #if !defined(NDEBUG)
169 # define TRACEJAVACALLINDENT (THREADOBJECT->tracejavacallindent)
170 # define TRACEJAVACALLCOUNT (THREADOBJECT->tracejavacallcount)
171 #endif
172 
173 inline static threadobject* thread_get_current(void);
174 
175 
176 // Includes.
177 #include "native/localref.hpp"
178 
179 #include "threads/lock.hpp"
180 
181 #include "vm/global.hpp"
182 #include "vm/vm.hpp"
183 
184 #if defined(ENABLE_GC_CACAO)
185 # include "vm/jit/executionstate.hpp"
186 # include "vm/jit/replace.hpp"
187 #endif
188 
189 #if defined(ENABLE_INTRP)
190 #include "vm/jit/intrp/intrp.h"
191 #endif
192 
193 
194 /* inline functions ***********************************************************/
195 
196 /**
197  * Return the Thread object of the current thread.
198  *
199  * @return The current Thread object.
200  */
201 inline static threadobject* thread_get_current(void)
202 {
203  threadobject *t;
204 
205 #if defined(HAVE___THREAD)
206  t = thread_current;
207 #else
208  t = (threadobject *) pthread_getspecific(thread_current_key);
209 #endif
210 
211  return t;
212 }
213 
214 
215 /**
216  * Set the current Thread object.
217  *
218  * @param t The thread object to set.
219  */
220 inline static void thread_set_current(threadobject* t)
221 {
222 #if defined(HAVE___THREAD)
223  thread_current = t;
224 #else
225  int result;
226 
227  result = pthread_setspecific(thread_current_key, t);
228 
229  if (result != 0)
230  //os::abort_errnum(result, "thread_set_current: pthread_setspecific failed");
231  vm_abort("thread_set_current: pthread_setspecific failed");
232 #endif
233 }
234 
235 
237 {
238  return THREADOBJECT->_stackframeinfo;
239 }
240 
242 {
243  THREADOBJECT->_stackframeinfo = sfi;
244 }
245 
246 #endif
247 
248 /*
249  * These are local overrides for various environment variables in Emacs.
250  * Please do not remove this and leave it at the end of the file, where
251  * Emacs will automagically detect them.
252  * ---------------------------------------------------------------------
253  * Local variables:
254  * mode: c++
255  * indent-tabs-mode: t
256  * c-basic-offset: 4
257  * tab-width: 4
258  * End:
259  * vim:noexpandtab:sw=4:ts=4:
260  */
SuspendReason
Definition: thread.hpp:65
Mutex * waitmutex
Definition: thread.hpp:113
bool park_permit
Definition: thread.hpp:121
Mutex * suspendmutex
Definition: thread.hpp:116
s8 Cell
Definition: intrp.h:42
detail::threadobject impl
struct stackframeinfo_t * _stackframeinfo
struct threadobject * flc_list
Definition: thread.hpp:105
Definition: tlh.hpp:34
Dummy implementation of a mutex.
Definition: mutex-none.hpp:33
uint8_t u1
Definition: types.hpp:40
struct threadobject * flc_next
Definition: thread.hpp:107
void vm_abort(const char *text,...)
Definition: vm.cpp:2586
Mutex * flc_lock
Definition: thread.hpp:109
ptrint thinlock
Definition: thread.hpp:95
Condition * waitcond
Definition: thread.hpp:114
struct localref_table * _localref_table
u4 tracejavacallcount
Definition: thread.hpp:151
java_object_t * _exceptionptr
Definition: thread.hpp:128
Condition * suspendcond
Definition: thread.hpp:117
bool suspended
Definition: thread.hpp:123
uint16_t u2
Definition: types.hpp:43
bool interrupted
Definition: thread.hpp:119
static void thread_set_current(threadobject *t)
Set the current Thread object.
static threadobject * thread_get_current(void)
Return the Thread object of the current thread.
SuspendReason suspend_reason
Definition: thread.hpp:124
Dummy condition variable.
threadobject * thread_current
Definition: thread-none.cpp:41
#define THREADOBJECT
int32_t s4
Definition: types.hpp:45
static struct stackframeinfo_t * threads_get_current_stackframeinfo(void)
ThreadState state
Definition: thread.hpp:97
struct threadobject * flc_tail
Definition: thread.hpp:106
static void threads_set_current_stackframeinfo(struct stackframeinfo_t *sfi)
bool flc_bit
Definition: thread.hpp:104
java_handle_t * flc_object
Definition: thread.hpp:108
s4 tracejavacallindent
Definition: thread.hpp:150
uint32_t u4
Definition: types.hpp:46
u2 filterverbosecallctr[2]
Definition: thread.hpp:146
bool signaled
Definition: thread.hpp:120
java_object_t * object
Definition: thread.hpp:93
Condition * flc_cond
Definition: thread.hpp:110
DumpMemory * _dumpmemory
Dump memory structure.
Definition: thread.hpp:143
bool is_in_active_list
Definition: thread.hpp:100
uintptr_t ptrint
Definition: types.hpp:54
Thread-local dump memory structure.
Definition: dumpmemory.hpp:60
ThreadState
Definition: thread.hpp:47