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 3828 2005-12-01 19:46:05Z 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/hashtable.h"
53 #include "vm/loader.h"
54 #include "vm/options.h"
55 #include "vm/resolve.h"
56 #include "vm/stringlocal.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 hashtable_library;
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 hashtable_create(&hashtable_library, 10);
301 /* everything's ok */
307 /* native_hashtable_library_add ************************************************
309 Adds an entry to the native library hashtable.
311 *******************************************************************************/
313 #if !defined(ENABLE_STATICVM)
314 void native_hashtable_library_add(utf *filename, java_objectheader *loader,
317 hashtable_library_loader_entry *le;
318 hashtable_library_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 & (hashtable_library.size - 1);
326 le = hashtable_library.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(hashtable_library_loader_entry);
345 /* insert entry into hashtable */
348 (hashtable_library_loader_entry *) hashtable_library.ptr[slot];
349 hashtable_library.ptr[slot] = le;
351 /* update number of hashtable-entries */
353 hashtable_library.entries++;
357 /* search for library name */
362 if (ne->name == filename)
365 ne = ne->hashlink; /* next element in external chain */
368 /* not found? add the library name to the classloader */
370 ne = NEW(hashtable_library_name_entry);
375 /* insert entry into external chain */
377 ne->hashlink = le->namelink;
380 #endif /* !defined(ENABLE_STATICVM) */
383 /* native_hashtable_library_find ***********************************************
385 Find an entry in the native library hashtable.
387 *******************************************************************************/
389 #if !defined(ENABLE_STATICVM)
390 hashtable_library_name_entry *native_hashtable_library_find(utf *filename,
391 java_objectheader *loader)
393 hashtable_library_loader_entry *le;
394 hashtable_library_name_entry *ne; /* library name */
395 u4 key; /* hashkey */
396 u4 slot; /* slot in hashtable */
398 /* normally addresses are aligned to 4, 8 or 16 bytes */
400 key = ((u4) (ptrint) loader) >> 4; /* align to 16-byte boundaries */
401 slot = key & (hashtable_library.size - 1);
402 le = hashtable_library.ptr[slot];
404 /* search external hash chain for the entry */
407 if (le->loader == loader)
410 le = le->hashlink; /* next element in external chain */
413 /* no loader found? return NULL */
418 /* search for library name */
423 if (ne->name == filename)
426 ne = ne->hashlink; /* next element in external chain */
429 /* return entry, if no entry was found, ne is NULL */
433 #endif /* !defined(ENABLE_STATICVM) */
436 /* native_findfunction *********************************************************
438 Looks up a method (must have the same class name, method name,
439 descriptor and 'static'ness) and returns a function pointer to it.
440 Returns: function pointer or NULL (if there is no such method)
442 Remark: For faster operation, the names/descriptors are converted
443 from C strings to Unicode the first time this function is called.
445 *******************************************************************************/
447 #if defined(ENABLE_STATICVM)
448 functionptr native_findfunction(utf *cname, utf *mname, utf *desc,
451 /* entry of table for fast string comparison */
452 struct nativecompref *n;
455 isstatic = isstatic ? true : false;
457 if (!nativecompdone) {
458 for (i = 0; i < NATIVETABLESIZE; i++) {
459 nativecomptable[i].classname =
460 utf_new_char(nativetable[i].classname);
462 nativecomptable[i].methodname =
463 utf_new_char(nativetable[i].methodname);
465 nativecomptable[i].descriptor =
466 utf_new_char(nativetable[i].descriptor);
468 nativecomptable[i].isstatic = nativetable[i].isstatic;
469 nativecomptable[i].func = nativetable[i].func;
472 nativecompdone = true;
475 for (i = 0; i < NATIVETABLESIZE; i++) {
476 n = &(nativecomptable[i]);
478 if (cname == n->classname && mname == n->methodname &&
479 desc == n->descriptor && isstatic == n->isstatic)
484 /* no function was found, throw exception */
487 new_exception_utfmessage(string_java_lang_UnsatisfiedLinkError,
492 #endif /* defined(ENABLE_STATICVM) */
495 /* native_make_overloaded_function *********************************************
499 *******************************************************************************/
501 #if !defined(ENABLE_STATICVM)
502 static char *native_make_overloaded_function(char *name, utf *desc)
510 utf_ptr = desc->text;
511 namelen = strlen(name) + strlen("__") + strlen("0");
513 /* calculate additional length */
515 while ((c = utf_nextu2(&utf_ptr)) != ')') {
532 while (utf_nextu2(&utf_ptr) != ';')
544 /* reallocate memory */
548 newname = DMNEW(char, namelen);
549 MCOPY(newname, name, char, i);
551 utf_ptr = desc->text;
556 while ((c = utf_nextu2(&utf_ptr)) != ')') {
574 while ((c = utf_nextu2(&utf_ptr)) != ';')
575 if (((c >= 'a') && (c <= 'z')) ||
576 ((c >= 'A') && (c <= 'Z')) ||
577 ((c >= '0') && (c <= '9')))
599 /* native_resolve_function *****************************************************
601 Resolves a native function, maybe from a dynamic library.
603 *******************************************************************************/
605 functionptr native_resolve_function(methodinfo *m)
614 hashtable_library_loader_entry *le;
615 hashtable_library_name_entry *ne;
616 u4 key; /* hashkey */
617 u4 slot; /* slot in hashtable */
623 if (opt_verbosejni) {
624 printf("[Dynamic-linking native method ");
625 utf_display_classname(m->class->name);
627 utf_display(m->name);
631 /* calculate length of native function name */
633 namelen = strlen("Java_") + utf_strlen(m->class->name) + strlen("_") +
634 utf_strlen(m->name) + strlen("0");
636 /* check for underscores in class name */
638 utf_ptr = m->class->name->text;
639 utf_endptr = UTF_END(m->class->name);
641 while (utf_ptr < utf_endptr)
642 if (utf_nextu2(&utf_ptr) == '_')
645 /* check for underscores in method name */
647 utf_ptr = m->name->text;
648 utf_endptr = UTF_END(m->name);
650 while (utf_ptr < utf_endptr)
651 if (utf_nextu2(&utf_ptr) == '_')
654 /* allocate memory */
656 dumpsize = dump_size();
658 name = DMNEW(char, namelen);
661 /* generate name of native functions */
663 strcpy(name, "Java_");
666 utf_ptr = m->class->name->text;
667 utf_endptr = UTF_END(m->class->name);
669 for (; utf_ptr < utf_endptr; utf_ptr++, i++) {
672 /* escape sequence for '_' is '_1' */
677 /* replace '/' with '_' */
683 /* seperator between class and method */
687 utf_ptr = m->name->text;
688 utf_endptr = UTF_END(m->name);
690 for (; utf_ptr < utf_endptr; utf_ptr++, i++) {
693 /* escape sequence for '_' is '_1' */
704 /* generate overloaded function (having the types in it's name) */
706 newname = native_make_overloaded_function(name, m->descriptor);
708 /* check the library hash entries of the classloader of the methods's */
713 /* normally addresses are aligned to 4, 8 or 16 bytes */
715 key = ((u4) (ptrint) m->class->classloader) >> 4; /* align to 16-byte */
716 slot = key & (hashtable_library.size - 1);
717 le = hashtable_library.ptr[slot];
719 /* iterate through loaders in this hash slot */
722 /* iterate through names in this loader */
727 sym = lt_dlsym(ne->handle, name);
730 sym = lt_dlsym(ne->handle, newname);
743 /* if not found, try to find the native function symbol in the main */
747 sym = lt_dlsym(mainhandle, name);
750 sym = lt_dlsym(mainhandle, newname);
754 printf("internal ]\n");
758 /* no symbol found? throw exception */
762 new_exception_utfmessage(string_java_lang_UnsatisfiedLinkError,
767 dump_release(dumpsize);
769 return (functionptr) (ptrint) sym;
771 #endif /* !defined(ENABLE_STATICVM) */
774 /* native_new_and_init *********************************************************
776 Creates a new object on the heap and calls the initializer.
777 Returns the object pointer or NULL if memory is exhausted.
779 *******************************************************************************/
781 java_objectheader *native_new_and_init(classinfo *c)
784 java_objectheader *o;
787 return *exceptionptr;
796 /* find initializer */
798 m = class_findmethod(c, utf_init, utf_void__void);
800 /* initializer not found */
805 /* call initializer */
807 asm_calljavafunction(m, o, NULL, NULL, NULL);
813 java_objectheader *native_new_and_init_string(classinfo *c, java_lang_String *s)
816 java_objectheader *o;
819 return *exceptionptr;
828 /* find initializer */
830 m = class_resolveclassmethod(c,
832 utf_java_lang_String__void,
836 /* initializer not found */
841 /* call initializer */
843 asm_calljavafunction(m, o, s, NULL, NULL);
849 java_objectheader *native_new_and_init_int(classinfo *c, s4 i)
852 java_objectheader *o;
855 return *exceptionptr;
864 /* find initializer */
866 m = class_resolveclassmethod(c, utf_init, utf_int__void, NULL, true);
868 /* initializer not found */
873 /* call initializer */
875 asm_calljavafunction(m, o, (void *) (ptrint) i, NULL, NULL);
881 java_objectheader *native_new_and_init_throwable(classinfo *c, java_lang_Throwable *t)
884 java_objectheader *o;
887 return *exceptionptr;
896 /* find initializer */
898 m = class_findmethod(c, utf_init, utf_java_lang_Throwable__void);
900 /* initializer not found */
905 /* call initializer */
907 asm_calljavafunction(m, o, t, NULL, NULL);
913 void copy_vftbl(vftbl_t **dest, vftbl_t *src)
917 /* XXX this kind of copying does not work (in the general
918 * case). The interface tables would have to be copied, too. I
919 * don't see why we should make a copy anyway. -Edwin
921 *dest = mem_alloc(sizeof(vftbl) + sizeof(methodptr)*(src->vftbllength-1));
922 memcpy(*dest, src, sizeof(vftbl) - sizeof(methodptr));
923 memcpy(&(*dest)->table, &src->table, src->vftbllength * sizeof(methodptr));
928 /******************************************************************************************
930 creates method signature (excluding return type) from array of
931 class-objects representing the parameters of the method
933 *******************************************************************************************/
936 utf *create_methodsig(java_objectarray* types, char *retType)
938 char *buffer; /* buffer for building the desciptor */
939 char *pos; /* current position in buffer */
940 utf *result; /* the method signature */
941 u4 buffer_size = 3; /* minimal size=3: room for parenthesis and returntype */
944 if (!types) return NULL;
946 /* determine required buffer-size */
947 for (i = 0; i < types->header.size; i++) {
948 classinfo *c = (classinfo *) types->data[i];
949 buffer_size = buffer_size + c->name->blength + 2;
952 if (retType) buffer_size += strlen(retType);
954 /* allocate buffer */
955 buffer = MNEW(char, buffer_size);
958 /* method-desciptor starts with parenthesis */
961 for (i = 0; i < types->header.size; i++) {
964 /* current argument */
965 classinfo *c = (classinfo *) types->data[i];
967 /* current position in utf-text */
968 char *utf_ptr = c->name->text;
970 /* determine type of argument */
971 if ((ch = utf_nextu2(&utf_ptr)) == '[') {
973 for (utf_ptr--; utf_ptr < UTF_END(c->name); utf_ptr++) {
974 *pos++ = *utf_ptr; /* copy text */
978 /* check for primitive types */
979 for (j = 0; j < PRIMITIVETYPE_COUNT; j++) {
980 char *utf_pos = utf_ptr - 1;
981 char *primitive = primitivetype_table[j].wrapname;
984 while (utf_pos < UTF_END(c->name)) {
985 if (*utf_pos++ != *primitive++) goto nomatch;
988 /* primitive type found */
989 *pos++ = primitivetype_table[j].typesig;
996 /* no primitive type and no arrayclass, so must be object */
1000 for (utf_ptr--; utf_ptr < UTF_END(c->name); utf_ptr++) {
1014 for (i = 0; i < strlen(retType); i++) {
1015 *pos++ = retType[i];
1019 /* create utf-string */
1020 result = utf_new(buffer, (pos - buffer));
1021 MFREE(buffer, char, buffer_size);
1027 /* native_get_parametertypes ***************************************************
1029 Use the descriptor of a method to generate a java/lang/Class array
1030 which contains the classes of the parametertypes of the method.
1032 *******************************************************************************/
1034 java_objectarray *native_get_parametertypes(methodinfo *m)
1037 typedesc *paramtypes;
1039 java_objectarray *oa;
1044 /* is the descriptor fully parsed? */
1046 if (!m->parseddesc->params)
1047 if (!descriptor_params_from_paramtypes(md, m->flags))
1050 paramtypes = md->paramtypes;
1051 paramcount = md->paramcount;
1053 /* skip `this' pointer */
1055 if (!(m->flags & ACC_STATIC)) {
1060 /* create class-array */
1062 oa = builtin_anewarray(paramcount, class_java_lang_Class);
1069 for (i = 0; i < paramcount; i++)
1070 if (!resolve_class_from_typedesc(¶mtypes[i], true, false,
1071 (classinfo **) &oa->data[i]))
1078 /* native_get_exceptiontypes ***************************************************
1080 Get the exceptions which can be thrown by a method.
1082 *******************************************************************************/
1084 java_objectarray *native_get_exceptiontypes(methodinfo *m)
1086 java_objectarray *oa;
1090 /* create class-array */
1092 oa = builtin_anewarray(m->thrownexceptionscount, class_java_lang_Class);
1097 for (i = 0; i < m->thrownexceptionscount; i++) {
1098 if (!resolve_classref_or_classinfo(NULL, m->thrownexceptions[i],
1099 resolveEager, true, false, &c))
1102 oa->data[i] = (java_objectheader *) c;
1109 /* native_get_returntype *******************************************************
1111 Get the returntype class of a method.
1113 *******************************************************************************/
1115 classinfo *native_get_returntype(methodinfo *m)
1119 if (!resolve_class_from_typedesc(&(m->parseddesc->returntype), true, false,
1127 /*****************************************************************************/
1128 /*****************************************************************************/
1131 /*--------------------------------------------------------*/
1132 void printNativeCall(nativeCall nc) {
1135 printf("\n%s's Native Methods call:\n",nc.classname); fflush(stdout);
1136 for (i=0; i<nc.methCnt; i++) {
1137 printf("\tMethod=%s %s\n",nc.methods[i].methodname, nc.methods[i].descriptor);fflush(stdout);
1139 for (j=0; j<nc.callCnt[i]; j++) {
1140 printf("\t\t<%i,%i>aCalled = %s %s %s\n",i,j,
1141 nc.methods[i].methodCalls[j].classname,
1142 nc.methods[i].methodCalls[j].methodname,
1143 nc.methods[i].methodCalls[j].descriptor);fflush(stdout);
1146 printf("-+++++--------------------\n");fflush(stdout);
1149 /*--------------------------------------------------------*/
1150 void printCompNativeCall(nativeCompCall nc) {
1152 printf("printCompNativeCall BEGIN\n");fflush(stdout);
1153 printf("\n%s's Native Comp Methods call:\n",nc.classname->text);fflush(stdout);
1154 utf_display(nc.classname); fflush(stdout);
1156 for (i=0; i<nc.methCnt; i++) {
1157 printf("\tMethod=%s %s\n",nc.methods[i].methodname->text,nc.methods[i].descriptor->text);fflush(stdout);
1158 utf_display(nc.methods[i].methodname); fflush(stdout);
1159 utf_display(nc.methods[i].descriptor);fflush(stdout);
1160 printf("\n");fflush(stdout);
1162 for (j=0; j<nc.callCnt[i]; j++) {
1163 printf("\t\t<%i,%i>bCalled = ",i,j);fflush(stdout);
1164 utf_display(nc.methods[i].methodCalls[j].classname);fflush(stdout);
1165 utf_display(nc.methods[i].methodCalls[j].methodname); fflush(stdout);
1166 utf_display(nc.methods[i].methodCalls[j].descriptor);fflush(stdout);
1167 printf("\n");fflush(stdout);
1170 printf("---------------------\n");fflush(stdout);
1174 /*--------------------------------------------------------*/
1175 classMeth findNativeMethodCalls(utf *c, utf *m, utf *d )
1188 /*--------------------------------------------------------*/
1189 nativeCall* findNativeClassCalls(char *aclassname ) {
1192 for (i=0;i<NATIVECALLSSIZE; i++) {
1193 /* convert table to utf later to speed up search */
1194 if (strcmp(nativeCalls[i].classname, aclassname) == 0)
1195 return &nativeCalls[i];
1200 /*--------------------------------------------------------*/
1201 /*--------------------------------------------------------*/
1202 void utfNativeCall(nativeCall nc, nativeCompCall *ncc) {
1206 ncc->classname = utf_new_char(nc.classname);
1207 ncc->methCnt = nc.methCnt;
1209 for (i=0; i<nc.methCnt; i++) {
1210 ncc->methods[i].methodname = utf_new_char(nc.methods[i].methodname);
1211 ncc->methods[i].descriptor = utf_new_char(nc.methods[i].descriptor);
1212 ncc->callCnt[i] = nc.callCnt[i];
1214 for (j=0; j<nc.callCnt[i]; j++) {
1216 ncc->methods[i].methodCalls[j].classname = utf_new_char(nc.methods[i].methodCalls[j].classname);
1218 if (strcmp("", nc.methods[i].methodCalls[j].methodname) != 0) {
1219 ncc->methods[i].methodCalls[j].methodname = utf_new_char(nc.methods[i].methodCalls[j].methodname);
1220 ncc->methods[i].methodCalls[j].descriptor = utf_new_char(nc.methods[i].methodCalls[j].descriptor);
1223 ncc->methods[i].methodCalls[j].methodname = NULL;
1224 ncc->methods[i].methodCalls[j].descriptor = NULL;
1232 /*--------------------------------------------------------*/
1234 bool natcall2utf(bool natcallcompdone) {
1237 if (natcallcompdone)
1240 for (i=0;i<NATIVECALLSSIZE; i++) {
1241 utfNativeCall (nativeCalls[i], &nativeCompCalls[i]);
1248 * These are local overrides for various environment variables in Emacs.
1249 * Please do not remove this and leave it at the end of the file, where
1250 * Emacs will automagically detect them.
1251 * ---------------------------------------------------------------------
1254 * indent-tabs-mode: t