1 /* src/native/llni.h - low level native interfarce (LLNI)
3 Copyright (C) 2007, 2008
4 CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
6 This file is part of CACAO.
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.
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.
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
31 /* forward defines ************************************************************/
33 /* LLNI wrapping / unwrapping macros *******************************************
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!
39 *******************************************************************************/
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)
47 # define LLNI_WRAP(obj) (obj)
48 # define LLNI_UNWRAP(hdl) (hdl)
49 # define LLNI_QUICKWRAP(obj) (obj)
50 # define LLNI_DIRECT(hdl) (hdl)
54 #include "native/localref.h"
56 #include "threads/thread.h"
59 /* LLNI macros *****************************************************************
61 The following macros should be used whenever a Java Object is
62 accessed in native code without the use of an JNI function.
64 LLNI_field_set_val, LLNI_field_get_val:
65 Deal with primitive values like integer and float values. Do
66 not use these macros to access pointers or references!
68 LLNI_field_set_ref, LLNI_field_get_ref:
69 Deal with references to other objects.
71 LLNI_field_set_cls, LLNI_field_get_cls:
72 Deal with references to Java Classes which are internally
73 represented by classinfo or java_lang_Class.
75 *******************************************************************************/
77 #define LLNI_field_set_val(obj, field, value) \
78 LLNI_field_direct(obj, field) = (value)
80 #define LLNI_field_set_ref(obj, field, reference) \
81 LLNI_field_direct(obj, field) = LLNI_UNWRAP(reference)
83 #define LLNI_field_set_cls(obj, field, value) \
84 LLNI_field_direct(obj, field) = (java_lang_Class *) (value)
86 #define LLNI_field_get_val(obj, field, variable) \
87 (variable) = LLNI_field_direct(obj, field)
89 #define LLNI_field_get_ref(obj, field, variable) \
90 (variable) = LLNI_WRAP(LLNI_field_direct(obj, field))
92 #define LLNI_field_get_cls(obj, field, variable) \
93 (variable) = (classinfo *) LLNI_field_direct(obj, field)
95 #define LLNI_class_get(obj, variable) \
96 (variable) = LLNI_field_direct((java_handle_t *) obj, vftbl->class)
99 /* LLNI_equals ****************************************************************
101 Test if two java_handle_t* point to the same java_object_t*.
103 ******************************************************************************/
105 #define LLNI_equals(obj1, obj2, result) \
106 LLNI_CRITICAL_START; \
107 (result) = LLNI_UNWRAP(obj1) == LLNI_UNWRAP(obj2); \
111 /* LLNI_classinfo_field_get ***************************************************
113 Get a field from classinfo that is a java object.
115 ******************************************************************************/
117 #define LLNI_classinfo_field_get(cls, field, variable) \
118 LLNI_CRITICAL_START; \
119 (variable) = LLNI_WRAP((cls)->field); \
123 /* LLNI_classinfo_field_set ***************************************************
125 Set a field from classinfo that is a java object.
127 ******************************************************************************/
129 #define LLNI_classinfo_field_set(cls, field, variable) \
130 LLNI_CRITICAL_START; \
131 (cls)->field = LLNI_UNWRAP(variable); \
135 /* LLNI classinfo wrapping / unwrapping macros *********************************
137 The following macros are used to wrap or unwrap a classinfo from
138 or into a handle (typically java_lang_Class). No critical sections
139 are needed here, because classinfos are not placed on the GC heap.
141 XXX This might change once we implement Class Unloading!
143 *******************************************************************************/
145 #define LLNI_classinfo_wrap(classinfo) \
146 ((java_lang_Class *) LLNI_WRAP(classinfo))
148 #define LLNI_classinfo_unwrap(clazz) \
149 ((classinfo *) LLNI_UNWRAP((java_handle_t *) (clazz)))
152 /* XXX the direct macros have to be used inside a critical section!!! */
154 #define LLNI_field_direct(obj, field) (LLNI_DIRECT(obj)->field)
155 #define LLNI_vftbl_direct(obj) (LLNI_DIRECT((java_handle_t *) (obj))->vftbl)
156 #define LLNI_array_direct(arr, index) (LLNI_DIRECT(arr)->data[(index)])
157 #define LLNI_array_data(arr) (LLNI_DIRECT(arr)->data)
158 #define LLNI_array_size(arr) (LLNI_DIRECT((java_handle_objectarray_t *) (arr))->header.size)
161 /* LLNI critical sections ******************************************************
163 These macros handle the LLNI critical sections. While a critical
164 section is active, the absolute position of objects on the GC heap
165 is not allowed to change (no moving Garbage Collection).
167 ATTENTION: Use a critical section whenever you have a direct
168 pointer onto the GC heap!
170 *******************************************************************************/
172 #if defined(ENABLE_THREADS) && defined(ENABLE_GC_CACAO)
173 # define LLNI_CRITICAL_START llni_critical_start()
174 # define LLNI_CRITICAL_END llni_critical_end()
175 # define LLNI_CRITICAL_START_THREAD(t) llni_critical_start_thread(t)
176 # define LLNI_CRITICAL_END_THREAD(t) llni_critical_end_thread(t)
178 # define LLNI_CRITICAL_START
179 # define LLNI_CRITICAL_END
180 # define LLNI_CRITICAL_START_THREAD(t)
181 # define LLNI_CRITICAL_END_THREAD(t)
184 void llni_critical_start();
185 void llni_critical_end();
186 void llni_critical_start_thread(threadobject *t);
187 void llni_critical_end_thread(threadobject *t);
194 * These are local overrides for various environment variables in Emacs.
195 * Please do not remove this and leave it at the end of the file, where
196 * Emacs will automagically detect them.
197 * ---------------------------------------------------------------------
200 * indent-tabs-mode: t