* Updated to jitcache-arm-x86 branch d4f6023b26c5+d1b5b1c106ac
[cacao.git] / src / vm / jit / builtin.cpp
index ef5545fff2cd74e61f8d501bcfa8cb13af29ac7f..f4d23e8eb90c3fd8bceab46c14a26f230851ec21 100644 (file)
 
 #include "native/llni.h"
 
-#include "threads/lock-common.h"
+#include "threads/lock.hpp"
 #include "threads/mutex.hpp"
 #include "threads/thread.hpp"
 
 #include "toolbox/logging.h"
 #include "toolbox/util.h"
 
-#include "vm/array.h"
+#include "vm/array.hpp"
 #include "vm/jit/builtin.hpp"
 #include "vm/class.h"
 #include "vm/cycles-stats.h"
@@ -108,11 +108,9 @@ static bool builtintable_init(void)
        descriptor_pool    *descpool;
        builtintable_entry *bte;
        methodinfo         *m;
-       int32_t             dumpmarker;
 
-       /* mark start of dump memory area */
-
-       DMARKER;
+       // Create new dump memory area.
+       DumpMemoryArea dma;
 
        /* create a new descriptor pool */
 
@@ -132,22 +130,15 @@ static bool builtintable_init(void)
                bte->name       = utf_new_char(bte->cname);
                bte->descriptor = utf_new_char(bte->cdescriptor);
 
-               if (!descriptor_pool_add(descpool, bte->descriptor, NULL)) {
-                       /* release dump area */
-
-                       DRELEASE;
-
+               if (!descriptor_pool_add(descpool, bte->descriptor, NULL))
                        return false;
-               }
        }
 
        for (bte = builtintable_automatic; bte->fp != NULL; bte++) {
                bte->descriptor = utf_new_char(bte->cdescriptor);
 
-               if (!descriptor_pool_add(descpool, bte->descriptor, NULL)) {
-                       DRELEASE;
+               if (!descriptor_pool_add(descpool, bte->descriptor, NULL))
                        return false;
-               }
        }
 
        for (bte = builtintable_function; bte->fp != NULL; bte++) {
@@ -155,10 +146,8 @@ static bool builtintable_init(void)
                bte->name       = utf_new_char(bte->cname);
                bte->descriptor = utf_new_char(bte->cdescriptor);
 
-               if (!descriptor_pool_add(descpool, bte->descriptor, NULL)) {
-                       DRELEASE;
+               if (!descriptor_pool_add(descpool, bte->descriptor, NULL))
                        return false;
-               }
        }
 
        /* create the class reference table */
@@ -214,10 +203,6 @@ static bool builtintable_init(void)
                }
        }
 
-       /* release dump area */
-
-       DRELEASE;
-
        return true;
 }
 
@@ -282,6 +267,81 @@ bool builtin_init(void)
 }
 
 
+/* builtintable_get_by_key *****************************************************
+
+   Returns a key for the given builtintable_entry object which is suitable
+   for retrieving the instance again by calling builtintable_get_by_key.
+
+   The key can be regarded fixed between multiple runs of the JVM.
+
+*******************************************************************************/
+
+s4 builtintable_get_key(builtintable_entry *bte)
+{
+       s4 entries;
+/*
+       int i;
+       entries = sizeof(builtintable_internal) / sizeof(builtintable_entry) - 1;
+       for (i = 0; i < entries; i++)
+               if (&builtintable_internal[i] == bte)
+                       return i + 1;
+
+       entries = sizeof(builtintable_automatic) / sizeof(builtintable_entry) - 1;
+       for (i = 0; i < entries; i++)
+               if (&builtintable_automatic[i] == bte)
+                       return -i;
+
+       entries = sizeof(builtintable_function) / sizeof(builtintable_entry) - 1;
+       for (i = 0; i < entries; i++)
+               if (&builtintable_function[i] == bte)
+                       return -1000 - i;
+*/
+
+       entries = sizeof(builtintable_internal) / sizeof(builtintable_entry) - 1;
+       if (&builtintable_internal[0] <= bte
+               && &builtintable_internal[entries - 1] >= bte)
+       {
+               return (s4) (bte - &builtintable_internal[0]) + 1;
+       }
+
+       entries = sizeof(builtintable_automatic) / sizeof(builtintable_entry) - 1;
+       if (&builtintable_automatic[0] <= bte
+               && &builtintable_automatic[entries - 1] >= bte)
+       {
+               return -(s4) (bte - &builtintable_automatic[0]);
+       }
+
+       entries = sizeof(builtintable_function) / sizeof(builtintable_entry) - 1;
+       if (&builtintable_function[0] <= bte
+               && &builtintable_function[entries - 1] >= bte)
+       {
+               return -1000 - (s4) (bte - &builtintable_function[0]);
+       }
+
+       /* builtintable_entry is not in our tables. */
+       assert (0);
+
+       return 0;
+}
+
+/* builtintable_get_by_key *****************************************************
+
+   Retrieves an entry in the internal and automatic builtin functions tables
+   using a key that was retrived previously with builtintable_get_key()
+
+*******************************************************************************/
+
+builtintable_entry *builtintable_get_by_key(s4 key)
+{
+       /* If key is positive it is the index into builtintable_internal. If it is
+        * negative it is the index into builtintable_automatic. If it is <= -1000
+     * it is the index into builtintable_function.
+     */
+       return (key > 0)
+               ? &builtintable_internal[key - 1]
+               : (key > -1000 ? &builtintable_automatic[-key] : &builtintable_function[-(1000 + key)]);
+}
+
 /* builtintable_get_internal ***************************************************
 
    Finds an entry in the builtintable for internal functions and
@@ -893,7 +953,7 @@ java_handle_t *builtin_new(classinfo *c)
        LLNI_vftbl_direct(o) = c->vftbl;
 
 #if defined(ENABLE_THREADS)
-       lock_init_object_lock(LLNI_DIRECT(o));
+       LLNI_DIRECT(o)->lockword.init();
 #endif
 
        CYCLES_STATS_GET(cycles_end);
@@ -975,7 +1035,7 @@ java_handle_t *builtin_tlh_new(classinfo *c)
        LLNI_vftbl_direct(o) = c->vftbl;
 
 # if defined(ENABLE_THREADS)
-       lock_init_object_lock(LLNI_DIRECT(o));
+       LLNI_DIRECT(o)->lockword.init();
 # endif
 
        CYCLES_STATS_GET(cycles_end);
@@ -1054,7 +1114,7 @@ java_object_t *builtin_fast_new(classinfo *c)
        o->vftbl = c->vftbl;
 
 #if defined(ENABLE_THREADS)
-       lock_init_object_lock(o);
+       LLNI_DIRECT(o)->lockword.init();
 #endif
 
        CYCLES_STATS_GET(cycles_end);
@@ -1124,7 +1184,7 @@ java_handle_t *builtin_newarray(int32_t size, classinfo *arrayclass)
        LLNI_vftbl_direct(a) = arrayclass->vftbl;
 
 #if defined(ENABLE_THREADS)
-       lock_init_object_lock(LLNI_DIRECT(a));
+       LLNI_DIRECT(a)->lockword.init();
 #endif
 
        LLNI_array_size(a) = size;
@@ -1406,11 +1466,7 @@ s8 builtin_ladd(s8 a, s8 b)
 {
        s8 c;
 
-#if U8_AVAILABLE
        c = a + b; 
-#else
-       c = builtin_i2l(0);
-#endif
 
        return c;
 }
@@ -1419,11 +1475,7 @@ s8 builtin_lsub(s8 a, s8 b)
 {
        s8 c;
 
-#if U8_AVAILABLE
        c = a - b; 
-#else
-       c = builtin_i2l(0);
-#endif
 
        return c;
 }
@@ -1432,11 +1484,7 @@ s8 builtin_lneg(s8 a)
 {
        s8 c;
 
-#if U8_AVAILABLE
        c = -a;
-#else
-       c = builtin_i2l(0);
-#endif
 
        return c;
 }
@@ -1448,11 +1496,7 @@ s8 builtin_lmul(s8 a, s8 b)
 {
        s8 c;
 
-#if U8_AVAILABLE
        c = a * b; 
-#else
-       c = builtin_i2l(0);
-#endif
 
        return c;
 }
@@ -1464,11 +1508,7 @@ s8 builtin_ldiv(s8 a, s8 b)
 {
        s8 c;
 
-#if U8_AVAILABLE
        c = a / b; 
-#else
-       c = builtin_i2l(0);
-#endif
 
        return c;
 }
@@ -1477,11 +1517,7 @@ s8 builtin_lrem(s8 a, s8 b)
 {
        s8 c;
 
-#if U8_AVAILABLE
        c = a % b; 
-#else
-       c = builtin_i2l(0);
-#endif
 
        return c;
 }
@@ -1493,11 +1529,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;
 }
@@ -1506,11 +1538,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;
 }
@@ -1519,11 +1547,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;
 }
@@ -1535,11 +1559,7 @@ s8 builtin_land(s8 a, s8 b)
 {
        s8 c;
 
-#if U8_AVAILABLE
        c = a & b; 
-#else
-       c = builtin_i2l(0);
-#endif
 
        return c;
 }
@@ -1548,11 +1568,7 @@ s8 builtin_lor(s8 a, s8 b)
 {
        s8 c;
 
-#if U8_AVAILABLE
        c = a | b; 
-#else
-       c = builtin_i2l(0);
-#endif
 
        return c;
 }
@@ -1561,11 +1577,7 @@ s8 builtin_lxor(s8 a, s8 b)
 {
        s8 c;
 
-#if U8_AVAILABLE
        c = a ^ b; 
-#else
-       c = builtin_i2l(0);
-#endif
 
        return c;
 }
@@ -1575,7 +1587,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;
 
@@ -1583,9 +1594,6 @@ s4 builtin_lcmp(s8 a, s8 b)
                return 1;
 
        return 0;
-#else
-       return 0;
-#endif
 }
 #endif /* !(SUPPORT_LONG && SUPPORT_LONG_CMP) */
 
@@ -1983,30 +1991,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)
 {
@@ -2028,12 +2012,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) */
 
@@ -2041,12 +2021,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) */
 
@@ -2361,7 +2337,7 @@ java_handle_t *builtin_clone(void *env, java_handle_t *o)
 #endif
 
 #if defined(ENABLE_THREADS)
-               lock_init_object_lock(LLNI_DIRECT(co));
+               LLNI_DIRECT(co)->lockword.init();
 #endif
 
                LLNI_CRITICAL_END;
@@ -2396,7 +2372,7 @@ java_handle_t *builtin_clone(void *env, java_handle_t *o)
 #endif
 
 #if defined(ENABLE_THREADS)
-       lock_init_object_lock(LLNI_DIRECT(co));
+       LLNI_DIRECT(co)->lockword.init();
 #endif
 
        LLNI_CRITICAL_END;