random bug fixes & sleep call
authorbdemsky <bdemsky>
Wed, 14 Mar 2007 02:12:20 +0000 (02:12 +0000)
committerbdemsky <bdemsky>
Wed, 14 Mar 2007 02:12:20 +0000 (02:12 +0000)
Robust/src/ClassLibrary/HashMap.java
Robust/src/ClassLibrary/Object.java
Robust/src/ClassLibrary/ObjectJava.java
Robust/src/ClassLibrary/StringBuffer.java
Robust/src/ClassLibrary/Thread.java
Robust/src/Runtime/object.c
Robust/src/Runtime/object.h
Robust/src/Runtime/socket.c
Robust/src/Runtime/thread.c

index 11dfdf3f5fef477efeae57f3230d9576618af839..db3d56940f16e93429129ae0c8579b21ad9e34db 100644 (file)
@@ -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;
     }
index dfaa7d3f5458c1ad1e892887f62f51a98e7bb9c9..a972bfd23cb1d90cdf7617b0bbce38af0af3abad 100644 (file)
@@ -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 */
index 274d6490175cd4159d94a9d1cdfe8c0b77716e06..82b1ef68cc4894891c86049a89b6b627d5c7aa23 100644 (file)
@@ -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 */
index 02bb8a36d567245fcd592037c533a0180780c388..84e771e89cd05992841e67839dbc6000c5099556 100644 (file)
@@ -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;i<count;i++)
            value[i]=str.value[i+str.offset];
     }
@@ -15,7 +13,6 @@ public class StringBuffer {
     public StringBuffer() {
        value=new char[16];//16 is DEFAULTSIZE
        count=0;
-       offset=0;
     }
 
     public int length() {
@@ -27,42 +24,40 @@ public class StringBuffer {
     }
 
     public char charAt(int x) {
-       return value[x+offset];
+       return value[x];
     }
 
     public void append(String s) {
-       if ((s.count+count+offset)>value.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<count;i++)
-               newvalue[i]=value[i+offset];
+               newvalue[i]=value[i];
            for(int i=0;i<s.count;i++)
                newvalue[i+count]=s.value[i+s.offset];
            value=newvalue;
            count+=s.count;
-           offset=0;
        } else {
            for(int i=0;i<s.count;i++) {
-               value[i+count+offset]=s.value[i+s.offset];
+               value[i+count]=s.value[i+s.offset];
            }
            count+=s.count;
        }
     }
 
     public void append(StringBuffer s) {
-       if ((s.count+count+offset)>value.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<count;i++)
-               newvalue[i]=value[i+offset];
+               newvalue[i]=value[i];
            for(int i=0;i<s.count;i++)
-               newvalue[i+count]=s.value[i+s.offset];
+               newvalue[i+count]=s.value[i];
            value=newvalue;
            count+=s.count;
-           offset=0;
        } else {
            for(int i=0;i<s.count;i++) {
-               value[i+count+offset]=s.value[i+s.offset];
+               value[i+count]=s.value[i];
            }
            count+=s.count;
        }
index b9f2a82291806df1e2f34e09a844b3b298d40945..3008a067012d806701ed2c5e0103914e145d539e 100644 (file)
@@ -6,6 +6,8 @@ public class Thread {
     private static void staticStart(Thread t) {
        t.run();
     }
+
+    public native static void sleep(long millis);
     
     public void run() {}
 
index 4e7f7f964eda6fe869caaf7462eae6a3b8a0209c..ab986ecbb141d16cd2f282fe1a8499e25446c887 100644 (file)
@@ -6,7 +6,7 @@
 #include "thread.h"
 #endif
 
-int CALL01(___Object______hashCode____, struct ___Object___ * ___this___) {
+int CALL01(___Object______nativehashCode____, struct ___Object___ * ___this___) {
   return (int) VAR(___this___);
 }
 
index 73e201d81f00f81e3b44511a62cd54ab4e7cd956..f0d95d579745debd89faa11ab360751b3fb79f55 100644 (file)
@@ -3,8 +3,7 @@
 #include "runtime.h"
 #include "structdefs.h"
 
-int CALL01(___Object______hashCode____, struct ___Object___ * ___this___);
-int CALL01(___Object______getType____, struct ___Object___ * ___this___);
+int CALL01(___Object______nativehashCode____, struct ___Object___ * ___this___);int CALL01(___Object______getType____, struct ___Object___ * ___this___);
 #ifdef THREADS
 int CALL01(___Object______MonitorEnter____, struct ___Object___ * ___this___);
 int CALL01(___Object______MonitorExit____, struct ___Object___ * ___this___);
index 360db1329c47bbbda8ce7810f02c95c8be97a139..542f2deed8c455f7ac96c27fddca3d23e7fafe88 100644 (file)
@@ -19,9 +19,20 @@ int CALL24(___Socket______nativeConnect____I__AR_B_I, int ___fd___, int ___port_
   sin.sin_family= AF_INET;
   sin.sin_port=htons(___port___);
   sin.sin_addr.s_addr=htonl(*(int *)(((char *)&VAR(___address___)->___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;
 
index 7c22e069e9cef3268b1bb92874764756f52bafbd..5f34adf6187ce58c6257542deb0143cd5a75e4e8 100644 (file)
@@ -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;