1 /* src/native/native.c - table of native functions
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
8 This file is part of CACAO.
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.
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.
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
25 Contact: cacao@complang.tuwien.ac.at
27 Authors: Reinhard Grafl
31 Changes: Christian Thalinger
33 $Id: native.c 2891 2005-07-04 20:31:45Z twisti $
40 #if !defined(ENABLE_STATICVM)
41 # include "libltdl/ltdl.h"
46 #include "cacao/cacao.h"
47 #include "mm/memory.h"
48 #include "native/jni.h"
49 #include "native/native.h"
50 #include "native/include/java_lang_Throwable.h"
51 #include "toolbox/logging.h"
52 #include "vm/builtin.h"
53 #include "vm/exceptions.h"
54 #include "vm/global.h"
55 #include "vm/loader.h"
56 #include "vm/options.h"
57 #include "vm/resolve.h"
58 #include "vm/stringlocal.h"
59 #include "vm/tables.h"
60 #include "vm/jit/asmpart.h"
61 #include "vm/jit/jit.h"
64 /* include table of native functions ******************************************/
66 #include "native/include/java_lang_Cloneable.h"
67 #include "native/include/java_util_Properties.h"
68 #include "native/include/java_io_InputStream.h"
69 #include "native/include/java_io_PrintStream.h"
71 #include "native/include/gnu_classpath_VMStackWalker.h"
72 #include "native/include/gnu_classpath_VMSystemProperties.h"
73 #include "native/include/java_lang_Class.h"
74 #include "native/include/java_lang_Object.h"
75 #include "native/include/java_lang_VMClass.h"
76 #include "native/include/java_lang_VMClassLoader.h"
77 #include "native/include/java_lang_VMObject.h"
78 #include "native/include/java_lang_VMRuntime.h"
79 #include "native/include/java_lang_VMString.h"
80 #include "native/include/java_lang_VMSystem.h"
81 #include "native/include/java_lang_VMThread.h"
82 #include "native/include/java_lang_VMThrowable.h"
83 #include "native/include/java_lang_reflect_Constructor.h"
84 #include "native/include/java_lang_reflect_Field.h"
85 #include "native/include/java_lang_reflect_Proxy.h"
86 #include "native/include/java_lang_reflect_Method.h"
87 #include "native/include/java_security_VMAccessController.h"
89 #if defined(ENABLE_STATICVM)
91 /* these are required to prevent compiler warnings */
93 #include "native/include/java_net_DatagramPacket.h"
94 #include "native/include/java_net_InetAddress.h"
95 #include "native/include/java_net_SocketImpl.h"
97 #include "native/include/gnu_java_net_PlainDatagramSocketImpl.h"
98 #include "native/include/gnu_java_net_PlainSocketImpl.h"
99 #include "native/include/gnu_java_nio_PipeImpl.h"
100 #include "native/include/gnu_java_nio_channels_FileChannelImpl.h"
101 #include "native/include/gnu_java_nio_charset_iconv_IconvEncoder.h"
102 #include "native/include/gnu_java_nio_charset_iconv_IconvDecoder.h"
103 #include "native/include/java_lang_VMProcess.h"
104 #include "native/include/java_nio_MappedByteBufferImpl.h"
105 #include "native/include/java_nio_channels_spi_SelectorProvider.h"
107 /* now include the native table */
109 #include "native/nativetable.inc"
111 #else /* defined(ENABLE_STATICVM) */
113 /* Ensure that symbols for functions implemented within CACAO are used and */
114 /* exported to dlopen. */
116 static functionptr dummynativetable[] = {
117 (functionptr) Java_gnu_classpath_VMStackWalker_getClassContext,
119 (functionptr) Java_gnu_classpath_VMSystemProperties_preInit,
121 (functionptr) Java_java_lang_VMClass_isInstance,
122 (functionptr) Java_java_lang_VMClass_isAssignableFrom,
123 (functionptr) Java_java_lang_VMClass_isInterface,
124 (functionptr) Java_java_lang_VMClass_isPrimitive,
125 (functionptr) Java_java_lang_VMClass_getName,
126 (functionptr) Java_java_lang_VMClass_getSuperclass,
127 (functionptr) Java_java_lang_VMClass_getInterfaces,
128 (functionptr) Java_java_lang_VMClass_getComponentType,
129 (functionptr) Java_java_lang_VMClass_getModifiers,
130 (functionptr) Java_java_lang_VMClass_getDeclaringClass,
131 (functionptr) Java_java_lang_VMClass_getDeclaredClasses,
132 (functionptr) Java_java_lang_VMClass_getDeclaredFields,
133 (functionptr) Java_java_lang_VMClass_getDeclaredMethods,
134 (functionptr) Java_java_lang_VMClass_getDeclaredConstructors,
135 (functionptr) Java_java_lang_VMClass_getClassLoader,
136 (functionptr) Java_java_lang_VMClass_forName,
137 (functionptr) Java_java_lang_VMClass_isArray,
138 (functionptr) Java_java_lang_VMClass_initialize,
139 (functionptr) Java_java_lang_VMClass_loadArrayClass,
140 (functionptr) Java_java_lang_VMClass_throwException,
142 (functionptr) Java_java_lang_VMClassLoader_defineClass,
143 (functionptr) Java_java_lang_VMClassLoader_resolveClass,
144 (functionptr) Java_java_lang_VMClassLoader_loadClass,
145 (functionptr) Java_java_lang_VMClassLoader_getPrimitiveClass,
146 (functionptr) Java_java_lang_VMClassLoader_nativeGetResources,
148 (functionptr) Java_java_lang_VMObject_getClass,
149 (functionptr) Java_java_lang_VMObject_clone,
150 (functionptr) Java_java_lang_VMObject_notify,
151 (functionptr) Java_java_lang_VMObject_notifyAll,
152 (functionptr) Java_java_lang_VMObject_wait,
154 (functionptr) Java_java_lang_VMRuntime_availableProcessors,
155 (functionptr) Java_java_lang_VMRuntime_freeMemory,
156 (functionptr) Java_java_lang_VMRuntime_totalMemory,
157 (functionptr) Java_java_lang_VMRuntime_maxMemory,
158 (functionptr) Java_java_lang_VMRuntime_gc,
159 (functionptr) Java_java_lang_VMRuntime_runFinalization,
160 (functionptr) Java_java_lang_VMRuntime_runFinalizationForExit,
161 (functionptr) Java_java_lang_VMRuntime_traceInstructions,
162 (functionptr) Java_java_lang_VMRuntime_traceMethodCalls,
163 (functionptr) Java_java_lang_VMRuntime_runFinalizersOnExit,
164 (functionptr) Java_java_lang_VMRuntime_exit,
165 (functionptr) Java_java_lang_VMRuntime_nativeLoad,
166 (functionptr) Java_java_lang_VMRuntime_mapLibraryName,
168 (functionptr) Java_java_lang_VMString_intern,
170 (functionptr) Java_java_lang_VMSystem_arraycopy,
171 (functionptr) Java_java_lang_VMSystem_identityHashCode,
173 (functionptr) Java_java_lang_VMThread_start,
174 (functionptr) Java_java_lang_VMThread_interrupt,
175 (functionptr) Java_java_lang_VMThread_isInterrupted,
176 (functionptr) Java_java_lang_VMThread_suspend,
177 (functionptr) Java_java_lang_VMThread_resume,
178 (functionptr) Java_java_lang_VMThread_nativeSetPriority,
179 (functionptr) Java_java_lang_VMThread_nativeStop,
180 (functionptr) Java_java_lang_VMThread_currentThread,
181 (functionptr) Java_java_lang_VMThread_yield,
182 (functionptr) Java_java_lang_VMThread_interrupted,
183 (functionptr) Java_java_lang_VMThread_holdsLock,
185 (functionptr) Java_java_lang_VMThrowable_fillInStackTrace,
186 (functionptr) Java_java_lang_VMThrowable_getStackTrace,
188 (functionptr) Java_java_lang_reflect_Constructor_getModifiers,
189 (functionptr) Java_java_lang_reflect_Constructor_constructNative,
191 (functionptr) Java_java_lang_reflect_Field_getModifiers,
192 (functionptr) Java_java_lang_reflect_Field_getType,
193 (functionptr) Java_java_lang_reflect_Field_get,
194 (functionptr) Java_java_lang_reflect_Field_getBoolean,
195 (functionptr) Java_java_lang_reflect_Field_getByte,
196 (functionptr) Java_java_lang_reflect_Field_getChar,
197 (functionptr) Java_java_lang_reflect_Field_getShort,
198 (functionptr) Java_java_lang_reflect_Field_getInt,
199 (functionptr) Java_java_lang_reflect_Field_getLong,
200 (functionptr) Java_java_lang_reflect_Field_getFloat,
201 (functionptr) Java_java_lang_reflect_Field_getDouble,
202 (functionptr) Java_java_lang_reflect_Field_set,
203 (functionptr) Java_java_lang_reflect_Field_setBoolean,
204 (functionptr) Java_java_lang_reflect_Field_setByte,
205 (functionptr) Java_java_lang_reflect_Field_setChar,
206 (functionptr) Java_java_lang_reflect_Field_setShort,
207 (functionptr) Java_java_lang_reflect_Field_setInt,
208 (functionptr) Java_java_lang_reflect_Field_setLong,
209 (functionptr) Java_java_lang_reflect_Field_setFloat,
210 (functionptr) Java_java_lang_reflect_Field_setDouble,
212 (functionptr) Java_java_lang_reflect_Proxy_getProxyClass0,
213 (functionptr) Java_java_lang_reflect_Proxy_getProxyData0,
214 (functionptr) Java_java_lang_reflect_Proxy_generateProxyClass0,
216 (functionptr) Java_java_lang_reflect_Method_getModifiers,
217 (functionptr) Java_java_lang_reflect_Method_getReturnType,
218 (functionptr) Java_java_lang_reflect_Method_getParameterTypes,
219 (functionptr) Java_java_lang_reflect_Method_getExceptionTypes,
220 (functionptr) Java_java_lang_reflect_Method_invokeNative,
222 (functionptr) Java_java_security_VMAccessController_getStack,
225 #endif /* defined(ENABLE_STATICVM) */
228 /************* use classinfo structure as java.lang.Class object **************/
230 bool use_class_as_object(classinfo *c)
232 if (!c->classvftbl) {
233 /* is the class loaded */
235 /* if (!class_load(c)) */
236 /* throw_exception_exit(); */
237 log_text("use_class_as_object: class_load should not happen");
241 /* is the class linked */
246 assert(class_java_lang_Class);
248 c->header.vftbl = class_java_lang_Class->vftbl;
249 c->classvftbl = true;
256 /************************** tables for methods ********************************/
261 #ifdef ENABLE_STATICVM
262 #define NATIVETABLESIZE (sizeof(nativetable)/sizeof(struct nativeref))
264 /* table for fast string comparison */
265 static nativecompref nativecomptable[NATIVETABLESIZE];
267 /* string comparsion table initialized */
268 static bool nativecompdone = false;
272 /* XXX don't define this in a header file!!! */
274 static struct nativeCall nativeCalls[] =
276 #include "nativecalls.inc"
279 #define NATIVECALLSSIZE (sizeof(nativeCalls) / sizeof(struct nativeCall))
281 struct nativeCompCall nativeCompCalls[NATIVECALLSSIZE];
284 /* global variables ***********************************************************/
286 #if !defined(ENABLE_STATICVM)
287 static hashtable library_hash;
288 static lt_dlhandle mainhandle;
292 /* native_loadclasses **********************************************************
294 Load classes required for native methods.
296 *******************************************************************************/
298 bool native_init(void)
300 #if !defined(ENABLE_STATICVM)
303 /* We need to access the dummy native table, not only to remove a warning */
304 /* but to be sure that the table is not optimized away (gcc does this */
307 p = &dummynativetable;
309 /* initialize libltdl */
312 /* XXX how can we throw an exception here? */
313 log_text(lt_dlerror());
318 /* get the handle for the main program */
320 if (!(mainhandle = lt_dlopen(NULL)))
323 /* initialize library hashtable, 10 entries should be enough */
325 init_hashtable(&library_hash, 10);
329 /* everything's ok */
335 /* native_library_hash_add *****************************************************
337 Adds an entry to the native library hashtable.
339 *******************************************************************************/
341 #if !defined(ENABLE_STATICVM)
342 void native_library_hash_add(utf *filename, java_objectheader *loader,
345 library_hash_loader_entry *le;
346 library_hash_name_entry *ne; /* library name */
347 u4 key; /* hashkey */
348 u4 slot; /* slot in hashtable */
350 /* normally addresses are aligned to 4, 8 or 16 bytes */
352 key = ((u4) (ptrint) loader) >> 4; /* align to 16-byte boundaries */
353 slot = key & (library_hash.size - 1);
354 le = library_hash.ptr[slot];
356 /* search external hash chain for the entry */
359 if (le->loader == loader)
362 le = le->hashlink; /* next element in external chain */
365 /* no loader found? create a new entry */
368 le = NEW(library_hash_loader_entry);
373 /* insert entry into hashtable */
375 le->hashlink = (library_hash_loader_entry *) library_hash.ptr[slot];
376 library_hash.ptr[slot] = le;
378 /* update number of hashtable-entries */
380 library_hash.entries++;
384 /* search for library name */
389 if (ne->name == filename)
392 ne = ne->hashlink; /* next element in external chain */
395 /* not found? add the library name to the classloader */
397 ne = NEW(library_hash_name_entry);
402 /* insert entry into external chain */
404 ne->hashlink = le->namelink;
407 #endif /* !defined(ENABLE_STATICVM) */
410 /* native_findfunction *********************************************************
412 Looks up a method (must have the same class name, method name,
413 descriptor and 'static'ness) and returns a function pointer to it.
414 Returns: function pointer or NULL (if there is no such method)
416 Remark: For faster operation, the names/descriptors are converted
417 from C strings to Unicode the first time this function is called.
419 *******************************************************************************/
421 #if defined(ENABLE_STATICVM)
422 functionptr native_findfunction(utf *cname, utf *mname, utf *desc,
425 /* entry of table for fast string comparison */
426 struct nativecompref *n;
429 isstatic = isstatic ? true : false;
431 if (!nativecompdone) {
432 for (i = 0; i < NATIVETABLESIZE; i++) {
433 nativecomptable[i].classname =
434 utf_new_char(nativetable[i].classname);
436 nativecomptable[i].methodname =
437 utf_new_char(nativetable[i].methodname);
439 nativecomptable[i].descriptor =
440 utf_new_char(nativetable[i].descriptor);
442 nativecomptable[i].isstatic = nativetable[i].isstatic;
443 nativecomptable[i].func = nativetable[i].func;
446 nativecompdone = true;
449 for (i = 0; i < NATIVETABLESIZE; i++) {
450 n = &(nativecomptable[i]);
452 if (cname == n->classname && mname == n->methodname &&
453 desc == n->descriptor && isstatic == n->isstatic)
458 /* no function was found, throw exception */
461 new_exception_utfmessage(string_java_lang_UnsatisfiedLinkError,
466 #endif /* defined(ENABLE_STATICVM) */
469 /* native_make_overloaded_function *********************************************
473 *******************************************************************************/
475 #if !defined(ENABLE_STATICVM)
476 static char *native_make_overloaded_function(char *name, utf *desc)
484 utf_ptr = desc->text;
485 namelen = strlen(name) + strlen("__") + strlen("0");
487 /* calculate additional length */
489 while ((c = utf_nextu2(&utf_ptr)) != ')') {
506 while (utf_nextu2(&utf_ptr) != ';')
518 /* reallocate memory */
522 newname = DMNEW(char, namelen);
523 MCOPY(newname, name, char, i);
525 utf_ptr = desc->text;
530 while ((c = utf_nextu2(&utf_ptr)) != ')') {
548 while ((c = utf_nextu2(&utf_ptr)) != ';')
549 if (((c >= 'a') && (c <= 'z')) ||
550 ((c >= 'A') && (c <= 'Z')) ||
551 ((c >= '0') && (c <= '9')))
573 /* native_resolve_function *****************************************************
575 Resolves a native function, maybe from a dynamic library.
577 *******************************************************************************/
579 functionptr native_resolve_function(methodinfo *m)
588 library_hash_loader_entry *le;
589 library_hash_name_entry *ne;
590 u4 key; /* hashkey */
591 u4 slot; /* slot in hashtable */
597 if (opt_verbosejni) {
598 printf("[Dynamic-linking native method ");
599 utf_display_classname(m->class->name);
601 utf_display(m->name);
605 /* calculate length of native function name */
607 namelen = strlen("Java_") + utf_strlen(m->class->name) + strlen("_") +
608 utf_strlen(m->name) + strlen("0");
610 /* check for underscores in class name */
612 utf_ptr = m->class->name->text;
613 utf_endptr = UTF_END(m->class->name);
615 while (utf_ptr < utf_endptr)
616 if (utf_nextu2(&utf_ptr) == '_')
619 /* check for underscores in method name */
621 utf_ptr = m->name->text;
622 utf_endptr = UTF_END(m->name);
624 while (utf_ptr < utf_endptr)
625 if (utf_nextu2(&utf_ptr) == '_')
628 /* allocate memory */
630 dumpsize = dump_size();
632 name = DMNEW(char, namelen);
635 /* generate name of native functions */
637 strcpy(name, "Java_");
640 utf_ptr = m->class->name->text;
641 utf_endptr = UTF_END(m->class->name);
643 for (; utf_ptr < utf_endptr; utf_ptr++, i++) {
646 /* escape sequence for '_' is '_1' */
651 /* replace '/' with '_' */
657 /* seperator between class and method */
661 utf_ptr = m->name->text;
662 utf_endptr = UTF_END(m->name);
664 for (; utf_ptr < utf_endptr; utf_ptr++, i++) {
667 /* escape sequence for '_' is '_1' */
678 /* check the library hash entries of the classloader of the methods's */
683 /* normally addresses are aligned to 4, 8 or 16 bytes */
685 key = ((u4) (ptrint) m->class->classloader) >> 4; /* align to 16-byte */
686 slot = key & (library_hash.size - 1);
687 le = library_hash.ptr[slot];
689 /* iterate through loaders in this hash slot */
692 /* iterate through names in this loader */
697 sym = lt_dlsym(ne->handle, name);
700 sym = lt_dlsym(ne->handle, newname);
713 /* if not found, try to find the native function symbol in the main */
717 sym = lt_dlsym(mainhandle, name);
720 /* we didn't find the symbol yet, try to resolve an overloaded */
721 /* function (having the types in it's name) */
723 newname = native_make_overloaded_function(name, m->descriptor);
725 /* try to find the overloaded symbol */
727 sym = lt_dlsym(mainhandle, newname);
732 printf("internal ]\n");
736 /* no symbol found? throw exception */
740 new_exception_utfmessage(string_java_lang_UnsatisfiedLinkError,
745 dump_release(dumpsize);
747 return (functionptr) (ptrint) sym;
749 #endif /* !defined(ENABLE_STATICVM) */
752 /****************** function class_findfield_approx ****************************
754 searches in 'classinfo'-structure for a field with the
757 *******************************************************************************/
759 fieldinfo *class_findfield_approx(classinfo *c, utf *name)
763 for (i = 0; i < c->fieldscount; i++) {
764 /* compare field names */
765 if ((c->fields[i].name == name))
766 return &(c->fields[i]);
769 /* field was not found, raise exception */
770 *exceptionptr = new_exception(string_java_lang_NoSuchFieldException);
776 s4 class_findfield_index_approx(classinfo *c, utf *name)
780 for (i = 0; i < c->fieldscount; i++) {
781 /* compare field names */
782 if ((c->fields[i].name == name))
786 /* field was not found, raise exception */
787 *exceptionptr = new_exception(string_java_lang_NoSuchFieldException);
793 /* native_new_and_init *********************************************************
795 Creates a new object on the heap and calls the initializer.
796 Returns the object pointer or NULL if memory is exhausted.
798 *******************************************************************************/
800 java_objectheader *native_new_and_init(classinfo *c)
803 java_objectheader *o;
806 return *exceptionptr;
815 /* find initializer */
817 m = class_findmethod(c, utf_init, utf_void__void);
819 /* initializer not found */
824 /* call initializer */
826 asm_calljavafunction(m, o, NULL, NULL, NULL);
832 java_objectheader *native_new_and_init_string(classinfo *c, java_lang_String *s)
835 java_objectheader *o;
838 return *exceptionptr;
847 /* find initializer */
849 m = class_resolveclassmethod(c,
851 utf_java_lang_String__void,
855 /* initializer not found */
860 /* call initializer */
862 asm_calljavafunction(m, o, s, NULL, NULL);
868 java_objectheader *native_new_and_init_int(classinfo *c, s4 i)
871 java_objectheader *o;
874 return *exceptionptr;
883 /* find initializer */
885 m = class_resolveclassmethod(c, utf_init, utf_int__void, NULL, true);
887 /* initializer not found */
892 /* call initializer */
894 asm_calljavafunction(m, o, (void *) (ptrint) i, NULL, NULL);
900 java_objectheader *native_new_and_init_throwable(classinfo *c, java_lang_Throwable *t)
903 java_objectheader *o;
906 return *exceptionptr;
915 /* find initializer */
917 m = class_findmethod(c, utf_init, utf_java_lang_Throwable__void);
919 /* initializer not found */
924 /* call initializer */
926 asm_calljavafunction(m, o, t, NULL, NULL);
932 void copy_vftbl(vftbl_t **dest, vftbl_t *src)
936 /* XXX this kind of copying does not work (in the general
937 * case). The interface tables would have to be copied, too. I
938 * don't see why we should make a copy anyway. -Edwin
940 *dest = mem_alloc(sizeof(vftbl) + sizeof(methodptr)*(src->vftbllength-1));
941 memcpy(*dest, src, sizeof(vftbl) - sizeof(methodptr));
942 memcpy(&(*dest)->table, &src->table, src->vftbllength * sizeof(methodptr));
947 /******************************************************************************************
949 creates method signature (excluding return type) from array of
950 class-objects representing the parameters of the method
952 *******************************************************************************************/
955 utf *create_methodsig(java_objectarray* types, char *retType)
957 char *buffer; /* buffer for building the desciptor */
958 char *pos; /* current position in buffer */
959 utf *result; /* the method signature */
960 u4 buffer_size = 3; /* minimal size=3: room for parenthesis and returntype */
963 if (!types) return NULL;
965 /* determine required buffer-size */
966 for (i = 0; i < types->header.size; i++) {
967 classinfo *c = (classinfo *) types->data[i];
968 buffer_size = buffer_size + c->name->blength + 2;
971 if (retType) buffer_size += strlen(retType);
973 /* allocate buffer */
974 buffer = MNEW(char, buffer_size);
977 /* method-desciptor starts with parenthesis */
980 for (i = 0; i < types->header.size; i++) {
983 /* current argument */
984 classinfo *c = (classinfo *) types->data[i];
986 /* current position in utf-text */
987 char *utf_ptr = c->name->text;
989 /* determine type of argument */
990 if ((ch = utf_nextu2(&utf_ptr)) == '[') {
992 for (utf_ptr--; utf_ptr < UTF_END(c->name); utf_ptr++) {
993 *pos++ = *utf_ptr; /* copy text */
997 /* check for primitive types */
998 for (j = 0; j < PRIMITIVETYPE_COUNT; j++) {
999 char *utf_pos = utf_ptr - 1;
1000 char *primitive = primitivetype_table[j].wrapname;
1003 while (utf_pos < UTF_END(c->name)) {
1004 if (*utf_pos++ != *primitive++) goto nomatch;
1007 /* primitive type found */
1008 *pos++ = primitivetype_table[j].typesig;
1015 /* no primitive type and no arrayclass, so must be object */
1019 for (utf_ptr--; utf_ptr < UTF_END(c->name); utf_ptr++) {
1033 for (i = 0; i < strlen(retType); i++) {
1034 *pos++ = retType[i];
1038 /* create utf-string */
1039 result = utf_new(buffer, (pos - buffer));
1040 MFREE(buffer, char, buffer_size);
1046 /* native_get_parametertypes ***************************************************
1048 Use the descriptor of a method to generate a java/lang/Class array
1049 which contains the classes of the parametertypes of the method.
1051 *******************************************************************************/
1053 java_objectarray *native_get_parametertypes(methodinfo *m)
1056 typedesc *paramtypes;
1058 java_objectarray *oa;
1063 /* is the descriptor fully parsed? */
1065 if (!m->parseddesc->params)
1066 if (!descriptor_params_from_paramtypes(md, m->flags))
1069 paramtypes = md->paramtypes;
1070 paramcount = md->paramcount;
1072 /* skip `this' pointer */
1074 if (!(m->flags & ACC_STATIC)) {
1079 /* create class-array */
1081 oa = builtin_anewarray(paramcount, class_java_lang_Class);
1088 for (i = 0; i < paramcount; i++) {
1089 if (!resolve_class_from_typedesc(¶mtypes[i], true, false,
1090 (classinfo **) &oa->data[i]))
1093 use_class_as_object((classinfo *) oa->data[i]);
1100 /* native_get_exceptiontypes ***************************************************
1102 Get the exceptions which can be thrown by a method.
1104 *******************************************************************************/
1106 java_objectarray *native_get_exceptiontypes(methodinfo *m)
1109 java_objectarray *oa;
1113 /* create class-array */
1115 oa = builtin_anewarray(excount, class_java_lang_Class);
1120 /* get exceptions */
1122 excount = m->thrownexceptionscount;
1124 for (i = 0; i < excount; i++) {
1125 if (!resolve_classref_or_classinfo(NULL, m->thrownexceptions[i],
1126 resolveEager, true, false, &c))
1129 use_class_as_object(c);
1131 oa->data[i] = (java_objectheader *) c;
1138 /* native_get_returntype *******************************************************
1140 Get the returntype class of a method.
1142 *******************************************************************************/
1144 classinfo *native_get_returntype(methodinfo *m)
1148 if (!resolve_class_from_typedesc(&(m->parseddesc->returntype), true, false,
1152 use_class_as_object(c);
1158 /*****************************************************************************/
1159 /*****************************************************************************/
1162 /*--------------------------------------------------------*/
1163 void printNativeCall(nativeCall nc) {
1166 printf("\n%s's Native Methods call:\n",nc.classname); fflush(stdout);
1167 for (i=0; i<nc.methCnt; i++) {
1168 printf("\tMethod=%s %s\n",nc.methods[i].methodname, nc.methods[i].descriptor);fflush(stdout);
1170 for (j=0; j<nc.callCnt[i]; j++) {
1171 printf("\t\t<%i,%i>aCalled = %s %s %s\n",i,j,
1172 nc.methods[i].methodCalls[j].classname,
1173 nc.methods[i].methodCalls[j].methodname,
1174 nc.methods[i].methodCalls[j].descriptor);fflush(stdout);
1177 printf("-+++++--------------------\n");fflush(stdout);
1180 /*--------------------------------------------------------*/
1181 void printCompNativeCall(nativeCompCall nc) {
1183 printf("printCompNativeCall BEGIN\n");fflush(stdout);
1184 printf("\n%s's Native Comp Methods call:\n",nc.classname->text);fflush(stdout);
1185 utf_display(nc.classname); fflush(stdout);
1187 for (i=0; i<nc.methCnt; i++) {
1188 printf("\tMethod=%s %s\n",nc.methods[i].methodname->text,nc.methods[i].descriptor->text);fflush(stdout);
1189 utf_display(nc.methods[i].methodname); fflush(stdout);
1190 utf_display(nc.methods[i].descriptor);fflush(stdout);
1191 printf("\n");fflush(stdout);
1193 for (j=0; j<nc.callCnt[i]; j++) {
1194 printf("\t\t<%i,%i>bCalled = ",i,j);fflush(stdout);
1195 utf_display(nc.methods[i].methodCalls[j].classname);fflush(stdout);
1196 utf_display(nc.methods[i].methodCalls[j].methodname); fflush(stdout);
1197 utf_display(nc.methods[i].methodCalls[j].descriptor);fflush(stdout);
1198 printf("\n");fflush(stdout);
1201 printf("---------------------\n");fflush(stdout);
1205 /*--------------------------------------------------------*/
1206 classMeth findNativeMethodCalls(utf *c, utf *m, utf *d )
1219 /*--------------------------------------------------------*/
1220 nativeCall* findNativeClassCalls(char *aclassname ) {
1223 for (i=0;i<NATIVECALLSSIZE; i++) {
1224 /* convert table to utf later to speed up search */
1225 if (strcmp(nativeCalls[i].classname, aclassname) == 0)
1226 return &nativeCalls[i];
1231 /*--------------------------------------------------------*/
1232 /*--------------------------------------------------------*/
1233 void utfNativeCall(nativeCall nc, nativeCompCall *ncc) {
1237 ncc->classname = utf_new_char(nc.classname);
1238 ncc->methCnt = nc.methCnt;
1240 for (i=0; i<nc.methCnt; i++) {
1241 ncc->methods[i].methodname = utf_new_char(nc.methods[i].methodname);
1242 ncc->methods[i].descriptor = utf_new_char(nc.methods[i].descriptor);
1243 ncc->callCnt[i] = nc.callCnt[i];
1245 for (j=0; j<nc.callCnt[i]; j++) {
1247 ncc->methods[i].methodCalls[j].classname = utf_new_char(nc.methods[i].methodCalls[j].classname);
1249 if (strcmp("", nc.methods[i].methodCalls[j].methodname) != 0) {
1250 ncc->methods[i].methodCalls[j].methodname = utf_new_char(nc.methods[i].methodCalls[j].methodname);
1251 ncc->methods[i].methodCalls[j].descriptor = utf_new_char(nc.methods[i].methodCalls[j].descriptor);
1254 ncc->methods[i].methodCalls[j].methodname = NULL;
1255 ncc->methods[i].methodCalls[j].descriptor = NULL;
1263 /*--------------------------------------------------------*/
1265 bool natcall2utf(bool natcallcompdone) {
1268 if (natcallcompdone)
1271 for (i=0;i<NATIVECALLSSIZE; i++) {
1272 utfNativeCall (nativeCalls[i], &nativeCompCalls[i]);
1279 * These are local overrides for various environment variables in Emacs.
1280 * Please do not remove this and leave it at the end of the file, where
1281 * Emacs will automagically detect them.
1282 * ---------------------------------------------------------------------
1285 * indent-tabs-mode: t