-/* vm/loader.h - class loader header
+/* src/vm/loader.h - class loader header
- 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, 2008
+ CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
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.
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ 02110-1301, USA.
- Contact: cacao@complang.tuwien.ac.at
-
- Authors: Reinhard Grafl
-
- $Id: loader.h 1826 2004-12-29 12:47:18Z twisti $
*/
#ifndef _LOADER_H
#define _LOADER_H
-#include <stdio.h>
-
-#if defined(USE_ZLIB)
-# include "vm/unzip.h"
-#endif
-
+/* forward typedefs ***********************************************************/
-/* datastruture from a classfile */
+typedef struct classbuffer classbuffer;
-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;
+#include "config.h"
+#include <stdio.h>
-/* classpath_info *************************************************************/
-
-#define CLASSPATH_PATH 0
-#define CLASSPATH_ARCHIVE 1
+#include "vm/types.h"
-typedef struct classpath_info classpath_info;
+#include "vm/descriptor.h"
+#include "vm/class.h"
+#include "vm/global.h"
+#include "vm/method.h"
+#include "vm/references.h"
+#include "vm/utf8.h"
-struct classpath_info {
- s4 type;
- char *path;
- s4 pathlen;
-#if defined(USE_ZLIB)
- unzFile uf;
-#endif
- classpath_info *next;
-};
+/* constant pool entries *******************************************************
-/* export variables */
+ 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:
-#if defined(USE_THREADS)
-extern int blockInts;
-#endif
+ kind structure generated?
+ ----------------------------------------------------------------------
+ CONSTANT_Class constant_classref yes
+ 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 ******************************************/
+typedef struct { /* Integer */
+ s4 value;
+} constant_integer;
-extern classinfo *class_java_lang_Object;
-extern classinfo *class_java_lang_String;
-extern classinfo *class_java_lang_Cloneable;
-extern classinfo *class_java_io_Serializable;
-extern utf *utf_fillInStackTrace_name;
-extern utf *utf_fillInStackTrace_desc;
+
+typedef struct { /* Float */
+ float value;
+} constant_float;
-/* pseudo classes for the type checker ****************************************/
-/*
- * 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 { /* Long */
+ s8 value;
+} constant_long;
+
-extern classinfo *pseudo_class_Arraystub;
-extern classinfo *pseudo_class_Null;
-extern classinfo *pseudo_class_New;
-extern vftbl_t *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 loader, load important systemclasses */
-void loader_init(u1 *stackbottom);
+/* classbuffer ****************************************************************/
-void suck_init(char *cpath);
-void create_all_classes(void);
-void suck_stop(classbuffer *cb);
-
-/* free resources */
-void loader_close(void);
-
-void loader_compute_subclasses(classinfo *c);
+struct classbuffer {
+ classinfo *clazz; /* pointer to classinfo structure */
+ uint8_t *data; /* pointer to byte code */
+ int32_t size; /* size of the byte code */
+ uint8_t *pos; /* current read position */
+ char *path; /* path to file (for debugging) */
+};
-/* 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);
+/* hashtable_classloader_entry *************************************************
-s4 class_findmethodIndex(classinfo *c, utf *name, utf *desc);
+ ATTENTION: The pointer to the classloader object needs to be the
+ first field of the entry, so that it can be used as an indirection
+ cell. This is checked by gc_init() during startup.
-/* 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);
+typedef struct hashtable_classloader_entry hashtable_classloader_entry;
-/* 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);
+struct hashtable_classloader_entry {
+ java_object_t *object;
+ hashtable_classloader_entry *hashlink;
+};
-bool class_issubclass(classinfo *sub, classinfo *super);
-/* call initializer of class */
-classinfo *class_init(classinfo *c);
+/* classloader *****************************************************************
-void class_showconstanti(classinfo *c, int ii);
+ [!ENABLE_HANDLES]: The classloader is a Java Object which cannot move.
+ [ENABLE_HANDLES] : The classloader entry itself is a static handle for a
+ given classloader (use loader_hashtable_classloader_foo).
-/* debug purposes */
-void class_showmethods(classinfo *c);
-void class_showconstantpool(classinfo *c);
-void print_arraydescriptor(FILE *file, arraydescriptor *desc);
+*******************************************************************************/
-/* return the primitive class inidicated by the given signature character */
-classinfo *class_primitive_from_sig(char sig);
+#if defined(ENABLE_HANDLES)
+typedef hashtable_classloader_entry classloader_t;
+#else
+typedef java_object_t classloader_t;
+#endif
-/* return the class indicated by the given descriptor */
-/* (see loader.c for documentation) */
-#define CLASSLOAD_NEW 0 /* default */
-#define CLASSLOAD_LOAD 0x0001
-#define CLASSLOAD_SKIP 0x0002
-#define CLASSLOAD_PANIC 0 /* default */
-#define CLASSLOAD_NOPANIC 0x0010
-#define CLASSLOAD_PRIMITIVE 0 /* default */
-#define CLASSLOAD_NULLPRIMITIVE 0x0020
-#define CLASSLOAD_VOID 0 /* default */
-#define CLASSLOAD_NOVOID 0x0040
-#define CLASSLOAD_NOCHECKEND 0 /* default */
-#define CLASSLOAD_CHECKEND 0x1000
+/* function prototypes ********************************************************/
-classinfo *class_from_descriptor(char *utf_ptr,char *end_ptr,char **next,int mode);
-int type_from_descriptor(classinfo **cls,char *utf_ptr,char *end_ptr,char **next,int mode);
+void loader_preinit(void);
+void loader_init(void);
-/* (used by class_new, don't use directly) */
-void class_new_array(classinfo *c);
+/* classloader management functions */
+classloader_t *loader_hashtable_classloader_add(java_handle_t *cl);
+classloader_t *loader_hashtable_classloader_find(java_handle_t *cl);
-#define LAZYLOADING(class) { \
- if (!class->loaded) \
- if (!class_load(class)) \
- return 0; \
- if (!class->linked) \
- if (!class_link(class)) \
- return 0; }
+void loader_load_all_classes(void);
+bool loader_skip_attribute_body(classbuffer *cb);
-classinfo *class_load(classinfo *c);
-classinfo *class_load_intern(classbuffer *cb);
-classinfo *class_link(classinfo *c);
-void class_free(classinfo *c);
+#if defined(ENABLE_JAVASE)
+bool loader_load_attribute_signature(classbuffer *cb, utf **signature);
+#endif
-void field_display(fieldinfo *f);
+/* free resources */
+void loader_close(void);
-void method_display(methodinfo *m);
-void method_display_w_class(methodinfo *m);
+/* class loading functions */
+classinfo *load_class_from_sysloader(utf *name);
+classinfo *load_class_from_classloader(utf *name, classloader_t *cl);
+classinfo *load_class_bootstrap(utf *name);
-utf* clinit_desc(void);
-utf* clinit_name(void);
+/* (don't use the following directly) */
+classinfo *load_class_from_classbuffer(classbuffer *cb);
+classinfo *load_newly_created_array(classinfo *c, classloader_t *loader);
#endif /* _LOADER_H */
-
/*
* These are local overrides for various environment variables in Emacs.
* Please do not remove this and leave it at the end of the file, where
* c-basic-offset: 4
* tab-width: 4
* End:
+ * vim:noexpandtab:sw=4:ts=4:
*/