* Fixed ltdl.h include path.
[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 4051 2006-01-02 11:34:33Z twisti $
32
33 */
34
35
36 #ifndef _NATIVE_H
37 #define _NATIVE_H
38
39 #include "config.h"
40
41 #if !defined(ENABLE_STATICVM)
42 # include <ltdl.h>
43 #endif
44
45 #include "vm/class.h"
46 #include "vm/global.h"
47 #include "vm/method.h"
48 #include "vm/utf8.h"
49 #include "native/jni.h"
50 #include "native/include/java_lang_String.h"
51 #include "native/include/java_lang_ClassLoader.h"
52 #include "native/include/java_lang_Throwable.h"
53
54
55 /* table for locating native methods */
56
57 typedef struct nativeref nativeref;
58 typedef struct nativecompref nativecompref;
59
60
61 #if !defined(ENABLE_STATICVM)
62 typedef struct hashtable_library_loader_entry hashtable_library_loader_entry;
63 typedef struct hashtable_library_name_entry hashtable_library_name_entry;
64
65
66 /* hashtable_library_loader_entry *********************************************/
67
68 struct hashtable_library_loader_entry {
69         java_objectheader              *loader;  /* class loader                  */
70         hashtable_library_name_entry   *namelink;/* libs loaded by this loader    */
71         hashtable_library_loader_entry *hashlink;/* link for external chaining    */
72 };
73
74
75 /* hashtable_library_name_entry ***********************************************/
76
77 struct hashtable_library_name_entry {
78         utf                          *name;      /* library name                  */
79         lt_dlhandle                   handle;    /* libtool library handle        */
80         hashtable_library_name_entry *hashlink;  /* link for external chaining    */
81 };
82 #endif
83
84
85 struct nativeref {
86         char       *classname;
87         char       *methodname;
88         char       *descriptor;
89         bool        isstatic;
90         functionptr func;
91 };
92
93 /* table for fast string comparison */
94
95 struct nativecompref {
96         utf        *classname;
97         utf        *methodname;
98         utf        *descriptor;
99         bool        isstatic;
100         functionptr func;
101 };
102
103
104 bool use_class_as_object(classinfo *c);
105
106 /* initialize native subsystem */
107 bool native_init(void);
108
109 /* find native function */
110 functionptr native_findfunction(utf *cname, utf *mname, 
111                                                                 utf *desc, bool isstatic);
112
113 #if !defined(ENABLE_STATICVM)
114 /* add a library to the library hash */
115 void native_hashtable_library_add(utf *filename, java_objectheader *loader,
116                                                                   lt_dlhandle handle);
117
118 /* find a library entry in the library hash */
119 hashtable_library_name_entry *native_hashtable_library_find(utf *filename,
120                                                                                                                         java_objectheader *loader);
121
122 /* resolve native function */
123 functionptr native_resolve_function(methodinfo *m);
124 #endif /* !defined(ENABLE_STATICVM) */
125
126 /* create new object on the heap and call the initializer */
127 java_objectheader *native_new_and_init(classinfo *c);
128
129 /* create new object on the heap and call the initializer 
130    mainly used for exceptions with a message */
131 java_objectheader *native_new_and_init_string(classinfo *c, java_lang_String *s);
132
133 /* create new object on the heap and call the initializer 
134    mainly used for exceptions with an index */
135 java_objectheader *native_new_and_init_int(classinfo *c, s4 i);
136
137 /* create new object on the heap and call the initializer 
138    mainly used for exceptions with cause */
139 java_objectheader *native_new_and_init_throwable(classinfo *c, java_lang_Throwable *t);
140
141 /* add property to temporary property list -- located in vm/VMRuntime.c */
142 void create_property(char *key, char *value);
143
144 void copy_vftbl(vftbl_t **dest, vftbl_t *src);
145
146 utf *create_methodsig(java_objectarray* types, char *retType);
147
148 java_objectarray *native_get_parametertypes(methodinfo *m);
149 java_objectarray *native_get_exceptiontypes(methodinfo *m);
150 classinfo *native_get_returntype(methodinfo *m);
151
152
153 /*----- For Static Analysis of Natives by parseRT -----*/
154
155 /*---------- global variables ---------------------------*/
156 typedef struct classMeth classMeth;
157 typedef struct nativeCall   nativeCall;
158 typedef struct methodCall   methodCall;
159 typedef struct nativeMethod nativeMethod;
160
161 typedef struct nativeCompCall   nativeCompCall;
162 typedef struct methodCompCall   methodCompCall;
163 typedef struct nativeCompMethod nativeCompMethod;
164
165 /*---------- Define Constants ---------------------------*/
166 #define MAXCALLS 30 
167
168 struct classMeth {
169         int i_class;
170         int j_method;
171         int methCnt;
172 };
173
174 struct  methodCall{
175         char *classname;
176         char *methodname;
177         char *descriptor;
178 };
179
180 struct  nativeMethod  {
181         char *methodname;
182         char *descriptor;
183         struct methodCall methodCalls[MAXCALLS];
184 };
185
186
187 struct nativeCall {
188         char *classname;
189         struct nativeMethod methods[MAXCALLS];
190         int methCnt;
191         int callCnt[MAXCALLS];
192 };
193
194
195 struct methodCompCall {
196         utf *classname;
197         utf *methodname;
198         utf *descriptor;
199 };
200
201
202 struct nativeCompMethod {
203         utf *methodname;
204         utf *descriptor;
205         struct methodCompCall methodCalls[MAXCALLS];
206 };
207
208
209 struct nativeCompCall {
210         utf *classname;
211         struct nativeCompMethod methods[MAXCALLS];
212         int methCnt;
213         int callCnt[MAXCALLS];
214 };
215
216
217 bool natcall2utf(bool);
218 void printNativeCall(nativeCall);
219 void markNativeMethodsRT(utf *, utf* , utf* ); 
220
221 #endif /* _NATIVE_H */
222
223
224 /*
225  * These are local overrides for various environment variables in Emacs.
226  * Please do not remove this and leave it at the end of the file, where
227  * Emacs will automagically detect them.
228  * ---------------------------------------------------------------------
229  * Local variables:
230  * mode: c
231  * indent-tabs-mode: t
232  * c-basic-offset: 4
233  * tab-width: 4
234  * End:
235  */