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 3160 2005-09-10 14:29:52Z 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_Method.h"
86 #include "native/include/java_lang_reflect_VMProxy.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_throwException,
140 (functionptr) Java_java_lang_VMClassLoader_defineClass,
141 (functionptr) Java_java_lang_VMClassLoader_resolveClass,
142 (functionptr) Java_java_lang_VMClassLoader_loadClass,
143 (functionptr) Java_java_lang_VMClassLoader_getPrimitiveClass,
144 (functionptr) Java_java_lang_VMClassLoader_nativeGetResources,
145 (functionptr) Java_java_lang_VMClassLoader_findLoadedClass,
147 (functionptr) Java_java_lang_VMObject_getClass,
148 (functionptr) Java_java_lang_VMObject_clone,
149 (functionptr) Java_java_lang_VMObject_notify,
150 (functionptr) Java_java_lang_VMObject_notifyAll,
151 (functionptr) Java_java_lang_VMObject_wait,
153 (functionptr) Java_java_lang_VMRuntime_availableProcessors,
154 (functionptr) Java_java_lang_VMRuntime_freeMemory,
155 (functionptr) Java_java_lang_VMRuntime_totalMemory,
156 (functionptr) Java_java_lang_VMRuntime_maxMemory,
157 (functionptr) Java_java_lang_VMRuntime_gc,
158 (functionptr) Java_java_lang_VMRuntime_runFinalization,
159 (functionptr) Java_java_lang_VMRuntime_runFinalizationForExit,
160 (functionptr) Java_java_lang_VMRuntime_traceInstructions,
161 (functionptr) Java_java_lang_VMRuntime_traceMethodCalls,
162 (functionptr) Java_java_lang_VMRuntime_runFinalizersOnExit,
163 (functionptr) Java_java_lang_VMRuntime_exit,
164 (functionptr) Java_java_lang_VMRuntime_nativeLoad,
165 (functionptr) Java_java_lang_VMRuntime_mapLibraryName,
167 (functionptr) Java_java_lang_VMString_intern,
169 (functionptr) Java_java_lang_VMSystem_arraycopy,
170 (functionptr) Java_java_lang_VMSystem_identityHashCode,
172 (functionptr) Java_java_lang_VMThread_start,
173 (functionptr) Java_java_lang_VMThread_interrupt,
174 (functionptr) Java_java_lang_VMThread_isInterrupted,
175 (functionptr) Java_java_lang_VMThread_suspend,
176 (functionptr) Java_java_lang_VMThread_resume,
177 (functionptr) Java_java_lang_VMThread_nativeSetPriority,
178 (functionptr) Java_java_lang_VMThread_nativeStop,
179 (functionptr) Java_java_lang_VMThread_currentThread,
180 (functionptr) Java_java_lang_VMThread_yield,
181 (functionptr) Java_java_lang_VMThread_interrupted,
182 (functionptr) Java_java_lang_VMThread_holdsLock,
184 (functionptr) Java_java_lang_VMThrowable_fillInStackTrace,
185 (functionptr) Java_java_lang_VMThrowable_getStackTrace,
187 (functionptr) Java_java_lang_reflect_Constructor_getModifiers,
188 (functionptr) Java_java_lang_reflect_Constructor_constructNative,
190 (functionptr) Java_java_lang_reflect_Field_getModifiers,
191 (functionptr) Java_java_lang_reflect_Field_getType,
192 (functionptr) Java_java_lang_reflect_Field_get,
193 (functionptr) Java_java_lang_reflect_Field_getBoolean,
194 (functionptr) Java_java_lang_reflect_Field_getByte,
195 (functionptr) Java_java_lang_reflect_Field_getChar,
196 (functionptr) Java_java_lang_reflect_Field_getShort,
197 (functionptr) Java_java_lang_reflect_Field_getInt,
198 (functionptr) Java_java_lang_reflect_Field_getLong,
199 (functionptr) Java_java_lang_reflect_Field_getFloat,
200 (functionptr) Java_java_lang_reflect_Field_getDouble,
201 (functionptr) Java_java_lang_reflect_Field_set,
202 (functionptr) Java_java_lang_reflect_Field_setBoolean,
203 (functionptr) Java_java_lang_reflect_Field_setByte,
204 (functionptr) Java_java_lang_reflect_Field_setChar,
205 (functionptr) Java_java_lang_reflect_Field_setShort,
206 (functionptr) Java_java_lang_reflect_Field_setInt,
207 (functionptr) Java_java_lang_reflect_Field_setLong,
208 (functionptr) Java_java_lang_reflect_Field_setFloat,
209 (functionptr) Java_java_lang_reflect_Field_setDouble,
211 (functionptr) Java_java_lang_reflect_Method_getModifiers,
212 (functionptr) Java_java_lang_reflect_Method_getReturnType,
213 (functionptr) Java_java_lang_reflect_Method_getParameterTypes,
214 (functionptr) Java_java_lang_reflect_Method_getExceptionTypes,
215 (functionptr) Java_java_lang_reflect_Method_invokeNative,
217 (functionptr) Java_java_lang_reflect_VMProxy_getProxyClass,
218 (functionptr) Java_java_lang_reflect_VMProxy_getProxyData,
219 (functionptr) Java_java_lang_reflect_VMProxy_generateProxyClass,
221 (functionptr) Java_java_security_VMAccessController_getStack,
224 #endif /* defined(ENABLE_STATICVM) */
227 /************* use classinfo structure as java.lang.Class object **************/
229 bool use_class_as_object(classinfo *c)
231 if (!c->classvftbl) {
232 /* is the class loaded */
234 /* if (!class_load(c)) */
235 /* throw_exception_exit(); */
236 log_text("use_class_as_object: class_load should not happen");
240 /* is the class linked */
245 assert(class_java_lang_Class);
247 c->header.vftbl = class_java_lang_Class->vftbl;
248 c->classvftbl = true;
255 /************************** tables for methods ********************************/
260 #ifdef ENABLE_STATICVM
261 #define NATIVETABLESIZE (sizeof(nativetable)/sizeof(struct nativeref))
263 /* table for fast string comparison */
264 static nativecompref nativecomptable[NATIVETABLESIZE];
266 /* string comparsion table initialized */
267 static bool nativecompdone = false;
271 /* XXX don't define this in a header file!!! */
273 static struct nativeCall nativeCalls[] =
275 #include "nativecalls.inc"
278 #define NATIVECALLSSIZE (sizeof(nativeCalls) / sizeof(struct nativeCall))
280 struct nativeCompCall nativeCompCalls[NATIVECALLSSIZE];
283 /* global variables ***********************************************************/
285 #if !defined(ENABLE_STATICVM)
286 static hashtable library_hash;
287 static lt_dlhandle mainhandle;
291 /* native_loadclasses **********************************************************
293 Load classes required for native methods.
295 *******************************************************************************/
297 bool native_init(void)
299 #if !defined(ENABLE_STATICVM)
302 /* We need to access the dummy native table, not only to remove a warning */
303 /* but to be sure that the table is not optimized away (gcc does this */
306 p = &dummynativetable;
308 /* initialize libltdl */
311 /* XXX how can we throw an exception here? */
312 log_text(lt_dlerror());
317 /* get the handle for the main program */
319 if (!(mainhandle = lt_dlopen(NULL)))
322 /* initialize library hashtable, 10 entries should be enough */
324 init_hashtable(&library_hash, 10);
328 /* everything's ok */
334 /* native_library_hash_add *****************************************************
336 Adds an entry to the native library hashtable.
338 *******************************************************************************/
340 #if !defined(ENABLE_STATICVM)
341 void native_library_hash_add(utf *filename, java_objectheader *loader,
344 library_hash_loader_entry *le;
345 library_hash_name_entry *ne; /* library name */
346 u4 key; /* hashkey */
347 u4 slot; /* slot in hashtable */
349 /* normally addresses are aligned to 4, 8 or 16 bytes */
351 key = ((u4) (ptrint) loader) >> 4; /* align to 16-byte boundaries */
352 slot = key & (library_hash.size - 1);
353 le = library_hash.ptr[slot];
355 /* search external hash chain for the entry */
358 if (le->loader == loader)
361 le = le->hashlink; /* next element in external chain */
364 /* no loader found? create a new entry */
367 le = NEW(library_hash_loader_entry);
372 /* insert entry into hashtable */
374 le->hashlink = (library_hash_loader_entry *) library_hash.ptr[slot];
375 library_hash.ptr[slot] = le;
377 /* update number of hashtable-entries */
379 library_hash.entries++;
383 /* search for library name */
388 if (ne->name == filename)
391 ne = ne->hashlink; /* next element in external chain */
394 /* not found? add the library name to the classloader */
396 ne = NEW(library_hash_name_entry);
401 /* insert entry into external chain */
403 ne->hashlink = le->namelink;
406 #endif /* !defined(ENABLE_STATICVM) */
409 /* native_library_hash_find ****************************************************
411 Find an entry in the native library hashtable.
413 *******************************************************************************/
415 #if !defined(ENABLE_STATICVM)
416 library_hash_name_entry *native_library_hash_find(utf *filename,
417 java_objectheader *loader)
419 library_hash_loader_entry *le;
420 library_hash_name_entry *ne; /* library name */
421 u4 key; /* hashkey */
422 u4 slot; /* slot in hashtable */
424 /* normally addresses are aligned to 4, 8 or 16 bytes */
426 key = ((u4) (ptrint) loader) >> 4; /* align to 16-byte boundaries */
427 slot = key & (library_hash.size - 1);
428 le = library_hash.ptr[slot];
430 /* search external hash chain for the entry */
433 if (le->loader == loader)
436 le = le->hashlink; /* next element in external chain */
439 /* no loader found? return NULL */
444 /* search for library name */
449 if (ne->name == filename)
452 ne = ne->hashlink; /* next element in external chain */
455 /* return entry, if no entry was found, ne is NULL */
459 #endif /* !defined(ENABLE_STATICVM) */
462 /* native_findfunction *********************************************************
464 Looks up a method (must have the same class name, method name,
465 descriptor and 'static'ness) and returns a function pointer to it.
466 Returns: function pointer or NULL (if there is no such method)
468 Remark: For faster operation, the names/descriptors are converted
469 from C strings to Unicode the first time this function is called.
471 *******************************************************************************/
473 #if defined(ENABLE_STATICVM)
474 functionptr native_findfunction(utf *cname, utf *mname, utf *desc,
477 /* entry of table for fast string comparison */
478 struct nativecompref *n;
481 isstatic = isstatic ? true : false;
483 if (!nativecompdone) {
484 for (i = 0; i < NATIVETABLESIZE; i++) {
485 nativecomptable[i].classname =
486 utf_new_char(nativetable[i].classname);
488 nativecomptable[i].methodname =
489 utf_new_char(nativetable[i].methodname);
491 nativecomptable[i].descriptor =
492 utf_new_char(nativetable[i].descriptor);
494 nativecomptable[i].isstatic = nativetable[i].isstatic;
495 nativecomptable[i].func = nativetable[i].func;
498 nativecompdone = true;
501 for (i = 0; i < NATIVETABLESIZE; i++) {
502 n = &(nativecomptable[i]);
504 if (cname == n->classname && mname == n->methodname &&
505 desc == n->descriptor && isstatic == n->isstatic)
510 /* no function was found, throw exception */
513 new_exception_utfmessage(string_java_lang_UnsatisfiedLinkError,
518 #endif /* defined(ENABLE_STATICVM) */
521 /* native_make_overloaded_function *********************************************
525 *******************************************************************************/
527 #if !defined(ENABLE_STATICVM)
528 static char *native_make_overloaded_function(char *name, utf *desc)
536 utf_ptr = desc->text;
537 namelen = strlen(name) + strlen("__") + strlen("0");
539 /* calculate additional length */
541 while ((c = utf_nextu2(&utf_ptr)) != ')') {
558 while (utf_nextu2(&utf_ptr) != ';')
570 /* reallocate memory */
574 newname = DMNEW(char, namelen);
575 MCOPY(newname, name, char, i);
577 utf_ptr = desc->text;
582 while ((c = utf_nextu2(&utf_ptr)) != ')') {
600 while ((c = utf_nextu2(&utf_ptr)) != ';')
601 if (((c >= 'a') && (c <= 'z')) ||
602 ((c >= 'A') && (c <= 'Z')) ||
603 ((c >= '0') && (c <= '9')))
625 /* native_resolve_function *****************************************************
627 Resolves a native function, maybe from a dynamic library.
629 *******************************************************************************/
631 functionptr native_resolve_function(methodinfo *m)
640 library_hash_loader_entry *le;
641 library_hash_name_entry *ne;
642 u4 key; /* hashkey */
643 u4 slot; /* slot in hashtable */
649 if (opt_verbosejni) {
650 printf("[Dynamic-linking native method ");
651 utf_display_classname(m->class->name);
653 utf_display(m->name);
657 /* calculate length of native function name */
659 namelen = strlen("Java_") + utf_strlen(m->class->name) + strlen("_") +
660 utf_strlen(m->name) + strlen("0");
662 /* check for underscores in class name */
664 utf_ptr = m->class->name->text;
665 utf_endptr = UTF_END(m->class->name);
667 while (utf_ptr < utf_endptr)
668 if (utf_nextu2(&utf_ptr) == '_')
671 /* check for underscores in method name */
673 utf_ptr = m->name->text;
674 utf_endptr = UTF_END(m->name);
676 while (utf_ptr < utf_endptr)
677 if (utf_nextu2(&utf_ptr) == '_')
680 /* allocate memory */
682 dumpsize = dump_size();
684 name = DMNEW(char, namelen);
687 /* generate name of native functions */
689 strcpy(name, "Java_");
692 utf_ptr = m->class->name->text;
693 utf_endptr = UTF_END(m->class->name);
695 for (; utf_ptr < utf_endptr; utf_ptr++, i++) {
698 /* escape sequence for '_' is '_1' */
703 /* replace '/' with '_' */
709 /* seperator between class and method */
713 utf_ptr = m->name->text;
714 utf_endptr = UTF_END(m->name);
716 for (; utf_ptr < utf_endptr; utf_ptr++, i++) {
719 /* escape sequence for '_' is '_1' */
730 /* generate overloaded function (having the types in it's name) */
732 newname = native_make_overloaded_function(name, m->descriptor);
734 /* check the library hash entries of the classloader of the methods's */
739 /* normally addresses are aligned to 4, 8 or 16 bytes */
741 key = ((u4) (ptrint) m->class->classloader) >> 4; /* align to 16-byte */
742 slot = key & (library_hash.size - 1);
743 le = library_hash.ptr[slot];
745 /* iterate through loaders in this hash slot */
748 /* iterate through names in this loader */
753 sym = lt_dlsym(ne->handle, name);
756 sym = lt_dlsym(ne->handle, newname);
769 /* if not found, try to find the native function symbol in the main */
773 sym = lt_dlsym(mainhandle, name);
776 sym = lt_dlsym(mainhandle, newname);
780 printf("internal ]\n");
784 /* no symbol found? throw exception */
788 new_exception_utfmessage(string_java_lang_UnsatisfiedLinkError,
793 dump_release(dumpsize);
795 return (functionptr) (ptrint) sym;
797 #endif /* !defined(ENABLE_STATICVM) */
800 /****************** function class_findfield_approx ****************************
802 searches in 'classinfo'-structure for a field with the
805 *******************************************************************************/
807 fieldinfo *class_findfield_approx(classinfo *c, utf *name)
811 for (i = 0; i < c->fieldscount; i++) {
812 /* compare field names */
813 if ((c->fields[i].name == name))
814 return &(c->fields[i]);
817 /* field was not found, raise exception */
818 *exceptionptr = new_exception(string_java_lang_NoSuchFieldException);
824 s4 class_findfield_index_approx(classinfo *c, utf *name)
828 for (i = 0; i < c->fieldscount; i++) {
829 /* compare field names */
830 if ((c->fields[i].name == name))
834 /* field was not found, raise exception */
835 *exceptionptr = new_exception(string_java_lang_NoSuchFieldException);
841 /* native_new_and_init *********************************************************
843 Creates a new object on the heap and calls the initializer.
844 Returns the object pointer or NULL if memory is exhausted.
846 *******************************************************************************/
848 java_objectheader *native_new_and_init(classinfo *c)
851 java_objectheader *o;
854 return *exceptionptr;
863 /* find initializer */
865 m = class_findmethod(c, utf_init, utf_void__void);
867 /* initializer not found */
872 /* call initializer */
874 asm_calljavafunction(m, o, NULL, NULL, NULL);
880 java_objectheader *native_new_and_init_string(classinfo *c, java_lang_String *s)
883 java_objectheader *o;
886 return *exceptionptr;
895 /* find initializer */
897 m = class_resolveclassmethod(c,
899 utf_java_lang_String__void,
903 /* initializer not found */
908 /* call initializer */
910 asm_calljavafunction(m, o, s, NULL, NULL);
916 java_objectheader *native_new_and_init_int(classinfo *c, s4 i)
919 java_objectheader *o;
922 return *exceptionptr;
931 /* find initializer */
933 m = class_resolveclassmethod(c, utf_init, utf_int__void, NULL, true);
935 /* initializer not found */
940 /* call initializer */
942 asm_calljavafunction(m, o, (void *) (ptrint) i, NULL, NULL);
948 java_objectheader *native_new_and_init_throwable(classinfo *c, java_lang_Throwable *t)
951 java_objectheader *o;
954 return *exceptionptr;
963 /* find initializer */
965 m = class_findmethod(c, utf_init, utf_java_lang_Throwable__void);
967 /* initializer not found */
972 /* call initializer */
974 asm_calljavafunction(m, o, t, NULL, NULL);
980 void copy_vftbl(vftbl_t **dest, vftbl_t *src)
984 /* XXX this kind of copying does not work (in the general
985 * case). The interface tables would have to be copied, too. I
986 * don't see why we should make a copy anyway. -Edwin
988 *dest = mem_alloc(sizeof(vftbl) + sizeof(methodptr)*(src->vftbllength-1));
989 memcpy(*dest, src, sizeof(vftbl) - sizeof(methodptr));
990 memcpy(&(*dest)->table, &src->table, src->vftbllength * sizeof(methodptr));
995 /******************************************************************************************
997 creates method signature (excluding return type) from array of
998 class-objects representing the parameters of the method
1000 *******************************************************************************************/
1003 utf *create_methodsig(java_objectarray* types, char *retType)
1005 char *buffer; /* buffer for building the desciptor */
1006 char *pos; /* current position in buffer */
1007 utf *result; /* the method signature */
1008 u4 buffer_size = 3; /* minimal size=3: room for parenthesis and returntype */
1011 if (!types) return NULL;
1013 /* determine required buffer-size */
1014 for (i = 0; i < types->header.size; i++) {
1015 classinfo *c = (classinfo *) types->data[i];
1016 buffer_size = buffer_size + c->name->blength + 2;
1019 if (retType) buffer_size += strlen(retType);
1021 /* allocate buffer */
1022 buffer = MNEW(char, buffer_size);
1025 /* method-desciptor starts with parenthesis */
1028 for (i = 0; i < types->header.size; i++) {
1031 /* current argument */
1032 classinfo *c = (classinfo *) types->data[i];
1034 /* current position in utf-text */
1035 char *utf_ptr = c->name->text;
1037 /* determine type of argument */
1038 if ((ch = utf_nextu2(&utf_ptr)) == '[') {
1040 for (utf_ptr--; utf_ptr < UTF_END(c->name); utf_ptr++) {
1041 *pos++ = *utf_ptr; /* copy text */
1045 /* check for primitive types */
1046 for (j = 0; j < PRIMITIVETYPE_COUNT; j++) {
1047 char *utf_pos = utf_ptr - 1;
1048 char *primitive = primitivetype_table[j].wrapname;
1051 while (utf_pos < UTF_END(c->name)) {
1052 if (*utf_pos++ != *primitive++) goto nomatch;
1055 /* primitive type found */
1056 *pos++ = primitivetype_table[j].typesig;
1063 /* no primitive type and no arrayclass, so must be object */
1067 for (utf_ptr--; utf_ptr < UTF_END(c->name); utf_ptr++) {
1081 for (i = 0; i < strlen(retType); i++) {
1082 *pos++ = retType[i];
1086 /* create utf-string */
1087 result = utf_new(buffer, (pos - buffer));
1088 MFREE(buffer, char, buffer_size);
1094 /* native_get_parametertypes ***************************************************
1096 Use the descriptor of a method to generate a java/lang/Class array
1097 which contains the classes of the parametertypes of the method.
1099 *******************************************************************************/
1101 java_objectarray *native_get_parametertypes(methodinfo *m)
1104 typedesc *paramtypes;
1106 java_objectarray *oa;
1111 /* is the descriptor fully parsed? */
1113 if (!m->parseddesc->params)
1114 if (!descriptor_params_from_paramtypes(md, m->flags))
1117 paramtypes = md->paramtypes;
1118 paramcount = md->paramcount;
1120 /* skip `this' pointer */
1122 if (!(m->flags & ACC_STATIC)) {
1127 /* create class-array */
1129 oa = builtin_anewarray(paramcount, class_java_lang_Class);
1136 for (i = 0; i < paramcount; i++) {
1137 if (!resolve_class_from_typedesc(¶mtypes[i], true, false,
1138 (classinfo **) &oa->data[i]))
1141 use_class_as_object((classinfo *) oa->data[i]);
1148 /* native_get_exceptiontypes ***************************************************
1150 Get the exceptions which can be thrown by a method.
1152 *******************************************************************************/
1154 java_objectarray *native_get_exceptiontypes(methodinfo *m)
1156 java_objectarray *oa;
1160 /* create class-array */
1162 oa = builtin_anewarray(m->thrownexceptionscount, class_java_lang_Class);
1167 for (i = 0; i < m->thrownexceptionscount; i++) {
1168 if (!resolve_classref_or_classinfo(NULL, m->thrownexceptions[i],
1169 resolveEager, true, false, &c))
1172 use_class_as_object(c);
1174 oa->data[i] = (java_objectheader *) c;
1181 /* native_get_returntype *******************************************************
1183 Get the returntype class of a method.
1185 *******************************************************************************/
1187 classinfo *native_get_returntype(methodinfo *m)
1191 if (!resolve_class_from_typedesc(&(m->parseddesc->returntype), true, false,
1195 use_class_as_object(c);
1201 /*****************************************************************************/
1202 /*****************************************************************************/
1205 /*--------------------------------------------------------*/
1206 void printNativeCall(nativeCall nc) {
1209 printf("\n%s's Native Methods call:\n",nc.classname); fflush(stdout);
1210 for (i=0; i<nc.methCnt; i++) {
1211 printf("\tMethod=%s %s\n",nc.methods[i].methodname, nc.methods[i].descriptor);fflush(stdout);
1213 for (j=0; j<nc.callCnt[i]; j++) {
1214 printf("\t\t<%i,%i>aCalled = %s %s %s\n",i,j,
1215 nc.methods[i].methodCalls[j].classname,
1216 nc.methods[i].methodCalls[j].methodname,
1217 nc.methods[i].methodCalls[j].descriptor);fflush(stdout);
1220 printf("-+++++--------------------\n");fflush(stdout);
1223 /*--------------------------------------------------------*/
1224 void printCompNativeCall(nativeCompCall nc) {
1226 printf("printCompNativeCall BEGIN\n");fflush(stdout);
1227 printf("\n%s's Native Comp Methods call:\n",nc.classname->text);fflush(stdout);
1228 utf_display(nc.classname); fflush(stdout);
1230 for (i=0; i<nc.methCnt; i++) {
1231 printf("\tMethod=%s %s\n",nc.methods[i].methodname->text,nc.methods[i].descriptor->text);fflush(stdout);
1232 utf_display(nc.methods[i].methodname); fflush(stdout);
1233 utf_display(nc.methods[i].descriptor);fflush(stdout);
1234 printf("\n");fflush(stdout);
1236 for (j=0; j<nc.callCnt[i]; j++) {
1237 printf("\t\t<%i,%i>bCalled = ",i,j);fflush(stdout);
1238 utf_display(nc.methods[i].methodCalls[j].classname);fflush(stdout);
1239 utf_display(nc.methods[i].methodCalls[j].methodname); fflush(stdout);
1240 utf_display(nc.methods[i].methodCalls[j].descriptor);fflush(stdout);
1241 printf("\n");fflush(stdout);
1244 printf("---------------------\n");fflush(stdout);
1248 /*--------------------------------------------------------*/
1249 classMeth findNativeMethodCalls(utf *c, utf *m, utf *d )
1262 /*--------------------------------------------------------*/
1263 nativeCall* findNativeClassCalls(char *aclassname ) {
1266 for (i=0;i<NATIVECALLSSIZE; i++) {
1267 /* convert table to utf later to speed up search */
1268 if (strcmp(nativeCalls[i].classname, aclassname) == 0)
1269 return &nativeCalls[i];
1274 /*--------------------------------------------------------*/
1275 /*--------------------------------------------------------*/
1276 void utfNativeCall(nativeCall nc, nativeCompCall *ncc) {
1280 ncc->classname = utf_new_char(nc.classname);
1281 ncc->methCnt = nc.methCnt;
1283 for (i=0; i<nc.methCnt; i++) {
1284 ncc->methods[i].methodname = utf_new_char(nc.methods[i].methodname);
1285 ncc->methods[i].descriptor = utf_new_char(nc.methods[i].descriptor);
1286 ncc->callCnt[i] = nc.callCnt[i];
1288 for (j=0; j<nc.callCnt[i]; j++) {
1290 ncc->methods[i].methodCalls[j].classname = utf_new_char(nc.methods[i].methodCalls[j].classname);
1292 if (strcmp("", nc.methods[i].methodCalls[j].methodname) != 0) {
1293 ncc->methods[i].methodCalls[j].methodname = utf_new_char(nc.methods[i].methodCalls[j].methodname);
1294 ncc->methods[i].methodCalls[j].descriptor = utf_new_char(nc.methods[i].methodCalls[j].descriptor);
1297 ncc->methods[i].methodCalls[j].methodname = NULL;
1298 ncc->methods[i].methodCalls[j].descriptor = NULL;
1306 /*--------------------------------------------------------*/
1308 bool natcall2utf(bool natcallcompdone) {
1311 if (natcallcompdone)
1314 for (i=0;i<NATIVECALLSSIZE; i++) {
1315 utfNativeCall (nativeCalls[i], &nativeCompCalls[i]);
1322 * These are local overrides for various environment variables in Emacs.
1323 * Please do not remove this and leave it at the end of the file, where
1324 * Emacs will automagically detect them.
1325 * ---------------------------------------------------------------------
1328 * indent-tabs-mode: t