Hi All,
Last attempt - hopefully
with all 3 files, a patch, test case and results. The patch and results are
text format to avoid the filters on this list
Hopefully you are not all to irritated with this posting to review it :-)
Regards
Mike
>________________________________
>From: Mike Skells <mike.ske...@talk21.com>
>To: Core-Libs-Dev <core-libs-dev@openjdk.java.net>
>Sent: Monday, 10 October 2011, 22:39
>Subject: Re: Patch to Throwable and StackTraceElement (reduced CPU usage)
>
>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.
>>>>
>>>>
>>>>
>>>
>>>
>>
>>
>
>
jdk 7,,patch,,improvement
532097,,407846,,30%
320507,,335206,,-4%
216593,,197907,,9%
190965,,169199,,13%
189663,,116410,,63%
193342,,126100,,53%
189751,,115860,,64%
178320,,109064,,64%
166641,,108965,,53%
184206,,102506,,80%
144345,,99433,,45%
124943,,70944,,76%
104554,,44654,,134%
110993,,44804,,148%
117215,,50091,,134%
52642,,45423,,16%
51046,,41184,,24%
58967,,42020,,40%
52684,,42429,,24%
43411,,41553,,4%
52761,,41492,,27%
45869,,43455,,6%
55940,,41906,,33%
45611,,41132,,11%
48031,,36203,,33%
42047,,42988,,-2%
43978,,32739,,34%
51229,,31882,,61%
48835,,34577,,41%
118319,,36469,,224%
44398,,46378,,-4%
43190,,170411,,-75%
46336,,32013,,45%
42440,,30938,,37%
42965,,29748,,44%
59404,,32757,,81%
51075,,27676,,85%
82458,,25285,,226%
100563,,23822,,322%
122484,,24302,,404%
153515,,27754,,453%
98609,,29397,,235%
95821,,24044,,299%
141045,,27215,,418%
112558,,33717,,234%
43951,,25346,,73%
41975,,25909,,62%
49256,,26301,,87%
47572,,28152,,69%
42176,,27003,,56%
41257,,24526,,68%
41101,,28028,,47%
43160,,29266,,47%
53124,,27313,,95%
44201,,23665,,87%
40521,,24361,,66%
44937,,26482,,70%
43207,,44451,,-3%
42397,,25545,,66%
42039,,29072,,45%
60141,,27525,,118%
46216,,29291,,58%
42937,,51970,,-17%
48327,,25568,,89%
47054,,26390,,78%
62577,,25089,,149%
66673,,25452,,162%
129385,,26455,,389%
79855,,24656,,224%
66462,,24294,,174%
54075,,24986,,116%
99203,,25079,,296%
65513,,24527,,167%
60395,,28529,,112%
50502,,26965,,87%
82595,,23903,,246%
97140,,24822,,291%
111032,,36915,,201%
86366,,31137,,177%
98715,,32036,,208%
140232,,26138,,437%
115847,,25073,,362%
93456,,24741,,278%
103974,,26198,,297%
92590,,25846,,258%
104060,,29195,,256%
99421,,28166,,253%
93001,,29069,,220%
110939,,32432,,242%
110422,,31582,,250%
150810,,26930,,460%
49586,,25890,,92%
48745,,28346,,72%
84392,,32578,,159%
53346,,39977,,33%
102856,,29688,,246%
48843,,32783,,49%
102374,,33278,,208%
53532,,36225,,48%
63519,,45252,,40%
total,,total,,average
8950348,,4870294,,84%
,,,,
/*
* 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);
}
}