-/* loader.h - 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 1031 2004-04-26 16:06:03Z twisti $
+ $Id: loader.h 2154 2005-03-30 20:03:06Z twisti $
*/
#include <stdio.h>
-#ifdef USE_ZLIB
-#include "unzip.h"
+
+/* forward typedefs ***********************************************************/
+
+typedef struct classbuffer classbuffer;
+typedef struct classpath_info classpath_info;
+
+
+#include "config.h"
+#include "types.h"
+#include "vm/class.h"
+#include "vm/descriptor.h"
+#include "vm/global.h"
+#include "vm/method.h"
+#include "vm/utf8.h"
+
+#if defined(USE_ZLIB)
+# include "vm/unzip.h"
#endif
-/* datastruture from a classfile */
+/* signed suck defines ********************************************************/
-typedef 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 */
-} classbuffer;
+#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))
-/* export variables */
+/* constant pool entries *******************************************************
-#ifdef USE_THREADS
-extern int blockInts;
-#endif
+ 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:
+ 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 -
-/* references to some system classes ******************************************/
+*******************************************************************************/
-extern classinfo *class_java_lang_Object;
-extern classinfo *class_java_lang_String;
-extern classinfo *class_java_lang_Throwable;
-extern classinfo *class_java_lang_Cloneable;
-extern classinfo *class_java_io_Serializable;
+typedef struct { /* Fieldref, Methodref and InterfaceMethodref */
+ classinfo *class; /* class containing this field/method/intfmeth. */ /* XXX remove */
+ constant_classref *classref; /* class containing this field/meth./intfm. */
+ utf *name; /* field/method/interfacemethod name */
+ utf *descriptor; /* field/method/intfmeth. type descriptor string */
+ parseddesc parseddesc; /* parsed descriptor */
+} constant_FMIref;
-/* pseudo classes for the type checker ****************************************/
+typedef struct { /* Integer */
+ s4 value;
+} constant_integer;
-/*
- * pseudo_class_Arraystub
- * (extends Object implements Cloneable, java.io.Serializable)
- *
- * If two arrays of incompatible component types are merged,
- * the resulting reference has no accessible components.
- * The result does, however, implement the interfaces Cloneable
- * and java.io.Serializable. This pseudo class is used internally
- * to represent such results. (They are *not* considered arrays!)
- *
- * pseudo_class_Null
- *
- * This pseudo class is used internally to represent the
- * null type.
- *
- * pseudo_class_New
- *
- * This pseudo class is used internally to represent the
- * the 'uninitialized object' type.
- */
+
+typedef struct { /* Float */
+ float value;
+} constant_float;
+
+
+typedef struct { /* Long */
+ s8 value;
+} constant_long;
+
-extern classinfo *pseudo_class_Arraystub;
-extern classinfo *pseudo_class_Null;
-extern classinfo *pseudo_class_New;
-extern vftbl *pseudo_class_Arraystub_vftbl;
+typedef struct { /* Double */
+ double value;
+} constant_double;
-extern utf *array_packagename;
+typedef struct { /* NameAndType (Field or Method) */
+ utf *name; /* field/method name */
+ utf *descriptor; /* field/method type descriptor string */
+} constant_nameandtype;
-/************************ prototypes ******************************************/
-/* initialize laoder, load important systemclasses */
-void loader_init();
+/* classbuffer ****************************************************************/
+
+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 */
+};
+
+
+/* classpath_info *************************************************************/
+
+#define CLASSPATH_PATH 0
+#define CLASSPATH_ARCHIVE 1
+
+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;
+};
+
+
+/* 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 create_all_classes();
+void create_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 loader_close(void);
+
+/* class loading functions */
+classinfo *load_class_from_classloader(classinfo *c, java_objectheader *cl);
+classinfo *load_class_bootstrap(classinfo *c);
+classinfo *load_class_from_classbuffer(classbuffer *cb);
-void loader_compute_subclasses();
/* retrieve constantpool element */
voidptr class_getconstant(classinfo *class, u4 pos, u4 ctype);
/* determine type of a constantpool element */
u4 class_constanttype(classinfo *class, u4 pos);
-s4 class_findmethodIndex(classinfo *c, utf *name, utf *desc);
-
/* search class for a field */
fieldinfo *class_findfield(classinfo *c, utf *name, utf *desc);
fieldinfo *class_resolvefield(classinfo *c, utf *name, utf *desc, classinfo *referer, bool except);
/* search for a method with a specified name and descriptor */
methodinfo *class_findmethod(classinfo *c, utf *name, utf *desc);
methodinfo *class_fetchmethod(classinfo *c, utf *name, utf *desc);
-methodinfo *class_findmethod_w(classinfo *c, utf *name, utf *desc, char*);
methodinfo *class_resolvemethod(classinfo *c, utf *name, utf *dest);
methodinfo *class_resolveclassmethod(classinfo *c, utf *name, utf *dest, classinfo *referer, bool except);
methodinfo *class_resolveinterfacemethod(classinfo *c, utf *name, utf *dest, classinfo *referer, bool except);
/* call initializer of class */
classinfo *class_init(classinfo *c);
-void class_showconstanti(classinfo *c, int ii);
-
/* debug purposes */
void class_showmethods(classinfo *c);
void class_showconstantpool(classinfo *c);
/* (used by class_new, don't use directly) */
void class_new_array(classinfo *c);
-classinfo *class_load(classinfo *c);
-classinfo *class_load_intern(classbuffer *cb);
-void class_link(classinfo *c);
-
-void field_display(fieldinfo *f);
-
-void method_display(methodinfo *m);
-
-utf* clinit_desc();
-utf* clinit_name();
-
-
-/******************************** CLASSPATH handling *******************/
-#define CLASSPATH_MAXFILENAME 1000 /* maximum length of a filename */
-#define CLASSPATH_PATH 0
-#define CLASSPATH_ARCHIVE 1
-
-typedef union classpath_info {
- struct {
- int type;
- union classpath_info *next;
- char *filename;
- int pathlen; } filepath;
-#ifdef USE_ZLIB
- struct {
- int type;
- union classpath_info *next;
- unzFile uf;
- } archive;
-#endif
-} classpath_info;
-
#endif /* _LOADER_H */