* Removed all Id tags.
[cacao.git] / src / native / native.c
index ede33333be6cf0e5bf9693e68f72b969f5318be6..37f86f45c72fbd3da3442479f1440b929d0d0271 100644 (file)
@@ -22,8 +22,6 @@
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
    02110-1301, USA.
 
-   $Id: native.c 7813 2007-04-25 19:20:13Z twisti $
-
 */
 
 
 #include <assert.h>
 #include <ctype.h>
 
-#if !defined(WITH_STATIC_CLASSPATH)
+#if defined(ENABLE_LTDL) && defined(HAVE_LTDL_H)
 # include <ltdl.h>
 #endif
 
+#include <stdint.h>
+
 #include "vm/types.h"
 
 #include "mm/memory.h"
+
 #include "native/jni.h"
 #include "native/native.h"
-#include "native/include/java_lang_String.h"
-#include "native/include/java_lang_Throwable.h"
+
+#include "native/vm/nativevm.h"
 
 #include "threads/lock-common.h"
 
+#include "toolbox/avl.h"
 #include "toolbox/hashtable.h"
 #include "toolbox/logging.h"
 
 
 /* include table of native functions ******************************************/
 
-#include "native/include/java_lang_Object.h"
-
-#if defined(ENABLE_JAVASE)
-
-#include "native/include/java_io_InputStream.h"
-#include "native/include/java_io_PrintStream.h"
-
-#include "native/include/java_lang_Cloneable.h"
-#include "native/include/java_util_Properties.h"
-
-#include "native/include/gnu_classpath_VMStackWalker.h"
-#include "native/include/gnu_classpath_VMSystemProperties.h"
-#include "native/include/gnu_java_lang_management_VMClassLoadingMXBeanImpl.h"
-#include "native/include/gnu_java_lang_management_VMMemoryMXBeanImpl.h"
-#include "native/include/gnu_java_lang_management_VMRuntimeMXBeanImpl.h"
-#include "native/include/java_lang_VMClass.h"
-#include "native/include/java_security_ProtectionDomain.h"  /* required by... */
-#include "native/include/java_lang_VMClassLoader.h"
-#include "native/include/java_lang_VMObject.h"
-#include "native/include/java_lang_VMRuntime.h"
-#include "native/include/java_lang_VMString.h"
-#include "native/include/java_lang_VMSystem.h"
-#include "native/include/java_lang_VMThread.h"
-#include "native/include/java_lang_VMThrowable.h"
-#include "native/include/java_lang_management_VMManagementFactory.h"
-#include "native/include/java_lang_reflect_Constructor.h"
-#include "native/include/java_lang_reflect_Field.h"
-#include "native/include/java_lang_reflect_Method.h"
-#include "native/include/java_lang_reflect_VMProxy.h"
-#include "native/include/java_security_VMAccessController.h"
-#include "native/include/sun_misc_Unsafe.h"
-
-#if defined(ENABLE_JVMTI)
-#include "native/include/gnu_classpath_jdwp_event_EventRequest.h"
-#include "native/include/java_nio_ByteBuffer.h"
-#include "native/include/gnu_classpath_jdwp_VMVirtualMachine.h"
-#include "native/include/gnu_classpath_jdwp_VMFrame.h"
-#include "native/include/gnu_classpath_jdwp_VMMethod.h"
-#endif
-
-#elif defined(ENABLE_JAVAME_CLDC1_1)
-
-#include "native/include/com_sun_cldchi_io_ConsoleOutputStream.h"
-#include "native/include/com_sun_cldc_io_ResourceInputStream.h"
-#include "native/include/com_sun_cldc_io_j2me_socket_Protocol.h"
-#include "native/include/java_lang_Class.h"
-#include "native/include/java_lang_Double.h"
-#include "native/include/java_lang_Float.h"
-#include "native/include/java_lang_Math.h"
-#include "native/include/java_lang_Runtime.h"
-#include "native/include/java_lang_System.h"
-#include "native/include/java_lang_Thread.h"
-
-#endif
-
 #if defined(WITH_STATIC_CLASSPATH)
-
-/* these are required to prevent compiler warnings */
-
-#include "native/include/java_net_DatagramPacket.h"
-#include "native/include/java_net_InetAddress.h"
-#include "native/include/java_net_SocketImpl.h"
-
-#include "native/include/gnu_java_net_PlainDatagramSocketImpl.h"
-#include "native/include/gnu_java_net_PlainSocketImpl.h"
-#include "native/include/gnu_java_nio_PipeImpl.h"
-#include "native/include/gnu_java_nio_channels_FileChannelImpl.h"
-#include "native/include/gnu_java_nio_charset_iconv_IconvEncoder.h"
-#include "native/include/gnu_java_nio_charset_iconv_IconvDecoder.h"
-#include "native/include/java_lang_VMProcess.h"
-#include "native/include/java_nio_MappedByteBufferImpl.h"
-#include "native/include/java_nio_channels_spi_SelectorProvider.h"
-
-/* now include the native table */
-
-#include "native/nativetable.inc"
-
-#elif !defined(ENABLE_LIBJVM)
-
-/* dummynativetable ************************************************************
-
-   Ensure that symbols for functions implemented within CACAO are used
-   and exported to dlopen.
-
-   ATTENTION: Don't make this table static!!!  Otherwise the compiler
-   may optimize it away!
-
-*******************************************************************************/
-
-functionptr dummynativetable[] = {
-#if defined(ENABLE_JAVASE)
-       (functionptr) Java_gnu_classpath_VMStackWalker_getClassContext,
-       (functionptr) Java_gnu_classpath_VMStackWalker_getCallingClass,
-       (functionptr) Java_gnu_classpath_VMStackWalker_getCallingClassLoader,
-       (functionptr) Java_gnu_classpath_VMStackWalker_firstNonNullClassLoader,
-
-       (functionptr) Java_gnu_classpath_VMSystemProperties_preInit,
-
-       (functionptr) Java_gnu_java_lang_management_VMClassLoadingMXBeanImpl_getLoadedClassCount,
-       (functionptr) Java_gnu_java_lang_management_VMClassLoadingMXBeanImpl_getUnloadedClassCount,
-       (functionptr) Java_gnu_java_lang_management_VMClassLoadingMXBeanImpl_isVerbose,
-       (functionptr) Java_gnu_java_lang_management_VMClassLoadingMXBeanImpl_setVerbose,
-
-       (functionptr) Java_gnu_java_lang_management_VMMemoryMXBeanImpl_getHeapMemoryUsage,
-       (functionptr) Java_gnu_java_lang_management_VMMemoryMXBeanImpl_getNonHeapMemoryUsage,
-       (functionptr) Java_gnu_java_lang_management_VMMemoryMXBeanImpl_getObjectPendingFinalizationCount,
-       (functionptr) Java_gnu_java_lang_management_VMMemoryMXBeanImpl_isVerbose,
-       (functionptr) Java_gnu_java_lang_management_VMMemoryMXBeanImpl_setVerbose,
-
-       (functionptr) Java_gnu_java_lang_management_VMRuntimeMXBeanImpl_getInputArguments,
-       (functionptr) Java_gnu_java_lang_management_VMRuntimeMXBeanImpl_getStartTime,
-
-       (functionptr) Java_java_lang_VMClass_isInstance,
-       (functionptr) Java_java_lang_VMClass_isAssignableFrom,
-       (functionptr) Java_java_lang_VMClass_isInterface,
-       (functionptr) Java_java_lang_VMClass_isPrimitive,
-       (functionptr) Java_java_lang_VMClass_getName,
-       (functionptr) Java_java_lang_VMClass_getSuperclass,
-       (functionptr) Java_java_lang_VMClass_getInterfaces,
-       (functionptr) Java_java_lang_VMClass_getComponentType,
-       (functionptr) Java_java_lang_VMClass_getModifiers,
-       (functionptr) Java_java_lang_VMClass_getDeclaringClass,
-       (functionptr) Java_java_lang_VMClass_getDeclaredClasses,
-       (functionptr) Java_java_lang_VMClass_getDeclaredFields,
-       (functionptr) Java_java_lang_VMClass_getDeclaredMethods,
-       (functionptr) Java_java_lang_VMClass_getDeclaredConstructors,
-       (functionptr) Java_java_lang_VMClass_getClassLoader,
-       (functionptr) Java_java_lang_VMClass_forName,
-       (functionptr) Java_java_lang_VMClass_isArray,
-       (functionptr) Java_java_lang_VMClass_throwException,
-
-       (functionptr) Java_java_lang_VMClassLoader_defineClass,
-       (functionptr) Java_java_lang_VMClassLoader_resolveClass,
-       (functionptr) Java_java_lang_VMClassLoader_loadClass,
-       (functionptr) Java_java_lang_VMClassLoader_getPrimitiveClass,
-       (functionptr) Java_java_lang_VMClassLoader_nativeGetResources,
-       (functionptr) Java_java_lang_VMClassLoader_findLoadedClass,
-
-       (functionptr) Java_java_lang_VMObject_getClass,
-       (functionptr) Java_java_lang_VMObject_clone,
-       (functionptr) Java_java_lang_VMObject_notify,
-       (functionptr) Java_java_lang_VMObject_notifyAll,
-       (functionptr) Java_java_lang_VMObject_wait,
-
-       (functionptr) Java_java_lang_VMRuntime_availableProcessors,
-       (functionptr) Java_java_lang_VMRuntime_freeMemory,
-       (functionptr) Java_java_lang_VMRuntime_totalMemory,
-       (functionptr) Java_java_lang_VMRuntime_maxMemory,
-       (functionptr) Java_java_lang_VMRuntime_gc,
-       (functionptr) Java_java_lang_VMRuntime_runFinalization,
-       (functionptr) Java_java_lang_VMRuntime_runFinalizationForExit,
-       (functionptr) Java_java_lang_VMRuntime_traceInstructions,
-       (functionptr) Java_java_lang_VMRuntime_traceMethodCalls,
-       (functionptr) Java_java_lang_VMRuntime_runFinalizersOnExit,
-       (functionptr) Java_java_lang_VMRuntime_exit,
-       (functionptr) Java_java_lang_VMRuntime_nativeLoad,
-       (functionptr) Java_java_lang_VMRuntime_mapLibraryName,
-
-       (functionptr) Java_java_lang_VMString_intern,
-
-       (functionptr) Java_java_lang_VMSystem_arraycopy,
-       (functionptr) Java_java_lang_VMSystem_identityHashCode,
-
-       (functionptr) Java_java_lang_VMThread_start,
-       (functionptr) Java_java_lang_VMThread_interrupt,
-       (functionptr) Java_java_lang_VMThread_isInterrupted,
-       (functionptr) Java_java_lang_VMThread_suspend,
-       (functionptr) Java_java_lang_VMThread_resume,
-       (functionptr) Java_java_lang_VMThread_nativeSetPriority,
-       (functionptr) Java_java_lang_VMThread_nativeStop,
-       (functionptr) Java_java_lang_VMThread_currentThread,
-       (functionptr) Java_java_lang_VMThread_yield,
-       (functionptr) Java_java_lang_VMThread_interrupted,
-       (functionptr) Java_java_lang_VMThread_holdsLock,
-       (functionptr) Java_java_lang_VMThread_getState,
-
-       (functionptr) Java_java_lang_VMThrowable_fillInStackTrace,
-       (functionptr) Java_java_lang_VMThrowable_getStackTrace,
-
-       (functionptr) Java_java_lang_management_VMManagementFactory_getMemoryPoolNames,
-       (functionptr) Java_java_lang_management_VMManagementFactory_getMemoryManagerNames,
-       (functionptr) Java_java_lang_management_VMManagementFactory_getGarbageCollectorNames,
-
-       (functionptr) Java_java_lang_reflect_Constructor_getModifiersInternal,
-       (functionptr) Java_java_lang_reflect_Constructor_constructNative,
-
-       (functionptr) Java_java_lang_reflect_Field_getModifiersInternal,
-       (functionptr) Java_java_lang_reflect_Field_getType,
-       (functionptr) Java_java_lang_reflect_Field_get,
-       (functionptr) Java_java_lang_reflect_Field_getBoolean,
-       (functionptr) Java_java_lang_reflect_Field_getByte,
-       (functionptr) Java_java_lang_reflect_Field_getChar,
-       (functionptr) Java_java_lang_reflect_Field_getShort,
-       (functionptr) Java_java_lang_reflect_Field_getInt,
-       (functionptr) Java_java_lang_reflect_Field_getLong,
-       (functionptr) Java_java_lang_reflect_Field_getFloat,
-       (functionptr) Java_java_lang_reflect_Field_getDouble,
-       (functionptr) Java_java_lang_reflect_Field_set,
-       (functionptr) Java_java_lang_reflect_Field_setBoolean,
-       (functionptr) Java_java_lang_reflect_Field_setByte,
-       (functionptr) Java_java_lang_reflect_Field_setChar,
-       (functionptr) Java_java_lang_reflect_Field_setShort,
-       (functionptr) Java_java_lang_reflect_Field_setInt,
-       (functionptr) Java_java_lang_reflect_Field_setLong,
-       (functionptr) Java_java_lang_reflect_Field_setFloat,
-       (functionptr) Java_java_lang_reflect_Field_setDouble,
-
-       (functionptr) Java_java_lang_reflect_Method_getModifiersInternal,
-       (functionptr) Java_java_lang_reflect_Method_getReturnType,
-       (functionptr) Java_java_lang_reflect_Method_getParameterTypes,
-       (functionptr) Java_java_lang_reflect_Method_getExceptionTypes,
-       (functionptr) Java_java_lang_reflect_Method_invokeNative,
-
-       (functionptr) Java_java_lang_reflect_VMProxy_getProxyClass,
-       (functionptr) Java_java_lang_reflect_VMProxy_getProxyData,
-       (functionptr) Java_java_lang_reflect_VMProxy_generateProxyClass,
-
-       (functionptr) Java_java_security_VMAccessController_getStack,
-
-       (functionptr) Java_sun_misc_Unsafe_objectFieldOffset,
-       (functionptr) Java_sun_misc_Unsafe_compareAndSwapInt,
-
-#if defined(ENABLE_JVMTI)
-       (functionptr) Java_gnu_classpath_jdwp_VMVirtualMachine_suspendThread,
-       (functionptr) Java_gnu_classpath_jdwp_VMVirtualMachine_resumeThread,
-       (functionptr) Java_gnu_classpath_jdwp_VMVirtualMachine_getSuspendCount,
-       (functionptr) Java_gnu_classpath_jdwp_VMVirtualMachine_getAllLoadedClassesCount,
-       (functionptr) Java_gnu_classpath_jdwp_VMVirtualMachine_getClassStatus,
-       (functionptr) Java_gnu_classpath_jdwp_VMVirtualMachine_getAllClassMethods,
-       (functionptr) Java_gnu_classpath_jdwp_VMVirtualMachine_getClassMethod,
-       (functionptr) Java_gnu_classpath_jdwp_VMVirtualMachine_getFrames,
-       (functionptr) Java_gnu_classpath_jdwp_VMVirtualMachine_getFrame,
-       (functionptr) Java_gnu_classpath_jdwp_VMVirtualMachine_getFrameCount,
-       (functionptr) Java_gnu_classpath_jdwp_VMVirtualMachine_getThreadStatus,
-       (functionptr) Java_gnu_classpath_jdwp_VMVirtualMachine_getLoadRequests,
-       (functionptr) Java_gnu_classpath_jdwp_VMVirtualMachine_executeMethod,
-       (functionptr) Java_gnu_classpath_jdwp_VMVirtualMachine_getSourceFile,
-       (functionptr) Java_gnu_classpath_jdwp_VMVirtualMachine_registerEvent,
-       (functionptr) Java_gnu_classpath_jdwp_VMVirtualMachine_unregisterEvent,
-       (functionptr) Java_gnu_classpath_jdwp_VMVirtualMachine_clearEvents,
-       (functionptr) Java_gnu_classpath_jdwp_VMVirtualMachine_getAllLoadedClasses,
-       (functionptr) Java_gnu_classpath_jdwp_VMFrame_setValue,
-       (functionptr) Java_gnu_classpath_jdwp_VMFrame_getValue,
-       (functionptr) Java_gnu_classpath_jdwp_VMMethod_getName,
-       (functionptr) Java_gnu_classpath_jdwp_VMMethod_getSignature,
-       (functionptr) Java_gnu_classpath_jdwp_VMMethod_getModifiers,
-       (functionptr) Java_gnu_classpath_jdwp_VMMethod_getLineTable,
-       (functionptr) Java_gnu_classpath_jdwp_VMMethod_getVariableTable
-#endif
-
-#elif defined(ENABLE_JAVAME_CLDC1_1)
-       (functionptr) Java_com_sun_cldc_io_ResourceInputStream_open,
-
-       (functionptr) Java_com_sun_cldc_io_j2me_socket_Protocol_open0,
-       (functionptr) Java_com_sun_cldc_io_j2me_socket_Protocol_readBuf,
-       (functionptr) Java_com_sun_cldc_io_j2me_socket_Protocol_writeByte,
-
-       (functionptr) Java_com_sun_cldchi_io_ConsoleOutputStream_write,
-
-       (functionptr) Java_java_lang_Class_forName,
-       (functionptr) Java_java_lang_Class_newInstance,
-       (functionptr) Java_java_lang_Class_isInstance,
-       (functionptr) Java_java_lang_Class_isAssignableFrom,
-       (functionptr) Java_java_lang_Class_isInterface,
-       (functionptr) Java_java_lang_Class_isArray,
-       (functionptr) Java_java_lang_Class_getName,
-
-       (functionptr) Java_java_lang_Double_doubleToLongBits,
-
-       (functionptr) Java_java_lang_Float_floatToIntBits,
-
-       (functionptr) Java_java_lang_Math_ceil,
-       (functionptr) Java_java_lang_Math_cos,
-       (functionptr) Java_java_lang_Math_floor,
-       (functionptr) Java_java_lang_Math_sin,
-       (functionptr) Java_java_lang_Math_sqrt,
-       (functionptr) Java_java_lang_Math_tan,
-
-       (functionptr) Java_java_lang_Object_hashCode,
-       (functionptr) Java_java_lang_Object_notify,
-       (functionptr) Java_java_lang_Object_wait,
-
-       (functionptr) Java_java_lang_Runtime_exitInternal,
-       (functionptr) Java_java_lang_Runtime_freeMemory,
-       (functionptr) Java_java_lang_Runtime_totalMemory,
-       (functionptr) Java_java_lang_Runtime_gc,
-
-       (functionptr) Java_java_lang_String_hashCode,
-       (functionptr) Java_java_lang_String_indexOf__I,
-       (functionptr) Java_java_lang_String_indexOf__II,
-       (functionptr) Java_java_lang_String_lastIndexOf__II,
-       (functionptr) Java_java_lang_String_intern,
-
-       (functionptr) Java_java_lang_System_getProperty0,
-
-       (functionptr) Java_java_lang_Thread_currentThread,
-       (functionptr) Java_java_lang_Thread_setPriority0,
-       (functionptr) Java_java_lang_Thread_start0,
-       (functionptr) Java_java_lang_Thread_yield,
-
-       (functionptr) Java_java_lang_Throwable_printStackTrace,
-       (functionptr) Java_java_lang_Throwable_fillInStackTrace
+# include "native/nativetable.inc"
 #endif
-};
-
-#endif /* defined(ENABLE_LIBJVM) */
 
 
 /* tables for methods *********************************************************/
@@ -392,12 +91,18 @@ static bool nativecompdone = false;
 
 /* global variables ***********************************************************/
 
-#if !defined(WITH_STATIC_CLASSPATH)
+static avl_tree_t *tree_native_methods;
+
+#if defined(ENABLE_LTDL)
 static hashtable *hashtable_library;
-static lt_dlhandle mainhandle;
 #endif
 
 
+/* prototypes *****************************************************************/
+
+static s4 native_tree_native_methods_comparator(const void *treenode, const void *node);
+
+
 /* native_init *****************************************************************
 
    Initializes the native subsystem.
@@ -406,27 +111,12 @@ static lt_dlhandle mainhandle;
 
 bool native_init(void)
 {
-#if !defined(WITH_STATIC_CLASSPATH)
+#if defined(ENABLE_LTDL)
        /* initialize libltdl */
 
        if (lt_dlinit())
                vm_abort("native_init: lt_dlinit failed: %s\n", lt_dlerror());
 
-       /* Get the handle for the main program or for the libjvm.so,
-          depends on the configuration. */
-
-# if defined(ENABLE_LIBJVM)
-       /* First try to open where dlopen searches, e.g. LD_LIBRARY_PATH.
-          If not found, try the absolute path. */
-
-       if (!(mainhandle = lt_dlopenext("libjvm")))
-               if (!(mainhandle = lt_dlopenext(cacao_libjvm)))
-                       vm_abort("native_init: lt_dlopenext failed: %s\n", lt_dlerror());
-# else
-       if (!(mainhandle = lt_dlopen(NULL)))
-               vm_abort("native_init: lt_dlopen failed: %s\n", lt_dlerror());
-# endif
-
        /* initialize library hashtable, 10 entries should be enough */
 
        hashtable_library = NEW(hashtable);
@@ -434,204 +124,58 @@ bool native_init(void)
        hashtable_create(hashtable_library, 10);
 #endif
 
-       /* everything's ok */
-
-       return true;
-}
-
-
-/* native_hashtable_library_add ************************************************
-
-   Adds an entry to the native library hashtable.
-
-*******************************************************************************/
-
-#if !defined(WITH_STATIC_CLASSPATH)
-void native_hashtable_library_add(utf *filename, java_objectheader *loader,
-                                                                 lt_dlhandle handle)
-{
-       hashtable_library_loader_entry *le;
-       hashtable_library_name_entry   *ne; /* library name                       */
-       u4   key;                           /* hashkey                            */
-       u4   slot;                          /* slot in hashtable                  */
-
-       LOCK_MONITOR_ENTER(hashtable_library->header);
-
-       /* normally addresses are aligned to 4, 8 or 16 bytes */
-
-       key  = ((u4) (ptrint) loader) >> 4;        /* align to 16-byte boundaries */
-       slot = key & (hashtable_library->size - 1);
-       le   = hashtable_library->ptr[slot];
-
-       /* search external hash chain for the entry */
-
-       while (le) {
-               if (le->loader == loader)
-                       break;
-
-               le = le->hashlink;                  /* next element in external chain */
-       }
-
-       /* no loader found? create a new entry */
-
-       if (le == NULL) {
-               le = NEW(hashtable_library_loader_entry);
-
-               le->loader   = loader;
-               le->namelink = NULL;
-
-               /* insert entry into hashtable */
-
-               le->hashlink =
-                       (hashtable_library_loader_entry *) hashtable_library->ptr[slot];
-               hashtable_library->ptr[slot] = le;
-
-               /* update number of hashtable-entries */
-
-               hashtable_library->entries++;
-       }
-
-
-       /* search for library name */
-
-       ne = le->namelink;
-
-       while (ne) {
-               if (ne->name == filename) {
-                       LOCK_MONITOR_EXIT(hashtable_library->header);
-
-                       return;
-               }
-
-               ne = ne->hashlink;                  /* next element in external chain */
-       }
-
-       /* not found? add the library name to the classloader */
-
-       ne = NEW(hashtable_library_name_entry);
-
-       ne->name   = filename;
-       ne->handle = handle;
+       /* initialize the native methods table */
 
-       /* insert entry into external chain */
+       tree_native_methods = avl_create(&native_tree_native_methods_comparator);
 
-       ne->hashlink = le->namelink;
-       le->namelink = ne;
+       /* everything's ok */
 
-       LOCK_MONITOR_EXIT(hashtable_library->header);
+       return true;
 }
-#endif /* !defined(WITH_STATIC_CLASSPATH) */
-
-
-/* native_hashtable_library_find ***********************************************
-
-   Find an entry in the native library hashtable.
-
-*******************************************************************************/
-
-#if !defined(WITH_STATIC_CLASSPATH)
-hashtable_library_name_entry *native_hashtable_library_find(utf *filename,
-                                                                                                                       java_objectheader *loader)
-{
-       hashtable_library_loader_entry *le;
-       hashtable_library_name_entry   *ne; /* library name                       */
-       u4   key;                           /* hashkey                            */
-       u4   slot;                          /* slot in hashtable                  */
-
-       /* normally addresses are aligned to 4, 8 or 16 bytes */
-
-       key  = ((u4) (ptrint) loader) >> 4;        /* align to 16-byte boundaries */
-       slot = key & (hashtable_library->size - 1);
-       le   = hashtable_library->ptr[slot];
-
-       /* search external hash chain for the entry */
-
-       while (le) {
-               if (le->loader == loader)
-                       break;
-
-               le = le->hashlink;                  /* next element in external chain */
-       }
-
-       /* no loader found? return NULL */
-
-       if (!le)
-               return NULL;
-
-       /* search for library name */
-
-       ne = le->namelink;
-
-       while (ne) {
-               if (ne->name == filename)
-                       return ne;
-
-               ne = ne->hashlink;                  /* next element in external chain */
-       }
-
-       /* return entry, if no entry was found, ne is NULL */
 
-       return ne;
-}
-#endif /* !defined(WITH_STATIC_CLASSPATH) */
 
+/* native_tree_native_methods_comparator ***************************************
 
-/* native_findfunction *********************************************************
+   Comparison function for AVL tree of native methods.
 
-   Looks up a method (must have the same class name, method name,
-   descriptor and 'static'ness) and returns a function pointer to it.
-   Returns: function pointer or NULL (if there is no such method)
+   IN:
+       treenode....node in the tree
+          node........node to compare with tree-node
 
-   Remark: For faster operation, the names/descriptors are converted
-   from C strings to Unicode the first time this function is called.
+   RETURN VALUE:
+       -1, 0, +1
 
 *******************************************************************************/
 
-#if defined(WITH_STATIC_CLASSPATH)
-functionptr native_findfunction(utf *cname, utf *mname, utf *desc,
-                                                               bool isstatic)
+static s4 native_tree_native_methods_comparator(const void *treenode, const void *node)
 {
-       /* entry of table for fast string comparison */
-       struct nativecompref *n;
-       s4 i;
-
-       isstatic = isstatic ? true : false;
-       
-       if (!nativecompdone) {
-               for (i = 0; i < NATIVETABLESIZE; i++) {
-                       nativecomptable[i].classname  = 
-                               utf_new_char(nativetable[i].classname);
-
-                       nativecomptable[i].methodname = 
-                               utf_new_char(nativetable[i].methodname);
+       const native_methods_node_t *treenmn;
+       const native_methods_node_t *nmn;
 
-                       nativecomptable[i].descriptor =
-                               utf_new_char(nativetable[i].descriptor);
-
-                       nativecomptable[i].isstatic   = nativetable[i].isstatic;
-                       nativecomptable[i].func       = nativetable[i].func;
-               }
+       treenmn = treenode;
+       nmn     = node;
 
-               nativecompdone = true;
-       }
+       /* these are for walking the tree */
 
-       for (i = 0; i < NATIVETABLESIZE; i++) {
-               n = &(nativecomptable[i]);
+       if (treenmn->classname < nmn->classname)
+               return -1;
+       else if (treenmn->classname > nmn->classname)
+               return 1;
 
-               if (cname == n->classname && mname == n->methodname &&
-                   desc == n->descriptor && isstatic == n->isstatic)
-                       return n->func;
-       }
+       if (treenmn->name < nmn->name)
+               return -1;
+       else if (treenmn->name > nmn->name)
+               return 1;
 
-       /* no function was found, throw exception */
+       if (treenmn->descriptor < nmn->descriptor)
+               return -1;
+       else if (treenmn->descriptor > nmn->descriptor)
+               return 1;
 
-       *exceptionptr =
-                       new_exception_utfmessage(string_java_lang_UnsatisfiedLinkError,
-                                                                        mname);
+       /* all pointers are equal, we have found the entry */
 
-       return NULL;
+       return 0;
 }
-#endif /* defined(WITH_STATIC_CLASSPATH) */
 
 
 /* native_make_overloaded_function *********************************************
@@ -641,16 +185,22 @@ functionptr native_findfunction(utf *cname, utf *mname, utf *desc,
 *******************************************************************************/
 
 #if !defined(WITH_STATIC_CLASSPATH)
-static char *native_make_overloaded_function(char *name, utf *desc)
+static utf *native_make_overloaded_function(utf *name, utf *descriptor)
 {
        char *newname;
        s4    namelen;
        char *utf_ptr;
        u2    c;
        s4    i;
+       s4    dumpsize;
+       utf  *u;
+
+       /* mark memory */
+
+       dumpsize = dump_size();
 
-       utf_ptr = desc->text;
-       namelen = strlen(name) + strlen("__") + strlen("0");
+       utf_ptr = descriptor->text;
+       namelen = strlen(name->text) + strlen("__") + strlen("0");
 
        /* calculate additional length */
 
@@ -682,15 +232,14 @@ static char *native_make_overloaded_function(char *name, utf *desc)
                }
        }
 
-
        /* reallocate memory */
 
-       i = strlen(name);
+       i = strlen(name->text);
 
        newname = DMNEW(char, namelen);
-       MCOPY(newname, name, char, i);
+       MCOPY(newname, name->text, char, i);
 
-       utf_ptr = desc->text;
+       utf_ptr = descriptor->text;
 
        newname[i++] = '_';
        newname[i++] = '_';
@@ -734,7 +283,15 @@ static char *native_make_overloaded_function(char *name, utf *desc)
 
        newname[i] = '\0';
 
-       return newname;
+       /* make a utf-string */
+
+       u = utf_new_char(newname);
+
+       /* release memory */
+
+       dump_release(dumpsize);
+
+       return u;
 }
 
 
@@ -800,52 +357,41 @@ static s4 native_insert_char(char *name, u4 pos, u2 c)
 }
 
 
-/* native_resolve_function *****************************************************
+/* native_method_symbol ********************************************************
 
-   Resolves a native function, maybe from a dynamic library.
+   Generate a method-symbol string out of the class name and the
+   method name.
 
 *******************************************************************************/
 
-functionptr native_resolve_function(methodinfo *m)
+static utf *native_method_symbol(utf *classname, utf *methodname)
 {
-       lt_ptr                          sym;
-       char                           *name;
-       char                           *newname;
-       s4                              namelen;
-       char                           *utf_ptr;
-       char                           *utf_endptr;
-       u2                              c;
-       u4                              pos;
-       s4                              dumpsize;
-       hashtable_library_loader_entry *le;
-       hashtable_library_name_entry   *ne;
-       u4                              key;    /* hashkey                        */
-       u4                              slot;   /* slot in hashtable              */
+       char *name;
+       s4    namelen;
+       char *utf_ptr;
+       char *utf_endptr;
+       u2    c;
+       u4    pos;
+       s4    dumpsize;
+       utf  *u;
 
-       /* verbose output */
+       /* mark memory */
+
+       dumpsize = dump_size();
 
-       if (opt_verbosejni) {
-               printf("[Dynamic-linking native method ");
-               utf_display_printable_ascii_classname(m->class->name);
-               printf(".");
-               utf_display_printable_ascii(m->name);
-               printf(" ... ");
-       }
-               
        /* Calculate length of native function name.  We multiply the
           class and method name length by 6 as this is the maxium
           escape-sequence that can be generated (unicode). */
 
-       namelen = strlen("Java_") +
-               utf_get_number_of_u2s(m->class->name) * 6 +
+       namelen =
+               strlen("Java_") +
+               utf_get_number_of_u2s(classname) * 6 +
                strlen("_") +
-               utf_get_number_of_u2s(m->name) * 6 +
+               utf_get_number_of_u2s(methodname) * 6 +
                strlen("0");
 
        /* allocate memory */
 
-       dumpsize = dump_size();
-
        name = DMNEW(char, namelen);
 
        /* generate name of native functions */
@@ -853,8 +399,8 @@ functionptr native_resolve_function(methodinfo *m)
        strcpy(name, "Java_");
        pos = strlen("Java_");
 
-       utf_ptr    = m->class->name->text;
-       utf_endptr = UTF_END(m->class->name);
+       utf_ptr    = classname->text;
+       utf_endptr = UTF_END(classname);
 
        for (; utf_ptr < utf_endptr; utf_ptr++, pos++) {
                c   = *utf_ptr;
@@ -865,8 +411,8 @@ functionptr native_resolve_function(methodinfo *m)
 
        name[pos++] = '_';
 
-       utf_ptr    = m->name->text;
-       utf_endptr = UTF_END(m->name);
+       utf_ptr    = methodname->text;
+       utf_endptr = UTF_END(methodname);
 
        for (; utf_ptr < utf_endptr; utf_ptr++, pos++) {
                c   = *utf_ptr;
@@ -881,198 +427,475 @@ functionptr native_resolve_function(methodinfo *m)
 
        assert(pos <= namelen);
 
-       /* generate overloaded function (having the types in it's name)           */
+       /* make a utf-string */
 
-       newname = native_make_overloaded_function(name, m->descriptor);
+       u = utf_new_char(name);
 
-       /* check the library hash entries of the classloader of the
-          methods's class  */
+       /* release memory */
+
+       dump_release(dumpsize);
+
+       return u;
+}
+
+
+/* native_method_register ******************************************************
+
+   Register a native method in the native method table.
+
+*******************************************************************************/
+
+void native_method_register(utf *classname, const JNINativeMethod *methods,
+                                                       int32_t count)
+{
+       native_methods_node_t *nmn;
+       utf                   *name;
+       utf                   *descriptor;
+       int32_t                i;
+
+       /* insert all methods passed */
+
+       for (i = 0; i < count; i++) {
+               if (opt_verbosejni) {
+                       printf("[Registering JNI native method ");
+                       utf_display_printable_ascii_classname(classname);
+                       printf(".%s]\n", methods[i].name);
+               }
+
+               /* generate the utf8 names */
 
-       sym = NULL;
+               name       = utf_new_char(methods[i].name);
+               descriptor = utf_new_char(methods[i].signature);
+
+               /* allocate a new tree node */
+
+               nmn = NEW(native_methods_node_t);
+
+               nmn->classname  = classname;
+               nmn->name       = name;
+               nmn->descriptor = descriptor;
+               nmn->function   = (functionptr) (ptrint) methods[i].fnPtr;
+
+               /* insert the method into the tree */
+
+               avl_insert(tree_native_methods, nmn);
+       }
+}
+
+
+/* native_method_find **********************************************************
+
+   Find a native method in the native method table.
+
+*******************************************************************************/
+
+static functionptr native_method_find(methodinfo *m)
+{
+       native_methods_node_t  tmpnmn;
+       native_methods_node_t *nmn;
+
+       /* fill the temporary structure used for searching the tree */
+
+       tmpnmn.classname  = m->class->name;
+       tmpnmn.name       = m->name;
+       tmpnmn.descriptor = m->descriptor;
+
+       /* find the entry in the AVL-tree */
+
+       nmn = avl_find(tree_native_methods, &tmpnmn);
+
+       if (nmn == NULL)
+               return NULL;
+
+       return nmn->function;
+}
+
+
+/* native_library_open *********************************************************
+
+   Open a native library with the given utf8 name.
+
+*******************************************************************************/
+
+#if defined(ENABLE_LTDL)
+lt_dlhandle native_library_open(utf *filename)
+{
+       lt_dlhandle handle;
+
+       if (opt_verbosejni) {
+               printf("[Loading native library ");
+               utf_display_printable_ascii(filename);
+               printf(" ... ");
+       }
+
+       /* try to open the library */
+
+       handle = lt_dlopen(filename->text);
+
+       if (handle == NULL) {
+               if (opt_verbose) {
+                       log_start();
+                       log_print("native_library_load: lt_dlopen failed: ");
+                       log_print(lt_dlerror());
+                       log_finish();
+               }
+
+               return NULL;
+       }
+
+       return handle;
+}
+#endif
+
+
+/* native_library_add **********************************************************
+
+   Adds an entry to the native library hashtable.
+
+*******************************************************************************/
+
+#if defined(ENABLE_LTDL)
+void native_library_add(utf *filename, classloader *loader, lt_dlhandle handle)
+{
+       hashtable_library_loader_entry *le;
+       hashtable_library_name_entry   *ne; /* library name                       */
+       u4   key;                           /* hashkey                            */
+       u4   slot;                          /* slot in hashtable                  */
+
+       LOCK_MONITOR_ENTER(hashtable_library->header);
 
        /* normally addresses are aligned to 4, 8 or 16 bytes */
 
-       key  = ((u4) (ptrint) m->class->classloader) >> 4;    /* align to 16-byte */
+       key  = ((u4) (ptrint) loader) >> 4;        /* align to 16-byte boundaries */
        slot = key & (hashtable_library->size - 1);
        le   = hashtable_library->ptr[slot];
 
-       /* iterate through loaders in this hash slot */
+       /* search external hash chain for the entry */
 
-       while ((le != NULL) && (sym == NULL)) {
-               /* iterate through names in this loader */
+       while (le) {
+               if (le->loader == loader)
+                       break;
 
-               ne = le->namelink;
-                       
-               while ((ne != NULL) && (sym == NULL)) {
-                       sym = lt_dlsym(ne->handle, name);
+               le = le->hashlink;                  /* next element in external chain */
+       }
 
-                       if (sym == NULL)
-                               sym = lt_dlsym(ne->handle, newname);
+       /* no loader found? create a new entry */
 
-                       ne = ne->hashlink;
-               }
+       if (le == NULL) {
+               le = NEW(hashtable_library_loader_entry);
 
-               le = le->hashlink;
+               le->loader   = loader;
+               le->namelink = NULL;
+
+               /* insert entry into hashtable */
+
+               le->hashlink =
+                       (hashtable_library_loader_entry *) hashtable_library->ptr[slot];
+               hashtable_library->ptr[slot] = le;
+
+               /* update number of hashtable-entries */
+
+               hashtable_library->entries++;
        }
 
-       if (sym != NULL)
-               if (opt_verbosejni)
-                       printf("JNI ]\n");
 
+       /* search for library name */
 
-       /* If not found, try to find the native function symbol in the
-          main program. */
+       ne = le->namelink;
 
-       if (sym == NULL) {
-               sym = lt_dlsym(mainhandle, name);
+       while (ne) {
+               if (ne->name == filename) {
+                       LOCK_MONITOR_EXIT(hashtable_library->header);
 
-               if (sym == NULL)
-                       sym = lt_dlsym(mainhandle, newname);
+                       return;
+               }
 
-               if (sym != NULL)
-                       if (opt_verbosejni)
-                               printf("internal ]\n");
+               ne = ne->hashlink;                  /* next element in external chain */
        }
 
+       /* not found? add the library name to the classloader */
 
-#if defined(ENABLE_JVMTI)
-       /* fire Native Method Bind event */
-       if (jvmti) jvmti_NativeMethodBind(m, sym, &sym);
+       ne = NEW(hashtable_library_name_entry);
+
+       ne->name   = filename;
+       ne->handle = handle;
+
+       /* insert entry into external chain */
+
+       ne->hashlink = le->namelink;
+       le->namelink = ne;
+
+       LOCK_MONITOR_EXIT(hashtable_library->header);
+}
 #endif
 
-       /* no symbol found? throw exception */
 
-       if (sym == NULL) {
-               if (opt_verbosejni)
-                       printf("failed ]\n");
+/* native_library_find *********************************************************
 
-               exceptions_throw_unsatisfiedlinkerror(m->name);
+   Find an entry in the native library hashtable.
+
+*******************************************************************************/
+
+#if defined(ENABLE_LTDL)
+hashtable_library_name_entry *native_library_find(utf *filename,
+                                                                                                 classloader *loader)
+{
+       hashtable_library_loader_entry *le;
+       hashtable_library_name_entry   *ne; /* library name                       */
+       u4   key;                           /* hashkey                            */
+       u4   slot;                          /* slot in hashtable                  */
+
+       /* normally addresses are aligned to 4, 8 or 16 bytes */
+
+       key  = ((u4) (ptrint) loader) >> 4;        /* align to 16-byte boundaries */
+       slot = key & (hashtable_library->size - 1);
+       le   = hashtable_library->ptr[slot];
+
+       /* search external hash chain for the entry */
+
+       while (le) {
+               if (le->loader == loader)
+                       break;
+
+               le = le->hashlink;                  /* next element in external chain */
        }
 
-       /* release memory */
+       /* no loader found? return NULL */
 
-       dump_release(dumpsize);
+       if (le == NULL)
+               return NULL;
+
+       /* search for library name */
+
+       ne = le->namelink;
 
-       return (functionptr) (ptrint) sym;
+       while (ne) {
+               if (ne->name == filename)
+                       return ne;
+
+               ne = ne->hashlink;                  /* next element in external chain */
+       }
+
+       /* return entry, if no entry was found, ne is NULL */
+
+       return ne;
 }
 #endif /* !defined(WITH_STATIC_CLASSPATH) */
 
 
-/* native_new_and_init *********************************************************
+/* native_findfunction *********************************************************
+
+   Looks up a method (must have the same class name, method name,
+   descriptor and 'static'ness) and returns a function pointer to it.
+   Returns: function pointer or NULL (if there is no such method)
+
+   Remark: For faster operation, the names/descriptors are converted
+   from C strings to Unicode the first time this function is called.
 
-   Creates a new object on the heap and calls the initializer.
-   Returns the object pointer or NULL if memory is exhausted.
-                       
 *******************************************************************************/
 
-java_objectheader *native_new_and_init(classinfo *c)
+#if defined(WITH_STATIC_CLASSPATH)
+functionptr native_findfunction(utf *cname, utf *mname, utf *desc,
+                                                               bool isstatic)
 {
-       methodinfo *m;
-       java_objectheader *o;
+       /* entry of table for fast string comparison */
+       struct nativecompref *n;
+       s4 i;
 
-       if (c == NULL)
-               vm_abort("native_new_and_init: c == NULL");
+       isstatic = isstatic ? true : false;
+       
+       if (!nativecompdone) {
+               for (i = 0; i < NATIVETABLESIZE; i++) {
+                       nativecomptable[i].classname  = 
+                               utf_new_char(nativetable[i].classname);
 
-       /* create object */
+                       nativecomptable[i].methodname = 
+                               utf_new_char(nativetable[i].methodname);
 
-       o = builtin_new(c);
-       
-       if (o == NULL)
-               return NULL;
+                       nativecomptable[i].descriptor =
+                               utf_new_char(nativetable[i].descriptor);
 
-       /* try to find the initializer */
+                       nativecomptable[i].isstatic   = nativetable[i].isstatic;
+                       nativecomptable[i].func       = nativetable[i].func;
+               }
 
-       m = class_findmethod(c, utf_init, utf_void__void);
-                                                     
-       /* ATTENTION: returning the object here is ok, since the class may
-       not have an initializer */
+               nativecompdone = true;
+       }
 
-       if (m == NULL)
-               return o;
+       for (i = 0; i < NATIVETABLESIZE; i++) {
+               n = &(nativecomptable[i]);
 
-       /* call initializer */
+               if (cname == n->classname && mname == n->methodname &&
+                   desc == n->descriptor && isstatic == n->isstatic)
+                       return n->func;
+       }
 
-       (void) vm_call_method(m, o);
+       /* no function was found, throw exception */
 
-       return o;
+       exceptions_throw_unsatisfiedlinkerror(mname);
+
+       return NULL;
 }
+#endif /* defined(WITH_STATIC_CLASSPATH) */
+
+
+/* native_resolve_function *****************************************************
 
+   Resolves a native function, maybe from a dynamic library.
 
-java_objectheader *native_new_and_init_string(classinfo *c, java_objectheader *s)
+*******************************************************************************/
+
+functionptr native_resolve_function(methodinfo *m)
 {
-       methodinfo        *m;
-       java_objectheader *o;
+       classloader                    *cl;
+       utf                            *name;
+       utf                            *newname;
+       functionptr                     f;
+#if defined(ENABLE_LTDL)
+       hashtable_library_loader_entry *le;
+       hashtable_library_name_entry   *ne;
+       u4                              key;    /* hashkey                        */
+       u4                              slot;   /* slot in hashtable              */
+#endif
+#if defined(WITH_CLASSPATH_SUN)
+       methodinfo                     *method_findNative;
+       java_handle_t                  *s;
+#endif
 
-       if (c == NULL)
-               vm_abort("native_new_and_init_string: c == NULL");
+       cl = m->class->classloader;
 
-       /* create object */
+       /* verbose output */
 
-       o = builtin_new(c);
+       if (opt_verbosejni) {
+               printf("[Dynamic-linking native method ");
+               utf_display_printable_ascii_classname(m->class->name);
+               printf(".");
+               utf_display_printable_ascii(m->name);
+               printf(" ... ");
+       }
 
-       if (o == NULL)
-               return NULL;
+       /* generate method symbol string */
 
-       /* find initializer */
+       name = native_method_symbol(m->class->name, m->name);
 
-       m = class_resolveclassmethod(c,
-                                                                utf_init,
-                                                                utf_java_lang_String__void,
-                                                                NULL,
-                                                                true);
+       /* generate overloaded function (having the types in it's name)           */
 
-       /* initializer not found */
+       newname = native_make_overloaded_function(name, m->descriptor);
 
-       if (m == NULL)
-               return NULL;
+       /* check the library hash entries of the classloader of the
+          methods's class  */
 
-       /* call initializer */
+       f = NULL;
 
-       (void) vm_call_method(m, o, s);
+#if defined(ENABLE_LTDL)
+       /* normally addresses are aligned to 4, 8 or 16 bytes */
 
-       return o;
-}
+       key  = ((u4) (ptrint) cl) >> 4;                       /* align to 16-byte */
+       slot = key & (hashtable_library->size - 1);
+       le   = hashtable_library->ptr[slot];
 
+       /* iterate through loaders in this hash slot */
 
-java_objectheader *native_new_and_init_int(classinfo *c, s4 i)
-{
-       methodinfo *m;
-       java_objectheader *o;
+       while ((le != NULL) && (f == NULL)) {
+               /* iterate through names in this loader */
 
-       if (c == NULL)
-               vm_abort("native_new_and_init_int: c == NULL");
+               ne = le->namelink;
+                       
+               while ((ne != NULL) && (f == NULL)) {
+                       f = (functionptr) (ptrint) lt_dlsym(ne->handle, name->text);
 
-       /* create object */
+                       if (f == NULL)
+                               f = (functionptr) (ptrint) lt_dlsym(ne->handle, newname->text);
 
-       o = builtin_new(c);
-       
-       if (o == NULL)
-               return NULL;
+                       ne = ne->hashlink;
+               }
 
-       /* find initializer */
+               le = le->hashlink;
+       }
 
-       m = class_resolveclassmethod(c, utf_init, utf_int__void, NULL, true);
+# if defined(WITH_CLASSPATH_SUN)
+       if (f == NULL) {
+               /* We can resolve the function directly from
+                  java.lang.ClassLoader as it's a static function. */
+               /* XXX should be done in native_init */
 
-       /* initializer not found  */
+               method_findNative =
+                       class_resolveclassmethod(class_java_lang_ClassLoader,
+                                                                        utf_findNative,
+                                                                        utf_java_lang_ClassLoader_java_lang_String__J,
+                                                                        class_java_lang_ClassLoader,
+                                                                        true);
 
-       if (m == NULL)
-               return NULL;
+               if (method_findNative == NULL)
+                       return NULL;
 
-       /* call initializer */
+               /* try the normal name */
 
-       (void) vm_call_method(m, o, i);
+               s = javastring_new(name);
 
-       return o;
+               f = (functionptr) (intptr_t) vm_call_method_long(method_findNative,
+                                                                                                                NULL, cl, s);
+
+               /* if not found, try the mangled name */
+
+               if (f == NULL) {
+                       s = javastring_new(newname);
+
+                       f = (functionptr) (intptr_t) vm_call_method_long(method_findNative,
+                                                                                                                        NULL, cl, s);
+               }
+       }
+# endif
+
+       if (f != NULL)
+               if (opt_verbosejni)
+                       printf("JNI ]\n");
+#endif
+
+       /* If not found, try to find the native function symbol in the
+          main program. */
+
+       if (f == NULL) {
+               f = native_method_find(m);
+
+               if (f != NULL)
+                       if (opt_verbosejni)
+                               printf("internal ]\n");
+       }
+
+#if defined(ENABLE_JVMTI)
+       /* fire Native Method Bind event */
+       if (jvmti) jvmti_NativeMethodBind(m, f, &f);
+#endif
+
+       /* no symbol found? throw exception */
+
+       if (f == NULL) {
+               if (opt_verbosejni)
+                       printf("failed ]\n");
+
+               exceptions_throw_unsatisfiedlinkerror(m->name);
+       }
+
+       return f;
 }
+#endif /* !defined(WITH_STATIC_CLASSPATH) */
 
 
-java_objectheader *native_new_and_init_throwable(classinfo *c, java_objectheader *t)
+/* native_new_and_init *********************************************************
+
+   Creates a new object on the heap and calls the initializer.
+   Returns the object pointer or NULL if memory is exhausted.
+                       
+*******************************************************************************/
+
+java_handle_t *native_new_and_init(classinfo *c)
 {
-       java_objectheader *o;
-       methodinfo        *m;
+       methodinfo    *m;
+       java_handle_t *o;
 
        if (c == NULL)
-               vm_abort("native_new_and_init_throwable: c == NULL");
+               vm_abort("native_new_and_init: c == NULL");
 
        /* create object */
 
@@ -1081,61 +904,54 @@ java_objectheader *native_new_and_init_throwable(classinfo *c, java_objectheader
        if (o == NULL)
                return NULL;
 
-       /* find initializer */
+       /* try to find the initializer */
 
-       m = class_findmethod(c, utf_init, utf_java_lang_Throwable__void);
+       m = class_findmethod(c, utf_init, utf_void__void);
                                                      
-       /* initializer not found */
+       /* ATTENTION: returning the object here is ok, since the class may
+       not have an initializer */
 
        if (m == NULL)
-               return NULL;
+               return o;
 
        /* call initializer */
 
-       (void) vm_call_method(m, o, t);
+       (void) vm_call_method(m, o);
 
        return o;
 }
 
 
-/* native_class_getdeclaredannotations *****************************************
-
-   Implementation for
-   java.lang.Class.getDeclaredAnnotations(Ljava/lang/Class;)[Ljava/lang/annotation/Annotation;
-
-*******************************************************************************/
-
-#if defined(ENABLE_JAVASE)
-java_objectarray *native_class_getdeclaredannotations(classinfo *c)
+java_handle_t *native_new_and_init_string(classinfo *c, java_handle_t *s)
 {
-       java_objectarray *oa;
-       s4                count;
-       s4                i;
+       methodinfo    *m;
+       java_handle_t *o;
+
+       if (c == NULL)
+               vm_abort("native_new_and_init_string: c == NULL");
 
-       classinfo *class_java_lang_annotation_Annotation;
+       /* create object */
 
-       /* create Annotation-array */
+       o = builtin_new(c);
 
-       /* XXX should we cache that class? */
-       if (!(class_java_lang_annotation_Annotation =
-                 load_class_bootstrap(utf_new_char("java/lang/annotation/Annotation"))))
+       if (o == NULL)
                return NULL;
 
-       count = c->runtimevisibleannotationscount;
+       /* find initializer */
+
+       m = class_findmethod(c, utf_init, utf_java_lang_String__void);
 
-       oa = builtin_anewarray(count, class_java_lang_annotation_Annotation);
+       /* initializer not found */
 
-       if (oa == NULL)
+       if (m == NULL)
                return NULL;
 
-       /* fill the annotations */
+       /* call initializer */
 
-       for (i = 0; i < count; i++) {
-       }
+       (void) vm_call_method(m, o, s);
 
-       return oa;
+       return o;
 }
-#endif
 
 
 /*