* bug fixing in native library hash code, it should work now completely, at
[cacao.git] / src / native / native.h
index 4241a5ad78ea9a43b224a30ea982167898b414e2..07dc02ab2d451246cb4eac082fe6e080004c4377 100644 (file)
@@ -1,9 +1,9 @@
-/* native/native.h - table of native functions
+/* src/native/native.h - table of native functions
 
-   Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
-   R. Grafl, A. Krall, C. Kruegel, C. Oates, R. Obermaisser,
-   M. Probst, S. Ring, E. Steiner, C. Thalinger, D. Thuernbeck,
-   P. Tomsich, J. Wenninger
+   Copyright (C) 1996-2005 R. Grafl, A. Krall, C. Kruegel, C. Oates,
+   R. Obermaisser, M. Platter, M. Probst, S. Ring, E. Steiner,
+   C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich, J. Wenninger,
+   Institut f. Computersprachen - TU Wien
 
    This file is part of CACAO.
 
@@ -26,7 +26,9 @@
 
    Authors: Reinhard Grafl
 
-   $Id: native.h 1655 2004-12-02 16:51:20Z carolyn $
+   Changes: Christian Thalinger
+
+   $Id: native.h 2707 2005-06-15 13:40:36Z twisti $
 
 */
 
 #ifndef _NATIVE_H
 #define _NATIVE_H
 
+#if !defined(STATIC_CLASSPATH)
+# include "libltdl/ltdl.h"
+#endif
 
+#include "vm/class.h"
+#include "vm/global.h"
+#include "vm/method.h"
+#include "vm/utf8.h"
 #include "native/jni.h"
 #include "native/include/java_lang_String.h"
 #include "native/include/java_lang_ClassLoader.h"
 typedef struct nativeref nativeref;
 typedef struct nativecompref nativecompref;
 
+
+#if !defined(STATIC_CLASSPATH)
+typedef struct library_hash_loader_entry library_hash_loader_entry;
+typedef struct library_hash_name_entry library_hash_name_entry;
+
+/* library_hash_loader_entry **************************************************/
+
+struct library_hash_loader_entry {
+       java_objectheader         *loader;  /* class loader                       */
+       library_hash_name_entry   *namelink;/* libraries loaded by this loader    */
+       library_hash_loader_entry *hashlink;/* link for external chaining         */
+};
+
+
+/* library_hash_name_entry ****************************************************/
+
+struct library_hash_name_entry {
+       utf                     *name;      /* library name                       */
+       lt_dlhandle              handle;    /* libtool library handle             */
+       library_hash_name_entry *hashlink;  /* link for external chaining         */
+};
+#endif
+
+
 struct nativeref {
        char       *classname;
        char       *methodname;
@@ -65,49 +98,23 @@ struct nativecompref {
 };
 
 
-extern classinfo *class_java_lang_Class;
-extern classinfo *class_java_lang_VMClass;
-extern classinfo *class_java_lang_System;
-extern classinfo *class_java_lang_ClassLoader;
-extern classinfo *class_java_lang_Double;
-extern classinfo *class_java_lang_Float;
-extern classinfo *class_java_lang_Long;
-extern classinfo *class_java_lang_Byte;
-extern classinfo *class_java_lang_Short;
-extern classinfo *class_java_lang_Boolean;
-extern classinfo *class_java_lang_Void;
-extern classinfo *class_java_lang_Character;
-extern classinfo *class_java_lang_Integer;
-
-
-/* the system classloader object */
-extern java_lang_ClassLoader *SystemClassLoader;
-
-/* for raising exceptions from native methods */
-/* extern java_objectheader* exceptionptr; */
-
-/* javastring-hashtable */
-extern hashtable string_hash; 
-
 void use_class_as_object(classinfo *c);
 
-/* load classes required for native methods */
-void native_loadclasses();
+/* initialize native subsystem */
+bool native_init(void);
 
 /* find native function */
 functionptr native_findfunction(utf *cname, utf *mname, 
                                                                utf *desc, bool isstatic);
 
-/* creates a new object of type java/lang/String from a utf-text */
-/*  java_objectheader *javastring_new(utf *text); */
-java_lang_String *javastring_new(utf *text);
-
-/* creates a new object of type java/lang/String from a c-string */
-/*  java_objectheader *javastring_new_char(char *text); */
-java_lang_String *javastring_new_char(char *text);
+#if !defined(STATIC_CLASSPATH)
+/* add a library to the library hash */
+void native_library_hash_add(utf *filename, java_objectheader *loader,
+                                                        lt_dlhandle handle);
 
-/* make c-string from a javastring (debugging) */
-char *javastring_tochar(java_objectheader *s);
+/* resolve native function */
+functionptr native_resolve_function(methodinfo *m);
+#endif
 
 /* create new object on the heap and call the initializer */
 java_objectheader *native_new_and_init(classinfo *c);
@@ -131,32 +138,10 @@ void create_property(char *key, char *value);
 void stringtable_update();
 
 
-/* make utf symbol from javastring */
-utf *javastring_toutf(java_lang_String *string, bool isclassname);
-
-/* make utf symbol from u2 array */
-utf *utf_new_u2(u2 *unicodedata, u4 unicodelength, bool isclassname);
-
-/* determine utf length in bytes of a u2 array */
-u4 u2_utflength(u2 *text, u4 u2_length);
-
-/* create systemclassloader object and initialize its instance fields  */
-void init_systemclassloader();
-
 /* search 'classinfo'-structure for a field with the specified name */
 fieldinfo *class_findfield_approx(classinfo *c, utf *name);
 s4 class_findfield_index_approx(classinfo *c, utf *name);
 
-/* creates a new javastring with the text of the utf-symbol */
-java_objectheader *literalstring_new(utf *u);
-
-/* creates a new javastring with the text of the u2-array */
-java_objectheader *literalstring_u2(java_chararray *a, u4 length, u4 offset,
-                                                                       bool copymode);
-
-/* dispose a javastring */
-void literalstring_free(java_objectheader*);
-
 void copy_vftbl(vftbl_t **dest, vftbl_t *src);
 
 utf *create_methodsig(java_objectarray* types, char *retType);
@@ -166,11 +151,6 @@ java_objectarray* get_exceptiontypes(methodinfo *m);
 classinfo *get_returntype(methodinfo *m);
 
 
-
-
-java_objectarray *builtin_asm_createclasscontextarray(classinfo **end,classinfo **start);
-java_lang_ClassLoader *builtin_asm_getclassloader(classinfo **end,classinfo **start);
-
 /*----- For Static Analysis of Natives by parseRT -----*/
 
 /*---------- global variables ---------------------------*/
@@ -205,18 +185,13 @@ struct  nativeMethod  {
 };
 
 
-static struct nativeCall {
+struct nativeCall {
        char *classname;
        struct nativeMethod methods[MAXCALLS];
        int methCnt;
        int callCnt[MAXCALLS];
-} nativeCalls[] =
-{
-#include "nativecalls.inc"
 };
 
-#define NATIVECALLSSIZE  (sizeof(nativeCalls)/sizeof(struct nativeCall))
-
 
 struct methodCompCall {
        utf *classname;
@@ -237,7 +212,7 @@ struct nativeCompCall {
        struct nativeCompMethod methods[MAXCALLS];
        int methCnt;
        int callCnt[MAXCALLS];
-} nativeCompCalls[NATIVECALLSSIZE];
+};
 
 
 bool natcall2utf(bool);