/* src/vm/class.cpp - class related functions
- Copyright (C) 1996-2005, 2006, 2007, 2008
+ Copyright (C) 1996-2011
CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
This file is part of CACAO.
if (classname != utf_not_named_yet)
class_set_packagename(c);
- c->object.header.lockword.init();
+ Lockword(c->object.header.lockword).init();
return c;
}
static void class_freecpool(classinfo *c)
{
- u4 idx;
+ int idx;
u4 tag;
void* info;
/* check index and type of constantpool entry */
/* (pos == 0 is caught by type comparison) */
- if ((pos >= c->cpcount) || (c->cptags[pos] != ctype)) {
+ if (((int) pos >= c->cpcount) || (c->cptags[pos] != ctype)) {
exceptions_throw_classformaterror(c, "Illegal constant pool index");
return NULL;
}
{
/* invalid position in constantpool */
- if (pos >= c->cpcount) {
+ if ((int) pos >= c->cpcount) {
exceptions_throw_classformaterror(c, "Illegal constant pool index");
return NULL;
}
bool class_isanysubclass(classinfo *sub, classinfo *super)
{
- uint32_t diffval;
- bool result;
+ bool result;
/* This is the trivial case. */
#else
LOCK_CLASSRENUMBER_LOCK;
- diffval = sub->vftbl->baseval - super->vftbl->baseval;
- result = diffval <= (uint32_t) super->vftbl->diffval;
+ uint32_t diffval = sub->vftbl->baseval - super->vftbl->baseval;
+ result = diffval <= (uint32_t) super->vftbl->diffval;
UNLOCK_CLASSRENUMBER_LOCK;
#endif
}
+/* class_is_arraycompatible ****************************************************
+
+ Checks if two array type descriptors are assignment compatible.
+
+ RETURN VALUE:
+ true .... target = desc is possible
+ false ... otherwise
+
+*******************************************************************************/
+
+bool class_is_arraycompatible(arraydescriptor *desc, arraydescriptor *target)
+{
+ if (desc == target)
+ return true;
+
+ if (desc->arraytype != target->arraytype)
+ return false;
+
+ if (desc->arraytype != ARRAYTYPE_OBJECT)
+ return true;
+
+ /* {both arrays are arrays of references} */
+
+ if (desc->dimension == target->dimension) {
+ if (!desc->elementvftbl)
+ return false;
+
+ /* an array which contains elements of interface types is
+ allowed to be casted to array of Object (JOWENN) */
+
+ if ((desc->elementvftbl->baseval < 0) &&
+ (target->elementvftbl->baseval == 1))
+ return true;
+
+ return class_isanysubclass(desc->elementvftbl->clazz,
+ target->elementvftbl->clazz);
+ }
+
+ if (desc->dimension < target->dimension)
+ return false;
+
+ /* {desc has higher dimension than target} */
+
+ return class_isanysubclass(pseudo_class_Arraystub,
+ target->elementvftbl->clazz);
+}
+
+
/* class_is_assignable_from ****************************************************
Return whether an instance of the "from" class parameter would be
if (!link_class(from))
return false;
- return class_isanysubclass(from, to);
+ /* Decide whether we are dealing with array types or object types. */
+
+ if (class_is_array(to) && class_is_array(from))
+ return class_is_arraycompatible(from->vftbl->arraydesc, to->vftbl->arraydesc);
+ else
+ return class_isanysubclass(from, to);
}
if (!link_class(c))
return false;
- return builtin_instanceof(h, c);
+ /* Decide whether we are dealing with array types or object types. */
+
+ if (class_is_array(c))
+ return builtin_arrayinstanceof(h, c);
+ else
+ return builtin_instanceof(h, c);
}
java_handle_objectarray_t* class_get_interfaces(classinfo *c)
{
classinfo* ic;
- u4 i;
+ int i;
if (!(c->state & CLASS_LINKED))
if (!link_class(c))
}
+/**
+ * Helper function for the CLASS_IS_OR_ALMOST_INITIALIZED macro.
+ */
+bool class_initializing_thread_is_self(classinfo *c)
+{
+ threadobject *t = thread_get_current();
+ return t == c->initializing_thread;
+}
+
/* class_get_signature *********************************************************
Return the signature of the given class. For array and primitive
#if !defined(NDEBUG)
void class_showconstantpool (classinfo *c)
{
- u4 i;
+ int i;
void* e;
printf ("---- dump of constant pool ----\n");
for (i=0; i<c->cpcount; i++) {
- printf ("#%d: ", (int) i);
+ printf ("#%d: ", i);
e = c -> cpinfos [i];
if (e) {