* Removed all Id tags.
[cacao.git] / src / native / native.h
index dafe3e035b79a69ac777b3a3e9d385ce544b34dc..ee0403283c7a7a7e42e985590d6241005f7ee3bf 100644 (file)
@@ -1,9 +1,9 @@
 /* src/native/native.h - table of native functions
 
-   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
+   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
-
-   Changes: Christian Thalinger
-
-   $Id: native.h 2139 2005-03-30 10:24:10Z twisti $
+   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+   02110-1301, USA.
 
 */
 
 #ifndef _NATIVE_H
 #define _NATIVE_H
 
-#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"
-#include "native/include/java_lang_Throwable.h"
+#include "config.h"
 
+#if defined(ENABLE_LTDL) && defined(HAVE_LTDL_H)
+# include <ltdl.h>
+#endif
 
-/* table for locating native methods */
+#include <stdint.h>
 
-typedef struct nativeref nativeref;
-typedef struct nativecompref nativecompref;
-
-struct nativeref {
-       char       *classname;
-       char       *methodname;
-       char       *descriptor;
-       bool        isstatic;
-       functionptr func;
-};
-
-/* table for fast string comparison */
+#include "native/jni.h"
 
-struct nativecompref {
-       utf        *classname;
-       utf        *methodname;
-       utf        *descriptor;
-       bool        isstatic;
-       functionptr func;
-};
+#include "vm/global.h"
 
+#include "vmcore/class.h"
+#include "vmcore/method.h"
+#include "vmcore/utf8.h"
 
-void use_class_as_object(classinfo *c);
 
-/* load classes required for native methods */
-bool native_init(void);
+/* defines ********************************************************************/
 
-/* find native function */
-functionptr native_findfunction(utf *cname, utf *mname, 
-                                                               utf *desc, bool isstatic);
+#define NATIVE_METHODS_COUNT    sizeof(methods) / sizeof(JNINativeMethod)
 
-/* create new object on the heap and call the initializer */
-java_objectheader *native_new_and_init(classinfo *c);
 
-/* 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);
-
-/* 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);
+/* table for locating native methods */
 
-/* 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);
+#if defined(WITH_STATIC_CLASSPATH)
+typedef struct nativeref nativeref;
+typedef struct nativecompref nativecompref;
+#endif
 
-/* add property to temporary property list -- located in nat/VMRuntime.c */
-void create_property(char *key, char *value);
 
-/* correct vftbl-entries of javastring-hash */
-void stringtable_update();
+/* native_methods_node_t ******************************************************/
 
+typedef struct native_methods_node_t native_methods_node_t;
 
-/* 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);
+struct native_methods_node_t {
+       utf         *classname;             /* class name                         */
+       utf         *name;                  /* method name                        */
+       utf         *descriptor;            /* descriptor name                    */
+       functionptr  function;              /* pointer to the implementation      */
+};
 
-void copy_vftbl(vftbl_t **dest, vftbl_t *src);
 
-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);
+/* hashtable_library_loader_entry *********************************************/
 
+#if defined(ENABLE_LTDL)
+typedef struct hashtable_library_loader_entry hashtable_library_loader_entry;
+typedef struct hashtable_library_name_entry   hashtable_library_name_entry;
 
+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
 
 
-java_objectarray *builtin_asm_createclasscontextarray(classinfo **end,classinfo **start);
-java_lang_ClassLoader *builtin_asm_getclassloader(classinfo **end,classinfo **start);
+/* hashtable_library_name_entry ***********************************************/
 
-/*----- For Static Analysis of Natives by parseRT -----*/
+#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
 
-/*---------- global variables ---------------------------*/
-typedef struct classMeth classMeth;
-typedef struct nativeCall   nativeCall;
-typedef struct methodCall   methodCall;
-typedef struct nativeMethod nativeMethod;
 
-typedef struct nativeCompCall   nativeCompCall;
-typedef struct methodCompCall   methodCompCall;
-typedef struct nativeCompMethod nativeCompMethod;
+struct nativeref {
+       char       *classname;
+       char       *methodname;
+       char       *descriptor;
+       bool        isstatic;
+       functionptr func;
+};
 
-/*---------- Define Constants ---------------------------*/
-#define MAXCALLS 30 
+/* table for fast string comparison */
 
-struct classMeth {
-       int i_class;
-       int j_method;
-       int methCnt;
+struct nativecompref {
+       utf        *classname;
+       utf        *methodname;
+       utf        *descriptor;
+       bool        isstatic;
+       functionptr func;
 };
 
-struct  methodCall{
-       char *classname;
-       char *methodname;
-       char *descriptor;
-};
 
-struct  nativeMethod  {
-       char *methodname;
-       char *descriptor;
-       struct methodCall methodCalls[MAXCALLS];
-};
+/* function prototypes ********************************************************/
 
+bool native_init(void);
 
-struct nativeCall {
-       char *classname;
-       struct nativeMethod methods[MAXCALLS];
-       int methCnt;
-       int callCnt[MAXCALLS];
-};
+void native_method_register(utf *classname, const JNINativeMethod *methods,
+                                                       int32_t count);
 
+#if defined(WITH_STATIC_CLASSPATH)
 
-struct methodCompCall {
-       utf *classname;
-       utf *methodname;
-       utf *descriptor;
-};
+functionptr native_findfunction(utf *cname, utf *mname, utf *desc,
+                                                               bool isstatic);
 
+#else /* defined(WITH_STATIC_CLASSPATH) */
 
-struct nativeCompMethod {
-       utf *methodname;
-       utf *descriptor;
-       struct methodCompCall methodCalls[MAXCALLS];
-};
+# 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);
 
-struct nativeCompCall {
-       utf *classname;
-       struct nativeCompMethod methods[MAXCALLS];
-       int methCnt;
-       int callCnt[MAXCALLS];
-};
+#endif /* defined(WITH_STATIC_CLASSPATH) */
 
+java_handle_t *native_new_and_init(classinfo *c);
 
-bool natcall2utf(bool);
-void printNativeCall(nativeCall);
-void markNativeMethodsRT(utf *, utf* , utf* ); 
+java_handle_t *native_new_and_init_string(classinfo *c, java_handle_t *s);
 
 #endif /* _NATIVE_H */