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 3801 2005-11-26 19:15:45Z twisti $
43 #include "cacao/cacao.h"
44 #include "mm/memory.h"
45 #include "native/jni.h"
46 #include "native/native.h"
47 #include "native/include/java_lang_Throwable.h"
48 #include "toolbox/logging.h"
49 #include "vm/builtin.h"
50 #include "vm/exceptions.h"
51 #include "vm/global.h"
52 #include "vm/loader.h"
53 #include "vm/options.h"
54 #include "vm/resolve.h"
55 #include "vm/stringlocal.h"
56 #include "vm/tables.h"
57 #include "vm/jit/asmpart.h"
58 #include "vm/jit/jit.h"
60 #if !defined(ENABLE_STATICVM)
61 # include "libltdl/ltdl.h"
65 /* include table of native functions ******************************************/
67 #include "native/include/java_lang_Cloneable.h"
68 #include "native/include/java_util_Properties.h"
69 #include "native/include/java_io_InputStream.h"
70 #include "native/include/java_io_PrintStream.h"
72 #include "native/include/gnu_classpath_VMStackWalker.h"
73 #include "native/include/gnu_classpath_VMSystemProperties.h"
74 #include "native/include/java_lang_Class.h"
75 #include "native/include/java_lang_Object.h"
76 #include "native/include/java_lang_VMClass.h"
77 #include "native/include/java_lang_VMClassLoader.h"
78 #include "native/include/java_lang_VMObject.h"
79 #include "native/include/java_lang_VMRuntime.h"
80 #include "native/include/java_lang_VMString.h"
81 #include "native/include/java_lang_VMSystem.h"
82 #include "native/include/java_lang_VMThread.h"
83 #include "native/include/java_lang_VMThrowable.h"
84 #include "native/include/java_lang_reflect_Constructor.h"
85 #include "native/include/java_lang_reflect_Field.h"
86 #include "native/include/java_lang_reflect_Method.h"
87 #include "native/include/java_lang_reflect_VMProxy.h"
88 #include "native/include/java_security_VMAccessController.h"
90 #if defined(ENABLE_STATICVM)
92 /* these are required to prevent compiler warnings */
94 #include "native/include/java_net_DatagramPacket.h"
95 #include "native/include/java_net_InetAddress.h"
96 #include "native/include/java_net_SocketImpl.h"
98 #include "native/include/gnu_java_net_PlainDatagramSocketImpl.h"
99 #include "native/include/gnu_java_net_PlainSocketImpl.h"
100 #include "native/include/gnu_java_nio_PipeImpl.h"
101 #include "native/include/gnu_java_nio_channels_FileChannelImpl.h"
102 #include "native/include/gnu_java_nio_charset_iconv_IconvEncoder.h"
103 #include "native/include/gnu_java_nio_charset_iconv_IconvDecoder.h"
104 #include "native/include/java_lang_VMProcess.h"
105 #include "native/include/java_nio_MappedByteBufferImpl.h"
106 #include "native/include/java_nio_channels_spi_SelectorProvider.h"
108 /* now include the native table */
110 #include "native/nativetable.inc"
112 #else /* defined(ENABLE_STATICVM) */
114 /* Ensure that symbols for functions implemented within CACAO are used and */
115 /* exported to dlopen. */
117 static functionptr dummynativetable[] = {
118 (functionptr) Java_gnu_classpath_VMStackWalker_getClassContext,
120 (functionptr) Java_gnu_classpath_VMSystemProperties_preInit,
122 (functionptr) Java_java_lang_VMClass_isInstance,
123 (functionptr) Java_java_lang_VMClass_isAssignableFrom,
124 (functionptr) Java_java_lang_VMClass_isInterface,
125 (functionptr) Java_java_lang_VMClass_isPrimitive,
126 (functionptr) Java_java_lang_VMClass_getName,
127 (functionptr) Java_java_lang_VMClass_getSuperclass,
128 (functionptr) Java_java_lang_VMClass_getInterfaces,
129 (functionptr) Java_java_lang_VMClass_getComponentType,
130 (functionptr) Java_java_lang_VMClass_getModifiers,
131 (functionptr) Java_java_lang_VMClass_getDeclaringClass,
132 (functionptr) Java_java_lang_VMClass_getDeclaredClasses,
133 (functionptr) Java_java_lang_VMClass_getDeclaredFields,
134 (functionptr) Java_java_lang_VMClass_getDeclaredMethods,
135 (functionptr) Java_java_lang_VMClass_getDeclaredConstructors,
136 (functionptr) Java_java_lang_VMClass_getClassLoader,
137 (functionptr) Java_java_lang_VMClass_forName,
138 (functionptr) Java_java_lang_VMClass_isArray,
139 (functionptr) Java_java_lang_VMClass_throwException,
141 (functionptr) Java_java_lang_VMClassLoader_defineClass,
142 (functionptr) Java_java_lang_VMClassLoader_resolveClass,
143 (functionptr) Java_java_lang_VMClassLoader_loadClass,
144 (functionptr) Java_java_lang_VMClassLoader_getPrimitiveClass,
145 (functionptr) Java_java_lang_VMClassLoader_nativeGetResources,
146 (functionptr) Java_java_lang_VMClassLoader_findLoadedClass,
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_Method_getModifiers,
213 (functionptr) Java_java_lang_reflect_Method_getReturnType,
214 (functionptr) Java_java_lang_reflect_Method_getParameterTypes,
215 (functionptr) Java_java_lang_reflect_Method_getExceptionTypes,
216 (functionptr) Java_java_lang_reflect_Method_invokeNative,
218 (functionptr) Java_java_lang_reflect_VMProxy_getProxyClass,
219 (functionptr) Java_java_lang_reflect_VMProxy_getProxyData,
220 (functionptr) Java_java_lang_reflect_VMProxy_generateProxyClass,
222 (functionptr) Java_java_security_VMAccessController_getStack,
225 #endif /* defined(ENABLE_STATICVM) */
228 /************************** tables for methods ********************************/
233 #ifdef ENABLE_STATICVM
234 #define NATIVETABLESIZE (sizeof(nativetable)/sizeof(struct nativeref))
236 /* table for fast string comparison */
237 static nativecompref nativecomptable[NATIVETABLESIZE];
239 /* string comparsion table initialized */
240 static bool nativecompdone = false;
244 /* XXX don't define this in a header file!!! */
246 static struct nativeCall nativeCalls[] =
248 #include "nativecalls.inc"
251 #define NATIVECALLSSIZE (sizeof(nativeCalls) / sizeof(struct nativeCall))
253 struct nativeCompCall nativeCompCalls[NATIVECALLSSIZE];
256 /* global variables ***********************************************************/
258 #if !defined(ENABLE_STATICVM)
259 static hashtable library_hash;
260 static lt_dlhandle mainhandle;
264 /* native_loadclasses **********************************************************
266 Load classes required for native methods.
268 *******************************************************************************/
270 bool native_init(void)
272 #if !defined(ENABLE_STATICVM)
275 /* We need to access the dummy native table, not only to remove a warning */
276 /* but to be sure that the table is not optimized away (gcc does this */
279 p = &dummynativetable;
281 /* initialize libltdl */
284 /* XXX how can we throw an exception here? */
285 log_text(lt_dlerror());
290 /* get the handle for the main program */
292 if (!(mainhandle = lt_dlopen(NULL)))
295 /* initialize library hashtable, 10 entries should be enough */
297 init_hashtable(&library_hash, 10);
301 /* everything's ok */
307 /* native_library_hash_add *****************************************************
309 Adds an entry to the native library hashtable.
311 *******************************************************************************/
313 #if !defined(ENABLE_STATICVM)
314 void native_library_hash_add(utf *filename, java_objectheader *loader,
317 library_hash_loader_entry *le;
318 library_hash_name_entry *ne; /* library name */
319 u4 key; /* hashkey */
320 u4 slot; /* slot in hashtable */
322 /* normally addresses are aligned to 4, 8 or 16 bytes */
324 key = ((u4) (ptrint) loader) >> 4; /* align to 16-byte boundaries */
325 slot = key & (library_hash.size - 1);
326 le = library_hash.ptr[slot];
328 /* search external hash chain for the entry */
331 if (le->loader == loader)
334 le = le->hashlink; /* next element in external chain */
337 /* no loader found? create a new entry */
340 le = NEW(library_hash_loader_entry);
345 /* insert entry into hashtable */
347 le->hashlink = (library_hash_loader_entry *) library_hash.ptr[slot];
348 library_hash.ptr[slot] = le;
350 /* update number of hashtable-entries */
352 library_hash.entries++;
356 /* search for library name */
361 if (ne->name == filename)
364 ne = ne->hashlink; /* next element in external chain */
367 /* not found? add the library name to the classloader */
369 ne = NEW(library_hash_name_entry);
374 /* insert entry into external chain */
376 ne->hashlink = le->namelink;
379 #endif /* !defined(ENABLE_STATICVM) */
382 /* native_library_hash_find ****************************************************
384 Find an entry in the native library hashtable.
386 *******************************************************************************/
388 #if !defined(ENABLE_STATICVM)
389 library_hash_name_entry *native_library_hash_find(utf *filename,
390 java_objectheader *loader)
392 library_hash_loader_entry *le;
393 library_hash_name_entry *ne; /* library name */
394 u4 key; /* hashkey */
395 u4 slot; /* slot in hashtable */
397 /* normally addresses are aligned to 4, 8 or 16 bytes */
399 key = ((u4) (ptrint) loader) >> 4; /* align to 16-byte boundaries */
400 slot = key & (library_hash.size - 1);
401 le = library_hash.ptr[slot];
403 /* search external hash chain for the entry */
406 if (le->loader == loader)
409 le = le->hashlink; /* next element in external chain */
412 /* no loader found? return NULL */
417 /* search for library name */
422 if (ne->name == filename)
425 ne = ne->hashlink; /* next element in external chain */
428 /* return entry, if no entry was found, ne is NULL */
432 #endif /* !defined(ENABLE_STATICVM) */
435 /* native_findfunction *********************************************************
437 Looks up a method (must have the same class name, method name,
438 descriptor and 'static'ness) and returns a function pointer to it.
439 Returns: function pointer or NULL (if there is no such method)
441 Remark: For faster operation, the names/descriptors are converted
442 from C strings to Unicode the first time this function is called.
444 *******************************************************************************/
446 #if defined(ENABLE_STATICVM)
447 functionptr native_findfunction(utf *cname, utf *mname, utf *desc,
450 /* entry of table for fast string comparison */
451 struct nativecompref *n;
454 isstatic = isstatic ? true : false;
456 if (!nativecompdone) {
457 for (i = 0; i < NATIVETABLESIZE; i++) {
458 nativecomptable[i].classname =
459 utf_new_char(nativetable[i].classname);
461 nativecomptable[i].methodname =
462 utf_new_char(nativetable[i].methodname);
464 nativecomptable[i].descriptor =
465 utf_new_char(nativetable[i].descriptor);
467 nativecomptable[i].isstatic = nativetable[i].isstatic;
468 nativecomptable[i].func = nativetable[i].func;
471 nativecompdone = true;
474 for (i = 0; i < NATIVETABLESIZE; i++) {
475 n = &(nativecomptable[i]);
477 if (cname == n->classname && mname == n->methodname &&
478 desc == n->descriptor && isstatic == n->isstatic)
483 /* no function was found, throw exception */
486 new_exception_utfmessage(string_java_lang_UnsatisfiedLinkError,
491 #endif /* defined(ENABLE_STATICVM) */
494 /* native_make_overloaded_function *********************************************
498 *******************************************************************************/
500 #if !defined(ENABLE_STATICVM)
501 static char *native_make_overloaded_function(char *name, utf *desc)
509 utf_ptr = desc->text;
510 namelen = strlen(name) + strlen("__") + strlen("0");
512 /* calculate additional length */
514 while ((c = utf_nextu2(&utf_ptr)) != ')') {
531 while (utf_nextu2(&utf_ptr) != ';')
543 /* reallocate memory */
547 newname = DMNEW(char, namelen);
548 MCOPY(newname, name, char, i);
550 utf_ptr = desc->text;
555 while ((c = utf_nextu2(&utf_ptr)) != ')') {
573 while ((c = utf_nextu2(&utf_ptr)) != ';')
574 if (((c >= 'a') && (c <= 'z')) ||
575 ((c >= 'A') && (c <= 'Z')) ||
576 ((c >= '0') && (c <= '9')))
598 /* native_resolve_function *****************************************************
600 Resolves a native function, maybe from a dynamic library.
602 *******************************************************************************/
604 functionptr native_resolve_function(methodinfo *m)
613 library_hash_loader_entry *le;
614 library_hash_name_entry *ne;
615 u4 key; /* hashkey */
616 u4 slot; /* slot in hashtable */
622 if (opt_verbosejni) {
623 printf("[Dynamic-linking native method ");
624 utf_display_classname(m->class->name);
626 utf_display(m->name);
630 /* calculate length of native function name */
632 namelen = strlen("Java_") + utf_strlen(m->class->name) + strlen("_") +
633 utf_strlen(m->name) + strlen("0");
635 /* check for underscores in class name */
637 utf_ptr = m->class->name->text;
638 utf_endptr = UTF_END(m->class->name);
640 while (utf_ptr < utf_endptr)
641 if (utf_nextu2(&utf_ptr) == '_')
644 /* check for underscores in method name */
646 utf_ptr = m->name->text;
647 utf_endptr = UTF_END(m->name);
649 while (utf_ptr < utf_endptr)
650 if (utf_nextu2(&utf_ptr) == '_')
653 /* allocate memory */
655 dumpsize = dump_size();
657 name = DMNEW(char, namelen);
660 /* generate name of native functions */
662 strcpy(name, "Java_");
665 utf_ptr = m->class->name->text;
666 utf_endptr = UTF_END(m->class->name);
668 for (; utf_ptr < utf_endptr; utf_ptr++, i++) {
671 /* escape sequence for '_' is '_1' */
676 /* replace '/' with '_' */
682 /* seperator between class and method */
686 utf_ptr = m->name->text;
687 utf_endptr = UTF_END(m->name);
689 for (; utf_ptr < utf_endptr; utf_ptr++, i++) {
692 /* escape sequence for '_' is '_1' */
703 /* generate overloaded function (having the types in it's name) */
705 newname = native_make_overloaded_function(name, m->descriptor);
707 /* check the library hash entries of the classloader of the methods's */
712 /* normally addresses are aligned to 4, 8 or 16 bytes */
714 key = ((u4) (ptrint) m->class->classloader) >> 4; /* align to 16-byte */
715 slot = key & (library_hash.size - 1);
716 le = library_hash.ptr[slot];
718 /* iterate through loaders in this hash slot */
721 /* iterate through names in this loader */
726 sym = lt_dlsym(ne->handle, name);
729 sym = lt_dlsym(ne->handle, newname);
742 /* if not found, try to find the native function symbol in the main */
746 sym = lt_dlsym(mainhandle, name);
749 sym = lt_dlsym(mainhandle, newname);
753 printf("internal ]\n");
757 /* no symbol found? throw exception */
761 new_exception_utfmessage(string_java_lang_UnsatisfiedLinkError,
766 dump_release(dumpsize);
768 return (functionptr) (ptrint) sym;
770 #endif /* !defined(ENABLE_STATICVM) */
773 /* native_new_and_init *********************************************************
775 Creates a new object on the heap and calls the initializer.
776 Returns the object pointer or NULL if memory is exhausted.
778 *******************************************************************************/
780 java_objectheader *native_new_and_init(classinfo *c)
783 java_objectheader *o;
786 return *exceptionptr;
795 /* find initializer */
797 m = class_findmethod(c, utf_init, utf_void__void);
799 /* initializer not found */
804 /* call initializer */
806 asm_calljavafunction(m, o, NULL, NULL, NULL);
812 java_objectheader *native_new_and_init_string(classinfo *c, java_lang_String *s)
815 java_objectheader *o;
818 return *exceptionptr;
827 /* find initializer */
829 m = class_resolveclassmethod(c,
831 utf_java_lang_String__void,
835 /* initializer not found */
840 /* call initializer */
842 asm_calljavafunction(m, o, s, NULL, NULL);
848 java_objectheader *native_new_and_init_int(classinfo *c, s4 i)
851 java_objectheader *o;
854 return *exceptionptr;
863 /* find initializer */
865 m = class_resolveclassmethod(c, utf_init, utf_int__void, NULL, true);
867 /* initializer not found */
872 /* call initializer */
874 asm_calljavafunction(m, o, (void *) (ptrint) i, NULL, NULL);
880 java_objectheader *native_new_and_init_throwable(classinfo *c, java_lang_Throwable *t)
883 java_objectheader *o;
886 return *exceptionptr;
895 /* find initializer */
897 m = class_findmethod(c, utf_init, utf_java_lang_Throwable__void);
899 /* initializer not found */
904 /* call initializer */
906 asm_calljavafunction(m, o, t, NULL, NULL);
912 void copy_vftbl(vftbl_t **dest, vftbl_t *src)
916 /* XXX this kind of copying does not work (in the general
917 * case). The interface tables would have to be copied, too. I
918 * don't see why we should make a copy anyway. -Edwin
920 *dest = mem_alloc(sizeof(vftbl) + sizeof(methodptr)*(src->vftbllength-1));
921 memcpy(*dest, src, sizeof(vftbl) - sizeof(methodptr));
922 memcpy(&(*dest)->table, &src->table, src->vftbllength * sizeof(methodptr));
927 /******************************************************************************************
929 creates method signature (excluding return type) from array of
930 class-objects representing the parameters of the method
932 *******************************************************************************************/
935 utf *create_methodsig(java_objectarray* types, char *retType)
937 char *buffer; /* buffer for building the desciptor */
938 char *pos; /* current position in buffer */
939 utf *result; /* the method signature */
940 u4 buffer_size = 3; /* minimal size=3: room for parenthesis and returntype */
943 if (!types) return NULL;
945 /* determine required buffer-size */
946 for (i = 0; i < types->header.size; i++) {
947 classinfo *c = (classinfo *) types->data[i];
948 buffer_size = buffer_size + c->name->blength + 2;
951 if (retType) buffer_size += strlen(retType);
953 /* allocate buffer */
954 buffer = MNEW(char, buffer_size);
957 /* method-desciptor starts with parenthesis */
960 for (i = 0; i < types->header.size; i++) {
963 /* current argument */
964 classinfo *c = (classinfo *) types->data[i];
966 /* current position in utf-text */
967 char *utf_ptr = c->name->text;
969 /* determine type of argument */
970 if ((ch = utf_nextu2(&utf_ptr)) == '[') {
972 for (utf_ptr--; utf_ptr < UTF_END(c->name); utf_ptr++) {
973 *pos++ = *utf_ptr; /* copy text */
977 /* check for primitive types */
978 for (j = 0; j < PRIMITIVETYPE_COUNT; j++) {
979 char *utf_pos = utf_ptr - 1;
980 char *primitive = primitivetype_table[j].wrapname;
983 while (utf_pos < UTF_END(c->name)) {
984 if (*utf_pos++ != *primitive++) goto nomatch;
987 /* primitive type found */
988 *pos++ = primitivetype_table[j].typesig;
995 /* no primitive type and no arrayclass, so must be object */
999 for (utf_ptr--; utf_ptr < UTF_END(c->name); utf_ptr++) {
1013 for (i = 0; i < strlen(retType); i++) {
1014 *pos++ = retType[i];
1018 /* create utf-string */
1019 result = utf_new(buffer, (pos - buffer));
1020 MFREE(buffer, char, buffer_size);
1026 /* native_get_parametertypes ***************************************************
1028 Use the descriptor of a method to generate a java/lang/Class array
1029 which contains the classes of the parametertypes of the method.
1031 *******************************************************************************/
1033 java_objectarray *native_get_parametertypes(methodinfo *m)
1036 typedesc *paramtypes;
1038 java_objectarray *oa;
1043 /* is the descriptor fully parsed? */
1045 if (!m->parseddesc->params)
1046 if (!descriptor_params_from_paramtypes(md, m->flags))
1049 paramtypes = md->paramtypes;
1050 paramcount = md->paramcount;
1052 /* skip `this' pointer */
1054 if (!(m->flags & ACC_STATIC)) {
1059 /* create class-array */
1061 oa = builtin_anewarray(paramcount, class_java_lang_Class);
1068 for (i = 0; i < paramcount; i++)
1069 if (!resolve_class_from_typedesc(¶mtypes[i], true, false,
1070 (classinfo **) &oa->data[i]))
1077 /* native_get_exceptiontypes ***************************************************
1079 Get the exceptions which can be thrown by a method.
1081 *******************************************************************************/
1083 java_objectarray *native_get_exceptiontypes(methodinfo *m)
1085 java_objectarray *oa;
1089 /* create class-array */
1091 oa = builtin_anewarray(m->thrownexceptionscount, class_java_lang_Class);
1096 for (i = 0; i < m->thrownexceptionscount; i++) {
1097 if (!resolve_classref_or_classinfo(NULL, m->thrownexceptions[i],
1098 resolveEager, true, false, &c))
1101 oa->data[i] = (java_objectheader *) c;
1108 /* native_get_returntype *******************************************************
1110 Get the returntype class of a method.
1112 *******************************************************************************/
1114 classinfo *native_get_returntype(methodinfo *m)
1118 if (!resolve_class_from_typedesc(&(m->parseddesc->returntype), true, false,
1126 /*****************************************************************************/
1127 /*****************************************************************************/
1130 /*--------------------------------------------------------*/
1131 void printNativeCall(nativeCall nc) {
1134 printf("\n%s's Native Methods call:\n",nc.classname); fflush(stdout);
1135 for (i=0; i<nc.methCnt; i++) {
1136 printf("\tMethod=%s %s\n",nc.methods[i].methodname, nc.methods[i].descriptor);fflush(stdout);
1138 for (j=0; j<nc.callCnt[i]; j++) {
1139 printf("\t\t<%i,%i>aCalled = %s %s %s\n",i,j,
1140 nc.methods[i].methodCalls[j].classname,
1141 nc.methods[i].methodCalls[j].methodname,
1142 nc.methods[i].methodCalls[j].descriptor);fflush(stdout);
1145 printf("-+++++--------------------\n");fflush(stdout);
1148 /*--------------------------------------------------------*/
1149 void printCompNativeCall(nativeCompCall nc) {
1151 printf("printCompNativeCall BEGIN\n");fflush(stdout);
1152 printf("\n%s's Native Comp Methods call:\n",nc.classname->text);fflush(stdout);
1153 utf_display(nc.classname); fflush(stdout);
1155 for (i=0; i<nc.methCnt; i++) {
1156 printf("\tMethod=%s %s\n",nc.methods[i].methodname->text,nc.methods[i].descriptor->text);fflush(stdout);
1157 utf_display(nc.methods[i].methodname); fflush(stdout);
1158 utf_display(nc.methods[i].descriptor);fflush(stdout);
1159 printf("\n");fflush(stdout);
1161 for (j=0; j<nc.callCnt[i]; j++) {
1162 printf("\t\t<%i,%i>bCalled = ",i,j);fflush(stdout);
1163 utf_display(nc.methods[i].methodCalls[j].classname);fflush(stdout);
1164 utf_display(nc.methods[i].methodCalls[j].methodname); fflush(stdout);
1165 utf_display(nc.methods[i].methodCalls[j].descriptor);fflush(stdout);
1166 printf("\n");fflush(stdout);
1169 printf("---------------------\n");fflush(stdout);
1173 /*--------------------------------------------------------*/
1174 classMeth findNativeMethodCalls(utf *c, utf *m, utf *d )
1187 /*--------------------------------------------------------*/
1188 nativeCall* findNativeClassCalls(char *aclassname ) {
1191 for (i=0;i<NATIVECALLSSIZE; i++) {
1192 /* convert table to utf later to speed up search */
1193 if (strcmp(nativeCalls[i].classname, aclassname) == 0)
1194 return &nativeCalls[i];
1199 /*--------------------------------------------------------*/
1200 /*--------------------------------------------------------*/
1201 void utfNativeCall(nativeCall nc, nativeCompCall *ncc) {
1205 ncc->classname = utf_new_char(nc.classname);
1206 ncc->methCnt = nc.methCnt;
1208 for (i=0; i<nc.methCnt; i++) {
1209 ncc->methods[i].methodname = utf_new_char(nc.methods[i].methodname);
1210 ncc->methods[i].descriptor = utf_new_char(nc.methods[i].descriptor);
1211 ncc->callCnt[i] = nc.callCnt[i];
1213 for (j=0; j<nc.callCnt[i]; j++) {
1215 ncc->methods[i].methodCalls[j].classname = utf_new_char(nc.methods[i].methodCalls[j].classname);
1217 if (strcmp("", nc.methods[i].methodCalls[j].methodname) != 0) {
1218 ncc->methods[i].methodCalls[j].methodname = utf_new_char(nc.methods[i].methodCalls[j].methodname);
1219 ncc->methods[i].methodCalls[j].descriptor = utf_new_char(nc.methods[i].methodCalls[j].descriptor);
1222 ncc->methods[i].methodCalls[j].methodname = NULL;
1223 ncc->methods[i].methodCalls[j].descriptor = NULL;
1231 /*--------------------------------------------------------*/
1233 bool natcall2utf(bool natcallcompdone) {
1236 if (natcallcompdone)
1239 for (i=0;i<NATIVECALLSSIZE; i++) {
1240 utfNativeCall (nativeCalls[i], &nativeCompCalls[i]);
1247 * These are local overrides for various environment variables in Emacs.
1248 * Please do not remove this and leave it at the end of the file, where
1249 * Emacs will automagically detect them.
1250 * ---------------------------------------------------------------------
1253 * indent-tabs-mode: t