Hi All,
Trying to request a review again with different file types

hopefully it will get through the filter

Regards
Mike



>________________________________
>From: Mike Skells <mike.ske...@talk21.com>
>To: Mike Skells <mike.ske...@talk21.com>; Alan Bateman 
><alan.bate...@oracle.com>
>Cc: Core-Libs-Dev <core-libs-dev@openjdk.java.net>
>Sent: Monday, 10 October 2011, 9:17
>Subject: Re: Patch to Throwable and StackTraceElement (reduced CPU usage)
>
>
>The patch (.patch) and results (.xlsx) seem to be filtered out. What is the 
>best format to submit files to avoid list filtering attachments?
>
>
>
>>________________________________
>>From: Mike Skells <mike.ske...@talk21.com>
>>To: Alan Bateman <alan.bate...@oracle.com>
>>Cc: Core-Libs-Dev <core-libs-dev@openjdk.java.net>
>>Sent: Monday, 10 October 2011, 8:53
>>Subject: Re: Patch to Throwable and StackTraceElement (reduced CPU usage)
>>
>>Doh,
>>This time with the patches, test code, and CPU usage stats attached
>>
>>Regard
>>
>>Mike 
>>
>>
>>
>>>________________________________
>>>From: Alan Bateman <alan.bate...@oracle.com>
>>>To: mike.ske...@talk21.com
>>>Cc: Core-Libs-Dev <core-libs-dev@openjdk.java.net>
>>>Sent: Monday, 10 October 2011, 0:15
>>>Subject: Re: Patch to Throwable and StackTraceElement (reduced CPU usage)
>>>
>>>mike.ske...@talk21.com wrote:
>>>> :
>>>>
>>>>
>>>> I include the patch, a micro-benchmark and the results of the 
>>>> micro-benchmark which show an improvement of 80% throughput (ie it is 
>>>> almost twice as fast)
>>>>  
>>>Mike - I don't think there is a patch attached to your mail.
>>>
>>>
>>>
>>
>>
>
>
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package compare;

import java.io.PrintWriter;
import java.io.StringWriter;

/**
 *
 * @author mike
 */
public class TestThrow {

    public static void main(String[] args) throws InterruptedException {
        try {
            generateThrow1(5);
        } catch (Throwable t) {
            int count = 100;
            StringWriter sw = new StringWriter(20000);
            PrintWriter pw = new PrintWriter(sw);

            System.out.println(sw);
            for (int j = 0; j < 100; j++) {
                long total = 0;
                for (int i = 0; i < count; i++) {
                    sw.getBuffer().setLength(0);
                    long start = System.nanoTime();
                    t.printStackTrace(pw);
                    long end = System.nanoTime();
                    total += end - start;
                }
                System.out.println((total / count));
                
            }



        }
    }

    private static void generateThrow1(int depth) {
        generateThrow2(depth);
    }

    private static void generateThrow2(int depth) {
        generateThrow3(depth);
    }

    private static void generateThrow3(int depth) {
        generateThrow4(depth);
    }

    private static void generateThrow4(int depth) {
        generateThrow5(depth);
    }

    private static void generateThrow5(int depth) {
        if (depth == 0) {
            throw new RuntimeException("some text ..." + depth);
        } else {
            try {
                generateThrow1(depth - 1);
            } catch (RuntimeException x) {
                throw new RuntimeException("some text ..." + depth, x);
            }
        }
    }
}
# HG changeset patch
# User mskells
# Date 1317936816 -3600
# Node ID 5c074aac92279aa9b7f984fde9a2de4b0a3fe48b
# Parent  39d6a02582a20f56c9183ed4e8d1e0caf46d7271
Reduction in StringBuffer usage

diff -r 39d6a02582a2 -r 5c074aac9227 
src/share/classes/java/lang/StackTraceElement.java
--- a/src/share/classes/java/lang/StackTraceElement.java        Thu Jun 16 
22:12:17 2011 +0100
+++ b/src/share/classes/java/lang/StackTraceElement.java        Thu Oct 06 
22:33:36 2011 +0100
@@ -169,11 +169,21 @@
      * @see    Throwable#printStackTrace()
      */
     public String toString() {
-        return getClassName() + "." + methodName +
-            (isNativeMethod() ? "(Native Method)" :
-             (fileName != null && lineNumber >= 0 ?
-              "(" + fileName + ":" + lineNumber + ")" :
-              (fileName != null ?  "("+fileName+")" : "(Unknown Source)")));
+        StringBuilder sb = new StringBuilder();
+        appendTo(sb);
+        return sb.toString();
+    }
+    void appendTo(StringBuilder sb) {
+        sb.append(getClassName()).append('.').append(methodName);
+        if (isNativeMethod()) {
+            sb.append("(Native Method)");
+        } else if (fileName != null && lineNumber >= 0) {
+            
sb.append('(').append(fileName).append(':').append(lineNumber).append(')');
+        } else if (fileName != null) {
+            sb.append('(').append(fileName).append(')');
+        } else {
+            sb.append("(Unknown Source)");
+        }
     }
 
     /**
diff -r 39d6a02582a2 -r 5c074aac9227 src/share/classes/java/lang/Throwable.java
--- a/src/share/classes/java/lang/Throwable.java        Thu Jun 16 22:12:17 
2011 +0100
+++ b/src/share/classes/java/lang/Throwable.java        Thu Oct 06 22:33:36 
2011 +0100
@@ -586,22 +586,28 @@
         Set<Throwable> dejaVu =
             Collections.newSetFromMap(new IdentityHashMap<Throwable, 
Boolean>());
         dejaVu.add(this);
+        StringBuilder sb = new StringBuilder("\tat ");
 
         synchronized (s.lock()) {
             // Print our stack trace
             s.println(this);
+            int length = sb.length();
+            
             StackTraceElement[] trace = getOurStackTrace();
-            for (StackTraceElement traceElement : trace)
-                s.println("\tat " + traceElement);
+            for (StackTraceElement traceElement : trace) {
+                sb.setLength(length);
+                traceElement.appendTo(sb);
+                s.println(sb);
+            }
 
             // Print suppressed exceptions, if any
             for (Throwable se : getSuppressed())
-                se.printEnclosedStackTrace(s, trace, SUPPRESSED_CAPTION, "\t", 
dejaVu);
+                se.printEnclosedStackTrace(s, sb, trace, SUPPRESSED_CAPTION, 
"\t", dejaVu);
 
             // Print cause, if any
             Throwable ourCause = getCause();
             if (ourCause != null)
-                ourCause.printEnclosedStackTrace(s, trace, CAUSE_CAPTION, "", 
dejaVu);
+                ourCause.printEnclosedStackTrace(s, sb, trace, CAUSE_CAPTION, 
"", dejaVu);
         }
     }
 
@@ -609,16 +615,15 @@
      * Print our stack trace as an enclosed exception for the specified
      * stack trace.
      */
-    private void printEnclosedStackTrace(PrintStreamOrWriter s,
+    private void printEnclosedStackTrace(PrintStreamOrWriter s, StringBuilder 
sb,
                                          StackTraceElement[] enclosingTrace,
                                          String caption,
                                          String prefix,
                                          Set<Throwable> dejaVu) {
         assert Thread.holdsLock(s.lock());
-        if (dejaVu.contains(this)) {
+        if (!dejaVu.add(this)) {
             s.println("\t[CIRCULAR REFERENCE:" + this + "]");
         } else {
-            dejaVu.add(this);
             // Compute number of frames in common between this and enclosing 
trace
             StackTraceElement[] trace = getOurStackTrace();
             int m = trace.length - 1;
@@ -628,22 +633,40 @@
             }
             int framesInCommon = trace.length - 1 - m;
 
+            
+            
             // Print our stack trace
-            s.println(prefix + caption + this);
-            for (int i = 0; i <= m; i++)
-                s.println(prefix + "\tat " + trace[i]);
-            if (framesInCommon != 0)
-                s.println(prefix + "\t... " + framesInCommon + " more");
+            sb.setLength(0);
+            sb.append(prefix).append(caption).append(this);
+            s.println(sb);
+            
+            sb.setLength(prefix.length());
+            sb.append("\tat ");
+            final int length = sb.length();
+            
+            for (int i = 0; i <= m; i++) {
+                sb.setLength(length);
+                trace[i].appendTo(sb);
+                s.println(sb);
+            }
+            if (framesInCommon != 0) {
+                sb.setLength(0);
+                sb.append(prefix).append("\t... 
").append(framesInCommon).append(" more");
+                s.println(sb);
+            }
 
             // Print suppressed exceptions, if any
-            for (Throwable se : getSuppressed())
-                se.printEnclosedStackTrace(s, trace, SUPPRESSED_CAPTION,
-                                           prefix +"\t", dejaVu);
-
+            Throwable[] suppressed = getSuppressed();
+            if (suppressed.length > 0) {
+                String nextPrefix = prefix +"\t";
+                for (Throwable se : suppressed)
+                    se.printEnclosedStackTrace(s, sb, trace, 
SUPPRESSED_CAPTION,
+                                           nextPrefix, dejaVu);
+            }
             // Print cause, if any
             Throwable ourCause = getCause();
             if (ourCause != null)
-                ourCause.printEnclosedStackTrace(s, trace, CAUSE_CAPTION, 
prefix, dejaVu);
+                ourCause.printEnclosedStackTrace(s, sb, trace, CAUSE_CAPTION, 
prefix, dejaVu);
         }
     }
 

Reply via email to