* renamed CACAO_TYPECHECK to ENABLE_VERIFIER
[cacao.git] / src / vm / loader.h
index 35cd9bafc6125e0194689fe3429d2deb3b6fb6c9..1bd005f6f4202717d9f451e974a366fb4d6ec44a 100644 (file)
@@ -1,9 +1,9 @@
-/* loader.c - class loader header
+/* src/vm/loader.h - class loader header
 
-   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.
 
 
    Authors: Reinhard Grafl
 
-   $Id: loader.h 669 2003-11-23 14:04:20Z edwin $
+   $Id: loader.h 3501 2005-10-26 20:27:15Z twisti $
 */
 
 
 #ifndef _LOADER_H
 #define _LOADER_H
 
-/************************* program switches ***********************************/
+#include <stdio.h>
 
-extern bool loadverbose;         /* Print debug messages during loading */
-extern bool linkverbose;
-extern bool initverbose;         /* Log class initialization */ 
-extern bool makeinitializations; /* Initialize classes automatically */
 
-extern bool getloadingtime;
-extern long int loadingtime;     /* CPU time for class loading */
+/* forward typedefs ***********************************************************/
 
-extern list unlinkedclasses;     /* List containing all unlinked classes */
-extern list linkedclasses;       /* List containing all linked classes */
+typedef struct classbuffer classbuffer;
+typedef struct classpath_info classpath_info;
 
 
-/************************ prototypes ******************************************/
+#include "vm/global.h"
+#include "vm/utf8.h"
+#include "vm/references.h"
+#include "vm/descriptor.h"
+#include "vm/method.h"
 
-/* initialize laoder, load important systemclasses */
-void loader_init();
+#if defined(USE_ZLIB)
+# include "vm/unzip.h"
+#endif
 
-void suck_init(char *cpath);
 
-/* free resources */
-void loader_close();
+/* signed suck defines ********************************************************/
 
-/* load a class and all referenced classes */
-classinfo *loader_load(utf *topname);
+#define suck_s8(a)    (s8) suck_u8((a))
+#define suck_s2(a)    (s2) suck_u2((a))
+#define suck_s4(a)    (s4) suck_u4((a))
+#define suck_s1(a)    (s1) suck_u1((a))
 
-/* initializes all loaded classes */
-void loader_initclasses();
 
-void loader_compute_subclasses();
+/* constant pool entries *******************************************************
 
-/* retrieve constantpool element */
-voidptr class_getconstant(classinfo *class, u4 pos, u4 ctype);
+       All constant pool entries need a data structure which contain the entrys
+       value. In some cases this structure exist already, in the remaining cases
+       this structure must be generated:
 
-/* determine type of a constantpool element */
-u4 class_constanttype(classinfo *class, u4 pos);
+               kind                      structure                     generated?
+       ----------------------------------------------------------------------
+    CONSTANT_Class               classinfo                           no   XXX this will change
+    CONSTANT_Fieldref            constant_FMIref                    yes
+    CONSTANT_Methodref           constant_FMIref                    yes
+    CONSTANT_InterfaceMethodref  constant_FMIref                    yes
+    CONSTANT_String              unicode                             no
+    CONSTANT_Integer             constant_integer                   yes
+    CONSTANT_Float               constant_float                     yes
+    CONSTANT_Long                constant_long                      yes
+    CONSTANT_Double              constant_double                    yes
+    CONSTANT_NameAndType         constant_nameandtype               yes
+    CONSTANT_Utf8                unicode                             no
+    CONSTANT_UNUSED              -
 
-/* search class for a field */
-fieldinfo *class_findfield(classinfo *c, utf *name, utf *desc);
+*******************************************************************************/
 
-/* search for a method with a specified name and descriptor */
-methodinfo *class_findmethod(classinfo *c, utf *name, utf *desc);
-methodinfo *class_resolvemethod(classinfo *c, utf *name, utf *dest);
+typedef struct {            /* Integer                                        */
+       s4 value;
+} constant_integer;
 
-/* search for a method with specified name and arguments (returntype ignored) */
-methodinfo *class_findmethod_approx(classinfo *c, utf *name, utf *desc);
-methodinfo *class_resolvemethod_approx(classinfo *c, utf *name, utf *dest);
+       
+typedef struct {            /* Float                                          */
+       float value;
+} constant_float;
 
-bool class_issubclass(classinfo *sub, classinfo *super);
 
-/* call initializer of class */
-void class_init(classinfo *c);
+typedef struct {            /* Long                                           */
+       s8 value;
+} constant_long;
+       
 
-void class_showconstanti(classinfo *c, int ii);
+typedef struct {            /* Double                                         */
+       double value;
+} constant_double;
 
-/* debug purposes */
-void class_showmethods (classinfo *c);
-void class_showconstantpool (classinfo *c);
-void print_arraydescriptor(FILE *file,arraydescriptor *desc);
 
-classinfo *loader_load(utf *topname);
+typedef struct {            /* NameAndType (Field or Method)                  */
+       utf *name;              /* field/method name                              */
+       utf *descriptor;        /* field/method type descriptor string            */
+} constant_nameandtype;
 
-/* set buffer for reading classdata */
-void classload_buffer(u1 *buf,int len);
 
-/* return the primitive class inidicated by the given signature character */
-classinfo *class_primitive_from_sig(char sig);
+/* classbuffer ****************************************************************/
 
-/* return the class indicated by the given descriptor */
-#define CLASSLOAD_SKIP  0
-#define CLASSLOAD_NEW   1
-#define CLASSLOAD_LOAD  2
-classinfo *class_from_descriptor(char *utf_ptr,char *end_ptr,char **next,int mode);
+struct classbuffer {
+       classinfo *class;                   /* pointer to classinfo structure     */
+       u1        *data;                    /* pointer to byte code               */
+       s4         size;                    /* size of the byte code              */
+       u1        *pos;                     /* current read position              */
+       char      *path;                    /* path to file (for debugging)       */
+};
 
-/* (used by class_new, don't use directly) */
-void class_new_array(classinfo *c);
 
-void class_link(classinfo *c);
+/* classpath_info *************************************************************/
 
-void field_display(fieldinfo *f);
+#define CLASSPATH_PATH       0
+#define CLASSPATH_ARCHIVE    1
 
-void method_display(methodinfo *m);
+struct classpath_info {
+#if defined(USE_THREADS)
+       /* Required for monitor locking on zip/jar files. */
+       java_objectheader  header;
+#endif
+       s4                 type;
+       char              *path;
+       s4                 pathlen;
+#if defined(USE_ZLIB)
+       unzFile            uf;
+#endif
+       classpath_info    *next;
+};
 
-utf* clinit_desc();
-utf* clinit_name();
 
-#endif /* _LOADER_H */
+/* export variables ***********************************************************/
+
+#if defined(USE_THREADS)
+extern int blockInts;
+#endif
+
+extern classpath_info *classpath_entries;
+
+
+/* function prototypes ********************************************************/
+
+/* initialize loader, load important systemclasses */
+bool loader_init(u1 *stackbottom);
+
+void suck_init(char *cpath);
+void loader_load_all_classes(void);
+void suck_stop(classbuffer *cb);
 
+inline bool check_classbuffer_size(classbuffer *cb, s4 len);
+
+inline u1 suck_u1(classbuffer *cb);
+inline u2 suck_u2(classbuffer *cb);
+inline u4 suck_u4(classbuffer *cb);
+
+/* free resources */
+void loader_close(void);
+
+/* class loading functions */
+classinfo *load_class_from_sysloader(utf *name);
+classinfo *load_class_from_classloader(utf *name, java_objectheader *cl);
+classinfo *load_class_bootstrap(utf *name);
+
+/* (don't use the following directly) */
+classinfo *load_class_from_classbuffer(classbuffer *cb);
+classinfo *load_newly_created_array(classinfo *c,java_objectheader *loader);
+
+/* return the primitive class inidicated by the given signature character */
+classinfo *class_primitive_from_sig(char sig);
+
+/* debug helpers */
+void fprintflags(FILE *fp, u2 f);
+void printflags(u2 f);
+
+#endif /* _LOADER_H */
 
 /*
  * These are local overrides for various environment variables in Emacs.