From cb7db70967814b92d2c2012958afacada606f300 Mon Sep 17 00:00:00 2001 From: bdemsky Date: Wed, 14 Mar 2007 02:12:20 +0000 Subject: [PATCH] random bug fixes & sleep call --- Robust/src/ClassLibrary/HashMap.java | 24 ++++++++++++----------- Robust/src/ClassLibrary/Object.java | 12 +++++++++++- Robust/src/ClassLibrary/ObjectJava.java | 12 +++++++++++- Robust/src/ClassLibrary/StringBuffer.java | 21 ++++++++------------ Robust/src/ClassLibrary/Thread.java | 2 ++ Robust/src/Runtime/object.c | 2 +- Robust/src/Runtime/object.h | 3 +-- Robust/src/Runtime/socket.c | 11 +++++++++++ Robust/src/Runtime/thread.c | 14 +++++++++++++ 9 files changed, 72 insertions(+), 29 deletions(-) diff --git a/Robust/src/ClassLibrary/HashMap.java b/Robust/src/ClassLibrary/HashMap.java index 11dfdf3f..db3d5694 100644 --- a/Robust/src/ClassLibrary/HashMap.java +++ b/Robust/src/ClassLibrary/HashMap.java @@ -63,19 +63,21 @@ public class HashMap { Object remove(Object key) { int bin=hash(key); HashEntry ptr=table[bin]; - if (ptr.key.equals(key)) { - table[bin]=ptr.next; - numItems--; - return ptr.value; - } - while(ptr.next!=null) { - if (ptr.next.key.equals(key)) { - Object oldvalue=ptr.value; - ptr.next=ptr.next.next; + if (ptr!=null) { + if (ptr.key.equals(key)) { + table[bin]=ptr.next; numItems--; - return oldvalue; + return ptr.value; + } + while(ptr.next!=null) { + if (ptr.next.key.equals(key)) { + Object oldvalue=ptr.value; + ptr.next=ptr.next.next; + numItems--; + return oldvalue; + } + ptr=ptr.next; } - ptr=ptr.next; } return null; } diff --git a/Robust/src/ClassLibrary/Object.java b/Robust/src/ClassLibrary/Object.java index dfaa7d3f..a972bfd2 100644 --- a/Robust/src/ClassLibrary/Object.java +++ b/Robust/src/ClassLibrary/Object.java @@ -1,5 +1,15 @@ public class Object { - public native int hashCode(); + public native int nativehashCode(); + private int cachedCode; + private boolean cachedHash; + + public int hashCode() { + if (!cachedHash) { + cachedCode=nativehashCode(); + cachedHash=true; + } + return cachedCode; + } /* DON'T USE THIS METHOD UNLESS NECESSARY */ /* WE WILL DEPRECATE IT AS SOON AS INSTANCEOF WORKS */ diff --git a/Robust/src/ClassLibrary/ObjectJava.java b/Robust/src/ClassLibrary/ObjectJava.java index 274d6490..82b1ef68 100644 --- a/Robust/src/ClassLibrary/ObjectJava.java +++ b/Robust/src/ClassLibrary/ObjectJava.java @@ -1,8 +1,18 @@ public class Object { - public native int hashCode(); + public int cachedCode; + public boolean cachedHash; + + public native int nativehashCode(); private Object nextlockobject; private Object prevlockobject; + public int hashCode() { + if (!cachedHash) { + cachedCode=nativehashCode(); + cachedHash=true; + } + return cachedCode; + } /* DON'T USE THIS METHOD UNLESS NECESSARY */ /* WE WILL DEPRECATE IT AS SOON AS INSTANCEOF WORKS */ diff --git a/Robust/src/ClassLibrary/StringBuffer.java b/Robust/src/ClassLibrary/StringBuffer.java index 02bb8a36..84e771e8 100644 --- a/Robust/src/ClassLibrary/StringBuffer.java +++ b/Robust/src/ClassLibrary/StringBuffer.java @@ -1,13 +1,11 @@ public class StringBuffer { char value[]; int count; - int offset; // private static final int DEFAULTSIZE=16; public StringBuffer(String str) { value=new char[str.count+16];//16 is DEFAULTSIZE count=str.count; - offset=0; for(int i=0;ivalue.length) { + if ((s.count+count)>value.length) { // Need to allocate char newvalue[]=new char[s.count+count+16]; //16 is DEFAULTSIZE for(int i=0;ivalue.length) { + if ((s.count+count)>value.length) { // Need to allocate char newvalue[]=new char[s.count+count+16]; //16 is DEFAULTSIZE for(int i=0;i___length___)+sizeof(int))); +#ifdef THREADS +#ifdef PRECISE_GC + struct listitem *tmp=stopforgc((struct garbagelist *)___params___); +#endif +#endif do { rc = connect(___fd___, (struct sockaddr *) &sin, sizeof(sin)); } while (rc<0 && errno==EINTR); /* repeat if interrupted */ +#ifdef THREADS +#ifdef PRECISE_GC + restartaftergc(tmp); +#endif +#endif + if (rc<0) goto error; diff --git a/Robust/src/Runtime/thread.c b/Robust/src/Runtime/thread.c index 7c22e069..5f34adf6 100644 --- a/Robust/src/Runtime/thread.c +++ b/Robust/src/Runtime/thread.c @@ -78,6 +78,20 @@ void initthread(struct ___Thread___ * ___this___) { pthread_mutex_unlock(&gclistlock); } +void CALL11(___Thread______sleep____J, long long ___millis___, long long ___millis___) { +#ifdef THREADS +#ifdef PRECISE_GC + struct listitem *tmp=stopforgc((struct garbagelist *)___params___); +#endif +#endif + usleep(___millis___); +#ifdef THREADS +#ifdef PRECISE_GC + restartaftergc(tmp); +#endif +#endif +} + void CALL01(___Thread______nativeCreate____, struct ___Thread___ * ___this___) { pthread_t thread; int retval; -- 2.34.1