X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=src%2Fvm%2Floader.h;h=3b2c353bacca74719dbb1acf455821e1c8c10de0;hb=63495c3464decbf8d8104060a57079a03ab817a6;hp=4f4d9f7d91b16b06392a0ad96ccd0e44e9e8a02b;hpb=4286740008b051044cc060ae42f9cf7a4244a47b;p=cacao.git diff --git a/src/vm/loader.h b/src/vm/loader.h index 4f4d9f7d9..3b2c353ba 100644 --- a/src/vm/loader.h +++ b/src/vm/loader.h @@ -1,9 +1,7 @@ -/* 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, 2006, 2007, 2008 + CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO This file is part of CACAO. @@ -19,153 +17,155 @@ 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 972 2004-03-24 22:48:01Z edwin $ */ #ifndef _LOADER_H #define _LOADER_H +/* forward typedefs ***********************************************************/ + +typedef struct classbuffer classbuffer; + + +#include "config.h" + #include -#ifdef USE_ZLIB -#include "unzip.h" -#endif +#include "vm/types.h" -/* export variables */ +#include "vm/descriptor.h" +#include "vm/class.h" +#include "vm/global.h" +#include "vm/method.h" +#include "vm/references.h" +#include "vm/utf8.h" -extern list unloadedclasses; /* list of all referenced but not loaded classes */ -extern list unlinkedclasses; /* List containing all unlinked classes */ -extern list linkedclasses; /* List containing all linked classes */ -#ifdef USE_THREADS -extern int blockInts; -#endif +/* constant pool entries ******************************************************* + 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: -/************************ prototypes ******************************************/ + 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 - -/* initialize laoder, load important systemclasses */ -void loader_init(); +*******************************************************************************/ -void suck_init(char *cpath); +typedef struct { /* Integer */ + s4 value; +} constant_integer; -/* free resources */ -void loader_close(); + +typedef struct { /* Float */ + float value; +} constant_float; -/* load a class and all referenced classes */ -classinfo *loader_load(utf *topname); -/* initializes all loaded classes */ -void loader_initclasses(); +typedef struct { /* Long */ + s8 value; +} constant_long; + -void loader_compute_subclasses(); +typedef struct { /* Double */ + double value; +} constant_double; -/* 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); +typedef struct { /* NameAndType (Field or Method) */ + utf *name; /* field/method name */ + utf *descriptor; /* field/method type descriptor string */ +} constant_nameandtype; -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); +/* classbuffer ****************************************************************/ -/* 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); -methodinfo *class_resolveinterfacemethod(classinfo *c, utf *name, utf *dest, classinfo *referer); +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) */ +}; -/* 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); -bool class_issubclass(classinfo *sub, classinfo *super); +/* hashtable_classloader_entry ************************************************* -/* call initializer of class */ -void class_init(classinfo *c); + 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. -void class_showconstanti(classinfo *c, int ii); +*******************************************************************************/ -/* debug purposes */ -void class_showmethods(classinfo *c); -void class_showconstantpool(classinfo *c); -void print_arraydescriptor(FILE *file, arraydescriptor *desc); +typedef struct hashtable_classloader_entry hashtable_classloader_entry; -classinfo *loader_load(utf *topname); -classinfo *loader_load_sysclass(classinfo **top,utf *topname); +struct hashtable_classloader_entry { + java_object_t *object; + hashtable_classloader_entry *hashlink; +}; -/* 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); +/* classloader ***************************************************************** + [!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). -/* 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 +*******************************************************************************/ -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); +#if defined(ENABLE_HANDLES) +typedef hashtable_classloader_entry classloader_t; +#else +typedef java_object_t classloader_t; +#endif -/* (used by class_new, don't use directly) */ -void class_new_array(classinfo *c); -void class_link(classinfo *c); +/* function prototypes ********************************************************/ -void field_display(fieldinfo *f); +void loader_preinit(void); +void loader_init(void); -void method_display(methodinfo *m); +/* classloader management functions */ +classloader_t *loader_hashtable_classloader_add(java_handle_t *cl); +classloader_t *loader_hashtable_classloader_find(java_handle_t *cl); -utf* clinit_desc(); -utf* clinit_name(); +void loader_load_all_classes(void); +bool loader_skip_attribute_body(classbuffer *cb); -/******************************** CLASSPATH handling *******************/ -#define CLASSPATH_MAXFILENAME 1000 /* maximum length of a filename */ -#define CLASSPATH_PATH 0 -#define CLASSPATH_ARCHIVE 1 +#if defined(ENABLE_JAVASE) +bool loader_load_attribute_signature(classbuffer *cb, utf **signature); +#endif -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; +/* free resources */ +void loader_close(void); -#endif /* _LOADER_H */ +/* 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); + +/* (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. @@ -178,4 +178,5 @@ typedef union classpath_info { * c-basic-offset: 4 * tab-width: 4 * End: + * vim:noexpandtab:sw=4:ts=4: */