Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] LTW : thisJoinPoint.getStaticPart().getSourceLocation().getLine() always returns 0

Le 24/12/2012 16:04, Pasturel a écrit :
Le 24/12/2012 12:25, Pasturel a écrit :
Hi,
withAspectJ Compiler 1.7.1 (DEVELOPMENT - Built: Wednesday Oct 24, 2012 at 18:06:22 GMT) and LTW,
the call  thisJoinPoint.getStaticPart().getSourceLocation().getLine() always returns 0

My advice is an around advice. I test if( null != thisJoinPoint.getStaticPart().getSourceLocation())
The pointcut is correctly weaved, and the advice excecutes correctly ( except for retrieving the noLine)

How can we explain this? a bug ?
I  give below the code to test ( my tests give always a getLine() =0)  :

The Class :

package jlp.aspectj.test;

import java.util.HashMap;
public class TestingClass implements Runnable {
    private String name = "";
    public boolean running = true;
    private int limit = 1000000;
    Thread thread = new Thread(this);

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;

    }

    public TestingClass(String name, int limit) {
        this.name = name;
        this.limit = limit;
    }

    public TestingClass(String name) {
        this.name = name;
    }

    public TestingClass() {
        this("no_name");

    }

    public void myShortMethod() {
        System.out.println("I will sleep for 100 ms");
        try {
            Thread.sleep(100);
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    public void myLongMethod() {
        System.out.println("I will sleep for 1s");
        try {

            Thread.sleep(1000);
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

    }

    public void myStressingMethod(int limit) {
        HashMap<String, Integer> hm = new HashMap<String, Integer>();
        System.out.println("Entering in myStressingMethod limit=" + limit);
        for (int i = 0; i < limit; i++) {
            hm.put(new Integer(i % 100).toString(), new Integer(i % 1000));
        }
        hm.clear();

    }

    public void run() {
        while (running) {

            myShortMethod();

            myStressingMethod(limit);
            myLongMethod();
        }
    }

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        TestingClass[] tabRunners = new TestingClass[Integer.parseInt(args[0])];
        for (int i = 0; i < tabRunners.length; i++) {
            tabRunners[i] = new TestingClass("thread_" + i,
                    Integer.parseInt(args[1]));
            tabRunners[i].thread.start();
        }
    }

}


The AspectJ to (LTW) weave :

package jlp.perf.aspects.concreteAspects;

public aspect ConcreteTester {
    public  pointcut methods():execution(public * *..*.*(..));
    Object around() : methods()
    {
    Object ret = proceed();
    String str="Aspect ConcreteTester :"+thisJoinPointStaticPart.getSignature().getDeclaringTypeName()+"."+
            thisJoinPointStaticPart.getSignature().getName()+";"+thisJoinPointStaticPart
            .getSourceLocation().getLine();
    System.out.println(str);
   
    return ret;
    }

}




_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/aspectj-users
but Compile Time Weaving makes the Aspect running correctly, as shown by the traces below :
I will sleep for 1s
Aspect ConcreteTester :jlp.aspectj.test.TestingClass.myShortMethod;39
Entering in myStressingMethod limit=1000000
Aspect ConcreteTester :jlp.aspectj.test.TestingClass.myStressingMethod;61
I will sleep for 1s
Aspect ConcreteTester :jlp.aspectj.test.TestingClass.myShortMethod;39
Entering in myStressingMethod limit=1000000
Aspect ConcreteTester :jlp.aspectj.test.TestingClass.myLongMethod;49
I will sleep for 100 ms
Aspect ConcreteTester :jlp.aspectj.test.TestingClass.myStressingMethod;61
I will sleep for 1s
Aspect ConcreteTester :jlp.aspectj.test.TestingClass.myShortMethod;39
Entering in myStressingMethod limit=1000000
Aspect ConcreteTester :jlp.aspectj.test.TestingClass.myLongMethod;49
I will sleep for 100 ms
Aspect ConcreteTester :jlp.aspectj.test.TestingClass.myStressingMethod;61
I will sleep for 1s
Aspect ConcreteTester :jlp.aspectj.test.TestingClass.myStressingMethod;61
I will sleep for 1s
Aspect ConcreteTester :jlp.aspectj.test.TestingClass.myShortMethod;39
Entering in myStressingMethod limit=1000000
Aspect ConcreteTester :jlp.aspectj.test.TestingClass.myShortMethod;39
Entering in myStressingMethod limit=1000000
Aspect ConcreteTester :jlp.aspectj.test.TestingClass.myStressingMethod;61
I will sleep for 1s
Aspect ConcreteTester :jlp.aspectj.test.TestingClass.myStressingMethod;61
I will sleep for 1s


Back to the top