From 6be70973a704548a42e396e996c9d49915b92a64 Mon Sep 17 00:00:00 2001 From: mwebster Date: Fri, 25 Aug 2006 14:37:34 +0000 Subject: [PATCH] Bug 155148 "jdk14 trace deadlock in oc4j" (use formatObj for _all_ arguments) --- .../loadtime/DefaultWeavingContext.java | 2 +- .../aspectj/weaver/tools/AbstractTrace.java | 12 +++++- .../org/aspectj/weaver/AbstractTraceTest.java | 41 +++++++++++++++++-- .../org/aspectj/weaver/tools/Jdk14Trace.java | 6 +-- 4 files changed, 51 insertions(+), 10 deletions(-) diff --git a/loadtime/src/org/aspectj/weaver/loadtime/DefaultWeavingContext.java b/loadtime/src/org/aspectj/weaver/loadtime/DefaultWeavingContext.java index bd4c3280f..403a3576f 100644 --- a/loadtime/src/org/aspectj/weaver/loadtime/DefaultWeavingContext.java +++ b/loadtime/src/org/aspectj/weaver/loadtime/DefaultWeavingContext.java @@ -53,7 +53,7 @@ public class DefaultWeavingContext implements IWeavingContext { * @return classname@hashcode */ public String getClassLoaderName() { - return ((loader!=null)?loader.getClass().getName()+"@"+loader.hashCode():"null"); + return ((loader!=null)?loader.getClass().getName()+"@"+Integer.toHexString(loader.hashCode()):"null"); } /** diff --git a/weaver/src/org/aspectj/weaver/tools/AbstractTrace.java b/weaver/src/org/aspectj/weaver/tools/AbstractTrace.java index 23d2aba39..28755dfd2 100644 --- a/weaver/src/org/aspectj/weaver/tools/AbstractTrace.java +++ b/weaver/src/org/aspectj/weaver/tools/AbstractTrace.java @@ -139,11 +139,11 @@ public abstract class AbstractTrace implements Trace { } /* Use classname@hashcode */ - else return obj.getClass().getName() + "@" + Integer.toString(obj.hashCode(),16); + else return obj.getClass().getName() + "@" + Integer.toHexString(obj.hashCode()); /* Object.hashCode() can be override and may thow an exception */ } catch (Exception ex) { - return obj.getClass().getName(); + return obj.getClass().getName() + "@FFFFFFFF"; } } @@ -172,4 +172,12 @@ public abstract class AbstractTrace implements Trace { return sb.toString(); } + + protected Object[] formatObjects(Object[] args) { + for (int i = 0; i < args.length; i++) { + args[i] = formatObj(args[i]); + } + + return args; + } } \ No newline at end of file diff --git a/weaver/testsrc/org/aspectj/weaver/AbstractTraceTest.java b/weaver/testsrc/org/aspectj/weaver/AbstractTraceTest.java index 8f895a81b..334690b62 100644 --- a/weaver/testsrc/org/aspectj/weaver/AbstractTraceTest.java +++ b/weaver/testsrc/org/aspectj/weaver/AbstractTraceTest.java @@ -34,23 +34,56 @@ public abstract class AbstractTraceTest extends TestCase { public void testEnterWithThisAndArray() { Object arg1 = new String[] { "s1", "s2" }; Object arg2 = new char[] { 'a', 'b', 'c' }; - trace.enter("testEnterWithThisAndArgs",this,new Object[] { arg1, arg2 }); + trace.enter(getName(),this,new Object[] { arg1, arg2 }); } public void testEnterWithThisAndCollection() { Object arg1 = new ArrayList(); - trace.enter("testEnterWithThisAndArgs",this,new Object[] { arg1 }); + trace.enter(getName(),this,new Object[] { arg1 }); } public void testEnterWithThisAndTraceable () { Object arg1 = new Traceable() { public String toTraceString() { - return "Traceable"; + return getClass().getName() + "[Traceable]"; } }; - trace.enter("testEnterWithThisAndArgs",this,new Object[] { arg1 }); + trace.enter(getName(),this,new Object[] { arg1 }); + } + + public void testEnterWithThisAndToStringException () { + Object arg1 = new Object() { + + public String toString() { + throw new RuntimeException("toString() can throw an Exception"); + } + + }; + trace.enter(getName(),this,new Object[] { arg1 }); + } + + public void testEnterWithThisAndHashCodeException () { + Object arg1 = new Object() { + + public int hashCode() { + throw new RuntimeException("hashCode can throw an Exception"); + } + + }; + trace.enter(getName(),this,new Object[] { arg1 }); + } + + public void testEnterWithThisAndClassLoader () { + Object arg1 = new ClassLoader() { + + public String toString() { + throw new Error("Don't call ClassLoader.toString()"); + } + + }; + trace.enter(getName(),this,new Object[] { arg1 }); } public void testEnterWithThis() { diff --git a/weaver5/java5-src/org/aspectj/weaver/tools/Jdk14Trace.java b/weaver5/java5-src/org/aspectj/weaver/tools/Jdk14Trace.java index 28c46d4ea..7072ffcb6 100644 --- a/weaver5/java5-src/org/aspectj/weaver/tools/Jdk14Trace.java +++ b/weaver5/java5-src/org/aspectj/weaver/tools/Jdk14Trace.java @@ -29,7 +29,7 @@ public class Jdk14Trace extends AbstractTrace { if (logger.isLoggable(Level.FINE)) { logger.entering(name,methodName,formatObj(thiz)); if (args != null && logger.isLoggable(Level.FINER)) { - logger.entering(name,methodName,args); + logger.entering(name,methodName,formatObjects(args)); } } } @@ -40,7 +40,7 @@ public class Jdk14Trace extends AbstractTrace { public void exit(String methodName, Object ret) { if (logger.isLoggable(Level.FINE)) { - logger.exiting(name,methodName,ret); + logger.exiting(name,methodName,formatObj(ret)); } } @@ -60,7 +60,7 @@ public class Jdk14Trace extends AbstractTrace { if (logger.isLoggable(Level.FINE)) { logger.logp(Level.FINER,name,methodName,"EVENT",formatObj(thiz)); if (args != null && logger.isLoggable(Level.FINER)) { - logger.logp(Level.FINER,name,methodName,"EVENT",args); + logger.logp(Level.FINER,name,methodName,"EVENT",formatObjects(args)); } } } -- 2.39.5