Merged branch subtype-trunk into default.
[cacao.git] / src / vm / jit / builtin.cpp
index 1b9ccb99c0eb23d4fc18d6df2d62d6d88b848c41..491d48ce6c056cac6b6c212424807374485f3d46 100644 (file)
@@ -48,7 +48,7 @@
 #endif
 
 #include "mm/gc.hpp"
-#include "mm/memory.h"
+#include "mm/memory.hpp"
 
 #include "native/llni.h"
 
@@ -56,7 +56,7 @@
 #include "threads/mutex.hpp"
 #include "threads/thread.hpp"
 
-#include "toolbox/logging.h"
+#include "toolbox/logging.hpp"
 #include "toolbox/util.h"
 
 #include "vm/array.hpp"
@@ -67,7 +67,7 @@
 #include "vm/global.h"
 #include "vm/globals.hpp"
 #include "vm/initialize.hpp"
-#include "vm/linker.h"
+#include "vm/linker.hpp"
 #include "vm/loader.hpp"
 #include "vm/options.h"
 #include "vm/primitive.hpp"
@@ -640,6 +640,28 @@ bool builtin_canstore(java_handle_objectarray_t *oa, java_handle_t *o)
        return result;
 }
 
+#if USES_NEW_SUBTYPE
+/* fast_subtype_check **********************************************************
+
+   Checks if s is a subtype of t, using both the restricted subtype relation
+   and the overflow array (see Cliff Click and John Rose: Fast subtype checking
+   in the Hotspot JVM.)
+
+   RETURN VALUE:
+      1......s is a subtype of t.
+      0......otherwise
+
+*******************************************************************************/
+
+bool fast_subtype_check(struct _vftbl *s, struct _vftbl *t)
+{
+   if (s->subtype_display[t->subtype_depth] == t)
+       return true;
+   if (t->subtype_offset != OFFSET(vftbl_t, subtype_display[DISPLAY_SIZE]))
+       return false;
+   return s->subtype_depth >= t->subtype_depth && s->subtype_overflow[t->subtype_depth - DISPLAY_SIZE] == t;
+}
+#endif
 
 /* builtin_fast_canstore *******************************************************
 
@@ -653,15 +675,6 @@ bool builtin_canstore(java_handle_objectarray_t *oa, java_handle_t *o)
 
 *******************************************************************************/
 
-bool fast_subtype_check(struct _vftbl *s, struct _vftbl *t)
-{
-       if (s->subtype_display[t->subtype_depth] == t)
-               return true;
-       if (t->subtype_offset != OFFSET(vftbl_t, subtype_display[DISPLAY_SIZE]))
-               return false;
-       return s->subtype_depth >= t->subtype_depth && s->subtype_overflow[t->subtype_depth - DISPLAY_SIZE] == t;
-}
-
 bool builtin_fast_canstore(java_objectarray_t *oa, java_object_t *o)
 {
        arraydescriptor *desc;
@@ -694,6 +707,8 @@ bool builtin_fast_canstore(java_objectarray_t *oa, java_object_t *o)
                if (valuevftbl == componentvftbl)
                        return 1;
 
+               LOCK_CLASSRENUMBER_LOCK;
+
                baseval = componentvftbl->baseval;
 
                if (baseval <= 0) {
@@ -703,8 +718,15 @@ bool builtin_fast_canstore(java_objectarray_t *oa, java_object_t *o)
                                          (valuevftbl->interfacetable[baseval] != NULL));
                }
                else {
+#if USES_NEW_SUBTYPE
                        result = fast_subtype_check(valuevftbl, componentvftbl);
+#else
+                       diffval = valuevftbl->baseval - componentvftbl->baseval;
+                       result  = diffval <= (uint32_t) componentvftbl->diffval;
+#endif
                }
+
+               UNLOCK_CLASSRENUMBER_LOCK;
        }
        else if (valuedesc == NULL) {
                /* {oa has dimension > 1} */
@@ -756,6 +778,8 @@ bool builtin_fast_canstore_onedim(java_objectarray_t *a, java_object_t *o)
        if (valuevftbl == elementvftbl)
                return 1;
 
+       LOCK_CLASSRENUMBER_LOCK;
+
        baseval = elementvftbl->baseval;
 
        if (baseval <= 0) {
@@ -764,9 +788,16 @@ bool builtin_fast_canstore_onedim(java_objectarray_t *a, java_object_t *o)
                                  (valuevftbl->interfacetable[baseval] != NULL));
        }
        else {
+#if USES_NEW_SUBTYPE
                result = fast_subtype_check(valuevftbl, elementvftbl);
+#else
+               diffval = valuevftbl->baseval - elementvftbl->baseval;
+               result  = diffval <= (uint32_t) elementvftbl->diffval;
+#endif
        }
 
+       UNLOCK_CLASSRENUMBER_LOCK;
+
        return result;
 }
 
@@ -800,7 +831,16 @@ bool builtin_fast_canstore_onedim_class(java_objectarray_t *a, java_object_t *o)
        if (valuevftbl == elementvftbl)
                return 1;
 
+       LOCK_CLASSRENUMBER_LOCK;
+
+#if USES_NEW_SUBTYPE
        result = fast_subtype_check(valuevftbl, elementvftbl);
+#else
+       diffval = valuevftbl->baseval - elementvftbl->baseval;
+       result  = diffval <= (uint32_t) elementvftbl->diffval;
+#endif
+
+       UNLOCK_CLASSRENUMBER_LOCK;
 
        return result;
 }