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
35 /* forward defines ************************************************************/
37 /* LLNI wrapping / unwrapping macros *******************************************
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!
43 *******************************************************************************/
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)
51 # define LLNI_WRAP(obj) (obj)
52 # define LLNI_UNWRAP(hdl) (hdl)
53 # define LLNI_QUICKWRAP(obj) (obj)
54 # define LLNI_DIRECT(hdl) (hdl)
58 #include "native/localref.h"
60 #include "threads/thread.hpp"
63 #define LLNI_class_get(obj, variable) \
64 (variable) = LLNI_field_direct((java_handle_t *) obj, vftbl->clazz)
67 /* LLNI_equals ****************************************************************
69 Test if two java_handle_t* point to the same java_object_t*.
71 ******************************************************************************/
73 #define LLNI_equals(obj1, obj2, result) \
74 LLNI_CRITICAL_START; \
75 (result) = LLNI_UNWRAP(obj1) == LLNI_UNWRAP(obj2); \
79 /* LLNI_classinfo_field_get ***************************************************
81 Get a field from classinfo that is a java object.
83 ******************************************************************************/
85 #define LLNI_classinfo_field_get(cls, field, variable) \
86 LLNI_CRITICAL_START; \
87 (variable) = LLNI_WRAP((cls)->field); \
91 /* LLNI_classinfo_field_set ***************************************************
93 Set a field from classinfo that is a java object.
95 ******************************************************************************/
97 #define LLNI_classinfo_field_set(cls, field, variable) \
98 LLNI_CRITICAL_START; \
99 (cls)->field = LLNI_UNWRAP(variable); \
103 /* LLNI classinfo wrapping / unwrapping macros *********************************
105 The following macros are used to wrap or unwrap a classinfo from
106 or into a handle (typically java_lang_Class). No critical sections
107 are needed here, because classinfos are not placed on the GC heap.
109 XXX This might change once we implement Class Unloading!
111 *******************************************************************************/
113 #define LLNI_classinfo_wrap(classinfo) \
114 ((java_handle_t*) LLNI_WRAP(classinfo))
116 #define LLNI_classinfo_unwrap(clazz) \
117 ((classinfo *) LLNI_UNWRAP((java_handle_t *) (clazz)))
120 /* XXX the direct macros have to be used inside a critical section!!! */
122 #define LLNI_field_direct(obj, field) (LLNI_DIRECT(obj)->field)
123 #define LLNI_vftbl_direct(obj) (LLNI_DIRECT((java_handle_t *) (obj))->vftbl)
124 #define LLNI_array_direct(arr, index) (LLNI_DIRECT(arr)->data[(index)])
125 #define LLNI_array_data(arr) (LLNI_DIRECT(arr)->data)
126 #define LLNI_array_size(arr) (LLNI_DIRECT((java_handle_objectarray_t *) (arr))->header.size)
129 /* LLNI critical sections ******************************************************
131 These macros handle the LLNI critical sections. While a critical
132 section is active, the absolute position of objects on the GC heap
133 is not allowed to change (no moving Garbage Collection).
135 ATTENTION: Use a critical section whenever you have a direct
136 pointer onto the GC heap!
138 *******************************************************************************/
140 #if defined(ENABLE_THREADS) && defined(ENABLE_GC_CACAO)
141 # define LLNI_CRITICAL_START llni_critical_start()
142 # define LLNI_CRITICAL_END llni_critical_end()
143 # define LLNI_CRITICAL_START_THREAD(t) llni_critical_start_thread(t)
144 # define LLNI_CRITICAL_END_THREAD(t) llni_critical_end_thread(t)
146 # define LLNI_CRITICAL_START
147 # define LLNI_CRITICAL_END
148 # define LLNI_CRITICAL_START_THREAD(t)
149 # define LLNI_CRITICAL_END_THREAD(t)
152 void llni_critical_start();
153 void llni_critical_end();
154 void llni_critical_start_thread(threadobject *t);
155 void llni_critical_end_thread(threadobject *t);
165 * These are local overrides for various environment variables in Emacs.
166 * Please do not remove this and leave it at the end of the file, where
167 * Emacs will automagically detect them.
168 * ---------------------------------------------------------------------
171 * indent-tabs-mode: t