1 /* src/native/llni.h - low level native interfarce (LLNI)
3 Copyright (C) 2007 R. Grafl, A. Krall, C. Kruegel,
4 C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
5 E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
6 J. Wenninger, Institut f. Computersprachen - TU Wien
8 This file is part of CACAO.
10 This program is free software; you can redistribute it and/or
11 modify it under the terms of the GNU General Public License as
12 published by the Free Software Foundation; either version 2, or (at
13 your option) any later version.
15 This program is distributed in the hope that it will be useful, but
16 WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
25 $Id: llni.h 8368 2007-08-20 21:36:53Z michi $
35 #include "native/localref.h"
38 /* LLNI macros *****************************************************************
40 The following macros should be used whenever a Java Object is
41 accessed in native code without the use of an JNI function.
43 LLNI_field_set_val, LLNI_field_get_val:
44 Deal with primitive values like integer and float values. Do
45 not use these macros to access pointers or references!
47 LLNI_field_set_ref, LLNI_field_get_ref:
48 Deal with references to other objects.
50 LLNI_field_set_cls, LLNI_field_get_cls:
51 Deal with references to Java Classes which are internally
52 represented by classinfo or java_lang_Class.
54 *******************************************************************************/
56 #define LLNI_field_set_val(obj, field, value) \
57 LLNI_field_direct(obj, field) = (value)
59 #define LLNI_field_set_ref(obj, field, reference) \
60 LLNI_field_direct(obj, field) = LLNI_DIRECT(reference)
62 #define LLNI_field_set_cls(obj, field, value) \
63 LLNI_field_direct(obj, field) = (java_lang_Class *) (value)
65 #define LLNI_field_get_val(obj, field, variable) \
66 (variable) = LLNI_field_direct(obj, field)
68 #define LLNI_field_get_ref(obj, field, variable) \
69 (variable) = LLNI_WRAP(LLNI_field_direct(obj, field))
71 #define LLNI_field_get_cls(obj, field, variable) \
72 (variable) = (classinfo *) LLNI_field_direct(obj, field)
74 #define LLNI_class_get(obj, variable) \
75 (variable) = LLNI_field_direct((java_handle_t *) obj, vftbl->class)
78 /* LLNI classinfo wrapping / unwrapping macros *********************************
80 The following macros are used to wrap or unwrap a classinfo from
81 or into a handle (typically java_lang_Class). No critical sections
82 are needed here, because classinfos are not placed on the GC heap.
84 XXX This might change once we implement Class Unloading!
86 *******************************************************************************/
88 #define LLNI_classinfo_wrap(classinfo) \
89 ((java_lang_Class *) LLNI_WRAP(classinfo))
91 #define LLNI_classinfo_unwrap(clazz) \
92 ((classinfo *) LLNI_UNWRAP((java_handle_t *) (clazz)))
95 /* XXX the direct macros have to be used inside a critical section!!! */
97 #define LLNI_field_direct(obj, field) (LLNI_DIRECT(obj)->field)
98 #define LLNI_vftbl_direct(obj) (LLNI_DIRECT((java_handle_t *) (obj))->vftbl)
99 #define LLNI_array_direct(arr, index) (LLNI_DIRECT(arr)->data[(index)])
100 #define LLNI_array_data(arr) (LLNI_DIRECT(arr)->data)
101 #define LLNI_array_size(arr) (LLNI_DIRECT((java_handle_objectarray_t *) (arr))->header.size)
104 /* XXX document me */
106 #define LLNI_objectarray_element_set(arr, index, reference) \
107 LLNI_array_direct(arr, index) = LLNI_DIRECT(reference)
109 #define LLNI_objectarray_element_get(arr, index, variable) \
110 (variable) = LLNI_WRAP(LLNI_array_direct(arr, index))
113 /* LLNI wrapping / unwrapping macros *******************************************
115 ATTENTION: Only use these macros inside a LLNI critical section!
116 Once the ciritical section ends, all pointers onto the GC heap
117 retrieved through these macros are void!
119 *******************************************************************************/
121 #if defined(ENABLE_HANDLES)
122 # define LLNI_WRAP(obj) ((obj) == NULL ? NULL : localref_add(obj))
123 # define LLNI_UNWRAP(hdl) ((hdl) == NULL ? NULL : (hdl)->heap_object)
124 # define LLNI_DIRECT(obj) ((obj)->heap_object)
126 # define LLNI_WRAP(obj) ((java_handle_t *) obj)
127 # define LLNI_UNWRAP(hdl) ((java_object_t *) hdl)
128 # define LLNI_DIRECT(obj) (obj)
132 /* LLNI critical sections ******************************************************
134 These macros handle the LLNI critical sections. While a critical
135 section is active, the absolute position of objects on the GC heap
136 is not allowed to change (no moving Garbage Collection).
138 ATTENTION: Use a critical section whenever you have a direct
139 pointer onto the GC heap!
141 *******************************************************************************/
143 #if defined(ENABLE_THREADS) && defined(ENABLE_GC_CACAO)
144 void llni_critical_start(void);
145 void llni_critical_end(void);
146 # define LLNI_CRITICAL_START llni_critical_start()
147 # define LLNI_CRITICAL_END llni_critical_end()
149 # define LLNI_CRITICAL_START
150 # define LLNI_CRITICAL_END
158 * These are local overrides for various environment variables in Emacs.
159 * Please do not remove this and leave it at the end of the file, where
160 * Emacs will automagically detect them.
161 * ---------------------------------------------------------------------
164 * indent-tabs-mode: t