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 3445 2005-10-19 11:28:41Z 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 /************* 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_library_hash_find ****************************************************
412 Find an entry in the native library hashtable.
414 *******************************************************************************/
416 #if !defined(ENABLE_STATICVM)
417 library_hash_name_entry *native_library_hash_find(utf *filename,
418 java_objectheader *loader)
420 library_hash_loader_entry *le;
421 library_hash_name_entry *ne; /* library name */
422 u4 key; /* hashkey */
423 u4 slot; /* slot in hashtable */
425 /* normally addresses are aligned to 4, 8 or 16 bytes */
427 key = ((u4) (ptrint) loader) >> 4; /* align to 16-byte boundaries */
428 slot = key & (library_hash.size - 1);
429 le = library_hash.ptr[slot];
431 /* search external hash chain for the entry */
434 if (le->loader == loader)
437 le = le->hashlink; /* next element in external chain */
440 /* no loader found? return NULL */
445 /* search for library name */
450 if (ne->name == filename)
453 ne = ne->hashlink; /* next element in external chain */
456 /* return entry, if no entry was found, ne is NULL */
460 #endif /* !defined(ENABLE_STATICVM) */
463 /* native_findfunction *********************************************************
465 Looks up a method (must have the same class name, method name,
466 descriptor and 'static'ness) and returns a function pointer to it.
467 Returns: function pointer or NULL (if there is no such method)
469 Remark: For faster operation, the names/descriptors are converted
470 from C strings to Unicode the first time this function is called.
472 *******************************************************************************/
474 #if defined(ENABLE_STATICVM)
475 functionptr native_findfunction(utf *cname, utf *mname, utf *desc,
478 /* entry of table for fast string comparison */
479 struct nativecompref *n;
482 isstatic = isstatic ? true : false;
484 if (!nativecompdone) {
485 for (i = 0; i < NATIVETABLESIZE; i++) {
486 nativecomptable[i].classname =
487 utf_new_char(nativetable[i].classname);
489 nativecomptable[i].methodname =
490 utf_new_char(nativetable[i].methodname);
492 nativecomptable[i].descriptor =
493 utf_new_char(nativetable[i].descriptor);
495 nativecomptable[i].isstatic = nativetable[i].isstatic;
496 nativecomptable[i].func = nativetable[i].func;
499 nativecompdone = true;
502 for (i = 0; i < NATIVETABLESIZE; i++) {
503 n = &(nativecomptable[i]);
505 if (cname == n->classname && mname == n->methodname &&
506 desc == n->descriptor && isstatic == n->isstatic)
511 /* no function was found, throw exception */
514 new_exception_utfmessage(string_java_lang_UnsatisfiedLinkError,
519 #endif /* defined(ENABLE_STATICVM) */
522 /* native_make_overloaded_function *********************************************
526 *******************************************************************************/
528 #if !defined(ENABLE_STATICVM)
529 static char *native_make_overloaded_function(char *name, utf *desc)
537 utf_ptr = desc->text;
538 namelen = strlen(name) + strlen("__") + strlen("0");
540 /* calculate additional length */
542 while ((c = utf_nextu2(&utf_ptr)) != ')') {
559 while (utf_nextu2(&utf_ptr) != ';')
571 /* reallocate memory */
575 newname = DMNEW(char, namelen);
576 MCOPY(newname, name, char, i);
578 utf_ptr = desc->text;
583 while ((c = utf_nextu2(&utf_ptr)) != ')') {
601 while ((c = utf_nextu2(&utf_ptr)) != ';')
602 if (((c >= 'a') && (c <= 'z')) ||
603 ((c >= 'A') && (c <= 'Z')) ||
604 ((c >= '0') && (c <= '9')))
626 /* native_resolve_function *****************************************************
628 Resolves a native function, maybe from a dynamic library.
630 *******************************************************************************/
632 functionptr native_resolve_function(methodinfo *m)
641 library_hash_loader_entry *le;
642 library_hash_name_entry *ne;
643 u4 key; /* hashkey */
644 u4 slot; /* slot in hashtable */
650 if (opt_verbosejni) {
651 printf("[Dynamic-linking native method ");
652 utf_display_classname(m->class->name);
654 utf_display(m->name);
658 /* calculate length of native function name */
660 namelen = strlen("Java_") + utf_strlen(m->class->name) + strlen("_") +
661 utf_strlen(m->name) + strlen("0");
663 /* check for underscores in class name */
665 utf_ptr = m->class->name->text;
666 utf_endptr = UTF_END(m->class->name);
668 while (utf_ptr < utf_endptr)
669 if (utf_nextu2(&utf_ptr) == '_')
672 /* check for underscores in method name */
674 utf_ptr = m->name->text;
675 utf_endptr = UTF_END(m->name);
677 while (utf_ptr < utf_endptr)
678 if (utf_nextu2(&utf_ptr) == '_')
681 /* allocate memory */
683 dumpsize = dump_size();
685 name = DMNEW(char, namelen);
688 /* generate name of native functions */
690 strcpy(name, "Java_");
693 utf_ptr = m->class->name->text;
694 utf_endptr = UTF_END(m->class->name);
696 for (; utf_ptr < utf_endptr; utf_ptr++, i++) {
699 /* escape sequence for '_' is '_1' */
704 /* replace '/' with '_' */
710 /* seperator between class and method */
714 utf_ptr = m->name->text;
715 utf_endptr = UTF_END(m->name);
717 for (; utf_ptr < utf_endptr; utf_ptr++, i++) {
720 /* escape sequence for '_' is '_1' */
731 /* generate overloaded function (having the types in it's name) */
733 newname = native_make_overloaded_function(name, m->descriptor);
735 /* check the library hash entries of the classloader of the methods's */
740 /* normally addresses are aligned to 4, 8 or 16 bytes */
742 key = ((u4) (ptrint) m->class->classloader) >> 4; /* align to 16-byte */
743 slot = key & (library_hash.size - 1);
744 le = library_hash.ptr[slot];
746 /* iterate through loaders in this hash slot */
749 /* iterate through names in this loader */
754 sym = lt_dlsym(ne->handle, name);
757 sym = lt_dlsym(ne->handle, newname);
770 /* if not found, try to find the native function symbol in the main */
774 sym = lt_dlsym(mainhandle, name);
777 sym = lt_dlsym(mainhandle, newname);
781 printf("internal ]\n");
785 /* no symbol found? throw exception */
789 new_exception_utfmessage(string_java_lang_UnsatisfiedLinkError,
794 dump_release(dumpsize);
796 return (functionptr) (ptrint) sym;
798 #endif /* !defined(ENABLE_STATICVM) */
801 /* native_new_and_init *********************************************************
803 Creates a new object on the heap and calls the initializer.
804 Returns the object pointer or NULL if memory is exhausted.
806 *******************************************************************************/
808 java_objectheader *native_new_and_init(classinfo *c)
811 java_objectheader *o;
814 return *exceptionptr;
823 /* find initializer */
825 m = class_findmethod(c, utf_init, utf_void__void);
827 /* initializer not found */
832 /* call initializer */
834 asm_calljavafunction(m, o, NULL, NULL, NULL);
840 java_objectheader *native_new_and_init_string(classinfo *c, java_lang_String *s)
843 java_objectheader *o;
846 return *exceptionptr;
855 /* find initializer */
857 m = class_resolveclassmethod(c,
859 utf_java_lang_String__void,
863 /* initializer not found */
868 /* call initializer */
870 asm_calljavafunction(m, o, s, NULL, NULL);
876 java_objectheader *native_new_and_init_int(classinfo *c, s4 i)
879 java_objectheader *o;
882 return *exceptionptr;
891 /* find initializer */
893 m = class_resolveclassmethod(c, utf_init, utf_int__void, NULL, true);
895 /* initializer not found */
900 /* call initializer */
902 asm_calljavafunction(m, o, (void *) (ptrint) i, NULL, NULL);
908 java_objectheader *native_new_and_init_throwable(classinfo *c, java_lang_Throwable *t)
911 java_objectheader *o;
914 return *exceptionptr;
923 /* find initializer */
925 m = class_findmethod(c, utf_init, utf_java_lang_Throwable__void);
927 /* initializer not found */
932 /* call initializer */
934 asm_calljavafunction(m, o, t, NULL, NULL);
940 void copy_vftbl(vftbl_t **dest, vftbl_t *src)
944 /* XXX this kind of copying does not work (in the general
945 * case). The interface tables would have to be copied, too. I
946 * don't see why we should make a copy anyway. -Edwin
948 *dest = mem_alloc(sizeof(vftbl) + sizeof(methodptr)*(src->vftbllength-1));
949 memcpy(*dest, src, sizeof(vftbl) - sizeof(methodptr));
950 memcpy(&(*dest)->table, &src->table, src->vftbllength * sizeof(methodptr));
955 /******************************************************************************************
957 creates method signature (excluding return type) from array of
958 class-objects representing the parameters of the method
960 *******************************************************************************************/
963 utf *create_methodsig(java_objectarray* types, char *retType)
965 char *buffer; /* buffer for building the desciptor */
966 char *pos; /* current position in buffer */
967 utf *result; /* the method signature */
968 u4 buffer_size = 3; /* minimal size=3: room for parenthesis and returntype */
971 if (!types) return NULL;
973 /* determine required buffer-size */
974 for (i = 0; i < types->header.size; i++) {
975 classinfo *c = (classinfo *) types->data[i];
976 buffer_size = buffer_size + c->name->blength + 2;
979 if (retType) buffer_size += strlen(retType);
981 /* allocate buffer */
982 buffer = MNEW(char, buffer_size);
985 /* method-desciptor starts with parenthesis */
988 for (i = 0; i < types->header.size; i++) {
991 /* current argument */
992 classinfo *c = (classinfo *) types->data[i];
994 /* current position in utf-text */
995 char *utf_ptr = c->name->text;
997 /* determine type of argument */
998 if ((ch = utf_nextu2(&utf_ptr)) == '[') {
1000 for (utf_ptr--; utf_ptr < UTF_END(c->name); utf_ptr++) {
1001 *pos++ = *utf_ptr; /* copy text */
1005 /* check for primitive types */
1006 for (j = 0; j < PRIMITIVETYPE_COUNT; j++) {
1007 char *utf_pos = utf_ptr - 1;
1008 char *primitive = primitivetype_table[j].wrapname;
1011 while (utf_pos < UTF_END(c->name)) {
1012 if (*utf_pos++ != *primitive++) goto nomatch;
1015 /* primitive type found */
1016 *pos++ = primitivetype_table[j].typesig;
1023 /* no primitive type and no arrayclass, so must be object */
1027 for (utf_ptr--; utf_ptr < UTF_END(c->name); utf_ptr++) {
1041 for (i = 0; i < strlen(retType); i++) {
1042 *pos++ = retType[i];
1046 /* create utf-string */
1047 result = utf_new(buffer, (pos - buffer));
1048 MFREE(buffer, char, buffer_size);
1054 /* native_get_parametertypes ***************************************************
1056 Use the descriptor of a method to generate a java/lang/Class array
1057 which contains the classes of the parametertypes of the method.
1059 *******************************************************************************/
1061 java_objectarray *native_get_parametertypes(methodinfo *m)
1064 typedesc *paramtypes;
1066 java_objectarray *oa;
1071 /* is the descriptor fully parsed? */
1073 if (!m->parseddesc->params)
1074 if (!descriptor_params_from_paramtypes(md, m->flags))
1077 paramtypes = md->paramtypes;
1078 paramcount = md->paramcount;
1080 /* skip `this' pointer */
1082 if (!(m->flags & ACC_STATIC)) {
1087 /* create class-array */
1089 oa = builtin_anewarray(paramcount, class_java_lang_Class);
1096 for (i = 0; i < paramcount; i++) {
1097 if (!resolve_class_from_typedesc(¶mtypes[i], true, false,
1098 (classinfo **) &oa->data[i]))
1101 use_class_as_object((classinfo *) oa->data[i]);
1108 /* native_get_exceptiontypes ***************************************************
1110 Get the exceptions which can be thrown by a method.
1112 *******************************************************************************/
1114 java_objectarray *native_get_exceptiontypes(methodinfo *m)
1116 java_objectarray *oa;
1120 /* create class-array */
1122 oa = builtin_anewarray(m->thrownexceptionscount, class_java_lang_Class);
1127 for (i = 0; i < m->thrownexceptionscount; i++) {
1128 if (!resolve_classref_or_classinfo(NULL, m->thrownexceptions[i],
1129 resolveEager, true, false, &c))
1132 if (!use_class_as_object(c))
1135 oa->data[i] = (java_objectheader *) c;
1142 /* native_get_returntype *******************************************************
1144 Get the returntype class of a method.
1146 *******************************************************************************/
1148 classinfo *native_get_returntype(methodinfo *m)
1152 if (!resolve_class_from_typedesc(&(m->parseddesc->returntype), true, false,
1156 use_class_as_object(c);
1162 /*****************************************************************************/
1163 /*****************************************************************************/
1166 /*--------------------------------------------------------*/
1167 void printNativeCall(nativeCall nc) {
1170 printf("\n%s's Native Methods call:\n",nc.classname); fflush(stdout);
1171 for (i=0; i<nc.methCnt; i++) {
1172 printf("\tMethod=%s %s\n",nc.methods[i].methodname, nc.methods[i].descriptor);fflush(stdout);
1174 for (j=0; j<nc.callCnt[i]; j++) {
1175 printf("\t\t<%i,%i>aCalled = %s %s %s\n",i,j,
1176 nc.methods[i].methodCalls[j].classname,
1177 nc.methods[i].methodCalls[j].methodname,
1178 nc.methods[i].methodCalls[j].descriptor);fflush(stdout);
1181 printf("-+++++--------------------\n");fflush(stdout);
1184 /*--------------------------------------------------------*/
1185 void printCompNativeCall(nativeCompCall nc) {
1187 printf("printCompNativeCall BEGIN\n");fflush(stdout);
1188 printf("\n%s's Native Comp Methods call:\n",nc.classname->text);fflush(stdout);
1189 utf_display(nc.classname); fflush(stdout);
1191 for (i=0; i<nc.methCnt; i++) {
1192 printf("\tMethod=%s %s\n",nc.methods[i].methodname->text,nc.methods[i].descriptor->text);fflush(stdout);
1193 utf_display(nc.methods[i].methodname); fflush(stdout);
1194 utf_display(nc.methods[i].descriptor);fflush(stdout);
1195 printf("\n");fflush(stdout);
1197 for (j=0; j<nc.callCnt[i]; j++) {
1198 printf("\t\t<%i,%i>bCalled = ",i,j);fflush(stdout);
1199 utf_display(nc.methods[i].methodCalls[j].classname);fflush(stdout);
1200 utf_display(nc.methods[i].methodCalls[j].methodname); fflush(stdout);
1201 utf_display(nc.methods[i].methodCalls[j].descriptor);fflush(stdout);
1202 printf("\n");fflush(stdout);
1205 printf("---------------------\n");fflush(stdout);
1209 /*--------------------------------------------------------*/
1210 classMeth findNativeMethodCalls(utf *c, utf *m, utf *d )
1223 /*--------------------------------------------------------*/
1224 nativeCall* findNativeClassCalls(char *aclassname ) {
1227 for (i=0;i<NATIVECALLSSIZE; i++) {
1228 /* convert table to utf later to speed up search */
1229 if (strcmp(nativeCalls[i].classname, aclassname) == 0)
1230 return &nativeCalls[i];
1235 /*--------------------------------------------------------*/
1236 /*--------------------------------------------------------*/
1237 void utfNativeCall(nativeCall nc, nativeCompCall *ncc) {
1241 ncc->classname = utf_new_char(nc.classname);
1242 ncc->methCnt = nc.methCnt;
1244 for (i=0; i<nc.methCnt; i++) {
1245 ncc->methods[i].methodname = utf_new_char(nc.methods[i].methodname);
1246 ncc->methods[i].descriptor = utf_new_char(nc.methods[i].descriptor);
1247 ncc->callCnt[i] = nc.callCnt[i];
1249 for (j=0; j<nc.callCnt[i]; j++) {
1251 ncc->methods[i].methodCalls[j].classname = utf_new_char(nc.methods[i].methodCalls[j].classname);
1253 if (strcmp("", nc.methods[i].methodCalls[j].methodname) != 0) {
1254 ncc->methods[i].methodCalls[j].methodname = utf_new_char(nc.methods[i].methodCalls[j].methodname);
1255 ncc->methods[i].methodCalls[j].descriptor = utf_new_char(nc.methods[i].methodCalls[j].descriptor);
1258 ncc->methods[i].methodCalls[j].methodname = NULL;
1259 ncc->methods[i].methodCalls[j].descriptor = NULL;
1267 /*--------------------------------------------------------*/
1269 bool natcall2utf(bool natcallcompdone) {
1272 if (natcallcompdone)
1275 for (i=0;i<NATIVECALLSSIZE; i++) {
1276 utfNativeCall (nativeCalls[i], &nativeCompCalls[i]);
1283 * These are local overrides for various environment variables in Emacs.
1284 * Please do not remove this and leave it at the end of the file, where
1285 * Emacs will automagically detect them.
1286 * ---------------------------------------------------------------------
1289 * indent-tabs-mode: t