1 /* src/native/native.c - table of native functions
3 Copyright (C) 1996-2005, 2006 R. Grafl, A. Krall, C. Kruegel,
4 C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
5 E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
6 J. Wenninger, 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., 51 Franklin Street, Fifth Floor, Boston, MA
25 Contact: cacao@cacaojvm.org
27 Authors: Reinhard Grafl
32 $Id: native.c 6213 2006-12-18 17:36:06Z twisti $
42 #if !defined(WITH_STATIC_CLASSPATH)
48 #include "mm/memory.h"
49 #include "native/jni.h"
50 #include "native/native.h"
51 #include "native/include/java_lang_Throwable.h"
53 #if defined(ENABLE_THREADS)
54 # include "threads/native/lock.h"
56 # include "threads/none/lock.h"
59 #include "toolbox/logging.h"
60 #include "vm/builtin.h"
61 #include "vm/exceptions.h"
62 #include "vm/global.h"
63 #include "vm/hashtable.h"
64 #include "vm/loader.h"
65 #include "vm/options.h"
66 #include "vm/resolve.h"
67 #include "vm/stringlocal.h"
69 #include "vm/jit/asmpart.h"
70 #include "vm/jit/jit.h"
72 #if defined(ENABLE_JVMTI)
73 #include "native/jvmti/cacaodbg.h"
77 /* include table of native functions ******************************************/
79 #include "native/include/java_lang_Cloneable.h"
80 #include "native/include/java_util_Properties.h"
81 #include "native/include/java_io_InputStream.h"
82 #include "native/include/java_io_PrintStream.h"
84 #include "native/include/gnu_classpath_VMStackWalker.h"
85 #include "native/include/gnu_classpath_VMSystemProperties.h"
86 #include "native/include/gnu_java_lang_management_VMClassLoadingMXBeanImpl.h"
87 #include "native/include/gnu_java_lang_management_VMMemoryMXBeanImpl.h"
88 #include "native/include/gnu_java_lang_management_VMRuntimeMXBeanImpl.h"
89 #include "native/include/java_lang_Class.h"
90 #include "native/include/java_lang_Object.h"
91 #include "native/include/java_lang_VMClass.h"
92 #include "native/include/java_lang_VMClassLoader.h"
93 #include "native/include/java_lang_VMObject.h"
94 #include "native/include/java_lang_VMRuntime.h"
95 #include "native/include/java_lang_VMString.h"
96 #include "native/include/java_lang_VMSystem.h"
97 #include "native/include/java_lang_VMThread.h"
98 #include "native/include/java_lang_VMThrowable.h"
99 #include "native/include/java_lang_management_VMManagementFactory.h"
100 #include "native/include/java_lang_reflect_Constructor.h"
101 #include "native/include/java_lang_reflect_Field.h"
102 #include "native/include/java_lang_reflect_Method.h"
103 #include "native/include/java_lang_reflect_VMProxy.h"
104 #include "native/include/java_security_VMAccessController.h"
106 #if defined(ENABLE_JVMTI)
107 #include "native/include/gnu_classpath_jdwp_event_EventRequest.h"
108 #include "native/include/java_nio_ByteBuffer.h"
109 #include "native/include/gnu_classpath_jdwp_VMVirtualMachine.h"
110 #include "native/include/gnu_classpath_jdwp_VMFrame.h"
111 #include "native/include/gnu_classpath_jdwp_VMMethod.h"
114 #if defined(WITH_STATIC_CLASSPATH)
116 /* these are required to prevent compiler warnings */
118 #include "native/include/java_net_DatagramPacket.h"
119 #include "native/include/java_net_InetAddress.h"
120 #include "native/include/java_net_SocketImpl.h"
122 #include "native/include/gnu_java_net_PlainDatagramSocketImpl.h"
123 #include "native/include/gnu_java_net_PlainSocketImpl.h"
124 #include "native/include/gnu_java_nio_PipeImpl.h"
125 #include "native/include/gnu_java_nio_channels_FileChannelImpl.h"
126 #include "native/include/gnu_java_nio_charset_iconv_IconvEncoder.h"
127 #include "native/include/gnu_java_nio_charset_iconv_IconvDecoder.h"
128 #include "native/include/java_lang_VMProcess.h"
129 #include "native/include/java_nio_MappedByteBufferImpl.h"
130 #include "native/include/java_nio_channels_spi_SelectorProvider.h"
132 /* now include the native table */
134 #include "native/nativetable.inc"
136 #elif !defined(ENABLE_LIBJVM)
138 /* dummynativetable ************************************************************
140 Ensure that symbols for functions implemented within CACAO are used
141 and exported to dlopen.
143 ATTENTION: Don't make this table static!!! Otherwise the compiler
144 may optimize it away!
146 *******************************************************************************/
148 functionptr dummynativetable[] = {
149 (functionptr) Java_gnu_classpath_VMStackWalker_getClassContext,
150 (functionptr) Java_gnu_classpath_VMStackWalker_getCallingClass,
151 (functionptr) Java_gnu_classpath_VMStackWalker_getCallingClassLoader,
152 (functionptr) Java_gnu_classpath_VMStackWalker_firstNonNullClassLoader,
154 (functionptr) Java_gnu_classpath_VMSystemProperties_preInit,
156 (functionptr) Java_gnu_java_lang_management_VMClassLoadingMXBeanImpl_getLoadedClassCount,
157 (functionptr) Java_gnu_java_lang_management_VMClassLoadingMXBeanImpl_getUnloadedClassCount,
158 (functionptr) Java_gnu_java_lang_management_VMClassLoadingMXBeanImpl_isVerbose,
159 (functionptr) Java_gnu_java_lang_management_VMClassLoadingMXBeanImpl_setVerbose,
161 (functionptr) Java_gnu_java_lang_management_VMMemoryMXBeanImpl_getHeapMemoryUsage,
162 (functionptr) Java_gnu_java_lang_management_VMMemoryMXBeanImpl_getNonHeapMemoryUsage,
163 (functionptr) Java_gnu_java_lang_management_VMMemoryMXBeanImpl_getObjectPendingFinalizationCount,
164 (functionptr) Java_gnu_java_lang_management_VMMemoryMXBeanImpl_isVerbose,
165 (functionptr) Java_gnu_java_lang_management_VMMemoryMXBeanImpl_setVerbose,
167 (functionptr) Java_gnu_java_lang_management_VMRuntimeMXBeanImpl_getInputArguments,
168 (functionptr) Java_gnu_java_lang_management_VMRuntimeMXBeanImpl_getStartTime,
170 (functionptr) Java_java_lang_VMClass_isInstance,
171 (functionptr) Java_java_lang_VMClass_isAssignableFrom,
172 (functionptr) Java_java_lang_VMClass_isInterface,
173 (functionptr) Java_java_lang_VMClass_isPrimitive,
174 (functionptr) Java_java_lang_VMClass_getName,
175 (functionptr) Java_java_lang_VMClass_getSuperclass,
176 (functionptr) Java_java_lang_VMClass_getInterfaces,
177 (functionptr) Java_java_lang_VMClass_getComponentType,
178 (functionptr) Java_java_lang_VMClass_getModifiers,
179 (functionptr) Java_java_lang_VMClass_getDeclaringClass,
180 (functionptr) Java_java_lang_VMClass_getDeclaredClasses,
181 (functionptr) Java_java_lang_VMClass_getDeclaredFields,
182 (functionptr) Java_java_lang_VMClass_getDeclaredMethods,
183 (functionptr) Java_java_lang_VMClass_getDeclaredConstructors,
184 (functionptr) Java_java_lang_VMClass_getClassLoader,
185 (functionptr) Java_java_lang_VMClass_forName,
186 (functionptr) Java_java_lang_VMClass_isArray,
187 (functionptr) Java_java_lang_VMClass_throwException,
189 (functionptr) Java_java_lang_VMClassLoader_defineClass,
190 (functionptr) Java_java_lang_VMClassLoader_resolveClass,
191 (functionptr) Java_java_lang_VMClassLoader_loadClass,
192 (functionptr) Java_java_lang_VMClassLoader_getPrimitiveClass,
193 (functionptr) Java_java_lang_VMClassLoader_nativeGetResources,
194 (functionptr) Java_java_lang_VMClassLoader_findLoadedClass,
196 (functionptr) Java_java_lang_VMObject_getClass,
197 (functionptr) Java_java_lang_VMObject_clone,
198 (functionptr) Java_java_lang_VMObject_notify,
199 (functionptr) Java_java_lang_VMObject_notifyAll,
200 (functionptr) Java_java_lang_VMObject_wait,
202 (functionptr) Java_java_lang_VMRuntime_availableProcessors,
203 (functionptr) Java_java_lang_VMRuntime_freeMemory,
204 (functionptr) Java_java_lang_VMRuntime_totalMemory,
205 (functionptr) Java_java_lang_VMRuntime_maxMemory,
206 (functionptr) Java_java_lang_VMRuntime_gc,
207 (functionptr) Java_java_lang_VMRuntime_runFinalization,
208 (functionptr) Java_java_lang_VMRuntime_runFinalizationForExit,
209 (functionptr) Java_java_lang_VMRuntime_traceInstructions,
210 (functionptr) Java_java_lang_VMRuntime_traceMethodCalls,
211 (functionptr) Java_java_lang_VMRuntime_runFinalizersOnExit,
212 (functionptr) Java_java_lang_VMRuntime_exit,
213 (functionptr) Java_java_lang_VMRuntime_nativeLoad,
214 (functionptr) Java_java_lang_VMRuntime_mapLibraryName,
216 (functionptr) Java_java_lang_VMString_intern,
218 (functionptr) Java_java_lang_VMSystem_arraycopy,
219 (functionptr) Java_java_lang_VMSystem_identityHashCode,
221 (functionptr) Java_java_lang_VMThread_start,
222 (functionptr) Java_java_lang_VMThread_interrupt,
223 (functionptr) Java_java_lang_VMThread_isInterrupted,
224 (functionptr) Java_java_lang_VMThread_suspend,
225 (functionptr) Java_java_lang_VMThread_resume,
226 (functionptr) Java_java_lang_VMThread_nativeSetPriority,
227 (functionptr) Java_java_lang_VMThread_nativeStop,
228 (functionptr) Java_java_lang_VMThread_currentThread,
229 (functionptr) Java_java_lang_VMThread_yield,
230 (functionptr) Java_java_lang_VMThread_interrupted,
231 (functionptr) Java_java_lang_VMThread_holdsLock,
233 (functionptr) Java_java_lang_VMThrowable_fillInStackTrace,
234 (functionptr) Java_java_lang_VMThrowable_getStackTrace,
236 (functionptr) Java_java_lang_management_VMManagementFactory_getMemoryPoolNames,
237 (functionptr) Java_java_lang_management_VMManagementFactory_getMemoryManagerNames,
238 (functionptr) Java_java_lang_management_VMManagementFactory_getGarbageCollectorNames,
240 (functionptr) Java_java_lang_reflect_Constructor_getModifiersInternal,
241 (functionptr) Java_java_lang_reflect_Constructor_constructNative,
243 (functionptr) Java_java_lang_reflect_Field_getModifiersInternal,
244 (functionptr) Java_java_lang_reflect_Field_getType,
245 (functionptr) Java_java_lang_reflect_Field_get,
246 (functionptr) Java_java_lang_reflect_Field_getBoolean,
247 (functionptr) Java_java_lang_reflect_Field_getByte,
248 (functionptr) Java_java_lang_reflect_Field_getChar,
249 (functionptr) Java_java_lang_reflect_Field_getShort,
250 (functionptr) Java_java_lang_reflect_Field_getInt,
251 (functionptr) Java_java_lang_reflect_Field_getLong,
252 (functionptr) Java_java_lang_reflect_Field_getFloat,
253 (functionptr) Java_java_lang_reflect_Field_getDouble,
254 (functionptr) Java_java_lang_reflect_Field_set,
255 (functionptr) Java_java_lang_reflect_Field_setBoolean,
256 (functionptr) Java_java_lang_reflect_Field_setByte,
257 (functionptr) Java_java_lang_reflect_Field_setChar,
258 (functionptr) Java_java_lang_reflect_Field_setShort,
259 (functionptr) Java_java_lang_reflect_Field_setInt,
260 (functionptr) Java_java_lang_reflect_Field_setLong,
261 (functionptr) Java_java_lang_reflect_Field_setFloat,
262 (functionptr) Java_java_lang_reflect_Field_setDouble,
264 (functionptr) Java_java_lang_reflect_Method_getModifiersInternal,
265 (functionptr) Java_java_lang_reflect_Method_getReturnType,
266 (functionptr) Java_java_lang_reflect_Method_getParameterTypes,
267 (functionptr) Java_java_lang_reflect_Method_getExceptionTypes,
268 (functionptr) Java_java_lang_reflect_Method_invokeNative,
270 (functionptr) Java_java_lang_reflect_VMProxy_getProxyClass,
271 (functionptr) Java_java_lang_reflect_VMProxy_getProxyData,
272 (functionptr) Java_java_lang_reflect_VMProxy_generateProxyClass,
274 (functionptr) Java_java_security_VMAccessController_getStack,
276 #if defined(ENABLE_JVMTI)
277 (functionptr) Java_gnu_classpath_jdwp_VMVirtualMachine_suspendThread,
278 (functionptr) Java_gnu_classpath_jdwp_VMVirtualMachine_resumeThread,
279 (functionptr) Java_gnu_classpath_jdwp_VMVirtualMachine_getSuspendCount,
280 (functionptr) Java_gnu_classpath_jdwp_VMVirtualMachine_getAllLoadedClassesCount,
281 (functionptr) Java_gnu_classpath_jdwp_VMVirtualMachine_getClassStatus,
282 (functionptr) Java_gnu_classpath_jdwp_VMVirtualMachine_getAllClassMethods,
283 (functionptr) Java_gnu_classpath_jdwp_VMVirtualMachine_getClassMethod,
284 (functionptr) Java_gnu_classpath_jdwp_VMVirtualMachine_getFrames,
285 (functionptr) Java_gnu_classpath_jdwp_VMVirtualMachine_getFrame,
286 (functionptr) Java_gnu_classpath_jdwp_VMVirtualMachine_getFrameCount,
287 (functionptr) Java_gnu_classpath_jdwp_VMVirtualMachine_getThreadStatus,
288 (functionptr) Java_gnu_classpath_jdwp_VMVirtualMachine_getLoadRequests,
289 (functionptr) Java_gnu_classpath_jdwp_VMVirtualMachine_executeMethod,
290 (functionptr) Java_gnu_classpath_jdwp_VMVirtualMachine_getSourceFile,
291 (functionptr) Java_gnu_classpath_jdwp_VMVirtualMachine_registerEvent,
292 (functionptr) Java_gnu_classpath_jdwp_VMVirtualMachine_unregisterEvent,
293 (functionptr) Java_gnu_classpath_jdwp_VMVirtualMachine_clearEvents,
294 (functionptr) Java_gnu_classpath_jdwp_VMVirtualMachine_getAllLoadedClasses,
295 (functionptr) Java_gnu_classpath_jdwp_VMFrame_setValue,
296 (functionptr) Java_gnu_classpath_jdwp_VMFrame_getValue,
297 (functionptr) Java_gnu_classpath_jdwp_VMMethod_getName,
298 (functionptr) Java_gnu_classpath_jdwp_VMMethod_getSignature,
299 (functionptr) Java_gnu_classpath_jdwp_VMMethod_getModifiers,
300 (functionptr) Java_gnu_classpath_jdwp_VMMethod_getLineTable,
301 (functionptr) Java_gnu_classpath_jdwp_VMMethod_getVariableTable
306 #endif /* defined(ENABLE_LIBJVM) */
309 /* tables for methods *********************************************************/
311 #if defined(WITH_STATIC_CLASSPATH)
312 #define NATIVETABLESIZE (sizeof(nativetable)/sizeof(struct nativeref))
314 /* table for fast string comparison */
315 static nativecompref nativecomptable[NATIVETABLESIZE];
317 /* string comparsion table initialized */
318 static bool nativecompdone = false;
322 /* global variables ***********************************************************/
324 #if !defined(WITH_STATIC_CLASSPATH)
325 static hashtable *hashtable_library;
326 static lt_dlhandle mainhandle;
330 /* native_init *****************************************************************
332 Initializes the native subsystem.
334 *******************************************************************************/
336 bool native_init(void)
338 #if !defined(WITH_STATIC_CLASSPATH)
339 /* initialize libltdl */
342 vm_abort("lt_dlinit failed: %s\n", lt_dlerror());
344 /* Get the handle for the main program or for the libjvm.so,
345 depends on the configuration. */
347 # if defined(ENABLE_LIBJVM)
348 /* First try to open where dlopen searches, e.g. LD_LIBRARY_PATH.
349 If not found, try the absolute path. */
351 if (!(mainhandle = lt_dlopenext("libjvm")))
352 if (!(mainhandle = lt_dlopenext(cacao_libjvm)))
353 vm_abort("lt_dlopenext failed: %s\n", lt_dlerror());
355 if (!(mainhandle = lt_dlopen(NULL)))
356 vm_abort("lt_dlopen failed: %s\n", lt_dlerror());
359 /* initialize library hashtable, 10 entries should be enough */
361 hashtable_library = NEW(hashtable);
363 hashtable_create(hashtable_library, 10);
366 /* everything's ok */
372 /* native_hashtable_library_add ************************************************
374 Adds an entry to the native library hashtable.
376 *******************************************************************************/
378 #if !defined(WITH_STATIC_CLASSPATH)
379 void native_hashtable_library_add(utf *filename, java_objectheader *loader,
382 hashtable_library_loader_entry *le;
383 hashtable_library_name_entry *ne; /* library name */
384 u4 key; /* hashkey */
385 u4 slot; /* slot in hashtable */
387 LOCK_MONITOR_ENTER(hashtable_library->header);
389 /* normally addresses are aligned to 4, 8 or 16 bytes */
391 key = ((u4) (ptrint) loader) >> 4; /* align to 16-byte boundaries */
392 slot = key & (hashtable_library->size - 1);
393 le = hashtable_library->ptr[slot];
395 /* search external hash chain for the entry */
398 if (le->loader == loader)
401 le = le->hashlink; /* next element in external chain */
404 /* no loader found? create a new entry */
407 le = NEW(hashtable_library_loader_entry);
412 /* insert entry into hashtable */
415 (hashtable_library_loader_entry *) hashtable_library->ptr[slot];
416 hashtable_library->ptr[slot] = le;
418 /* update number of hashtable-entries */
420 hashtable_library->entries++;
424 /* search for library name */
429 if (ne->name == filename) {
430 LOCK_MONITOR_EXIT(hashtable_library->header);
435 ne = ne->hashlink; /* next element in external chain */
438 /* not found? add the library name to the classloader */
440 ne = NEW(hashtable_library_name_entry);
445 /* insert entry into external chain */
447 ne->hashlink = le->namelink;
450 LOCK_MONITOR_EXIT(hashtable_library->header);
452 #endif /* !defined(WITH_STATIC_CLASSPATH) */
455 /* native_hashtable_library_find ***********************************************
457 Find an entry in the native library hashtable.
459 *******************************************************************************/
461 #if !defined(WITH_STATIC_CLASSPATH)
462 hashtable_library_name_entry *native_hashtable_library_find(utf *filename,
463 java_objectheader *loader)
465 hashtable_library_loader_entry *le;
466 hashtable_library_name_entry *ne; /* library name */
467 u4 key; /* hashkey */
468 u4 slot; /* slot in hashtable */
470 /* normally addresses are aligned to 4, 8 or 16 bytes */
472 key = ((u4) (ptrint) loader) >> 4; /* align to 16-byte boundaries */
473 slot = key & (hashtable_library->size - 1);
474 le = hashtable_library->ptr[slot];
476 /* search external hash chain for the entry */
479 if (le->loader == loader)
482 le = le->hashlink; /* next element in external chain */
485 /* no loader found? return NULL */
490 /* search for library name */
495 if (ne->name == filename)
498 ne = ne->hashlink; /* next element in external chain */
501 /* return entry, if no entry was found, ne is NULL */
505 #endif /* !defined(WITH_STATIC_CLASSPATH) */
508 /* native_findfunction *********************************************************
510 Looks up a method (must have the same class name, method name,
511 descriptor and 'static'ness) and returns a function pointer to it.
512 Returns: function pointer or NULL (if there is no such method)
514 Remark: For faster operation, the names/descriptors are converted
515 from C strings to Unicode the first time this function is called.
517 *******************************************************************************/
519 #if defined(WITH_STATIC_CLASSPATH)
520 functionptr native_findfunction(utf *cname, utf *mname, utf *desc,
523 /* entry of table for fast string comparison */
524 struct nativecompref *n;
527 isstatic = isstatic ? true : false;
529 if (!nativecompdone) {
530 for (i = 0; i < NATIVETABLESIZE; i++) {
531 nativecomptable[i].classname =
532 utf_new_char(nativetable[i].classname);
534 nativecomptable[i].methodname =
535 utf_new_char(nativetable[i].methodname);
537 nativecomptable[i].descriptor =
538 utf_new_char(nativetable[i].descriptor);
540 nativecomptable[i].isstatic = nativetable[i].isstatic;
541 nativecomptable[i].func = nativetable[i].func;
544 nativecompdone = true;
547 for (i = 0; i < NATIVETABLESIZE; i++) {
548 n = &(nativecomptable[i]);
550 if (cname == n->classname && mname == n->methodname &&
551 desc == n->descriptor && isstatic == n->isstatic)
556 /* no function was found, throw exception */
559 new_exception_utfmessage(string_java_lang_UnsatisfiedLinkError,
564 #endif /* defined(WITH_STATIC_CLASSPATH) */
567 /* native_make_overloaded_function *********************************************
571 *******************************************************************************/
573 #if !defined(WITH_STATIC_CLASSPATH)
574 static char *native_make_overloaded_function(char *name, utf *desc)
582 utf_ptr = desc->text;
583 namelen = strlen(name) + strlen("__") + strlen("0");
585 /* calculate additional length */
587 while ((c = utf_nextu2(&utf_ptr)) != ')') {
604 while (utf_nextu2(&utf_ptr) != ';')
616 /* reallocate memory */
620 newname = DMNEW(char, namelen);
621 MCOPY(newname, name, char, i);
623 utf_ptr = desc->text;
628 while ((c = utf_nextu2(&utf_ptr)) != ')') {
646 while ((c = utf_nextu2(&utf_ptr)) != ';')
647 if (((c >= 'a') && (c <= 'z')) ||
648 ((c >= 'A') && (c <= 'Z')) ||
649 ((c >= '0') && (c <= '9')))
671 /* native_insert_char **********************************************************
673 Inserts the passed UTF character into the native method name. If
674 necessary it is escaped properly.
676 *******************************************************************************/
678 static s4 native_insert_char(char *name, u4 pos, u2 c)
686 /* replace '/' or '.' with '_' */
691 /* escape sequence for '_' is '_1' */
697 /* escape sequence for ';' is '_2' */
703 /* escape sequence for '[' is '_1' */
712 /* unicode character */
716 for (i = 0; i < 4; ++i) {
718 name[pos + 4 - i] = (val > 10) ? ('a' + val - 10) : ('0' + val);
727 /* return the new buffer index */
733 /* native_resolve_function *****************************************************
735 Resolves a native function, maybe from a dynamic library.
737 *******************************************************************************/
739 functionptr native_resolve_function(methodinfo *m)
750 hashtable_library_loader_entry *le;
751 hashtable_library_name_entry *ne;
752 u4 key; /* hashkey */
753 u4 slot; /* slot in hashtable */
757 if (opt_verbosejni) {
758 printf("[Dynamic-linking native method ");
759 utf_display_printable_ascii_classname(m->class->name);
761 utf_display_printable_ascii(m->name);
765 /* Calculate length of native function name. We multiply the
766 class and method name length by 6 as this is the maxium
767 escape-sequence that can be generated (unicode). */
769 namelen = strlen("Java_") +
770 utf_get_number_of_u2s(m->class->name) * 6 +
772 utf_get_number_of_u2s(m->name) * 6 +
775 /* allocate memory */
777 dumpsize = dump_size();
779 name = DMNEW(char, namelen);
781 /* generate name of native functions */
783 strcpy(name, "Java_");
784 pos = strlen("Java_");
786 utf_ptr = m->class->name->text;
787 utf_endptr = UTF_END(m->class->name);
789 for (; utf_ptr < utf_endptr; utf_ptr++, pos++) {
791 pos = native_insert_char(name, pos, c);
794 /* seperator between class and method */
798 utf_ptr = m->name->text;
799 utf_endptr = UTF_END(m->name);
801 for (; utf_ptr < utf_endptr; utf_ptr++, pos++) {
803 pos = native_insert_char(name, pos, c);
810 /* check for an buffer overflow */
812 assert(pos <= namelen);
814 /* generate overloaded function (having the types in it's name) */
816 newname = native_make_overloaded_function(name, m->descriptor);
818 /* check the library hash entries of the classloader of the
823 /* normally addresses are aligned to 4, 8 or 16 bytes */
825 key = ((u4) (ptrint) m->class->classloader) >> 4; /* align to 16-byte */
826 slot = key & (hashtable_library->size - 1);
827 le = hashtable_library->ptr[slot];
829 /* iterate through loaders in this hash slot */
831 while ((le != NULL) && (sym == NULL)) {
832 /* iterate through names in this loader */
836 while ((ne != NULL) && (sym == NULL)) {
837 sym = lt_dlsym(ne->handle, name);
840 sym = lt_dlsym(ne->handle, newname);
853 /* If not found, try to find the native function symbol in the
857 sym = lt_dlsym(mainhandle, name);
860 sym = lt_dlsym(mainhandle, newname);
864 printf("internal ]\n");
868 #if defined(ENABLE_JVMTI)
869 /* fire Native Method Bind event */
870 if (jvmti) jvmti_NativeMethodBind(m, sym, &sym);
873 /* no symbol found? throw exception */
877 printf("failed ]\n");
880 new_exception_utfmessage(string_java_lang_UnsatisfiedLinkError,
886 dump_release(dumpsize);
888 return (functionptr) (ptrint) sym;
890 #endif /* !defined(WITH_STATIC_CLASSPATH) */
893 /* native_new_and_init *********************************************************
895 Creates a new object on the heap and calls the initializer.
896 Returns the object pointer or NULL if memory is exhausted.
898 *******************************************************************************/
900 java_objectheader *native_new_and_init(classinfo *c)
903 java_objectheader *o;
906 return *exceptionptr;
915 /* try to find the initializer */
917 m = class_findmethod(c, utf_init, utf_void__void);
919 /* ATTENTION: returning the object here is ok, since the class may
920 not have an initializer */
925 /* call initializer */
927 (void) vm_call_method(m, o);
933 java_objectheader *native_new_and_init_string(classinfo *c, java_lang_String *s)
936 java_objectheader *o;
939 return *exceptionptr;
948 /* find initializer */
950 m = class_resolveclassmethod(c,
952 utf_java_lang_String__void,
956 /* initializer not found */
961 /* call initializer */
963 (void) vm_call_method(m, o, s);
969 java_objectheader *native_new_and_init_int(classinfo *c, s4 i)
972 java_objectheader *o;
975 return *exceptionptr;
984 /* find initializer */
986 m = class_resolveclassmethod(c, utf_init, utf_int__void, NULL, true);
988 /* initializer not found */
993 /* call initializer */
995 (void) vm_call_method(m, o, i);
1001 java_objectheader *native_new_and_init_throwable(classinfo *c, java_lang_Throwable *t)
1004 java_objectheader *o;
1007 return *exceptionptr;
1016 /* find initializer */
1018 m = class_findmethod(c, utf_init, utf_java_lang_Throwable__void);
1020 /* initializer not found */
1025 /* call initializer */
1027 (void) vm_call_method(m, o, t);
1033 /* native_class_getdeclaredannotations *****************************************
1036 java.lang.Class.getDeclaredAnnotations(Ljava/lang/Class;)[Ljava/lang/annotation/Annotation;
1038 *******************************************************************************/
1040 java_objectarray *native_class_getdeclaredannotations(classinfo *c)
1042 java_objectarray *oa;
1046 classinfo *class_java_lang_annotation_Annotation;
1048 /* create Annotation-array */
1050 /* XXX should we cache that class? */
1051 if (!(class_java_lang_annotation_Annotation =
1052 load_class_bootstrap(utf_new_char("java/lang/annotation/Annotation"))))
1055 count = c->runtimevisibleannotationscount;
1057 oa = builtin_anewarray(count, class_java_lang_annotation_Annotation);
1062 /* fill the annotations */
1064 for (i = 0; i < count; i++) {
1071 /* native_get_parametertypes ***************************************************
1073 Use the descriptor of a method to generate a java/lang/Class array
1074 which contains the classes of the parametertypes of the method.
1076 *******************************************************************************/
1078 java_objectarray *native_get_parametertypes(methodinfo *m)
1081 typedesc *paramtypes;
1083 java_objectarray *oa;
1088 /* is the descriptor fully parsed? */
1090 if (!m->parseddesc->params)
1091 if (!descriptor_params_from_paramtypes(md, m->flags))
1094 paramtypes = md->paramtypes;
1095 paramcount = md->paramcount;
1097 /* skip `this' pointer */
1099 if (!(m->flags & ACC_STATIC)) {
1104 /* create class-array */
1106 oa = builtin_anewarray(paramcount, class_java_lang_Class);
1113 for (i = 0; i < paramcount; i++)
1114 if (!resolve_class_from_typedesc(¶mtypes[i], true, false,
1115 (classinfo **) &oa->data[i]))
1122 /* native_get_exceptiontypes ***************************************************
1124 Get the exceptions which can be thrown by a method.
1126 *******************************************************************************/
1128 java_objectarray *native_get_exceptiontypes(methodinfo *m)
1130 java_objectarray *oa;
1134 /* create class-array */
1136 oa = builtin_anewarray(m->thrownexceptionscount, class_java_lang_Class);
1141 for (i = 0; i < m->thrownexceptionscount; i++) {
1142 if (!resolve_classref_or_classinfo(NULL, m->thrownexceptions[i],
1143 resolveEager, true, false, &c))
1146 oa->data[i] = (java_objectheader *) c;
1153 /* native_get_returntype *******************************************************
1155 Get the returntype class of a method.
1157 *******************************************************************************/
1159 classinfo *native_get_returntype(methodinfo *m)
1163 if (!resolve_class_from_typedesc(&(m->parseddesc->returntype), true, false,
1172 * These are local overrides for various environment variables in Emacs.
1173 * Please do not remove this and leave it at the end of the file, where
1174 * Emacs will automagically detect them.
1175 * ---------------------------------------------------------------------
1178 * indent-tabs-mode: t