From 87fa4df683fec0561f3036e3f50eab0809c51309 Mon Sep 17 00:00:00 2001 From: yeom Date: Wed, 27 Apr 2011 18:16:03 +0000 Subject: [PATCH] attempts to have ssjava's own class library. starting from tiny class library: Object, String, Enumeratioin, System. the beginning seems to be humble, but the future will be prosperous :) --- .../src/ClassLibrary/SSJava/Enumeration.java | 12 + Robust/src/ClassLibrary/SSJava/Object.java | 17 + Robust/src/ClassLibrary/SSJava/String.java | 517 ++++++++++++++++++ Robust/src/ClassLibrary/SSJava/System.java | 91 +++ Robust/src/buildscript | 13 + 5 files changed, 650 insertions(+) create mode 100644 Robust/src/ClassLibrary/SSJava/Enumeration.java create mode 100644 Robust/src/ClassLibrary/SSJava/Object.java create mode 100644 Robust/src/ClassLibrary/SSJava/String.java create mode 100644 Robust/src/ClassLibrary/SSJava/System.java diff --git a/Robust/src/ClassLibrary/SSJava/Enumeration.java b/Robust/src/ClassLibrary/SSJava/Enumeration.java new file mode 100644 index 00000000..ac612421 --- /dev/null +++ b/Robust/src/ClassLibrary/SSJava/Enumeration.java @@ -0,0 +1,12 @@ +public class Enumeration { + + public Enumeration(){} + + public boolean hasMoreElements() { + return false; + } + + public Object nextElement() { + return null; + } +} diff --git a/Robust/src/ClassLibrary/SSJava/Object.java b/Robust/src/ClassLibrary/SSJava/Object.java new file mode 100644 index 00000000..e509356b --- /dev/null +++ b/Robust/src/ClassLibrary/SSJava/Object.java @@ -0,0 +1,17 @@ +public class Object { + public native int hashCode(); + + /* DON'T USE THIS METHOD UNLESS NECESSARY */ + /* WE WILL DEPRECATE IT AS SOON AS INSTANCEOF WORKS */ + public native int getType(); + + public String toString() { + return "Object"+hashCode(); + } + + public boolean equals(Object o) { + if (o==this) + return true; + return false; + } +} diff --git a/Robust/src/ClassLibrary/SSJava/String.java b/Robust/src/ClassLibrary/SSJava/String.java new file mode 100644 index 00000000..24a87cf0 --- /dev/null +++ b/Robust/src/ClassLibrary/SSJava/String.java @@ -0,0 +1,517 @@ +public class String { + char value[]; + int count; + int offset; + private int cachedHashcode; + + private String() { + } + + public String(char c) { + char[] str = new char[1]; + str[0] = c; + String(str); + } + + public String(char str[]) { + char charstr[]=new char[str.length]; + for(int i=0; i(str.length-offset)) + length=str.length-offset; + char charstr[]=new char[length]; + for(int i=0; i(str.length)) + length=str.length; + char charstr[]=new char[length]; + for(int i=0; i(str.length-offset)) + length=str.length-offset; + char charstr[]=new char[length]; + for(int i=0; ithis.count||endIndex>this.count||beginIndex>endIndex) { + // FIXME + System.printString("Index error: "+beginIndex+" "+endIndex+" "+count+"\n"+this); + } + str.value=this.value; + str.count=endIndex-beginIndex; + str.offset=this.offset+beginIndex; + return str; + } + + public String subString(int beginIndex) { + return this.subString(beginIndex, this.count); + } + + public int lastindexOf(int ch) { + return this.lastindexOf(ch, count - 1); + } + + public int lastIndexOf(char ch) { + return this.lastindexOf((int)ch, count - 1); + } + + public static String concat2(String s1, String s2) { + if (s1==null) + return "null".concat(s2); + else + return s1.concat(s2); + } + + public String concat(String str) { + String newstr=new String(); + newstr.count=this.count+str.count; + char charstr[]=new char[newstr.count]; + newstr.value=charstr; + newstr.offset=0; + for(int i=0; i0; i--) + if (this.charAt(i)==ch) + return i; + return -1; + } + + public String replace(char oldch, char newch) { + char[] buffer=new char[count]; + for(int i=0; i='a'&&x<='z') { + x=(char) ((x-'a')+'A'); + } + buffer[i]=x; + } + return new String(buffer); + } + + public String toLowerCase() { + char[] buffer=new char[count]; + for(int i=0; i='A'&&x<='Z') { + x=(char) ((x-'A')+'a'); + } + buffer[i]=x; + } + return new String(buffer); + } + + public int indexOf(int ch) { + return this.indexOf(ch, 0); + } + + public int indexOf(int ch, int fromIndex) { + for(int i=fromIndex; ifromIndex) + k=fromIndex; + for(; k>=0; k--) { + if (regionMatches(k, str, 0, str.count)) + return k; + } + return -1; + } + + public int lastIndexOf(String str) { + return lastIndexOf(str, count-str.count); + } + + public boolean startsWith(String str) { + return regionMatches(0, str, 0, str.count); + } + + public boolean startsWith(String str, int toffset) { + return regionMatches(toffset, str, 0, str.count); + } + + public boolean regionMatches(int toffset, String other, int ooffset, int len) { + if (toffset<0 || ooffset <0 || (toffset+len)>count || (ooffset+len)>other.count) + return false; + for(int i=0; i count) || (srcBegin > srcEnd)) { + // FIXME + System.printString("Index error: "+srcBegin+" "+srcEnd+" "+count+"\n"+this); + System.exit(-1); + } + int len = srcEnd - srcBegin; + int j = dstBegin; + for(int i=srcBegin; i='a'&&l<='z') + l=(char)((l-'a')+'A'); + if (r>='a'&&r<='z') + r=(char)((r-'a')+'A'); + if (l!=r) + return false; + } + return true; + } +/* + public Vector split() { + Vector splitted = new Vector(); + int i; + int cnt =0; + + // skip first spaces + for(i = 0; i< count;i++) { + if(value[i+offset] != '\n' && value[i+offset] != '\t' && value[i+offset] != ' ') + break; + } + + int oldi=i; + + while(i 0) || (len < count)) ? substring(st, len) : this; + } + + public boolean matches(String regex) { + System.println("String.matches() is not fully supported"); + return this.equals(regex); + } +} diff --git a/Robust/src/ClassLibrary/SSJava/System.java b/Robust/src/ClassLibrary/SSJava/System.java new file mode 100644 index 00000000..f02562b1 --- /dev/null +++ b/Robust/src/ClassLibrary/SSJava/System.java @@ -0,0 +1,91 @@ +public class System { + public static void printInt(int x) { + String s=String.valueOf(x); + printString(s); + } + + public static native void gc(); + + public static native long currentTimeMillis(); + + public static native long microTimes(); + + public static native long getticks(); + + public static native void printString(String s); + + public static void println(String s) { + System.printString(s+"\n"); + } + + public static void println(Object o) { + System.printString(""+o+"\n"); + } + + public static void println(int o) { + System.printString(""+o+"\n"); + } + + public static void println(double o) { + System.printString(""+o+"\n"); + } + + public static void println(long o) { + System.printString(""+o+"\n"); + } + + public static void println() { + System.printString("\n"); + } + + public static void print(String s) { + System.printString(s); + } + + public static void print(Object o) { + System.printString(""+o); + } + + public static void print(int o) { + System.printString(""+o); + } + + public static void print(double o) { + System.printString(""+o); + } + + public static void print(long o) { + System.printString(""+o); + } + + public static void error() { + System.printString("Error (Use Breakpoint on ___System______error method for more information!)\n"); + } + + public static native void exit(int status); + + public static native void printI(int status); + + public static native void clearPrefetchCache(); + + public static native void rangePrefetch(Object o, short[] offsets); + + public static native void deepArrayCopy(Object dst, Object src); + + public static native void Assert(boolean status); + + /* Only used for microbenchmark testing of SingleTM version */ + public static native void logevent(int event); + public static native void logevent(); + + /* Only used for microbenchmark testing of SingleTM version */ + public static native void initLog(); + + public static native void flushToFile(int threadid); + /* Only used for microbenchmark testing of SingleTM version */ + + public static native void arraycopy(Object src, int srcPos, Object dst, int destPos, int length); + + // for disjoint reachability analysis + public static void genReach(); +} diff --git a/Robust/src/buildscript b/Robust/src/buildscript index 3c8bb198..b5d760d2 100755 --- a/Robust/src/buildscript +++ b/Robust/src/buildscript @@ -601,6 +601,10 @@ elif [[ $1 = '-ooodebug-disable-task-mem-pool' ]] then EXTRAOPTIONS="$EXTRAOPTIONS -DOOO_DISABLE_TASKMEMPOOL" +elif [[ $1 = '-ssjava' ]] +then +SSJAVA=true + elif [[ $1 = '-mempool-detect-misuse' ]] then EXTRAOPTIONS="$EXTRAOPTIONS -DMEMPOOL_DETECT_MISUSE" @@ -775,6 +779,9 @@ elif $MGCFLAG then #base multicore gc files JAVAOPTS="$JAVAOPTS -classlibrary $ROBUSTROOT/ClassLibrary/MGC/ -classlibrary $ROBUSTROOT/ClassLibrary/MGC/gnu/" +elif $SSJAVA +then +JAVAOPTS="$JAVAOPTS -classlibrary $ROBUSTROOT/ClassLibrary/SSJava" else if $RECOVERFLAG then @@ -811,6 +818,12 @@ if ! ${ROBUSTROOT}/ourjava -Xms50m -Xmx1500m $JAVAFORWARDOPTS -classpath $ROBUST -classlibrary $ROBUSTROOT/ClassLibrary/gnu/ $SRCFILES then exit $? fi +elif $SSJAVA +then +if ! ${ROBUSTROOT}/ourjava -Xms50m -Xmx1500m $JAVAFORWARDOPTS -classpath $ROBUSTROOT/../cup/:$ROBUSTROOT Main.Main -dir $BUILDDIR -precise \ +$JAVAOPTS $SRCFILES +then exit $? +fi else #if ! ${ROBUSTROOT}/ourjava -Xms5m -Xmx100m $JAVAFORWARDOPTS -classpath $ROBUSTROOT/../cup/:$ROBUSTROOT Main.Main -classlibrary \ if $MGCINTELFLAG -- 2.34.1