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.hpp"
56 #include "threads/thread.hpp"
59 #define LLNI_class_get(obj, variable) \
60 (variable) = LLNI_field_direct((java_handle_t *) obj, vftbl->clazz)
63 /* LLNI_equals ****************************************************************
65 Test if two java_handle_t* point to the same java_object_t*.
67 ******************************************************************************/
69 #define LLNI_equals(obj1, obj2, result) \
70 LLNI_CRITICAL_START; \
71 (result) = LLNI_UNWRAP(obj1) == LLNI_UNWRAP(obj2); \
75 /* LLNI_classinfo_field_get ***************************************************
77 Get a field from classinfo that is a java object.
79 ******************************************************************************/
81 #define LLNI_classinfo_field_get(cls, field, variable) \
82 LLNI_CRITICAL_START; \
83 (variable) = LLNI_WRAP((cls)->field); \
87 /* LLNI_classinfo_field_set ***************************************************
89 Set a field from classinfo that is a java object.
91 ******************************************************************************/
93 #define LLNI_classinfo_field_set(cls, field, variable) \
94 LLNI_CRITICAL_START; \
95 (cls)->field = LLNI_UNWRAP(variable); \
99 /* LLNI classinfo wrapping / unwrapping macros *********************************
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.
105 XXX This might change once we implement Class Unloading!
107 *******************************************************************************/
109 #define LLNI_classinfo_wrap(classinfo) \
110 ((java_handle_t*) LLNI_WRAP(classinfo))
112 #define LLNI_classinfo_unwrap(clazz) \
113 ((classinfo *) LLNI_UNWRAP((java_handle_t *) (clazz)))
116 /* XXX the direct macros have to be used inside a critical section!!! */
118 #define LLNI_field_direct(obj, field) (LLNI_DIRECT(obj)->field)
119 #define LLNI_vftbl_direct(obj) (LLNI_DIRECT((java_handle_t *) (obj))->vftbl)
122 /* LLNI critical sections ******************************************************
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).
128 ATTENTION: Use a critical section whenever you have a direct
129 pointer onto the GC heap!
131 *******************************************************************************/
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)
139 # define LLNI_CRITICAL_START
140 # define LLNI_CRITICAL_END
141 # define LLNI_CRITICAL_START_THREAD(t)
142 # define LLNI_CRITICAL_END_THREAD(t)
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);
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 * ---------------------------------------------------------------------
168 * indent-tabs-mode: t