Fixes PR84 for arm.
[cacao.git] / src / vm / loader.h
index a4939b7fe82ead5495597dd751a926bf39845a2c..3b2c353bacca74719dbb1acf455821e1c8c10de0 100644 (file)
@@ -1,9 +1,7 @@
 /* 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 2303 2005-04-14 12:04:42Z edwin $
 */
 
 
 #ifndef _LOADER_H
 #define _LOADER_H
 
-#include <stdio.h>
-
-
 /* forward typedefs ***********************************************************/
 
 typedef struct classbuffer classbuffer;
-typedef struct classpath_info classpath_info;
-
 
-#include "vm/global.h"
-#include "vm/utf8.h"
-#include "vm/references.h"
-#include "vm/descriptor.h"
-#include "vm/method.h"
 
-#if defined(USE_ZLIB)
-# include "vm/unzip.h"
-#endif
+#include "config.h"
 
+#include <stdio.h>
 
-/* signed suck defines ********************************************************/
+#include "vm/types.h"
 
-#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))
+#include "vm/descriptor.h"
+#include "vm/class.h"
+#include "vm/global.h"
+#include "vm/method.h"
+#include "vm/references.h"
+#include "vm/utf8.h"
 
 
 /* constant pool entries *******************************************************
@@ -69,7 +53,7 @@ typedef struct classpath_info classpath_info;
 
                kind                      structure                     generated?
        ----------------------------------------------------------------------
-    CONSTANT_Class               classinfo                           no   XXX this will change
+    CONSTANT_Class               constant_classref                  yes
     CONSTANT_Fieldref            constant_FMIref                    yes
     CONSTANT_Methodref           constant_FMIref                    yes
     CONSTANT_InterfaceMethodref  constant_FMIref                    yes
@@ -113,108 +97,73 @@ typedef struct {            /* NameAndType (Field or Method)                  */
 /* 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              */
+       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)       */
 };
 
 
-/* classpath_info *************************************************************/
+/* hashtable_classloader_entry *************************************************
 
-#define CLASSPATH_PATH       0
-#define CLASSPATH_ARCHIVE    1
+   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.
 
-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;
+*******************************************************************************/
+
+typedef struct hashtable_classloader_entry hashtable_classloader_entry;
+
+struct hashtable_classloader_entry {
+       java_object_t               *object;
+       hashtable_classloader_entry *hashlink;
 };
 
 
-/* export variables ***********************************************************/
+/* classloader *****************************************************************
 
-#if defined(USE_THREADS)
-extern int blockInts;
-#endif
+   [!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).
+
+*******************************************************************************/
 
-extern classpath_info *classpath_entries;
+#if defined(ENABLE_HANDLES)
+typedef hashtable_classloader_entry classloader_t;
+#else
+typedef java_object_t               classloader_t;
+#endif
 
 
 /* function prototypes ********************************************************/
 
-/* initialize loader, load important systemclasses */
-bool loader_init(u1 *stackbottom);
+void loader_preinit(void);
+void loader_init(void);
 
-void suck_init(char *cpath);
-void create_all_classes(void);
-void suck_stop(classbuffer *cb);
+/* classloader management functions */
+classloader_t *loader_hashtable_classloader_add(java_handle_t *cl);
+classloader_t *loader_hashtable_classloader_find(java_handle_t *cl);
 
-inline bool check_classbuffer_size(classbuffer *cb, s4 len);
+void loader_load_all_classes(void);
 
-inline u1 suck_u1(classbuffer *cb);
-inline u2 suck_u2(classbuffer *cb);
-inline u4 suck_u4(classbuffer *cb);
+bool loader_skip_attribute_body(classbuffer *cb);
+
+#if defined(ENABLE_JAVASE)
+bool loader_load_attribute_signature(classbuffer *cb, utf **signature);
+#endif
 
 /* free resources */
 void loader_close(void);
 
 /* class loading functions */
-bool load_class_from_sysloader(utf *name, classinfo **result);
-bool load_class_from_classloader(utf *name, java_objectheader *cl, classinfo **result);
-bool load_class_bootstrap(utf *name,classinfo **result);
-/* (don't use the following directly:) */
-classinfo *load_class_from_classbuffer(classbuffer *cb);
-bool load_newly_created_array(classinfo *c,java_objectheader *loader);
-
-/* 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_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);
+classinfo *load_class_from_sysloader(utf *name);
+classinfo *load_class_from_classloader(utf *name, classloader_t *cl);
+classinfo *load_class_bootstrap(utf *name);
 
-/* 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);
-
-/* debug purposes */
-void class_showmethods(classinfo *c);
-void class_showconstantpool(classinfo *c);
-
-/* 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);
-
-/******************************************************************************/
-/* SYNCHRONIZATION                                                            */
-/******************************************************************************/
-
-#if defined(USE_THREADS) && defined(NATIVE_THREADS)
-#  define LOADER_LOCK()    tables_lock()
-#  define LOADER_UNLOCK()  tables_unlock()
-#else
-#  define LOADER_LOCK()
-#  define LOADER_UNLOCK()
-#endif
+/* (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 */
 
@@ -229,4 +178,5 @@ void printflags(u2 f);
  * c-basic-offset: 4
  * tab-width: 4
  * End:
+ * vim:noexpandtab:sw=4:ts=4:
  */