[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
RE: [aspectj-users] JoinPoint SourceLocation vs. Stack TraceInterigation

Hi. Creation of a stack trace is certainly one of the most expensive native operations you can do in Java. Hope that answers your question.

 

 

Eric

 

From: aspectj-users-bounces@xxxxxxxxxxx [mailto:aspectj-users-bounces@xxxxxxxxxxx] On Behalf Of Gregory Kedge
Sent: Saturday, September 02, 2006 4:42 PM
To: aspectj-users@xxxxxxxxxxx
Subject: [aspectj-users] JoinPoint SourceLocation vs. Stack TraceInterigation

 

It is my understanding that the use of JoinPoint is a reflective operation.  Therefore, I have the choice between two supposed inefficient mechanisms of obtaining the type of class and line number located at the join point, reflective JoinPoint.getSourceLocation() vs generating an exception and interrogating the stack:

 

    @After("call (net.kedges.Foo+.new(..))")

    public void fooCreatedHere(JoinPoint thisJoinPoint) {

        final SourceLocation sl = thisJoinPoint.getSourceLocation();

        final StringBuilder sb = new StringBuilder(sl.getWithinType().getName());

        sb.append('(').append(sl.getFileName()).append(':').append(sl.getLine()).append(')');

        System.out.println("Foo created here: " + sb.toString());

        System.out.println("Foo created here: " + new Exception().getStackTrace()[1].toString());

    }

 

Might produce the following in my stout:

Foo created here: net.kedges.Goo(Goo.java:666)

Foo created here: net.kedges.Goo.createFoo(Goo.java:666)

 

I would gladly sacrifice the method information provided in within the StackTraceElement for my purposes if accessing JoinPoint.SourceLocation was a typically more expeditious operation [, but curious all the same as to why it was omitted from SourceLocation...]  Which operation is supposedly more efficient?

 

 

Kind Regards,

Greg Kedge