From 43b3f2c0f0b3c519e84d221d4d6a5f41b74e2ec0 Mon Sep 17 00:00:00 2001 From: Reinier Zwitserloot Date: Thu, 14 Jul 2011 14:40:57 +0200 Subject: back-in-time debugging added. Of course now 164 isn't triggering anymore :/ --- src/core/lombok/eclipse/TransformEclipseAST.java | 4 ++++ src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java | 10 +++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) (limited to 'src/core/lombok') diff --git a/src/core/lombok/eclipse/TransformEclipseAST.java b/src/core/lombok/eclipse/TransformEclipseAST.java index 7ef06fca..b362f399 100644 --- a/src/core/lombok/eclipse/TransformEclipseAST.java +++ b/src/core/lombok/eclipse/TransformEclipseAST.java @@ -23,6 +23,7 @@ package lombok.eclipse; import java.lang.reflect.Field; +import lombok.core.debug.DebugSnapshotStore; import lombok.patcher.Symbols; import org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration; @@ -126,9 +127,12 @@ public class TransformEclipseAST { // Do NOT abort if (ast.bits & ASTNode.HasAllMethodBodies) != 0 - that doesn't work. try { + DebugSnapshotStore.INSTANCE.snapshot(ast, "transform entry"); EclipseAST existing = getAST(ast, false); new TransformEclipseAST(existing).go(); + DebugSnapshotStore.INSTANCE.snapshot(ast, "transform exit"); } catch (Throwable t) { + DebugSnapshotStore.INSTANCE.snapshot(ast, "transform error: %s", t.getClass().getSimpleName()); try { String message = "Lombok can't parse this source: " + t.toString(); diff --git a/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java b/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java index 627acecb..5f6691fd 100644 --- a/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java +++ b/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java @@ -25,6 +25,7 @@ import static lombok.eclipse.Eclipse.*; import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; +import org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration; import java.lang.reflect.Modifier; import java.util.ArrayList; import java.util.Arrays; @@ -37,6 +38,7 @@ import lombok.Getter; import lombok.Lombok; import lombok.core.AnnotationValues; import lombok.core.AST.Kind; +import lombok.core.debug.DebugSnapshotStore; import lombok.core.handlers.TransformationsUtil; import lombok.eclipse.Eclipse; import lombok.eclipse.EclipseNode; @@ -464,9 +466,11 @@ public class EclipseHandlerUtil { } if (report) { - Eclipse.warning("We believe you may have just stumbled on lombok issue #164. Please " + - "report the stack trace associated with this message at:\n" + - "http://code.google.com/p/projectlombok/issues/detail?id=164", new Throwable()); + CompilationUnitDeclaration cud = (CompilationUnitDeclaration) type.top().get(); + DebugSnapshotStore.INSTANCE.print(cud, "Printing: injecting whilst scope is already built."); +// Eclipse.warning("State: " + Issue164Fixer.getState(cud) + " -- We believe you may have just stumbled on lombok issue #164. Please " + +// "report the stack trace associated with this message at:\n" + +// "http://code.google.com/p/projectlombok/issues/detail?id=164. Occurred on class " + new String(parent.name), new Throwable()); } } -- cgit From 57f7576170dd832b269d0001eb1393f1fe3f9713 Mon Sep 17 00:00:00 2001 From: Reinier Zwitserloot Date: Mon, 18 Jul 2011 22:24:08 +0200 Subject: Heh, these weren't included due to .gitignore. Fixed that, so now I can add them. --- src/core/lombok/core/debug/DebugSnapshot.java | 72 ++++++++++++++++++++++ src/core/lombok/core/debug/DebugSnapshotStore.java | 52 ++++++++++++++++ 2 files changed, 124 insertions(+) create mode 100644 src/core/lombok/core/debug/DebugSnapshot.java create mode 100644 src/core/lombok/core/debug/DebugSnapshotStore.java (limited to 'src/core/lombok') diff --git a/src/core/lombok/core/debug/DebugSnapshot.java b/src/core/lombok/core/debug/DebugSnapshot.java new file mode 100644 index 00000000..a04a4820 --- /dev/null +++ b/src/core/lombok/core/debug/DebugSnapshot.java @@ -0,0 +1,72 @@ +package lombok.core.debug; + +import java.lang.ref.WeakReference; +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration; + +public class DebugSnapshot implements Comparable { + private final long when, nano; + private final List trace; + private final Thread thread; + private final String message; + private final Object[] params; + private final WeakReference owner; + + public DebugSnapshot(CompilationUnitDeclaration owner, int stackHiding, String message, Object... params) { + this.when = System.currentTimeMillis(); + StackTraceElement[] stackTrace = new Throwable().getStackTrace(); + this.trace = new ArrayList(); + for (int i = 1 + stackHiding; i < stackTrace.length; i++) trace.add(stackTrace[i]); + this.nano = System.nanoTime(); + this.thread = Thread.currentThread(); + this.message = message; + this.params = params == null ? new Object[0] : params; + this.owner = new WeakReference(owner); + } + + private String threadName() { + return thread.getName(); + } + + private String ownerName() { + CompilationUnitDeclaration node = owner.get(); + if (node == null) return "GCed"; + char[] tn = node.getMainTypeName(); + char[] fs = node.getFileName(); + if (tn == null || tn.length == 0) { + return (fs == null || fs.length == 0) ? "--UNKNOWN--" : new String(fs); + } + + return new String(tn); + } + + public String shortToString() { + StringBuilder out = new StringBuilder(); + out.append(String.format("WHEN: %14d THREAD: %s AST: %s", when, threadName(), ownerName())); + if (message != null) out.append(String.format(message, params)); + return out.toString(); + } + + @Override public String toString() { + StringBuilder out = new StringBuilder(); + out.append(shortToString()).append("\n"); + for (StackTraceElement elem : trace) { + out.append(" ").append(elem.toString()).append("\n"); + } + return out.toString(); + } + + @Override public int compareTo(DebugSnapshot o) { + if (o.thread == this.thread) { + return Long.valueOf(nano).compareTo(Long.valueOf(o.nano)); + } + + if (o.when != when) { + return Long.valueOf(when).compareTo(Long.valueOf(o.when)); + } + + return Integer.valueOf(System.identityHashCode(thread)).compareTo(System.identityHashCode(o.thread)); + } +} diff --git a/src/core/lombok/core/debug/DebugSnapshotStore.java b/src/core/lombok/core/debug/DebugSnapshotStore.java new file mode 100644 index 00000000..cb15d2eb --- /dev/null +++ b/src/core/lombok/core/debug/DebugSnapshotStore.java @@ -0,0 +1,52 @@ +package lombok.core.debug; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.WeakHashMap; + +import org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration; + +public class DebugSnapshotStore { + public static final DebugSnapshotStore INSTANCE = new DebugSnapshotStore(); + + private final Map> map = + new WeakHashMap>(); + + public void snapshot(CompilationUnitDeclaration owner, String message, Object... params) { + DebugSnapshot snapshot = new DebugSnapshot(owner, 1, message, params); + List list; + + synchronized (map) { + list = map.get(owner); + if (list == null) { + list = new ArrayList(); + map.put(owner, list); + } + list.add(snapshot); + } + } + + public void print(CompilationUnitDeclaration owner, String message, Object... params) { + List list; + + synchronized (map) { + snapshot(owner, message == null ? "Printing" : message, params); + list = new ArrayList(); + list.addAll(map.get(owner)); + } + + Collections.sort(list); + int idx = 1; + System.out.println("---------------------------"); + for (DebugSnapshot snapshot : list) { + System.out.printf("%3d: %s\n", idx++, snapshot.shortToString()); + } + System.out.println("******"); + idx = 1; + for (DebugSnapshot snapshot : list) { + System.out.printf("%3d: %s", idx++, snapshot.toString()); + } + } +} -- cgit From 23754573c1221c70596b6287a68b05580f7c39e9 Mon Sep 17 00:00:00 2001 From: Roel Spilker Date: Mon, 18 Jul 2011 23:21:43 +0200 Subject: Dump the debug snapshots for issue 164 to a file. --- src/core/lombok/core/debug/DebugSnapshot.java | 30 ++++++++-------------- src/core/lombok/core/debug/DebugSnapshotStore.java | 23 ++++++++++++++--- 2 files changed, 29 insertions(+), 24 deletions(-) (limited to 'src/core/lombok') diff --git a/src/core/lombok/core/debug/DebugSnapshot.java b/src/core/lombok/core/debug/DebugSnapshot.java index a04a4820..f12cbcc4 100644 --- a/src/core/lombok/core/debug/DebugSnapshot.java +++ b/src/core/lombok/core/debug/DebugSnapshot.java @@ -3,13 +3,16 @@ package lombok.core.debug; import java.lang.ref.WeakReference; import java.util.ArrayList; import java.util.List; +import java.util.concurrent.atomic.AtomicLong; import org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration; public class DebugSnapshot implements Comparable { - private final long when, nano; + private static AtomicLong counter = new AtomicLong(); + + private final long when, id = counter.getAndIncrement(); private final List trace; - private final Thread thread; + private final String threadName; private final String message; private final Object[] params; private final WeakReference owner; @@ -17,22 +20,17 @@ public class DebugSnapshot implements Comparable { public DebugSnapshot(CompilationUnitDeclaration owner, int stackHiding, String message, Object... params) { this.when = System.currentTimeMillis(); StackTraceElement[] stackTrace = new Throwable().getStackTrace(); - this.trace = new ArrayList(); + this.trace = new ArrayList(Math.max(0, stackTrace.length - stackHiding - 1)); for (int i = 1 + stackHiding; i < stackTrace.length; i++) trace.add(stackTrace[i]); - this.nano = System.nanoTime(); - this.thread = Thread.currentThread(); + this.threadName = Thread.currentThread().getName(); this.message = message; this.params = params == null ? new Object[0] : params; this.owner = new WeakReference(owner); } - private String threadName() { - return thread.getName(); - } - private String ownerName() { CompilationUnitDeclaration node = owner.get(); - if (node == null) return "GCed"; + if (node == null) return "--GCed--"; char[] tn = node.getMainTypeName(); char[] fs = node.getFileName(); if (tn == null || tn.length == 0) { @@ -44,7 +42,7 @@ public class DebugSnapshot implements Comparable { public String shortToString() { StringBuilder out = new StringBuilder(); - out.append(String.format("WHEN: %14d THREAD: %s AST: %s", when, threadName(), ownerName())); + out.append(String.format("WHEN: %14d THREAD: %s AST: %s", when, threadName, ownerName())); if (message != null) out.append(String.format(message, params)); return out.toString(); } @@ -59,14 +57,6 @@ public class DebugSnapshot implements Comparable { } @Override public int compareTo(DebugSnapshot o) { - if (o.thread == this.thread) { - return Long.valueOf(nano).compareTo(Long.valueOf(o.nano)); - } - - if (o.when != when) { - return Long.valueOf(when).compareTo(Long.valueOf(o.when)); - } - - return Integer.valueOf(System.identityHashCode(thread)).compareTo(System.identityHashCode(o.thread)); + return Long.valueOf(id).compareTo(o.id); } } diff --git a/src/core/lombok/core/debug/DebugSnapshotStore.java b/src/core/lombok/core/debug/DebugSnapshotStore.java index cb15d2eb..fda3ba14 100644 --- a/src/core/lombok/core/debug/DebugSnapshotStore.java +++ b/src/core/lombok/core/debug/DebugSnapshotStore.java @@ -1,5 +1,8 @@ package lombok.core.debug; +import java.io.File; +import java.io.FileOutputStream; +import java.io.OutputStream; import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -39,14 +42,26 @@ public class DebugSnapshotStore { Collections.sort(list); int idx = 1; - System.out.println("---------------------------"); + StringBuilder out = new StringBuilder(); + out.append("---------------------------\n"); for (DebugSnapshot snapshot : list) { - System.out.printf("%3d: %s\n", idx++, snapshot.shortToString()); + out.append(String.format("%3d: %s\n", idx++, snapshot.shortToString())); } - System.out.println("******"); + out.append("******\n"); idx = 1; for (DebugSnapshot snapshot : list) { - System.out.printf("%3d: %s", idx++, snapshot.toString()); + out.append(String.format("%3d: %s", idx++, snapshot.toString())); + } + + try { + OutputStream stream = new FileOutputStream(new File(System.getProperty("user.home", "."), String.format("lombok164-%d.err", System.currentTimeMillis()))); + try { + stream.write(out.toString().getBytes("UTF-8")); + } finally { + stream.close(); + } + } catch (Exception e) { + System.err.println(out); } } } -- cgit From a24daba66ce4705429b266972319ad15b1db0d70 Mon Sep 17 00:00:00 2001 From: Roel Spilker Date: Mon, 18 Jul 2011 23:49:26 +0200 Subject: Upgraded the issue 164 reporter to replace what we had. I think we'll roll this out in 0.10.0-RC2. --- src/core/lombok/core/debug/DebugSnapshot.java | 2 +- src/core/lombok/core/debug/DebugSnapshotStore.java | 7 +++++-- src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java | 6 ++---- 3 files changed, 8 insertions(+), 7 deletions(-) (limited to 'src/core/lombok') diff --git a/src/core/lombok/core/debug/DebugSnapshot.java b/src/core/lombok/core/debug/DebugSnapshot.java index f12cbcc4..d94798e8 100644 --- a/src/core/lombok/core/debug/DebugSnapshot.java +++ b/src/core/lombok/core/debug/DebugSnapshot.java @@ -43,7 +43,7 @@ public class DebugSnapshot implements Comparable { public String shortToString() { StringBuilder out = new StringBuilder(); out.append(String.format("WHEN: %14d THREAD: %s AST: %s", when, threadName, ownerName())); - if (message != null) out.append(String.format(message, params)); + if (message != null) out.append(" ").append(String.format(message, params)); return out.toString(); } diff --git a/src/core/lombok/core/debug/DebugSnapshotStore.java b/src/core/lombok/core/debug/DebugSnapshotStore.java index fda3ba14..7abfc07c 100644 --- a/src/core/lombok/core/debug/DebugSnapshotStore.java +++ b/src/core/lombok/core/debug/DebugSnapshotStore.java @@ -31,7 +31,7 @@ public class DebugSnapshotStore { } } - public void print(CompilationUnitDeclaration owner, String message, Object... params) { + public String print(CompilationUnitDeclaration owner, String message, Object... params) { List list; synchronized (map) { @@ -54,14 +54,17 @@ public class DebugSnapshotStore { } try { - OutputStream stream = new FileOutputStream(new File(System.getProperty("user.home", "."), String.format("lombok164-%d.err", System.currentTimeMillis()))); + File logFile = new File(System.getProperty("user.home", "."), String.format("lombok164-%d.err", System.currentTimeMillis())); + OutputStream stream = new FileOutputStream(logFile); try { stream.write(out.toString().getBytes("UTF-8")); } finally { stream.close(); } + return logFile.getAbsolutePath(); } catch (Exception e) { System.err.println(out); + return "(can't write log file - emitted to system err)"; } } } diff --git a/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java b/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java index 5f6691fd..45d58df3 100644 --- a/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java +++ b/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java @@ -467,10 +467,8 @@ public class EclipseHandlerUtil { if (report) { CompilationUnitDeclaration cud = (CompilationUnitDeclaration) type.top().get(); - DebugSnapshotStore.INSTANCE.print(cud, "Printing: injecting whilst scope is already built."); -// Eclipse.warning("State: " + Issue164Fixer.getState(cud) + " -- We believe you may have just stumbled on lombok issue #164. Please " + -// "report the stack trace associated with this message at:\n" + -// "http://code.google.com/p/projectlombok/issues/detail?id=164. Occurred on class " + new String(parent.name), new Throwable()); + String logFileLocation = DebugSnapshotStore.INSTANCE.print(cud, "Printing: injecting whilst scope is already built."); + Eclipse.warning("We believe you may have stumbled on issue 164. Please upload file " + logFileLocation + " to: http://code.google.com/p/projectlombok/issues/detail?id=164", new Throwable()); } } -- cgit