* added STATIC_CLASSPATH defines to fix compile problems
[cacao.git] / src / native / native.h
1 /* src/native/native.h - table of native functions
2
3    Copyright (C) 1996-2005 R. Grafl, A. Krall, C. Kruegel, C. Oates,
4    R. Obermaisser, M. Platter, M. Probst, S. Ring, E. Steiner,
5    C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich, J. Wenninger,
6    Institut f. Computersprachen - TU Wien
7
8    This file is part of CACAO.
9
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.
14
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.
19
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., 59 Temple Place - Suite 330, Boston, MA
23    02111-1307, USA.
24
25    Contact: cacao@complang.tuwien.ac.at
26
27    Authors: Reinhard Grafl
28
29    Changes: Christian Thalinger
30
31    $Id: native.h 2707 2005-06-15 13:40:36Z twisti $
32
33 */
34
35
36 #ifndef _NATIVE_H
37 #define _NATIVE_H
38
39 #if !defined(STATIC_CLASSPATH)
40 # include "libltdl/ltdl.h"
41 #endif
42
43 #include "vm/class.h"
44 #include "vm/global.h"
45 #include "vm/method.h"
46 #include "vm/utf8.h"
47 #include "native/jni.h"
48 #include "native/include/java_lang_String.h"
49 #include "native/include/java_lang_ClassLoader.h"
50 #include "native/include/java_lang_Throwable.h"
51
52
53 /* table for locating native methods */
54
55 typedef struct nativeref nativeref;
56 typedef struct nativecompref nativecompref;
57
58
59 #if !defined(STATIC_CLASSPATH)
60 typedef struct library_hash_loader_entry library_hash_loader_entry;
61 typedef struct library_hash_name_entry library_hash_name_entry;
62
63 /* library_hash_loader_entry **************************************************/
64
65 struct library_hash_loader_entry {
66         java_objectheader         *loader;  /* class loader                       */
67         library_hash_name_entry   *namelink;/* libraries loaded by this loader    */
68         library_hash_loader_entry *hashlink;/* link for external chaining         */
69 };
70
71
72 /* library_hash_name_entry ****************************************************/
73
74 struct library_hash_name_entry {
75         utf                     *name;      /* library name                       */
76         lt_dlhandle              handle;    /* libtool library handle             */
77         library_hash_name_entry *hashlink;  /* link for external chaining         */
78 };
79 #endif
80
81
82 struct nativeref {
83         char       *classname;
84         char       *methodname;
85         char       *descriptor;
86         bool        isstatic;
87         functionptr func;
88 };
89
90 /* table for fast string comparison */
91
92 struct nativecompref {
93         utf        *classname;
94         utf        *methodname;
95         utf        *descriptor;
96         bool        isstatic;
97         functionptr func;
98 };
99
100
101 void use_class_as_object(classinfo *c);
102
103 /* initialize native subsystem */
104 bool native_init(void);
105
106 /* find native function */
107 functionptr native_findfunction(utf *cname, utf *mname, 
108                                                                 utf *desc, bool isstatic);
109
110 #if !defined(STATIC_CLASSPATH)
111 /* add a library to the library hash */
112 void native_library_hash_add(utf *filename, java_objectheader *loader,
113                                                          lt_dlhandle handle);
114
115 /* resolve native function */
116 functionptr native_resolve_function(methodinfo *m);
117 #endif
118
119 /* create new object on the heap and call the initializer */
120 java_objectheader *native_new_and_init(classinfo *c);
121
122 /* create new object on the heap and call the initializer 
123    mainly used for exceptions with a message */
124 java_objectheader *native_new_and_init_string(classinfo *c, java_lang_String *s);
125
126 /* create new object on the heap and call the initializer 
127    mainly used for exceptions with an index */
128 java_objectheader *native_new_and_init_int(classinfo *c, s4 i);
129
130 /* create new object on the heap and call the initializer 
131    mainly used for exceptions with cause */
132 java_objectheader *native_new_and_init_throwable(classinfo *c, java_lang_Throwable *t);
133
134 /* add property to temporary property list -- located in nat/VMRuntime.c */
135 void create_property(char *key, char *value);
136
137 /* correct vftbl-entries of javastring-hash */
138 void stringtable_update();
139
140
141 /* search 'classinfo'-structure for a field with the specified name */
142 fieldinfo *class_findfield_approx(classinfo *c, utf *name);
143 s4 class_findfield_index_approx(classinfo *c, utf *name);
144
145 void copy_vftbl(vftbl_t **dest, vftbl_t *src);
146
147 utf *create_methodsig(java_objectarray* types, char *retType);
148 classinfo *get_type(char **utf_ptr,char *desc_end, bool skip);
149 java_objectarray* get_parametertypes(methodinfo *m);
150 java_objectarray* get_exceptiontypes(methodinfo *m);
151 classinfo *get_returntype(methodinfo *m);
152
153
154 /*----- For Static Analysis of Natives by parseRT -----*/
155
156 /*---------- global variables ---------------------------*/
157 typedef struct classMeth classMeth;
158 typedef struct nativeCall   nativeCall;
159 typedef struct methodCall   methodCall;
160 typedef struct nativeMethod nativeMethod;
161
162 typedef struct nativeCompCall   nativeCompCall;
163 typedef struct methodCompCall   methodCompCall;
164 typedef struct nativeCompMethod nativeCompMethod;
165
166 /*---------- Define Constants ---------------------------*/
167 #define MAXCALLS 30 
168
169 struct classMeth {
170         int i_class;
171         int j_method;
172         int methCnt;
173 };
174
175 struct  methodCall{
176         char *classname;
177         char *methodname;
178         char *descriptor;
179 };
180
181 struct  nativeMethod  {
182         char *methodname;
183         char *descriptor;
184         struct methodCall methodCalls[MAXCALLS];
185 };
186
187
188 struct nativeCall {
189         char *classname;
190         struct nativeMethod methods[MAXCALLS];
191         int methCnt;
192         int callCnt[MAXCALLS];
193 };
194
195
196 struct methodCompCall {
197         utf *classname;
198         utf *methodname;
199         utf *descriptor;
200 };
201
202
203 struct nativeCompMethod {
204         utf *methodname;
205         utf *descriptor;
206         struct methodCompCall methodCalls[MAXCALLS];
207 };
208
209
210 struct nativeCompCall {
211         utf *classname;
212         struct nativeCompMethod methods[MAXCALLS];
213         int methCnt;
214         int callCnt[MAXCALLS];
215 };
216
217
218 bool natcall2utf(bool);
219 void printNativeCall(nativeCall);
220 void markNativeMethodsRT(utf *, utf* , utf* ); 
221
222 #endif /* _NATIVE_H */
223
224
225 /*
226  * These are local overrides for various environment variables in Emacs.
227  * Please do not remove this and leave it at the end of the file, where
228  * Emacs will automagically detect them.
229  * ---------------------------------------------------------------------
230  * Local variables:
231  * mode: c
232  * indent-tabs-mode: t
233  * c-basic-offset: 4
234  * tab-width: 4
235  * End:
236  */