* configure.ac: New switch for disabling -O2 (--disable-optimizations).
[cacao.git] / src / native / llni.h
1 /* src/native/llni.h - low level native interfarce (LLNI)
2
3    Copyright (C) 2007, 2008
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 _LLNI_H
27 #define _LLNI_H
28
29 #include "config.h"
30
31 /* forward defines ************************************************************/
32
33 /* LLNI wrapping / unwrapping macros *******************************************
34
35    ATTENTION: Only use these macros inside a LLNI critical section!
36    Once the ciritical section ends, all pointers onto the GC heap
37    retrieved through these macros are void!
38
39 *******************************************************************************/
40
41 #if defined(ENABLE_HANDLES)
42 # define LLNI_WRAP(obj)      ((obj) == NULL ? NULL : localref_add(obj))
43 # define LLNI_UNWRAP(hdl)    ((hdl) == NULL ? NULL : (hdl)->heap_object)
44 # define LLNI_QUICKWRAP(obj) ((obj) == NULL ? NULL : &(obj))
45 # define LLNI_DIRECT(hdl)    ((hdl)->heap_object)
46 #else
47 # define LLNI_WRAP(obj)      (obj)
48 # define LLNI_UNWRAP(hdl)    (hdl)
49 # define LLNI_QUICKWRAP(obj) (obj)
50 # define LLNI_DIRECT(hdl)    (hdl)
51 #endif
52
53
54 #include "native/localref.hpp"
55
56 #include "threads/thread.hpp"
57
58
59 #define LLNI_class_get(obj, variable) \
60         (variable) = LLNI_field_direct((java_handle_t *) obj, vftbl->clazz)
61
62
63 /* LLNI_equals ****************************************************************
64  
65    Test if two java_handle_t* point to the same java_object_t*.
66
67 ******************************************************************************/
68
69 #define LLNI_equals(obj1, obj2, result) \
70         LLNI_CRITICAL_START; \
71         (result) = LLNI_UNWRAP(obj1) == LLNI_UNWRAP(obj2); \
72         LLNI_CRITICAL_END
73         
74
75 /* LLNI_classinfo_field_get ***************************************************
76  
77    Get a field from classinfo that is a java object.
78
79 ******************************************************************************/
80
81 #define LLNI_classinfo_field_get(cls, field, variable) \
82         LLNI_CRITICAL_START; \
83         (variable) = LLNI_WRAP((cls)->field); \
84         LLNI_CRITICAL_END
85
86
87 /* LLNI_classinfo_field_set ***************************************************
88  
89    Set a field from classinfo that is a java object.
90
91 ******************************************************************************/
92
93 #define LLNI_classinfo_field_set(cls, field, variable) \
94         LLNI_CRITICAL_START; \
95         (cls)->field = LLNI_UNWRAP(variable); \
96         LLNI_CRITICAL_END
97
98
99 /* LLNI classinfo wrapping / unwrapping macros *********************************
100
101    The following macros are used to wrap or unwrap a classinfo from
102    or into a handle (typically java_lang_Class). No critical sections
103    are needed here, because classinfos are not placed on the GC heap.
104
105    XXX This might change once we implement Class Unloading!
106
107 *******************************************************************************/
108
109 #define LLNI_classinfo_wrap(classinfo) \
110         ((java_handle_t*) LLNI_WRAP(classinfo))
111
112 #define LLNI_classinfo_unwrap(clazz) \
113         ((classinfo *) LLNI_UNWRAP((java_handle_t *) (clazz)))
114
115
116 /* XXX the direct macros have to be used inside a critical section!!! */
117
118 #define LLNI_field_direct(obj, field) (LLNI_DIRECT(obj)->field)
119 #define LLNI_vftbl_direct(obj)        (LLNI_DIRECT((java_handle_t *) (obj))->vftbl)
120
121
122 /* LLNI critical sections ******************************************************
123
124    These macros handle the LLNI critical sections. While a critical
125    section is active, the absolute position of objects on the GC heap
126    is not allowed to change (no moving Garbage Collection).
127
128    ATTENTION: Use a critical section whenever you have a direct
129    pointer onto the GC heap!
130
131 *******************************************************************************/
132
133 #if defined(ENABLE_THREADS) && defined(ENABLE_GC_CACAO)
134 # define LLNI_CRITICAL_START           llni_critical_start()
135 # define LLNI_CRITICAL_END             llni_critical_end()
136 # define LLNI_CRITICAL_START_THREAD(t) llni_critical_start_thread(t)
137 # define LLNI_CRITICAL_END_THREAD(t)   llni_critical_end_thread(t)
138 #else
139 # define LLNI_CRITICAL_START
140 # define LLNI_CRITICAL_END
141 # define LLNI_CRITICAL_START_THREAD(t)
142 # define LLNI_CRITICAL_END_THREAD(t)
143 #endif
144
145 #ifdef __cplusplus
146 extern "C" {
147 #endif
148
149 void llni_critical_start();
150 void llni_critical_end();
151 void llni_critical_start_thread(threadobject *t);
152 void llni_critical_end_thread(threadobject *t);
153
154 #ifdef __cplusplus
155 }
156 #endif
157
158 #endif /* _LLNI_H */
159
160
161 /*
162  * These are local overrides for various environment variables in Emacs.
163  * Please do not remove this and leave it at the end of the file, where
164  * Emacs will automagically detect them.
165  * ---------------------------------------------------------------------
166  * Local variables:
167  * mode: c
168  * indent-tabs-mode: t
169  * c-basic-offset: 4
170  * tab-width: 4
171  * End:
172  */