* Use new avl tree code.
authortwisti <none@none>
Tue, 3 Jan 2006 23:46:48 +0000 (23:46 +0000)
committertwisti <none@none>
Tue, 3 Jan 2006 23:46:48 +0000 (23:46 +0000)
src/threads/native/threads.c
src/vm/jit/codegen-common.c

index 98da3f941390ffd3c2e463f82d5ceaf834bfb905..b7f6c2718e9db5ba928d9d858ad2f497deb39de1 100644 (file)
@@ -28,7 +28,7 @@
 
    Changes: Christian Thalinger
 
-   $Id: threads.c 3830 2005-12-01 23:07:33Z twisti $
+   $Id: threads.c 4087 2006-01-03 23:46:48Z twisti $
 
 */
 
@@ -156,7 +156,7 @@ static void setPriority(pthread_t tid, int priority)
 }
 
 
-static struct avl_table *criticaltree;
+static avl_tree *criticaltree;
 threadobject *mainthreadobj;
 
 #ifndef HAVE___THREAD
@@ -188,7 +188,8 @@ void tables_unlock()
     pthread_mutex_unlock_rec(&tablelock);
 }
 
-static int criticalcompare(const void *pa, const void *pb, void *param)
+
+static s4 criticalcompare(const void *pa, const void *pb)
 {
        const threadcritnode *na = pa;
        const threadcritnode *nb = pb;
@@ -200,32 +201,41 @@ static int criticalcompare(const void *pa, const void *pb, void *param)
        return 0;
 }
 
+
 static const threadcritnode *findcritical(u1 *mcodeptr)
 {
-    struct avl_node *n = criticaltree->avl_root;
-    const threadcritnode *m = NULL;
+    avl_node *n;
+    const threadcritnode *m;
+
+    n = criticaltree->root;
+       m = NULL;
+
     if (!n)
         return NULL;
-    for (;;)
-    {
-        const threadcritnode *d = n->avl_data;
+
+    for (;;) {
+        const threadcritnode *d = n->data;
+
         if (mcodeptr == d->mcodebegin)
             return d;
+
         if (mcodeptr < d->mcodebegin) {
-            if (n->avl_link[0])
-                n = n->avl_link[0];
+            if (n->childs[0])
+                n = n->childs[0];
             else
                 return m;
+
         } else {
-            if (n->avl_link[1]) {
-                m = n->avl_data;
-                n = n->avl_link[1];
+            if (n->childs[1]) {
+                m = n->data;
+                n = n->childs[1];
             } else
-                return n->avl_data;
+                return n->data;
         }
     }
 }
 
+
 void thread_registercritical(threadcritnode *n)
 {
        avl_insert(criticaltree, n);
@@ -498,18 +508,24 @@ void threads_preinit(void)
        setthreadobject(mainthreadobj);
        initPools();
 
-    criticaltree = avl_create(criticalcompare, NULL, NULL);
-       thread_addstaticcritical();
-       sem_init(&suspend_ack, 0, 0);
-
        /* Every newly created object's monitorPtr points here so we save
           a check against NULL */
+
        dummyLR = NEW(monitorLockRecord);
        dummyLR->o = NULL;
        dummyLR->ownerThread = NULL;
        dummyLR->waiting = false;
+
+       /* we need a working dummyLR before initializing the critical
+          section tree */
+
+    criticaltree = avl_create(&criticalcompare);
+
+       thread_addstaticcritical();
+       sem_init(&suspend_ack, 0, 0);
 }
 
+
 static pthread_attr_t threadattr;
 
 static void freeLockRecordPools(lockRecordPool *);
index 682180680e88904d8e0c4cb82d764370cec1dc93..85e3611d780a0d4b9026fd066f8ed2d5a2b4678b 100644 (file)
@@ -47,7 +47,7 @@
    memory. All functions writing values into the data area return the offset
    relative the begin of the code area (start of procedure).   
 
-   $Id: codegen-common.c 4012 2005-12-30 14:17:30Z twisti $
+   $Id: codegen-common.c 4087 2006-01-03 23:46:48Z twisti $
 
 */
 
@@ -91,9 +91,8 @@
 /* in this tree we store all method addresses *********************************/
 
 #if defined(__I386__) || defined(__X86_64__) || defined(ENABLE_INTRP) || defined(DISABLE_GC)
-static struct avl_table *methodtree = NULL;
-static int methodtree_comparator(const void *pc, const void *element,
-                                                                void *param);
+static avl_tree *methodtree = NULL;
+static s4 methodtree_comparator(const void *pc, const void *element);
 #endif
 
 
@@ -113,7 +112,7 @@ void codegen_init(void)
                methodtree_element *mte;
 #endif
 
-               methodtree = avl_create(methodtree_comparator, NULL, NULL);
+               methodtree = avl_create(&methodtree_comparator);
 
 #if !defined(ENABLE_INTRP)
                /* insert asm_calljavafunction */
@@ -531,7 +530,7 @@ void codegen_addpatchref(codegendata *cd, voidptr branchptr,
 
 *******************************************************************************/
 
-static int methodtree_comparator(const void *pc, const void *element, void *param)
+static s4 methodtree_comparator(const void *pc, const void *element)
 {
        methodtree_element *mte;
        methodtree_element *mtepc;
@@ -568,32 +567,17 @@ void codegen_insertmethod(u1 *startpc, u1 *endpc)
 {
        methodtree_element *mte;
 
-#if defined(USE_THREADS)
-#if defined(NATIVE_THREADS)
-       tables_lock();
-#endif
-#endif
+       /* allocate new method entry */
 
        mte = NEW(methodtree_element);
+
        mte->startpc = startpc;
        mte->endpc   = endpc;
 
-       if (avl_insert(methodtree, mte)) {
-#if defined(USE_THREADS)
-#if defined(NATIVE_THREADS)
-               tables_unlock();
-#endif
-#endif
-               assert(0);
-               throw_cacao_exception_exit(string_java_lang_InternalError,
-                                                                  "duplicate entry");
-       }
+       /* this function does not return an error, but asserts for
+          duplicate entries */
 
-#if defined(USE_THREADS)
-#if defined(NATIVE_THREADS)
-       tables_unlock();
-#endif
-#endif
+       avl_insert(methodtree, mte);
 }
 
 
@@ -608,35 +592,21 @@ u1 *codegen_findmethod(u1 *pc)
        methodtree_element  mtepc;
        methodtree_element *mte;
 
-#if defined(USE_THREADS)
-#if defined(NATIVE_THREADS)
-       tables_lock();
-#endif
-#endif
+       /* allocation of the search structure on the stack is much faster */
 
        mtepc.startpc = pc;
-       mtepc.endpc = pc;
+       mtepc.endpc   = pc;
 
        mte = avl_find(methodtree, &mtepc);
 
        if (!mte) {
-#if defined(USE_THREADS)
-#if defined(NATIVE_THREADS)
-               tables_unlock();
-#endif
-#endif
                printf("Cannot find Java function at %p\n", (void *) (ptrint) pc);
                assert(0);
+
                throw_cacao_exception_exit(string_java_lang_InternalError,
                                                                   "Cannot find Java function at %p", pc);
        }
 
-#if defined(USE_THREADS)
-#if defined(NATIVE_THREADS)
-       tables_unlock();
-#endif
-#endif
-
        return mte->startpc;
 }
 #endif /* defined(__I386__) || defined(__X86_64__) || defined(ENABLE_INTRP) || defined(DISABLE_GC) */