* Removed all Id tags.
[cacao.git] / src / native / native.h
index 269c679740d626a8b611ff48741022b89fa3c842..ee0403283c7a7a7e42e985590d6241005f7ee3bf 100644 (file)
@@ -1,9 +1,9 @@
-/* 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, 2006, 2007 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.
 
 
    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
-   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
-   02111-1307, USA.
-
-   Contact: cacao@complang.tuwien.ac.at
-
-   Authors: Reinhard Grafl
-
-   $Id: native.h 1361 2004-07-28 10:51:14Z twisti $
+   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+   02110-1301, USA.
 
 */
 
 #ifndef _NATIVE_H
 #define _NATIVE_H
 
+#include "config.h"
 
-#include "jni.h"
-#include "nat/java_lang_String.h"
-#include "nat/java_lang_ClassLoader.h"
-#include "nat/java_lang_Throwable.h"
+#if defined(ENABLE_LTDL) && defined(HAVE_LTDL_H)
+# include <ltdl.h>
+#endif
 
+#include <stdint.h>
 
-/* table for locating native methods */
-
-typedef struct nativeref nativeref;
-typedef struct nativecompref nativecompref;
-
-struct nativeref {
-       char       *classname;
-       char       *methodname;
-       char       *descriptor;
-       bool        isstatic;
-       functionptr func;
-};
+#include "native/jni.h"
 
-/* table for fast string comparison */
+#include "vm/global.h"
 
-struct nativecompref {
-       utf        *classname;
-       utf        *methodname;
-       utf        *descriptor;
-       bool        isstatic;
-       functionptr func;
-};
+#include "vmcore/class.h"
+#include "vmcore/method.h"
+#include "vmcore/utf8.h"
 
 
-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;
+/* defines ********************************************************************/
 
+#define NATIVE_METHODS_COUNT    sizeof(methods) / sizeof(JNINativeMethod)
 
-/* the system classloader object */
-extern java_lang_ClassLoader *SystemClassLoader;
 
-/* for raising exceptions from native methods */
-/* extern java_objectheader* exceptionptr; */
+/* table for locating native methods */
 
-/* javastring-hashtable */
-extern hashtable string_hash; 
+#if defined(WITH_STATIC_CLASSPATH)
+typedef struct nativeref nativeref;
+typedef struct nativecompref nativecompref;
+#endif
 
-void use_class_as_object(classinfo *c);
 
-/* load classes required for native methods */
-void native_loadclasses();
+/* native_methods_node_t ******************************************************/
 
-/* find native function */
-functionptr native_findfunction(utf *cname, utf *mname, 
-                                                               utf *desc, bool isstatic);
+typedef struct native_methods_node_t native_methods_node_t;
 
-/* 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);
+struct native_methods_node_t {
+       utf         *classname;             /* class name                         */
+       utf         *name;                  /* method name                        */
+       utf         *descriptor;            /* descriptor name                    */
+       functionptr  function;              /* pointer to the implementation      */
+};
 
-/* 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);
 
-/* make c-string from a javastring (debugging) */
-char *javastring_tochar(java_objectheader *s);
+/* hashtable_library_loader_entry *********************************************/
 
-/* create new object on the heap and call the initializer */
-java_objectheader *native_new_and_init(classinfo *c);
+#if defined(ENABLE_LTDL)
+typedef struct hashtable_library_loader_entry hashtable_library_loader_entry;
+typedef struct hashtable_library_name_entry   hashtable_library_name_entry;
 
-/* create new object on the heap and call the initializer 
-   mainly used for exceptions with a message */
-java_objectheader *native_new_and_init_string(classinfo *c, java_lang_String *s);
+struct hashtable_library_loader_entry {
+       classloader                    *loader;  /* class loader                  */
+       hashtable_library_name_entry   *namelink;/* libs loaded by this loader    */
+       hashtable_library_loader_entry *hashlink;/* link for external chaining    */
+};
+#endif
 
-/* create new object on the heap and call the initializer 
-   mainly used for exceptions with an index */
-java_objectheader *native_new_and_init_int(classinfo *c, s4 i);
 
-/* create new object on the heap and call the initializer 
-   mainly used for exceptions with cause */
-java_objectheader *native_new_and_init_throwable(classinfo *c, java_lang_Throwable *t);
+/* hashtable_library_name_entry ***********************************************/
 
-/* add property to system-property vector */
-void attach_property(char *name, char *value);
+#if defined(ENABLE_LTDL)
+struct hashtable_library_name_entry {
+       utf                          *name;      /* library name                  */
+       lt_dlhandle                   handle;    /* libtool library handle        */
+       hashtable_library_name_entry *hashlink;  /* link for external chaining    */
+};
+#endif
 
-/* correct vftbl-entries of javastring-hash */
-void stringtable_update();
 
+struct nativeref {
+       char       *classname;
+       char       *methodname;
+       char       *descriptor;
+       bool        isstatic;
+       functionptr func;
+};
 
-/* make utf symbol from javastring */
-utf *javastring_toutf(struct java_lang_String *string, bool isclassname);
+/* table for fast string comparison */
 
-/* make utf symbol from u2 array */
-utf *utf_new_u2(u2 *unicodedata, u4 unicodelength, bool isclassname);
+struct nativecompref {
+       utf        *classname;
+       utf        *methodname;
+       utf        *descriptor;
+       bool        isstatic;
+       functionptr func;
+};
 
-/* 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();
+/* function prototypes ********************************************************/
 
-/* 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);
+bool native_init(void);
 
-/* creates a new javastring with the text of the utf-symbol */
-java_objectheader *literalstring_new(utf *u);
+void native_method_register(utf *classname, const JNINativeMethod *methods,
+                                                       int32_t count);
 
-/* creates a new javastring with the text of the u2-array */
-java_objectheader *literalstring_u2(java_chararray *a, u4 length, u4 offset,
-                                                                       bool copymode);
+#if defined(WITH_STATIC_CLASSPATH)
 
-/* dispose a javastring */
-void literalstring_free(java_objectheader*);
+functionptr native_findfunction(utf *cname, utf *mname, utf *desc,
+                                                               bool isstatic);
 
-void copy_vftbl(vftbl_t **dest, vftbl_t *src);
+#else /* defined(WITH_STATIC_CLASSPATH) */
 
-utf *create_methodsig(java_objectarray* types, char *retType);
-classinfo *get_type(char **utf_ptr,char *desc_end, bool skip);
-java_objectarray* get_parametertypes(methodinfo *m);
-java_objectarray* get_exceptiontypes(methodinfo *m);
-classinfo *get_returntype(methodinfo *m);
+# if defined(ENABLE_LTDL)
+lt_dlhandle native_library_open(utf *filename);
+void        native_library_add(utf *filename, classloader *loader,
+                                                          lt_dlhandle handle);
+hashtable_library_name_entry *native_library_find(utf *filename,
+                                                                                                 classloader *loader);
+# endif
 
+functionptr native_resolve_function(methodinfo *m);
 
+#endif /* defined(WITH_STATIC_CLASSPATH) */
 
+java_handle_t *native_new_and_init(classinfo *c);
 
-java_objectarray *builtin_asm_createclasscontextarray(classinfo **end,classinfo **start);
-java_lang_ClassLoader *builtin_asm_getclassloader(classinfo **end,classinfo **start);
+java_handle_t *native_new_and_init_string(classinfo *c, java_handle_t *s);
 
 #endif /* _NATIVE_H */