Merge from subtype.
[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 // Typedef the JNI types.
82 typedef java_handle_t*              jobject;
83 typedef java_handle_t*              jclass;
84 typedef java_handle_t*              jstring;
85 typedef java_handle_t*              jthrowable;
86 typedef java_handle_t*              jweak; // FIXME
87 typedef java_handle_array_t*        jarray;
88 typedef java_handle_objectarray_t*  jobjectArray;
89 typedef java_handle_booleanarray_t* jbooleanArray;
90 typedef java_handle_bytearray_t*    jbyteArray;
91 typedef java_handle_chararray_t*    jcharArray;
92 typedef java_handle_shortarray_t*   jshortArray;
93 typedef java_handle_intarray_t*     jintArray;
94 typedef java_handle_longarray_t*    jlongArray;
95 typedef java_handle_floatarray_t*   jfloatArray;
96 typedef java_handle_doublearray_t*  jdoubleArray;
97
98
99 // We need some additional stuff for the various JNI headers.
100 #if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH) || defined(WITH_JAVA_RUNTIME_LIBRARY_CLDC1_1)
101
102 // These typedefs and defines are copied from GNU Classpath's jni.h
103 #define JNI_TRUE true
104 #define JNI_FALSE false
105
106 typedef struct _Jv_JNIEnv JNIEnv;
107 typedef struct _Jv_JavaVM JavaVM;
108
109 #elif defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK)
110
111 // These typedefs are copied from OpenJDK's jni.h
112 typedef unsigned char   jboolean;
113 typedef unsigned short  jchar;
114 typedef short           jshort;
115 typedef float           jfloat;
116 typedef double          jdouble;
117
118 typedef jint            jsize;
119
120 typedef union jvalue {
121     jboolean z;
122     jbyte    b;
123     jchar    c;
124     jshort   s;
125     jint     i;
126     jlong    j;
127     jfloat   f;
128     jdouble  d;
129     jobject  l;
130 } jvalue;
131
132 struct _jfieldID;
133 typedef struct _jfieldID *jfieldID;
134
135 struct _jmethodID;
136 typedef struct _jmethodID *jmethodID;
137
138 /* Return values from jobjectRefType */
139 typedef enum _jobjectType {
140      JNIInvalidRefType    = 0,
141      JNILocalRefType      = 1,
142      JNIGlobalRefType     = 2,
143      JNIWeakGlobalRefType = 3
144 } jobjectRefType;
145
146 #endif
147
148
149 // Now include jni.h to complete the JNI header.
150 #include INCLUDE_JNI_H
151
152
153 // Includes.
154 #include "vm/global.h"
155
156
157 #ifdef __cplusplus
158 extern "C" {
159 #endif
160
161 /* CACAO related stuff ********************************************************/
162
163 extern const struct JNIInvokeInterface_ _Jv_JNIInvokeInterface;
164 extern struct JNINativeInterface_ _Jv_JNINativeInterface;
165
166
167 /* hashtable_global_ref_entry *************************************************/
168
169 typedef struct hashtable_global_ref_entry hashtable_global_ref_entry;
170
171 struct hashtable_global_ref_entry {
172         java_object_t              *o;      /* object pointer of global ref       */
173         int32_t                     refs;   /* references of the current pointer  */
174         hashtable_global_ref_entry *hashlink; /* link for external chaining       */
175 };
176
177
178 /* function prototypes ********************************************************/
179
180 bool jni_init(void);
181 bool jni_version_check(int version);
182
183 #ifdef __cplusplus
184 }
185 #endif
186
187 #endif // _JNI_HPP
188
189
190 /*
191  * These are local overrides for various environment variables in Emacs.
192  * Please do not remove this and leave it at the end of the file, where
193  * Emacs will automagically detect them.
194  * ---------------------------------------------------------------------
195  * Local variables:
196  * mode: c++
197  * indent-tabs-mode: t
198  * c-basic-offset: 4
199  * tab-width: 4
200  * End:
201  * vim:noexpandtab:sw=4:ts=4:
202  */