/* src/vm/class.h - class related functions 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.
-
- Contact: cacao@complang.tuwien.ac.at
-
- Authors: Christian Thalinger
-
- Changes:
-
- $Id: class.h 2275 2005-04-12 19:46:03Z twisti $
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ 02110-1301, USA.
*/
/* forward typedefs ***********************************************************/
+typedef struct classinfo classinfo;
typedef struct innerclassinfo innerclassinfo;
typedef struct extra_classref extra_classref;
+
#include "config.h"
-#include "toolbox/list.h"
+
+#include <stdint.h>
+
+#include "vm/types.h"
+
+#if defined(ENABLE_JAVASE)
+# include "vm/annotation.h"
+#endif
+
+#include "vm/field.hpp"
#include "vm/global.h"
-#include "vm/utf8.h"
-#include "vm/references.h"
-#include "vm/field.h"
#include "vm/linker.h"
-#include "vm/tables.h"
-#include "vm/jit/inline/sets.h"
+#include "vm/loader.hpp"
+#include "vm/method.h"
+#include "vm/references.h"
+#include "vm/string.hpp"
+#include "vm/utf8.h"
+
+/* class state defines ********************************************************/
+
+#define CLASS_LOADING 0x0001
+#define CLASS_LOADED 0x0002
+#define CLASS_LINKING 0x0004
+#define CLASS_LINKED 0x0008
+#define CLASS_INITIALIZING 0x0010
+#define CLASS_INITIALIZED 0x0020
+#define CLASS_ERROR 0x0040
+
+
+/* some macros ****************************************************************/
+
+#define CLASS_IS_OR_ALMOST_INITIALIZED(c) \
+ (((c)->state & CLASS_INITIALIZING) || ((c)->state & CLASS_INITIALIZED))
+
/* classinfo ******************************************************************/
-struct classinfo { /* class structure */
- java_objectheader header; /* classes are also objects */
- java_objectarray* signers;
- struct java_security_ProtectionDomain* pd;
- struct java_lang_VMClass* vmClass;
- struct java_lang_reflect_Constructor* constructor;
+/* We define this dummy structure of java_lang_Class so we can
+ bootstrap cacaoh without needing a java_lang_Class.h file. Whether
+ the size of the dummy structure is big enough is checked during
+ runtime in vm_create. */
+
+typedef struct {
+ java_object_t header;
+#if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH)
+ intptr_t padding[4];
+#elif defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK)
+ intptr_t padding[19];
+#elif defined(WITH_JAVA_RUNTIME_LIBRARY_CLDC1_1)
+ intptr_t padding[3];
+#else
+# error unknown classpath configuration
+#endif
+} dummy_java_lang_Class;
- s4 initializing_thread; /* gnu classpath */
- s4 erroneous_state; /* gnu classpath */
- struct gnu_classpath_RawData* vmData; /* gnu classpath */
+struct classinfo { /* class structure */
+ dummy_java_lang_Class object;
s4 flags; /* ACC flags */
utf *name; /* class name */
s4 cpcount; /* number of entries in constant pool */
u1 *cptags; /* constant pool tags */
- voidptr *cpinfos; /* pointer to constant pool info structures */
+ void* *cpinfos; /* pointer to constant pool info structures */
s4 classrefcount; /* number of symbolic class references */
constant_classref *classrefs; /* table of symbolic class references */
s4 parseddescsize; /* size of the parsed descriptors block */
u1 *parseddescs; /* parsed descriptors */
- classref_or_classinfo super; /* super class */
+ classinfo *super; /* super class */
classinfo *sub; /* sub class pointer */
classinfo *nextsub; /* pointer to next class in sub class list */
- s4 interfacescount; /* number of interfaces */
- classref_or_classinfo *interfaces; /* superinterfaces */
+ int32_t interfacescount; /* number of interfaces */
+ classinfo **interfaces; /* super interfaces */
- s4 fieldscount; /* number of fields */
+ int32_t fieldscount; /* number of fields */
fieldinfo *fields; /* field table */
- s4 methodscount; /* number of methods */
+ int32_t methodscount; /* number of methods */
methodinfo *methods; /* method table */
- listnode listnode; /* linkage */
-
- bool initialized; /* true, if class already initialized */
- bool initializing; /* flag for the compiler */
- bool loaded; /* true, if class already loaded */
- bool linked; /* true, if class already linked */
+ s4 state; /* current class state */
s4 index; /* hierarchy depth (classes) or index */
/* (interfaces) */
s4 instancesize; /* size of an instance of this class */
u2 innerclasscount; /* number of inner classes */
innerclassinfo *innerclass;
- bool classvftbl; /* has its own copy of the Class vtbl */
-
- s4 classUsed; /* 0= not used 1 = used CO-RT */
+ classref_or_classinfo declaringclass;
+ classref_or_classinfo enclosingclass; /* enclosing class */
+ constant_nameandtype *enclosingmethod; /* enclosing method */
- classSetNode *impldBy; /* interface class implemented by class set */
- /* Object class 's impldBy is list of all */
- /* interface classes used (RT & XTA only */
- /* normally no list of interfaces used) */
utf *packagename; /* full name of the package */
- utf *sourcefile; /* classfile name containing this class */
- java_objectheader *classloader; /* NULL for bootstrap classloader */
+ utf *sourcefile; /* SourceFile attribute */
+#if defined(ENABLE_JAVASE)
+ utf *signature; /* Signature attribute */
+#if defined(ENABLE_ANNOTATIONS)
+ /* All the annotation attributes are NULL (and not a zero length array) */
+ /* if there is nothing. */
+ java_object_t *annotations; /* annotations of this class */
+
+ java_object_t *method_annotations; /* array of annotations of the methods */
+ java_object_t *method_parameterannotations; /* array of parameter */
+ /* annotations of the methods */
+ java_object_t *method_annotationdefaults; /* array of annotation default */
+ /* values of the methods */
+
+ java_object_t *field_annotations; /* array of annotations of the fields */
+
+#endif
+#endif
+ classloader_t *classloader; /* NULL for bootstrap classloader */
+
+#if defined(ENABLE_JAVASE)
+# if defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK)
+ java_object_t *protectiondomain;
+ java_objectarray_t *signers;
+# endif
+#endif
+#if defined(ENABLE_JITCACHE)
+ int cache_file_fd;
+#endif
};
};
-/* global variables ***********************************************************/
+/* inline functions ***********************************************************/
-extern list unlinkedclasses; /* this is only used for eager class loading */
+#ifdef __cplusplus
+extern "C" {
+#endif
+/**
+ * Returns the classname of the class, where slashes ('/') are
+ * replaced by dots ('.').
+ *
+ * @param c class to get name of
+ * @return classname
+ */
+inline static java_handle_t* class_get_classname(classinfo* c)
+{
+ java_handle_t *s;
-/* frequently used classes ****************************************************/
+ /* Create a java string. */
-/* important system classes */
+ s = javastring_new_slash_to_dot(c->name);
-extern classinfo *class_java_lang_Object;
-extern classinfo *class_java_lang_Class;
-extern classinfo *class_java_lang_ClassLoader;
-extern classinfo *class_java_lang_Cloneable;
-extern classinfo *class_java_lang_SecurityManager;
-extern classinfo *class_java_lang_String;
-extern classinfo *class_java_lang_System;
-extern classinfo *class_java_io_Serializable;
+ return s;
+}
-/* system exception classes required in cacao */
+/* class_is_primitive **********************************************************
-extern classinfo *class_java_lang_Throwable;
-extern classinfo *class_java_lang_VMThrowable;
-extern classinfo *class_java_lang_Error;
-extern classinfo *class_java_lang_NoClassDefFoundError;
-extern classinfo *class_java_lang_OutOfMemoryError;
+ Checks if the given class is a primitive class.
-extern classinfo *class_java_lang_Exception;
-extern classinfo *class_java_lang_ClassNotFoundException;
+*******************************************************************************/
+static inline bool class_is_primitive(classinfo *c)
+{
+ if (c->flags & ACC_CLASS_PRIMITIVE)
+ return true;
-extern classinfo *class_java_lang_Void;
-extern classinfo *class_java_lang_Boolean;
-extern classinfo *class_java_lang_Byte;
-extern classinfo *class_java_lang_Character;
-extern classinfo *class_java_lang_Short;
-extern classinfo *class_java_lang_Integer;
-extern classinfo *class_java_lang_Long;
-extern classinfo *class_java_lang_Float;
-extern classinfo *class_java_lang_Double;
+ return false;
+}
-/* some classes which may be used more often */
+/* class_is_anonymousclass *****************************************************
-extern classinfo *class_java_util_Vector;
+ Checks if the given class is an anonymous class.
+*******************************************************************************/
-/* pseudo classes for the type checker ****************************************/
+static inline bool class_is_anonymousclass(classinfo *c)
+{
+ if (c->flags & ACC_CLASS_ANONYMOUS)
+ return true;
+
+ return false;
+}
+
+
+/* class_is_array **************************************************************
+
+ Checks if the given class is an array class.
+
+*******************************************************************************/
+
+static inline bool class_is_array(classinfo *c)
+{
+ if (!(c->state & CLASS_LINKED))
+ if (!link_class(c))
+ return false;
+
+ return (c->vftbl->arraydesc != NULL);
+}
-/*
- * 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.
- */
-extern classinfo *pseudo_class_Arraystub;
-extern classinfo *pseudo_class_Null;
-extern classinfo *pseudo_class_New;
+/* class_is_interface **********************************************************
+
+ Checks if the given class is an interface.
+
+*******************************************************************************/
+
+static inline bool class_is_interface(classinfo *c)
+{
+ if (c->flags & ACC_INTERFACE)
+ return true;
+
+ return false;
+}
+
+
+/* class_is_localclass *********************************************************
+
+ Checks if the given class is a local class.
+
+*******************************************************************************/
+
+static inline bool class_is_localclass(classinfo *c)
+{
+ if ((c->enclosingmethod != NULL) && !class_is_anonymousclass(c))
+ return true;
+
+ return false;
+}
+
+
+/* class_is_memberclass ********************************************************
+
+ Checks if the given class is a member class.
+
+*******************************************************************************/
+
+static inline bool class_is_memberclass(classinfo *c)
+{
+ if (c->flags & ACC_CLASS_MEMBER)
+ return true;
+
+ return false;
+}
+
+
+/* class_get_classloader *******************************************************
+
+ Return the classloader of the given class.
+
+*******************************************************************************/
+
+static inline classloader_t *class_get_classloader(classinfo *c)
+{
+ classloader_t *cl;
+
+ cl = c->classloader;
+
+ /* The classloader may be NULL. */
+
+ return cl;
+}
+
+
+/* class_get_superclass ********************************************************
+
+ Return the super class of the given class.
+
+*******************************************************************************/
+
+static inline classinfo *class_get_superclass(classinfo *c)
+{
+ /* For interfaces we return NULL. */
+
+ if (c->flags & ACC_INTERFACE)
+ return NULL;
+
+ /* For java/lang/Object, primitive-type and Void classes c->super
+ is NULL and we return NULL. */
+
+ return c->super;
+}
/* function prototypes ********************************************************/
-/* create a new classinfo struct */
classinfo *class_create_classinfo(utf *u);
+void class_postset_header_vftbl(void);
+classinfo *class_define(utf *name, classloader_t *cl, int32_t length, uint8_t *data, java_handle_t *pd);
+void class_set_packagename(classinfo *c);
+
+bool class_load_attributes(classbuffer *cb);
/* retrieve constantpool element */
-voidptr class_getconstant(classinfo *class, u4 pos, u4 ctype);
-voidptr innerclass_getconstant(classinfo *c, u4 pos, u4 ctype);
+void* class_getconstant(classinfo *c, u4 pos, u4 ctype);
+void* innerclass_getconstant(classinfo *c, u4 pos, u4 ctype);
/* frees all resources used by the class */
void class_free(classinfo *);
/* (does a linear search!) */
constant_classref *class_get_classref(classinfo *cls,utf *name);
+/* return a classref to the class itself */
+/* (does a linear search!) */
+constant_classref *class_get_self_classref(classinfo *cls);
+
/* return a classref for an array with the given dimension of with the */
/* given component type */
constant_classref *class_get_classref_multiarray_of(s4 dim,constant_classref *ref);
/* return a classref for the component type of the given array type */
constant_classref *class_get_classref_component_of(constant_classref *ref);
+/* get a class' field by name and descriptor */
+fieldinfo *class_findfield(classinfo *c, utf *name, utf *desc);
+
+/* search 'classinfo'-structure for a field with the specified name */
+fieldinfo *class_findfield_by_name(classinfo *c, utf *name);
+
+/* search class for a field */
+fieldinfo *class_resolvefield(classinfo *c, utf *name, utf *desc, classinfo *referer);
+
+/* 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);
+methodinfo *class_resolveclassmethod(classinfo *c, utf *name, utf *dest, classinfo *referer, bool throwexception);
+methodinfo *class_resolveinterfacemethod(classinfo *c, utf *name, utf *dest, classinfo *referer, bool throwexception);
+
+bool class_issubclass(classinfo *sub, classinfo *super);
+bool class_isanysubclass(classinfo *sub, classinfo *super);
+bool class_is_assignable_from(classinfo *to, classinfo *from);
+bool class_is_instance(classinfo *c, java_handle_t *h);
+
+classloader_t *class_get_classloader(classinfo *c);
+classinfo *class_get_superclass(classinfo *c);
+classinfo *class_get_componenttype(classinfo *c);
+java_handle_objectarray_t *class_get_declaredclasses(classinfo *c, bool publicOnly);
+java_handle_objectarray_t *class_get_declaredconstructors(classinfo *c, bool publicOnly);
+java_handle_objectarray_t *class_get_declaredfields(classinfo *c, bool publicOnly);
+java_handle_objectarray_t *class_get_declaredmethods(classinfo *c, bool publicOnly);
+classinfo *class_get_declaringclass(classinfo *c);
+classinfo *class_get_enclosingclass(classinfo *c);
+java_handle_t* class_get_enclosingconstructor(classinfo *c);
+methodinfo* class_get_enclosingmethod_raw(classinfo *c);
+java_handle_t* class_get_enclosingmethod(classinfo *c);
+java_handle_objectarray_t *class_get_interfaces(classinfo *c);
+java_handle_bytearray_t *class_get_annotations(classinfo *c);
+int32_t class_get_modifiers(classinfo *c, bool ignoreInnerClassesAttrib);
+java_handle_t *class_get_name(classinfo *c);
+
+#if defined(ENABLE_JAVASE)
+utf *class_get_signature(classinfo *c);
+#endif
+
+/* some debugging functions */
+
+#if !defined(NDEBUG)
+void class_printflags(classinfo *c);
+void class_print(classinfo *c);
+void class_println(classinfo *c);
+void class_classref_print(constant_classref *cr);
+void class_classref_println(constant_classref *cr);
+void class_classref_or_classinfo_print(classref_or_classinfo c);
+void class_classref_or_classinfo_println(classref_or_classinfo c);
+#endif
+
+/* debug purposes */
+void class_showmethods(classinfo *c);
+void class_showconstantpool(classinfo *c);
+
+#ifdef __cplusplus
+}
+#endif
+
#endif /* _CLASS_H */