|
From: | Bryce McKinlay |
Subject: | Re: debug output problem in ObjectInputStream |
Date: | Wed, 03 Apr 2002 18:42:29 +1200 |
User-agent: | Mozilla/5.0 (X11; U; Linux i686; en-US; rv:0.9.7) Gecko/20011221 |
Per Bothner wrote:
Having dumpElement[ln] as separate methods has the advantage that it could over overridden, but it seems like poinles generality. So if we want to keep the debugging printout, I suggest: if (Configuration.DEBUG && dump) for (int i=0, len=Array.getLength(array); i < len; i++) System.out.println(" ELEMENT[" + i + "]=" + Array.get(array, i)); This makes it possible for a compiler to do the optimization tomultiple print calls that my patch does.
I was originally hoping that the dumpElement() methods would get inlined and the compiler would figure out that the code could be removed, but you're right in that even if inlining worked properly the arguments would still have to be evaluated unless it could also figure out that the StringBuffer methods etc had no side-effects.
I agree that we should put the "if (Configuration.DEBUG ..." at the call site to fix this. However, fixing this doesn't really help our extremely crap serialization performance. eg the attached test runs more than 45X slower with GCJ than JDK 1.4! Serialization needs some work...
regards Bryce.
import java.util.*; import java.io.*; public class SerTest3 { static void showUsage() { System.err.println("Usage: SerTest3 <read|write>"); System.exit(1); } public static void main(String[] args) throws IOException, FileNotFoundException, ClassNotFoundException { if (args.length == 0) showUsage(); HashMap hm = null; long start = System.currentTimeMillis(); if (args[0].equals("write")) { hm = makeHugeHashMap(); System.out.println ("map created, writing it out..."); ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream("test.ser")); out.writeObject(hm); out.close(); } else if (args[0].equals("read")) { ObjectInputStream in = new ObjectInputStream(new FileInputStream("test.ser")); hm = (HashMap) in.readObject(); } else showUsage(); System.out.println(hm.hashCode()); System.out.println(System.currentTimeMillis() - start + "ms elapsed."); } static HashMap makeHugeHashMap() { HashMap hm = new HashMap(); for (int i=0; i < 200; i++) { ArrayList al = new ArrayList(); for (int j=0; j < 1000; j++) { al.add (Integer.toString(i - j)); } Integer integer = new Integer(i); hm.put(integer, al); } return hm; } }
[Prev in Thread] | Current Thread | [Next in Thread] |