From: jzhou Date: Fri, 15 Apr 2011 00:21:15 +0000 (+0000) Subject: Change the implementation of classobj X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=99763445001075d73520e3bdd8326af43962b273;p=IRC.git Change the implementation of classobj --- diff --git a/Robust/src/ClassLibrary/MGC/gnu/PrintStreamS.java b/Robust/src/ClassLibrary/MGC/gnu/PrintStreamS.java new file mode 100644 index 00000000..6319eb10 --- /dev/null +++ b/Robust/src/ClassLibrary/MGC/gnu/PrintStreamS.java @@ -0,0 +1,660 @@ +/* PrintStream.java -- OutputStream for printing output + Copyright (C) 1998, 1999, 2001, 2003, 2004, 2005, 2006 + Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +//package java.io; + +/*import java.util.Locale; +import java.util.Formatter; + +import gnu.classpath.SystemProperties; +*/ +/* Written using "Java Class Libraries", 2nd edition, ISBN 0-201-31002-3 + * "The Java Language Specification", ISBN 0-201-63451-1 + * Status: Believed complete and correct to 1.3 + */ + +/** + * This class prints Java primitive values and object to a stream as + * text. None of the methods in this class throw an exception. However, + * errors can be detected by calling the checkError() method. + * Additionally, this stream can be designated as "autoflush" when + * created so that any writes are automatically flushed to the underlying + * output sink when the current line is terminated. + *

+ * This class converts char's into byte's using the system default encoding. + * + * @author Aaron M. Renn (arenn@urbanophile.com) + * @author Tom Tromey (tromey@cygnus.com) + * @author Andrew John Hughes (gnu_andrew@member.fsf.org) + */ +public class PrintStreamS extends PrintStream //implements Appendable +{ + /* Notice the implementation is quite similar to OutputStreamWriter. + * This leads to some minor duplication, because neither inherits + * from the other, and we want to maximize performance. */ + + // Line separator string. + private static final char[] line_separator + = {'\n'}/*SystemProperties.getProperty("line.separator", "\n").toCharArray()*/; + + /** + * This method initializes a new PrintStream object to write + * to the specified output File. Doesn't autoflush. + * + * @param file The File to write to. + * @throws FileNotFoundException if an error occurs while opening the file. + * + * @since 1.5 + */ + public PrintStreamS (File file) + //throws FileNotFoundException + { + super (file); + } + + /** + * This method initializes a new PrintStream object to write + * to the specified output File. Doesn't autoflush. + * + * @param file The File to write to. + * @param encoding The name of the character encoding to use for this + * object. + * @throws FileNotFoundException If an error occurs while opening the file. + * @throws UnsupportedEncodingException If the charset specified by + * encoding is invalid. + * + * @since 1.5 + */ + public PrintStreamS (File file, String encoding) + //throws FileNotFoundException,UnsupportedEncodingException + { + super (file, encoding); + } + + /** + * This method initializes a new PrintStream object to write + * to the specified output File. Doesn't autoflush. + * + * @param fileName The name of the File to write to. + * @throws FileNotFoundException if an error occurs while opening the file, + * + * @since 1.5 + */ + public PrintStreamS (String fileName) + //throws FileNotFoundException + { + super (fileName); + } + + /** + * This method initializes a new PrintStream object to write + * to the specified output File. Doesn't autoflush. + * + * @param fileName The name of the File to write to. + * @param encoding The name of the character encoding to use for this + * object. + * @throws FileNotFoundException if an error occurs while opening the file. + * @throws UnsupportedEncodingException If the charset specified by + * encoding is invalid. + * + * @since 1.5 + */ + public PrintStreamS (String fileName, String encoding) + //throws FileNotFoundException,UnsupportedEncodingException + { + super (fileName); + } + + /** + * This method initializes a new PrintStream object to write + * to the specified output sink. Doesn't autoflush. + * + * @param out The OutputStream to write to. + */ + public PrintStreamS (OutputStream out) + { + super (out); + } + + /** + * This method initializes a new PrintStream object to write + * to the specified output sink. This constructor also allows "auto-flush" + * functionality to be specified where the stream will be flushed after + * every print or println call, when the + * write methods with array arguments are called, or when a + * single new-line character is written. + *

+ * + * @param out The OutputStream to write to. + * @param auto_flush true to flush the stream after every + * line, false otherwise + */ + public PrintStreamS (OutputStream out, boolean auto_flush) + { + super (out, auto_flush); + } + + /** + * This method initializes a new PrintStream object to write + * to the specified output sink. This constructor also allows "auto-flush" + * functionality to be specified where the stream will be flushed after + * every print or println call, when the + * write methods with array arguments are called, or when a + * single new-line character is written. + *

+ * + * @param out The OutputStream to write to. + * @param auto_flush true to flush the stream after every + * line, false otherwise + * @param encoding The name of the character encoding to use for this + * object. + */ + public PrintStreamS (OutputStream out, boolean auto_flush, String encoding) + //throws UnsupportedEncodingException + { + super (out, auto_flush, encoding); + } + + /** + * This method checks to see if an error has occurred on this stream. Note + * that once an error has occurred, this method will continue to report + * true forever for this stream. Before checking for an + * error condition, this method flushes the stream. + * + * @return true if an error has occurred, + * false otherwise + */ + public boolean checkError () + { + flush (); + return error_occurred; + } + + /** + * This method can be called by subclasses to indicate that an error + * has occurred and should be reported by checkError. + */ + protected void setError () + { + error_occurred = true; + } + + /** + * This method closes this stream and all underlying streams. + */ + public void close () + { + /*try + { + flush(); + out.close(); + } + catch (InterruptedIOException iioe) + { + Thread.currentThread().interrupt(); + } + catch (IOException e) + { + setError (); + }*/ + } + + /** + * This method flushes any buffered bytes to the underlying stream and + * then flushes that stream as well. + */ + public void flush () + { + /*try + { + out.flush(); + } + catch (InterruptedIOException iioe) + { + Thread.currentThread().interrupt(); + } + catch (IOException e) + { + setError (); + }*/ + } + + private synchronized void print (String str, boolean println) + { + /*try + { + writeChars(str, 0, str.length()); + if (println) + writeChars(line_separator, 0, line_separator.length); + if (auto_flush) + flush(); + } + catch (InterruptedIOException iioe) + { + Thread.currentThread().interrupt(); + } + catch (IOException e) + { + setError (); + }*/ + if(println) { + System.out.println("=== " + str); + } else { + System.out.print("=== " + str); + } + } + + private synchronized void print (char[] chars, int pos, int len, + boolean println) + { + /*try + { + writeChars(chars, pos, len); + if (println) + writeChars(line_separator, 0, line_separator.length); + if (auto_flush) + flush(); + } + catch (InterruptedIOException iioe) + { + Thread.currentThread().interrupt(); + } + catch (IOException e) + { + setError (); + }*/ + String str = new String(chars, pos, len); + if(println) { + System.out.println("=== " + str); + } else { + System.out.print("=== " + str); + } + } + + private void writeChars(char[] buf, int offset, int count) + //throws IOException + { + byte[] bytes = (new String(buf, offset, count)).getBytes(); + write(bytes, 0, bytes.length); + } + + private void writeChars(String str, int offset, int count) + //throws IOException + { + byte[] bytes = str.substring(offset, offset+count).getBytes(); + write(bytes, 0, bytes.length); + } + + /** + * This methods prints a boolean value to the stream. true + * values are printed as "true" and false values are printed + * as "false". + * + * @param bool The boolean value to print + */ + public void print (boolean bool) + { + System.out.print("=== " + String.valueOf(bool)); + } + + /** + * This method prints an integer to the stream. The value printed is + * determined using the String.valueOf() method. + * + * @param inum The int value to be printed + */ + public void print (int inum) + { + System.out.print("=== " + inum); + } + + /** + * This method prints a long to the stream. The value printed is + * determined using the String.valueOf() method. + * + * @param lnum The long value to be printed + */ + public void print (long lnum) + { + System.out.print("=== " + lnum); + } + + /** + * This method prints a float to the stream. The value printed is + * determined using the String.valueOf() method. + * + * @param fnum The float value to be printed + */ + public void print (float fnum) + { + System.out.print("=== " + fnum); + } + + /** + * This method prints a double to the stream. The value printed is + * determined using the String.valueOf() method. + * + * @param dnum The double value to be printed + */ + public void print (double dnum) + { + System.out.print("=== " + dnum); + } + + /** + * This method prints an Object to the stream. The actual + * value printed is determined by calling the String.valueOf() + * method. + * + * @param obj The Object to print. + */ + public void print (Object obj) + { + System.out.print("=== " + (obj == null ? "null" : obj.toString())); + } + + /** + * This method prints a String to the stream. The actual + * value printed depends on the system default encoding. + * + * @param str The String to print. + */ + public void print (String str) + { + System.out.print("=== " + (str == null ? "null" : str)); + } + + /** + * This method prints a char to the stream. The actual value printed is + * determined by the character encoding in use. + * + * @param ch The char value to be printed + */ + public synchronized void print (char ch) + { + String str = new String(ch); + System.out.print("=== " + str); + } + + /** + * This method prints an array of characters to the stream. The actual + * value printed depends on the system default encoding. + * + * @param charArray The array of characters to print. + */ + public void print (char[] charArray) + { + String str = new String(charArray, 0, charArray.length); + System.out.print("=== " + str); + } + + /** + * This method prints a line separator sequence to the stream. The value + * printed is determined by the system property

line.separator + * and is not necessarily the Unix '\n' newline character. + */ + public void println () + { + System.out.println("=== "); + } + + /** + * This methods prints a boolean value to the stream. true + * values are printed as "true" and false values are printed + * as "false". + *

+ * This method prints a line termination sequence after printing the value. + * + * @param bool The boolean value to print + */ + public void println (boolean bool) + { + System.out.println("=== " + String.valueOf(bool)); + } + + /** + * This method prints an integer to the stream. The value printed is + * determined using the String.valueOf() method. + *

+ * This method prints a line termination sequence after printing the value. + * + * @param inum The int value to be printed + */ + public void println (int inum) + { + System.out.println("=== " + inum); + } + + /** + * This method prints a long to the stream. The value printed is + * determined using the String.valueOf() method. + *

+ * This method prints a line termination sequence after printing the value. + * + * @param lnum The long value to be printed + */ + public void println (long lnum) + { + System.out.println("=== " + lnum); + } + + /** + * This method prints a float to the stream. The value printed is + * determined using the String.valueOf() method. + *

+ * This method prints a line termination sequence after printing the value. + * + * @param fnum The float value to be printed + */ + public void println (float fnum) + { + System.out.println("=== " + fnum); + } + + /** + * This method prints a double to the stream. The value printed is + * determined using the String.valueOf() method. + *

+ * This method prints a line termination sequence after printing the value. + * + * @param dnum The double value to be printed + */ + public void println (double dnum) + { + System.out.println("=== " + dnum); + } + + /** + * This method prints an Object to the stream. The actual + * value printed is determined by calling the String.valueOf() + * method. + *

+ * This method prints a line termination sequence after printing the value. + * + * @param obj The Object to print. + */ + public void println (Object obj) + { + System.out.println("=== " + (obj == null ? "null" : obj.toString())); + } + + /** + * This method prints a String to the stream. The actual + * value printed depends on the system default encoding. + *

+ * This method prints a line termination sequence after printing the value. + * + * @param str The String to print. + */ + public void println (String str) + { + System.out.println ("=== " + (str == null ? "null" : str)); + } + + /** + * This method prints a char to the stream. The actual value printed is + * determined by the character encoding in use. + *

+ * This method prints a line termination sequence after printing the value. + * + * @param ch The char value to be printed + */ + public synchronized void println (char ch) + { + String str = new String(ch); + System.out.println("=== " + str); + } + + /** + * This method prints an array of characters to the stream. The actual + * value printed depends on the system default encoding. + *

+ * This method prints a line termination sequence after printing the value. + * + * @param charArray The array of characters to print. + */ + public void println (char[] charArray) + { + String str = new String(charArray, 0, charArray.length); + System.out.println("=== " + str); + } + + /** + * This method writes a byte of data to the stream. If auto-flush is + * enabled, printing a newline character will cause the stream to be + * flushed after the character is written. + * + * @param oneByte The byte to be written + */ + public void write (int oneByte) + { + /*try + { + out.write (oneByte & 0xff); + + if (auto_flush && (oneByte == '\n')) + flush (); + } + catch (InterruptedIOException iioe) + { + Thread.currentThread ().interrupt (); + } + catch (IOException e) + { + setError (); + }*/ + System.out.print("=== " + oneByte); + } + + /** + * This method writes len bytes from the specified array + * starting at index offset into the array. + * + * @param buffer The array of bytes to write + * @param offset The index into the array to start writing from + * @param len The number of bytes to write + */ + public void write (byte[] buffer, int offset, int len) + { + /*try + { + out.write (buffer, offset, len); + + if (auto_flush) + flush (); + } + catch (InterruptedIOException iioe) + { + Thread.currentThread ().interrupt (); + } + catch (IOException e) + { + setError (); + }*/ + String str = new String(buffer, offset,len); + System.out.print("=== " + str); + } + + /** @since 1.5 */ + public PrintStream append(char c) + { + System.out.print("=== " + c); + return this; + } + + /** @since 1.5 */ + /*public PrintStream append(CharSequence cs) + { + print(cs == null ? "null" : cs.toString()); + return this; + }*/ + + /** @since 1.5 */ + /*public PrintStream append(CharSequence cs, int start, int end) + { + print(cs == null ? "null" : cs.subSequence(start, end).toString()); + return this; + }*/ + + /** @since 1.5 */ + /*public PrintStream printf(String format, Object... args) + { + return this; //format(format, args); + }*/ + + /** @since 1.5 */ + /*public PrintStream printf(Locale locale, String format, Object... args) + { + return format(locale, format, args); + }*/ + + /** @since 1.5 */ + /*public PrintStream format(String format, Object... args) + { + return this; //format(Locale.getDefault(), format, args); + }*/ + + /** @since 1.5 */ + /*public PrintStream format(Locale locale, String format, Object... args) + { + Formatter f = new Formatter(this, locale); + f.format(format, args); + return this; + }*/ +} // class PrintStream diff --git a/Robust/src/IR/Flat/BuildCode.java b/Robust/src/IR/Flat/BuildCode.java index 4cd60492..cd514fe4 100644 --- a/Robust/src/IR/Flat/BuildCode.java +++ b/Robust/src/IR/Flat/BuildCode.java @@ -152,6 +152,7 @@ public class BuildCode { outglobaldefs.println("struct global_defs_t {"); outglobaldefs.println(" int size;"); outglobaldefs.println(" void * next;"); + outglobaldefs.println(" struct ArrayObject * classobjs;"); outglobaldefsprim.println("#ifndef __GLOBALDEFPRIM_H_"); outglobaldefsprim.println("#define __GLOBALDEFPRIM_H_"); outglobaldefsprim.println(""); @@ -318,19 +319,25 @@ public class BuildCode { * getClass() method. * */ protected void outputClassObjects(PrintWriter outmethod) { - // for each class, initialize its Class object - SymbolTable ctbl = this.state.getClassSymbolTable(); - for(Iterator it_classes = ctbl.getDescriptorsIterator();it_classes.hasNext();) { - ClassDescriptor t_cd = (ClassDescriptor)it_classes.next(); - outmethod.println(" {"); - - if ((GENERATEPRECISEGC) || (this.state.MULTICOREGC)) { - outmethod.println(" struct garbagelist dummy={0,NULL};"); - outmethod.println(" global_defs_p->"+t_cd.getSafeSymbol()+"classobj = allocate_new(&dummy, " + typeutil.getClass(TypeUtil.ObjectClass).getId() + ");"); - } else - outmethod.println(" global_defs_p->"+t_cd.getSafeSymbol()+"classobj = allocate_new("+typeutil.getClass(TypeUtil.ObjectClass).getId() + ");"); - outmethod.println(" }"); + // create a global classobj array + outmethod.println(" {"); + outmethod.println(" int i = 0;"); + if ((GENERATEPRECISEGC) || (this.state.MULTICOREGC)) { + outmethod.println(" struct garbagelist dummy={0,NULL};"); + outmethod.println(" global_defs_p->classobjs = allocate_newarray(&dummy, OBJECTARRAYTYPE, " + + (state.numClasses()+state.numArrays()+state.numInterfaces()) + ");"); + } else { + outmethod.println(" global_defs_p->classobjs = allocate_newarray(OBJECTARRAYTYPE, " + + (state.numClasses()+state.numArrays()+state.numInterfaces()) + ");"); } + outmethod.println(" for(i = 0; i < " + (state.numClasses()+state.numArrays()+state.numInterfaces()) + "; i++) {"); + if ((GENERATEPRECISEGC) || (this.state.MULTICOREGC)) { + outmethod.println(" ((void **)(((char *) &(global_defs_p->classobjs->___length___))+sizeof(int)))[i] = allocate_new(NULL, " +typeutil.getClass(TypeUtil.ObjectClass).getId() + ");"); + } else { + outmethod.println(" ((void **)(((char *) &(global_defs_p->classobjs->___length___))+sizeof(int)))[i] = allocate_new(" +typeutil.getClass(TypeUtil.ObjectClass).getId() + ");"); + } + outmethod.println(" }"); + outmethod.println(" }"); } /* This code just generates the main C method for java programs. @@ -595,10 +602,6 @@ public class BuildCode { // static blocks have been executed outglobaldefsprim.println(" int "+cn.getSafeSymbol()+"static_block_exe_flag;"); } - - // for each class, create a global object - outglobaldefs.println(" struct ___Object___ *"+cn.getSafeSymbol()+"classobj;"); - globaldefscount++; } outclassdefs.println(""); //Print out definition for array type @@ -2376,7 +2379,7 @@ public class BuildCode { // call MonitorEnter/MonitorExit on a class obj if ((GENERATEPRECISEGC) || (this.state.MULTICOREGC)) { output.print(" struct "+cn.getSafeSymbol()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()+"_params __parameterlist__={"); - output.println("1," + localsprefixaddr + ", global_defs_p->"+ fc.getThis().getType().getClassDesc().getSafeSymbol() +"classobj};"); + output.println("1," + localsprefixaddr + ", ((void **)(((char *) &(global_defs_p->classobjs->___length___))+sizeof(int)))[" + fc.getThis().getType().getClassDesc().getId() + "]};"); if(md.getSymbol().equals("MonitorEnter") && state.OBJECTLOCKDEBUG) { output.println(" "+cn.getSafeSymbol()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()+"(& __parameterlist__, monitorenterline);"); } else { @@ -2384,8 +2387,8 @@ public class BuildCode { } } else { output.println(" " + cn.getSafeSymbol()+md.getSafeSymbol()+"_" - + md.getSafeMethodDescriptor() + "((struct ___Object___*)(global_defs_p->" - + fc.getThis().getType().getClassDesc().getSafeSymbol() +"classobj));"); + + md.getSafeMethodDescriptor() + "((struct ___Object___*)(((void **)(((char *) &(global_defs_p->classobjs->___length___))+sizeof(int)))[" + + fc.getThis().getType().getClassDesc().getId() + "]));"); } output.println("}"); return; diff --git a/Robust/src/IR/Tree/SemanticCheck.java b/Robust/src/IR/Tree/SemanticCheck.java index 14c3e6dc..bf7f8f51 100644 --- a/Robust/src/IR/Tree/SemanticCheck.java +++ b/Robust/src/IR/Tree/SemanticCheck.java @@ -1217,7 +1217,7 @@ NextMethod: continue; for(int i=0; i=BYTE)&&(type<=DOUBLE)); + return (((type>=BYTE)&&(type<=DOUBLE)) || isEnum()); } public boolean isEnum() { @@ -270,7 +274,7 @@ public class TypeDescriptor extends Descriptor { } public boolean isClass() { - return type==CLASS; + return (type==CLASS && !isEnum()); } public boolean isTag() { diff --git a/Robust/src/IR/TypeUtil.java b/Robust/src/IR/TypeUtil.java index 8613bbe3..c52679db 100644 --- a/Robust/src/IR/TypeUtil.java +++ b/Robust/src/IR/TypeUtil.java @@ -310,10 +310,6 @@ NextMethod: } public boolean isSuperorType(TypeDescriptor possiblesuper, TypeDescriptor cd2) { - if(possiblesuper.isClass() && possiblesuper.class_desc.isEnum() && cd2.isInt()) { - return true; - } - if (possiblesuper.isOffset() || cd2.isOffset()) return true; //Matching type are always okay if (possiblesuper.equals(cd2)) @@ -371,8 +367,14 @@ NextMethod: possiblesuper.isFloat()||possiblesuper.isDouble())) return true; if (cd2.isInt()&&(possiblesuper.isInt()||possiblesuper.isLong()|| - possiblesuper.isFloat()||possiblesuper.isDouble())) + possiblesuper.isFloat()||possiblesuper.isDouble() + ||possiblesuper.isEnum())) return true; + if (cd2.isEnum()&&(possiblesuper.isInt()||possiblesuper.isLong()|| + possiblesuper.isFloat()||possiblesuper.isDouble())) + return true; + if(cd2.isEnum()&&possiblesuper.isEnum()&&cd2.class_desc.equals(possiblesuper.class_desc)) + return true; if (cd2.isLong()&&(possiblesuper.isLong()|| possiblesuper.isFloat()||possiblesuper.isDouble())) return true; diff --git a/Robust/src/buildscript b/Robust/src/buildscript index 6298e638..5b3a6876 100755 --- a/Robust/src/buildscript +++ b/Robust/src/buildscript @@ -932,9 +932,6 @@ cp ../Runtime/*.c ./ cp ../Runtime/*.h ./ cp ../Runtime/*.S ./ cp ../Runtime/*.s ./ -#mkdir ./coreprof -#cp ../Runtime/coreprof/*.c ./coreprof/ -#cp ../Runtime/coreprof/*.h ./coreprof/ cp $BAMBOORUNTIME/*.c ./ cp $BAMBOORUNTIME/*.h ./ cp $BAMBOORUNTIME/RAW/*.c ./ @@ -1185,9 +1182,6 @@ cp ../Runtime/ObjectHash.h ./ cp ../Runtime/Queue.h ./ cp ../Runtime/runtime.h ./ cp ../Runtime/SimpleHash.h ./ -mkdir ./coreprof -cp ../Runtime/coreprof/coreprof.c ./coreprof/ -cp ../Runtime/coreprof/coreprof.h ./coreprof/ cp $BAMBOORUNTIME/multicoretask.c ./ cp $BAMBOORUNTIME/multicoreruntime.c ./ cp $BAMBOORUNTIME/multicoremem.c ./