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