classinfo *class_java_lang_System;
classinfo *class_java_lang_Thread;
classinfo *class_java_lang_ThreadGroup;
-classinfo *class_java_lang_VMSystem;
-classinfo *class_java_lang_VMThread;
-classinfo *class_java_io_Serializable;
-
-#if defined(WITH_CLASSPATH_SUN)
-classinfo *class_sun_reflect_MagicAccessorImpl;
-#endif
-
-/* system exception classes required in cacao */
-
classinfo *class_java_lang_Throwable;
-classinfo *class_java_lang_Error;
-classinfo *class_java_lang_LinkageError;
-classinfo *class_java_lang_NoClassDefFoundError;
-classinfo *class_java_lang_OutOfMemoryError;
-classinfo *class_java_lang_VirtualMachineError;
+classinfo *class_java_io_Serializable;
#if defined(WITH_CLASSPATH_GNU)
+classinfo *class_java_lang_VMSystem;
+classinfo *class_java_lang_VMThread;
classinfo *class_java_lang_VMThrowable;
#endif
-classinfo *class_java_lang_Exception;
-classinfo *class_java_lang_ClassCastException;
-classinfo *class_java_lang_ClassNotFoundException;
+#if defined(WITH_CLASSPATH_SUN)
+classinfo *class_sun_reflect_MagicAccessorImpl;
+#endif
#if defined(ENABLE_JAVASE)
classinfo *class_java_lang_Void;
classinfo *class_java_lang_Float;
classinfo *class_java_lang_Double;
-
-/* some runtime exception */
-
-classinfo *class_java_lang_NullPointerException;
-
-
/* some classes which may be used more often */
#if defined(ENABLE_JAVASE)
classinfo *class_java_lang_reflect_Method;
classinfo *class_java_security_PrivilegedAction;
classinfo *class_java_util_Vector;
+classinfo *class_java_util_HashMap;
classinfo *arrayclass_java_lang_Object;
-#if defined(ENABLE_ANNOTATIONS)
+# if defined(ENABLE_ANNOTATIONS)
classinfo *class_sun_reflect_ConstantPool;
-#if defined(WITH_CLASSPATH_GNU)
+# if defined(WITH_CLASSPATH_GNU)
classinfo *class_sun_reflect_annotation_AnnotationParser;
-#endif
-#endif
+# endif
+# endif
#endif
-
/* pseudo classes for the typechecker */
classinfo *pseudo_class_Arraystub;
/* class_set_packagename *******************************************************
- Derive the package name from the class name and store it in the struct.
+ Derive the package name from the class name and store it in the
+ struct.
+
+ An internal package name consists of the package name plus the
+ trailing '/', e.g. "java/lang/".
+
+ For classes in the unnamed package, the package name is set to
+ NULL.
*******************************************************************************/
void class_set_packagename(classinfo *c)
{
- char *p = UTF_END(c->name) - 1;
- char *start = c->name->text;
+ char *p;
+ char *start;
- /* set the package name */
- /* classes in the unnamed package keep packagename == NULL */
+ p = UTF_END(c->name) - 1;
+ start = c->name->text;
if (c->name->text[0] == '[') {
- /* set packagename of arrays to the element's package */
+ /* Set packagename of arrays to the element's package. */
for (; *start == '['; start++);
- /* skip the 'L' in arrays of references */
+ /* Skip the 'L' in arrays of references. */
+
if (*start == 'L')
start++;
+ }
- for (; (p > start) && (*p != '/'); --p);
+ /* Search for last '/'. */
- c->packagename = utf_new(start, p - start);
+ for (; (p > start) && (*p != '/'); --p);
- } else {
- for (; (p > start) && (*p != '/'); --p);
+ /* If we found a '/' we set the package name plus the trailing
+ '/'. Otherwise we set the packagename to NULL. */
- c->packagename = utf_new(start, p - start);
- }
+ if (p > start)
+ c->packagename = utf_new(start, p - start + 1);
+ else
+ c->packagename = NULL;
}
log_message_utf("Creating class: ", classname);
#endif
- /* GCNEW_UNCOLLECTABLE clears the allocated memory */
-
-#if defined(ENABLE_GC_CACAO)
+#if !defined(ENABLE_GC_BOEHM)
c = (classinfo *) heap_alloc_uncollectable(sizeof(classinfo));
+ /*c = NEW(classinfo);
+ MZERO(c, classinfo, 1);*/
#else
c = GCNEW_UNCOLLECTABLE(classinfo, 1);
- /*c=NEW(classinfo);*/
+ /* GCNEW_UNCOLLECTABLE clears the allocated memory */
#endif
+
c->name = classname;
/* Set the header.vftbl of all loaded classes to the one of
#endif
#if defined(ENABLE_ANNOTATIONS)
- /* XXX We can't do a release with that enabled */
-
else if (attribute_name == utf_RuntimeVisibleAnnotations) {
/* RuntimeVisibleAnnotations */
if (!annotation_load_class_attribute_runtimevisibleannotations(cb))
return false;
}
- /* XXX RuntimeInvisibleAnnotations should only be loaded
- * (or returned to Java) if some commandline options says so.
- * Currently there is no such option available in cacao,
- * therefore I load them allways (for testing purpose).
- * Anyway, bytecode for RuntimeInvisibleAnnotations is only
- * generated if you tell javac to do so. So in most cases
- * there won't be any.
- */
else if (attribute_name == utf_RuntimeInvisibleAnnotations) {
/* RuntimeInvisibleAnnotations */
if (!annotation_load_class_attribute_runtimeinvisibleannotations(cb))
{
s4 i;
vftbl_t *v;
-
+
class_freecpool(c);
if (c->interfaces != NULL)
if (c->fields) {
for (i = 0; i < c->fieldscount; i++)
field_free(&(c->fields[i]));
-#if defined(ENABLE_CACAO_GC)
MFREE(c->fields, fieldinfo, c->fieldscount);
-#endif
}
if (c->methods) {
}
-/* class_is_primitive **********************************************************
-
- Checks if the given class is a primitive class.
-
-*******************************************************************************/
-
-bool class_is_primitive(classinfo *c)
-{
- if (c->flags & ACC_CLASS_PRIMITIVE)
- return true;
-
- return false;
-}
-
-
-/* class_is_anonymousclass *****************************************************
-
- Checks if the given class is an anonymous class.
-
-*******************************************************************************/
-
-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.
-
-*******************************************************************************/
-
-bool class_is_array(classinfo *c)
-{
- if (!(c->state & CLASS_LINKED))
- if (!link_class(c))
- return false;
-
- return (c->vftbl->arraydesc != NULL);
-}
-
-
-/* class_is_interface **********************************************************
-
- Checks if the given class is an interface.
-
-*******************************************************************************/
-
-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.
-
-*******************************************************************************/
-
-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.
-
-*******************************************************************************/
-
-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.
-
-*******************************************************************************/
-
-classloader *class_get_classloader(classinfo *c)
-{
- classloader *cl;
-
- cl = c->classloader;
-
- if (cl == NULL)
- return NULL;
-
- return cl;
-}
-
-
-/* class_get_superclass ********************************************************
-
- Return the super class of the given class.
-
-*******************************************************************************/
-
-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;
-}
-
-
/* class_get_componenttype *****************************************************
Return the component class of the given class. If the given class
/* class_get_annotations *******************************************************
- Return the unparsed declared annotations in an byte array
- of the given class (or NULL if there aren't any).
+ Get the unparsed declared annotations in a byte array
+ of the given class.
+
+ IN:
+ c........the class of which the annotations should be returned
+
+ RETURN VALUE:
+ The unparsed declared annotations in a byte array
+ (or NULL if there aren't any).
*******************************************************************************/
java_handle_bytearray_t *class_get_annotations(classinfo *c)
{
#if defined(ENABLE_ANNOTATIONS)
- return c->annotations;
+ java_handle_t *annotations; /* unparsed annotations */
+
+ LLNI_classinfo_field_get(c, annotations, annotations);
+
+ return (java_handle_bytearray_t*)annotations;
#else
return NULL;
#endif
}
+/* class_get_modifiers *********************************************************
+
+ Get the modifier flags of the given class.
+
+ IN:
+ c....the class of which the modifier flags should be returned
+ ignoreInnerClassesAttrib
+ RETURN VALUE:
+ modifier flags
+
+*******************************************************************************/
+
+int32_t class_get_modifiers(classinfo *c, bool ignoreInnerClassesAttrib)
+{
+ classref_or_classinfo inner;
+ classref_or_classinfo outer;
+ utf *innername;
+ int i;
+
+ if (!ignoreInnerClassesAttrib && (c->innerclasscount != 0)) {
+ /* search for passed class as inner class */
+
+ for (i = 0; i < c->innerclasscount; i++) {
+ inner = c->innerclass[i].inner_class;
+ outer = c->innerclass[i].outer_class;
+
+ /* Check if inner is a classref or a real class and get
+ the name of the structure */
+
+ innername = IS_CLASSREF(inner) ? inner.ref->name : inner.cls->name;
+
+ /* innerclass is this class */
+
+ if (innername == c->name) {
+ /* has the class actually an outer class? */
+
+ if (outer.any)
+ /* return flags got from the outer class file */
+ return c->innerclass[i].flags & ACC_CLASS_REFLECT_MASK;
+ else
+ return c->flags & ACC_CLASS_REFLECT_MASK;
+ }
+ }
+ }
+
+ /* passed class is no inner class or it was not requested */
+
+ return c->flags & ACC_CLASS_REFLECT_MASK;
+}
+
+
/* class_get_signature *********************************************************
Return the signature of the given class. For array and primitive
*******************************************************************************/
+#if !defined(NDEBUG)
void class_classref_or_classinfo_println(classref_or_classinfo c)
{
class_classref_or_classinfo_print(c);
printf("\n");
}
+#endif
/* class_showconstantpool ******************************************************