Merged branch subtype-trunk into default.
[cacao.git] / src / vm / jit / builtin.cpp
index ba8c683859ffa6efe61890180e57e7b7263de938..491d48ce6c056cac6b6c212424807374485f3d46 100644 (file)
@@ -48,7 +48,7 @@
 #endif
 
 #include "mm/gc.hpp"
-#include "mm/memory.h"
+#include "mm/memory.hpp"
 
 #include "native/llni.h"
 
 #include "threads/mutex.hpp"
 #include "threads/thread.hpp"
 
-#include "toolbox/logging.h"
+#include "toolbox/logging.hpp"
 #include "toolbox/util.h"
 
 #include "vm/array.hpp"
 #include "vm/jit/builtin.hpp"
-#include "vm/class.h"
+#include "vm/class.hpp"
 #include "vm/cycles-stats.h"
 #include "vm/exceptions.hpp"
 #include "vm/global.h"
 #include "vm/globals.hpp"
-#include "vm/initialize.h"
-#include "vm/linker.h"
+#include "vm/initialize.hpp"
+#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 *******************************************************
 
@@ -685,7 +707,7 @@ bool builtin_fast_canstore(java_objectarray_t *oa, java_object_t *o)
                if (valuevftbl == componentvftbl)
                        return 1;
 
-               linker_classrenumber_mutex->lock();
+               LOCK_CLASSRENUMBER_LOCK;
 
                baseval = componentvftbl->baseval;
 
@@ -696,11 +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
                }
 
-               linker_classrenumber_mutex->unlock();
+               UNLOCK_CLASSRENUMBER_LOCK;
        }
        else if (valuedesc == NULL) {
                /* {oa has dimension > 1} */
@@ -752,7 +778,7 @@ bool builtin_fast_canstore_onedim(java_objectarray_t *a, java_object_t *o)
        if (valuevftbl == elementvftbl)
                return 1;
 
-       linker_classrenumber_mutex->lock();
+       LOCK_CLASSRENUMBER_LOCK;
 
        baseval = elementvftbl->baseval;
 
@@ -762,11 +788,15 @@ 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
        }
 
-       linker_classrenumber_mutex->unlock();
+       UNLOCK_CLASSRENUMBER_LOCK;
 
        return result;
 }
@@ -801,12 +831,16 @@ bool builtin_fast_canstore_onedim_class(java_objectarray_t *a, java_object_t *o)
        if (valuevftbl == elementvftbl)
                return 1;
 
-       linker_classrenumber_mutex->lock();
+       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
 
-       linker_classrenumber_mutex->unlock();
+       UNLOCK_CLASSRENUMBER_LOCK;
 
        return result;
 }
@@ -1391,11 +1425,7 @@ s8 builtin_ladd(s8 a, s8 b)
 {
        s8 c;
 
-#if U8_AVAILABLE
        c = a + b; 
-#else
-       c = builtin_i2l(0);
-#endif
 
        return c;
 }
@@ -1404,11 +1434,7 @@ s8 builtin_lsub(s8 a, s8 b)
 {
        s8 c;
 
-#if U8_AVAILABLE
        c = a - b; 
-#else
-       c = builtin_i2l(0);
-#endif
 
        return c;
 }
@@ -1417,11 +1443,7 @@ s8 builtin_lneg(s8 a)
 {
        s8 c;
 
-#if U8_AVAILABLE
        c = -a;
-#else
-       c = builtin_i2l(0);
-#endif
 
        return c;
 }
@@ -1433,11 +1455,7 @@ s8 builtin_lmul(s8 a, s8 b)
 {
        s8 c;
 
-#if U8_AVAILABLE
        c = a * b; 
-#else
-       c = builtin_i2l(0);
-#endif
 
        return c;
 }
@@ -1449,11 +1467,7 @@ s8 builtin_ldiv(s8 a, s8 b)
 {
        s8 c;
 
-#if U8_AVAILABLE
        c = a / b; 
-#else
-       c = builtin_i2l(0);
-#endif
 
        return c;
 }
@@ -1462,11 +1476,7 @@ s8 builtin_lrem(s8 a, s8 b)
 {
        s8 c;
 
-#if U8_AVAILABLE
        c = a % b; 
-#else
-       c = builtin_i2l(0);
-#endif
 
        return c;
 }
@@ -1478,11 +1488,7 @@ s8 builtin_lshl(s8 a, s4 b)
 {
        s8 c;
 
-#if U8_AVAILABLE
        c = a << (b & 63);
-#else
-       c = builtin_i2l(0);
-#endif
 
        return c;
 }
@@ -1491,11 +1497,7 @@ s8 builtin_lshr(s8 a, s4 b)
 {
        s8 c;
 
-#if U8_AVAILABLE
        c = a >> (b & 63);
-#else
-       c = builtin_i2l(0);
-#endif
 
        return c;
 }
@@ -1504,11 +1506,7 @@ s8 builtin_lushr(s8 a, s4 b)
 {
        s8 c;
 
-#if U8_AVAILABLE
        c = ((u8) a) >> (b & 63);
-#else
-       c = builtin_i2l(0);
-#endif
 
        return c;
 }
@@ -1520,11 +1518,7 @@ s8 builtin_land(s8 a, s8 b)
 {
        s8 c;
 
-#if U8_AVAILABLE
        c = a & b; 
-#else
-       c = builtin_i2l(0);
-#endif
 
        return c;
 }
@@ -1533,11 +1527,7 @@ s8 builtin_lor(s8 a, s8 b)
 {
        s8 c;
 
-#if U8_AVAILABLE
        c = a | b; 
-#else
-       c = builtin_i2l(0);
-#endif
 
        return c;
 }
@@ -1546,11 +1536,7 @@ s8 builtin_lxor(s8 a, s8 b)
 {
        s8 c;
 
-#if U8_AVAILABLE
        c = a ^ b; 
-#else
-       c = builtin_i2l(0);
-#endif
 
        return c;
 }
@@ -1560,7 +1546,6 @@ s8 builtin_lxor(s8 a, s8 b)
 #if !(SUPPORT_LONG && SUPPORT_LONG_CMP)
 s4 builtin_lcmp(s8 a, s8 b)
 { 
-#if U8_AVAILABLE
        if (a < b)
                return -1;
 
@@ -1568,9 +1553,6 @@ s4 builtin_lcmp(s8 a, s8 b)
                return 1;
 
        return 0;
-#else
-       return 0;
-#endif
 }
 #endif /* !(SUPPORT_LONG && SUPPORT_LONG_CMP) */
 
@@ -1968,30 +1950,6 @@ double builtin_drem(double a, double b)
 
 /* conversion operations ******************************************************/
 
-#if 0
-s8 builtin_i2l(s4 i)
-{
-#if U8_AVAILABLE
-       return i;
-#else
-       s8 v;
-       v.high = 0;
-       v.low = i;
-       return v;
-#endif
-}
-
-s4 builtin_l2i(s8 l)
-{
-#if U8_AVAILABLE
-       return (s4) l;
-#else
-       return l.low;
-#endif
-}
-#endif
-
-
 #if !(SUPPORT_FLOAT && SUPPORT_I2F)
 float builtin_i2f(s4 a)
 {
@@ -2013,12 +1971,8 @@ double builtin_i2d(s4 a)
 #if !(SUPPORT_LONG && SUPPORT_FLOAT && SUPPORT_L2F)
 float builtin_l2f(s8 a)
 {
-#if U8_AVAILABLE
        float f = (float) a;
        return f;
-#else
-       return 0.0;
-#endif
 }
 #endif /* !(SUPPORT_LONG && SUPPORT_FLOAT && SUPPORT_L2F) */
 
@@ -2026,12 +1980,8 @@ float builtin_l2f(s8 a)
 #if !(SUPPORT_LONG && SUPPORT_DOUBLE && SUPPORT_L2D)
 double builtin_l2d(s8 a)
 {
-#if U8_AVAILABLE
        double d = (double) a;
        return d;
-#else
-       return 0.0;
-#endif
 }
 #endif /* !(SUPPORT_LONG && SUPPORT_DOUBLE && SUPPORT_L2D) */