* src/native/jni.hpp (JNI_VERSION_CACAO): Added to be able to reveal ourselves.
[cacao.git] / src / native / jni.hpp
1 /* src/native/jni.hpp - JNI types and data structures
2
3    Copyright (C) 1996-2005, 2006, 2007, 2008
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 /* jni.hpp *********************************************************************
27
28    ATTENTION: We include this file before we actually define our own
29    jni.h.  We do this because otherwise we can get into unresolvable
30    circular header dependencies.
31
32    GNU Classpath's headers define:
33
34    #define __CLASSPATH_JNI_MD_H__
35    #define _CLASSPATH_JNI_H
36
37    and jni.h uses:
38
39    _CLASSPATH_VM_JNI_TYPES_DEFINED
40    
41    OpenJDK's headers define:
42
43    #define _JAVASOFT_JNI_MD_H_
44    #define _JAVASOFT_JNI_H_
45
46    and jni.h uses:
47
48    JNI_TYPES_ALREADY_DEFINED_IN_JNI_MD_H
49
50    CLASSPATH_JNI_MD_H and CLASSPATH_JNI_H are defined in config.h.
51
52    We include both headers (jni.h and jni_md.h) with the absolute path
53    so we can be sure that the preprocessor does not pick up another
54    header from the search path.  Furthermore we include jni_md.h
55    before jni.h as the latter includes the former.
56
57 *******************************************************************************/
58
59
60 #ifndef _JNI_HPP
61 #define _JNI_HPP
62
63 #include "config.h"
64
65 #include <stdbool.h>
66 #include <stdint.h>
67
68
69 // Define these to override the typedefs in jni.h
70 #define _CLASSPATH_VM_JNI_TYPES_DEFINED          1 // GNU Classpath
71 #define JNI_TYPES_ALREADY_DEFINED_IN_JNI_MD_H    1 // OpenJDK
72
73 // First include jni_md.h so we have the Java primitive types.
74 #include INCLUDE_JNI_MD_H
75
76
77 // Include the C++ wrapper classes.
78 //#include "vm/javaobjects.hpp"
79 #include "vm/global.h"
80
81
82 // Some additional JNI version numbers, we currently support JNI 1.6.
83 #define JNI_VERSION_SUPPORTED JNI_VERSION_1_6
84 #define JNI_VERSION_CACAO     0xcaca0000
85
86
87 // Typedef the JNI types.
88 typedef java_handle_t*              jobject;
89 typedef java_handle_t*              jclass;
90 typedef java_handle_t*              jstring;
91 typedef java_handle_t*              jthrowable;
92 typedef java_handle_t*              jweak; // FIXME
93 typedef java_handle_array_t*        jarray;
94 typedef java_handle_objectarray_t*  jobjectArray;
95 typedef java_handle_booleanarray_t* jbooleanArray;
96 typedef java_handle_bytearray_t*    jbyteArray;
97 typedef java_handle_chararray_t*    jcharArray;
98 typedef java_handle_shortarray_t*   jshortArray;
99 typedef java_handle_intarray_t*     jintArray;
100 typedef java_handle_longarray_t*    jlongArray;
101 typedef java_handle_floatarray_t*   jfloatArray;
102 typedef java_handle_doublearray_t*  jdoubleArray;
103
104
105 // We need some additional stuff for the various JNI headers.
106 #if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH) || defined(WITH_JAVA_RUNTIME_LIBRARY_CLDC1_1)
107
108 // These typedefs and defines are copied from GNU Classpath's jni.h
109 #define JNI_TRUE true
110 #define JNI_FALSE false
111
112 typedef struct _Jv_JNIEnv JNIEnv;
113 typedef struct _Jv_JavaVM JavaVM;
114
115 #elif defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK)
116
117 // These typedefs are copied from OpenJDK's jni.h
118 typedef unsigned char   jboolean;
119 typedef unsigned short  jchar;
120 typedef short           jshort;
121 typedef float           jfloat;
122 typedef double          jdouble;
123
124 typedef jint            jsize;
125
126 typedef union jvalue {
127     jboolean z;
128     jbyte    b;
129     jchar    c;
130     jshort   s;
131     jint     i;
132     jlong    j;
133     jfloat   f;
134     jdouble  d;
135     jobject  l;
136 } jvalue;
137
138 struct _jfieldID;
139 typedef struct _jfieldID *jfieldID;
140
141 struct _jmethodID;
142 typedef struct _jmethodID *jmethodID;
143
144 /* Return values from jobjectRefType */
145 typedef enum _jobjectType {
146      JNIInvalidRefType    = 0,
147      JNILocalRefType      = 1,
148      JNIGlobalRefType     = 2,
149      JNIWeakGlobalRefType = 3
150 } jobjectRefType;
151
152 #endif
153
154
155 // Now include jni.h to complete the JNI header.
156 #include INCLUDE_JNI_H
157
158
159 // Includes.
160 #include "vm/global.h"
161
162
163 #ifdef __cplusplus
164 extern "C" {
165 #endif
166
167 /* CACAO related stuff ********************************************************/
168
169 extern const struct JNIInvokeInterface_ _Jv_JNIInvokeInterface;
170 extern struct JNINativeInterface_ _Jv_JNINativeInterface;
171
172
173 /* hashtable_global_ref_entry *************************************************/
174
175 typedef struct hashtable_global_ref_entry hashtable_global_ref_entry;
176
177 struct hashtable_global_ref_entry {
178         java_object_t              *o;      /* object pointer of global ref       */
179         int32_t                     refs;   /* references of the current pointer  */
180         hashtable_global_ref_entry *hashlink; /* link for external chaining       */
181 };
182
183
184 /* function prototypes ********************************************************/
185
186 bool jni_init(void);
187 bool jni_version_check(int version);
188
189 #ifdef __cplusplus
190 }
191 #endif
192
193 #endif // _JNI_HPP
194
195
196 /*
197  * These are local overrides for various environment variables in Emacs.
198  * Please do not remove this and leave it at the end of the file, where
199  * Emacs will automagically detect them.
200  * ---------------------------------------------------------------------
201  * Local variables:
202  * mode: c++
203  * indent-tabs-mode: t
204  * c-basic-offset: 4
205  * tab-width: 4
206  * End:
207  * vim:noexpandtab:sw=4:ts=4:
208  */