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;
}
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 */
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 */
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];
}
public StringBuffer() {
value=new char[16];//16 is DEFAULTSIZE
count=0;
- offset=0;
}
public int length() {
}
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;
}
private static void staticStart(Thread t) {
t.run();
}
+
+ public native static void sleep(long millis);
public void run() {}
#include "thread.h"
#endif
-int CALL01(___Object______hashCode____, struct ___Object___ * ___this___) {
+int CALL01(___Object______nativehashCode____, struct ___Object___ * ___this___) {
return (int) VAR(___this___);
}
#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___);
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;
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;