Classes can be equal even if the pointers are not equal.
That's because array classes are not cached and the same class may
be represented by different copies of struct vm_class.

The proper soultion would be to cache array types also but it is
not something that can be easily done now.

Signed-off-by: Tomek Grabiec <tgrab...@gmail.com>
---
 vm/class.c |   29 ++++++++++++++++++++++++++++-
 1 files changed, 28 insertions(+), 1 deletions(-)

diff --git a/vm/class.c b/vm/class.c
index ed68cee..1236fb1 100644
--- a/vm/class.c
+++ b/vm/class.c
@@ -535,10 +535,37 @@ vm_class_resolve_method_recursive(const struct vm_class 
*vmc, uint16_t i)
        return result;
 }
 
+bool vm_class_is_equal_to(const struct vm_class *class,
+                         const struct vm_class *class2)
+{
+       enum vm_type type1;
+       enum vm_type type2;
+
+       if (class->kind != class2->kind)
+               return false;
+
+       if (class == class2)
+               return true;
+
+       switch (class->kind) {
+       case VM_CLASS_KIND_REGULAR:
+               return false;
+       case VM_CLASS_KIND_PRIMITIVE:
+               type1 = vm_class_get_storage_vmtype(class);
+               type2 = vm_class_get_storage_vmtype(class2);
+
+               return type1 == type2;
+       case VM_CLASS_KIND_ARRAY:
+               return strcmp(class->name, class2->name);
+       default:
+               error("Unknown class kind");
+       }
+}
+
 /* Reference: 
http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Class.html#isAssignableFrom(java.lang.Class)
 */
 bool vm_class_is_assignable_from(const struct vm_class *vmc, const struct 
vm_class *from)
 {
-       if (vmc == from)
+       if (vm_class_is_equal_to(vmc, from))
                return true;
 
        if (from->super && vm_class_is_assignable_from(vmc, from->super))
-- 
1.6.0.6


------------------------------------------------------------------------------
_______________________________________________
Jatovm-devel mailing list
Jatovm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jatovm-devel

Reply via email to