#include "arch.h"
-#include "mm/memory.h"
+#include "mm/memory.hpp"
#include "native/llni.h"
#include "threads/lock.hpp"
#include "threads/mutex.hpp"
-#include "toolbox/logging.h"
+#include "toolbox/logging.hpp"
#include "vm/array.hpp"
#include "vm/jit/builtin.hpp"
#include "vm/class.hpp"
-#include "vm/classcache.h"
+#include "vm/classcache.hpp"
#include "vm/exceptions.hpp"
#include "vm/global.h"
#include "vm/globals.hpp"
#include "vm/javaobjects.hpp"
-#include "vm/jit/jitcache.hpp"
-#include "vm/linker.h"
+#include "vm/linker.hpp"
#include "vm/loader.hpp"
#include "vm/options.h"
#include "vm/resolve.hpp"
if (classname != utf_not_named_yet)
class_set_packagename(c);
-#if defined (ENABLE_JITCACHE)
- c->cache_file_fd = 0;
-#endif
c->object.header.lockword.init();
s4 i;
vftbl_t *v;
-#if defined(ENABLE_JITCACHE)
-/* TODO: Find a way around the linker problem */
-/* jitcache_freeclass(c);*/
-#endif
-
class_freecpool(c);
if (c->interfaces != NULL)
bool class_isanysubclass(classinfo *sub, classinfo *super)
{
- uint32_t diffval;
- bool result;
+ bool result;
/* This is the trivial case. */
if (sub->flags & ACC_INTERFACE)
return (super == class_java_lang_Object);
+#if USES_NEW_SUBTYPE
result = fast_subtype_check(sub->vftbl, super->vftbl);
+#else
+ LOCK_CLASSRENUMBER_LOCK;
+
+ uint32_t diffval = sub->vftbl->baseval - super->vftbl->baseval;
+ result = diffval <= (uint32_t) super->vftbl->diffval;
+
+ UNLOCK_CLASSRENUMBER_LOCK;
+#endif
}
return result;
}
+/* 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);
}
classref_or_classinfo outer;
utf *innername;
int i;
+ int32_t flags;
+
+ /* default to flags of passed class */
+
+ flags = c->flags;
+
+ /* if requested we check if passed class is inner class */
if (!ignoreInnerClassesAttrib && (c->innerclasscount != 0)) {
/* search for passed class as inner 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;
+ flags = c->innerclass[i].flags;
+
+ break;
}
}
}
- /* passed class is no inner class or it was not requested */
+ /* remove ACC_SUPER bit from flags */
- return c->flags & ACC_CLASS_REFLECT_MASK;
+ return flags & ~ACC_SUPER & ACC_CLASS_REFLECT_MASK;
}