From: bdemsky Date: Sat, 17 Oct 2009 21:13:41 +0000 (+0000) Subject: more bug fixes X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=235e8d78c90ec7209ccbd9f47a3395fcf8873a5d;p=IRC.git more bug fixes --- diff --git a/Robust/src/Benchmarks/SingleTM/Yada/List_t.java b/Robust/src/Benchmarks/SingleTM/Yada/List_t.java index 0d6e75d4..c7f7c5aa 100644 --- a/Robust/src/Benchmarks/SingleTM/Yada/List_t.java +++ b/Robust/src/Benchmarks/SingleTM/Yada/List_t.java @@ -74,8 +74,9 @@ public class List_t { - public List_Node head; - int size; + public List_Node head; + int size; + int mode; public List_t() { head = new List_Node(); @@ -112,35 +113,17 @@ public class List_t { * */ - public static List_t alloc() - { - List_t listPtr = new List_t(); - - if(listPtr == null) { - return null; - } + //mode 0 = element_list_compare + //mode 1 = element_list_compareedge - listPtr.head.dataPtr = null; - listPtr.head.nextPtr = null; - listPtr.size = 0; - - return listPtr; - } + public List_t(int mode) { + List_t(); + this.mode=mode; + head.dataPtr = null; + head.nextPtr = null; + size = 0; + } -/* ============================================================================= - * list_free - * -- If NULL passed for 'compare' function, will compare data pointer addresses - * -- Returns NULL on failure - * ============================================================================= - * void list_free (list_t* listPtr); - */ - public static void free(List_t listPtr) - { - listPtr = null; - } - -// privae freeList - /* ============================================================================= * list_isEmpty * -- Return TRUE if list is empty, else FALSE @@ -188,30 +171,30 @@ public class List_t { * ============================================================================= * void* list_find (list_t* listPtr, void* dataPtr); */ - public Object find(Object dataPtr) { - List_Node nodePtr; - List_Node prevPtr = findPrevious(dataPtr); - - nodePtr = prevPtr.nextPtr; - - if((nodePtr == null) || - (compare(nodePtr.dataPtr,dataPtr) != 0)) { - return null; - } - - return (nodePtr.dataPtr); + public Object find(Object dataPtr) { + List_Node nodePtr; + List_Node prevPtr = findPrevious(dataPtr); + + nodePtr = prevPtr.nextPtr; + + if((nodePtr == null) || + (compare(nodePtr.dataPtr,dataPtr) != 0)) { + return null; } + + return nodePtr.dataPtr; + } - public int compare(Object obj1,Object obj2) - { - Reservation_Info aPtr=(Reservation_Info)obj1; - Reservation_Info bPtr=(Reservation_Info)obj2; - int typeDiff; - - typeDiff = aPtr.type - bPtr.type; - - return ((typeDiff != 0) ? (typeDiff) : (aPtr.id - bPtr.id)); + //mode 0 = element_list_compare + //mode 1 = element_list_compareedge + + public int compare(Object obj1,Object obj2) { + if (mode==0) { + return element.element_compare((element)obj1, (element)obj2); + } else { + return element.compareEdge((edge)obj1, (edge) obj2); } + } /* ============================================================================= * list_insert @@ -302,7 +285,7 @@ public class List_t { int i; System.out.println("Starting..."); - } + } } diff --git a/Robust/src/Benchmarks/SingleTM/Yada/Queue_t.java b/Robust/src/Benchmarks/SingleTM/Yada/Queue_t.java index c133cb20..901a4f29 100644 --- a/Robust/src/Benchmarks/SingleTM/Yada/Queue_t.java +++ b/Robust/src/Benchmarks/SingleTM/Yada/Queue_t.java @@ -69,63 +69,6 @@ public class Queue_t { this.capacity = capacity; } - - /* ============================================================================= - * Pqueue_alloc - * ============================================================================= - */ - public Queue_t - Pqueue_alloc (int initCapacity) - { - Queue_t queuePtr = new Queue_t(); - - int capacity = ((initCapacity < 2) ? 2 : initCapacity); - queuePtr.elements = new Object[capacity]; - if (queuePtr.elements == null) { - queuePtr = null; - return null; - } - queuePtr.pop = capacity - 1; - queuePtr.push = 0; - queuePtr.capacity = capacity; - - return queuePtr; - } - - /* ============================================================================= - * queue_free - * ============================================================================= - */ - public void queue_free (Queue_t queuePtr) { - queuePtr.elements = null; - queuePtr = null; - } - - - /* ============================================================================= - * Pqueue_free - * ============================================================================= - */ - public void - Pqueue_free (Queue_t queuePtr) - { - queuePtr.elements = null; - queuePtr = null; - } - - - /* ============================================================================= - * TMqueue_free - * ============================================================================= - * - public void - TMqueue_free (TM_ARGDECL Queue* queuePtr) - { - queuePtr.elements = null; - queuePtr = null; - } - -*/ /* ============================================================================= * queue_isEmpty * ============================================================================= diff --git a/Robust/src/Benchmarks/SingleTM/Yada/avltree.java b/Robust/src/Benchmarks/SingleTM/Yada/avltree.java index 9af1a9b9..7efece87 100644 --- a/Robust/src/Benchmarks/SingleTM/Yada/avltree.java +++ b/Robust/src/Benchmarks/SingleTM/Yada/avltree.java @@ -77,30 +77,32 @@ * ============================================================================= */ +#define HEIGHT_LIMIT 64 + /* Two way single rotation */ #define jsw_single(root,dir) do { \ - jsw_avlnode_t *save = root.link[!dir]; \ - root.link[!dir] = save.link[dir]; \ + avlnode save = root.link[1-dir]; \ + root.link[1-dir] = save.link[dir]; \ save.link[dir] = root; \ root = save; \ } while (false) /* Two way double rotation */ #define jsw_double(root,dir) do { \ - jsw_avlnode_t *save = root.link[!dir].link[dir]; \ - root.link[!dir].link[dir] = save.link[!dir]; \ - save.link[!dir] = root.link[!dir]; \ - root.link[!dir] = save; \ - save = root.link[!dir]; \ - root.link[!dir] = save.link[dir]; \ + avlnode save = root.link[1-dir].link[dir]; \ + root.link[1-dir].link[dir] = save.link[1-dir]; \ + save.link[1-dir] = root.link[1-dir]; \ + root.link[1-dir] = save; \ + save = root.link[1-dir]; \ + root.link[1-dir] = save.link[dir]; \ save.link[dir] = root; \ root = save; \ } while (false) /* Adjust balance before double rotation */ #define jsw_adjust_balance(root,dir,bal) do { \ - jsw_avlnode_t *n = root.link[dir]; \ - jsw_avlnode_t *nn = n.link[!dir]; \ + avlnode n = root.link[dir]; \ + avlnode nn = n.link[1-dir]; \ if ( nn.balance == 0 ) \ root.balance = n.balance = 0; \ else if ( nn.balance == bal ) { \ @@ -116,28 +118,28 @@ /* Rebalance after insertion */ #define jsw_insert_balance(root,dir) do { \ - jsw_avlnode_t *n = root.link[dir]; \ - long bal = dir == 0 ? -1 : +1; \ + avlnode n = root.link[dir]; \ + int bal = dir == 0 ? -1 : +1; \ if ( n.balance == bal ) { \ root.balance = n.balance = 0; \ - jsw_single ( root, !dir ); \ + jsw_single ( root, 1-dir ); \ } \ else { /* n.balance == -bal */ \ - jsw_adjust_balance ( root, dir, bal ); \ - jsw_double ( root, !dir ); \ + jsw_adjust_balance( root, dir, bal ); \ + jsw_double( root, 1-dir ); \ } \ } while (false) /* Rebalance after deletion */ #define jsw_remove_balance(root,dir,done) do { \ - jsw_avlnode_t *n = root.link[!dir]; \ - long bal = dir == 0 ? -1 : +1; \ + avlnode n = root.link[1-dir]; \ + int bal = dir == 0 ? -1 : +1; \ if ( n.balance == -bal ) { \ root.balance = n.balance = 0; \ jsw_single ( root, dir ); \ } \ else if ( n.balance == bal ) { \ - jsw_adjust_balance ( root, !dir, -bal ); \ + jsw_adjust_balance ( root, 1-dir, -bal ); \ jsw_double ( root, dir ); \ } \ else { /* n.balance == 0 */ \ @@ -204,9 +206,9 @@ class avltrav { path[top++] = it; it = it.link[dir]; - while (it.link[!dir] != null ) { + while (it.link[1-dir] != null ) { path[top++] = it; - it = it.link[!dir]; + it = it.link[1-dir]; } } else { /* Move to the next branch */ @@ -219,7 +221,7 @@ class avltrav { } last = it; - it = path[--trav.top]; + it = path[--top]; } while ( last == it.link[dir] ); } @@ -245,27 +247,30 @@ class avltrav { public class avltree { avlnode root; /* Top of the tree */ - cmp_f cmp; /* Compare two items */ int size; /* Number of items (user-defined) */ - public avltree( cmp_f cmp ) { + public avltree() { size = 0; } - void avlfind(Object data ) { - avlnode it = tree.root; + int cmp(Object a, Object b) { + return 0; + } - while ( it != NULL ) { - long cmp =cmp(it.data, data ); + Object avlfind(Object data ) { + avlnode it = root; + + while ( it != null ) { + int cmp =cmp(it.data, data ); if ( cmp == 0 ) break; - it = it.link[cmp < 0]; + it = it.link[(cmp < 0)?1:0]; } - return it == NULL ? NULL : it.data; + return it == null ? null : it.data; } boolean avlinsert(Object data ) { @@ -283,8 +288,8 @@ public class avltree { t.link[1] = root; /* Search down the tree, saving rebalance points */ - for ( s = p = t.link[1]; ; p=q ) { - dir = cmp ( p.data, data ) < 0; + for ( s = p = t.link[1]; true ; p=q ) { + dir = (cmp ( p.data, data ) < 0)?1:0; q = p.link[dir]; if ( q == null ) @@ -302,15 +307,15 @@ public class avltree { /* Update balance factors */ for ( p = s; p != q; p = p.link[dir] ) { - dir = cmp ( p.data, data ) < 0; - p.balance += dir == 0 ? -1 : +1; + dir = (cmp ( p.data, data ) < 0)?1:0; + p.balance += (dir == 0) ? -1 : +1; } q = s; /* Save rebalance point for parent fix */ /* Rebalance if necessary */ - if (abs(s.balance)>1) { - dir = cmp(s.data,data) < 0; + if ((s.balance<0?-s.balance:s.balance)>1) { + dir =(cmp(s.data,data) < 0)?1:0; jsw_insert_balance ( s, dir ); } @@ -318,7 +323,7 @@ public class avltree { if ( q == head.link[1] ) root = s; else - t.link[q == t.link[1]] = s; + t.link[(q == t.link[1])?1:0] = s; } size++; @@ -337,7 +342,7 @@ public class avltree { it = root; /* Search down tree and save path */ - for ( ; ; ) { + for ( ; true ; ) { if ( it == null ) return false; else if ( cmp ( it.data, data ) == 0 ) @@ -353,7 +358,7 @@ public class avltree { /* Remove the node */ if ( it.link[0] == null || it.link[1] == null ) { /* Which child is not null? */ - int dir = it.link[0] == null; + int dir = (it.link[0] == null)?1:0; /* Fix parent */ if (top != 0) @@ -384,7 +389,7 @@ public class avltree { } /* Walk back up the search path */ - while ( --top >= 0 && !done ) { + while ( --top >= 0 && (done==0) ) { /* Update balance factors */ up[top].balance += upd[top] != 0 ? -1 : +1; diff --git a/Robust/src/Benchmarks/SingleTM/Yada/coordinate.java b/Robust/src/Benchmarks/SingleTM/Yada/coordinate.java index 6585df0e..8a9da311 100644 --- a/Robust/src/Benchmarks/SingleTM/Yada/coordinate.java +++ b/Robust/src/Benchmarks/SingleTM/Yada/coordinate.java @@ -69,6 +69,12 @@ */ public class coordinate { + double x; + double y; + + public coordinate() { + } + static int coordinate_compare (coordinate aPtr, coordinate bPtr) { if (aPtr.x < bPtr.x) { return -1; diff --git a/Robust/src/Benchmarks/SingleTM/Yada/element.java b/Robust/src/Benchmarks/SingleTM/Yada/element.java index 0573795a..d81eea2a 100644 --- a/Robust/src/Benchmarks/SingleTM/Yada/element.java +++ b/Robust/src/Benchmarks/SingleTM/Yada/element.java @@ -223,7 +223,7 @@ public class element { * Note: Makes pairPtr sorted; i.e., coordinate_compare(first, second) < 0 * ============================================================================= */ - publicvoid setEdge(int i) { + public void setEdge(int i) { coordinate firstPtr = coordinates[i]; coordinate secondPtr = coordinates[(i + 1) % numCoordinate]; @@ -335,7 +335,7 @@ int element_compare (element aElementPtr, element bElementPtr) { checkAngles(); calculateCircumCircle(); initEdges(coordinates, numCoordinate); - neighborListPtr = TMLIST_ALLOC(element_listCompare); + neighborListPtr = new List_t(0);//TMLIST_ALLOC(element_listCompare); isGarbage = false; isReferenced = false; } diff --git a/Robust/src/Benchmarks/SingleTM/Yada/makefile b/Robust/src/Benchmarks/SingleTM/Yada/makefile index 0b5d38f3..71e04161 100644 --- a/Robust/src/Benchmarks/SingleTM/Yada/makefile +++ b/Robust/src/Benchmarks/SingleTM/Yada/makefile @@ -1,17 +1,17 @@ MAINCLASS=yada SRC=${MAINCLASS}.java \ tmpheap.java \ + List_t.java \ Random.java \ tmpQueue_t.java \ coordinate.java \ edge.java \ element.java \ List_Node.java \ - List_t.java \ mesh.java \ region.java \ Vector_t.java \ - avltree.java \ + tmpavltree.java \ ../../../ClassLibrary/JavaSTM/Barrier.java include ../common/Makefile.flags diff --git a/Robust/src/Benchmarks/SingleTM/Yada/region.java b/Robust/src/Benchmarks/SingleTM/Yada/region.java index 841df3f7..6da6ef03 100644 --- a/Robust/src/Benchmarks/SingleTM/Yada/region.java +++ b/Robust/src/Benchmarks/SingleTM/Yada/region.java @@ -81,8 +81,8 @@ public class region { */ public region() { expandQueuePtr = new Queue_t(-1); - beforeListPtr = PLIST_ALLOC(element_listCompare); - borderListPtr = PLIST_ALLOC(element_listCompareEdge); + beforeListPtr = new List_t(0);//PLIST_ALLOC(element_listCompare); + borderListPtr = new List_t(1);//PLIST_ALLOC(element_listCompareEdge); badVectorPtr = new Vector_t(1); }