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