ex09 task 3b

#14
Mausschubser
Mausschubser
Beiträge: 80
Registriert: 7. Dez 2007 13:54
Wohnort: Darmstadt

ex09 task 3b

Beitrag von #14 »

sorry to bother again.

can i please get more information about the second hint in the task and about how it is supposed to help me.
"Hint: By default only one instance of an aspect is instantiated per virtual machine. As covered in the lecture, you can change this with aspect associations (perthis, pertarget, percflow, percflowbelow, etc.), which are added to the signature of the aspect."

i already spent 5 hours on this one task and i seem to not get anywhere with it...

Benutzeravatar
sproksch
Computerversteher
Computerversteher
Beiträge: 346
Registriert: 15. Apr 2004 17:56

Re: ex09 task 3b

Beitrag von sproksch »

Ok... ignore the hint for a second. What is your current problem with this task?

#14
Mausschubser
Mausschubser
Beiträge: 80
Registriert: 7. Dez 2007 13:54
Wohnort: Darmstadt

Re: ex09 task 3b

Beitrag von #14 »

well... aspectJ is obviously new to me, so i'm trying to familiarize myself with all the options (syntax) aspectJ has to offer and which of those might be able to help me solve the task. the little information that can be found online seems not to be very helpful for me either. one of my many questions: how can i distinguish between method calls made from outside my package and those made within one of my function.run(int) methods... target and this seem to be always the same.

#14
Mausschubser
Mausschubser
Beiträge: 80
Registriert: 7. Dez 2007 13:54
Wohnort: Darmstadt

Re: ex09 task 3b

Beitrag von #14 »

if startup_calculator contains nothing but

fibonacci.run(2);

the output is supposed to be solely

RuntimeDataCollector: a call to Fibonacci
RuntimeDataCollector: ... is recursive

correct?

in order to do that i need to be able to tell whether the method call was made from startup_calculator or from fibonacci itself... while the method call from startup_calculator doesn't get recognized at all since its outside the package, the execution shows fibonacci for this and target...

#14
Mausschubser
Mausschubser
Beiträge: 80
Registriert: 7. Dez 2007 13:54
Wohnort: Darmstadt

Re: ex09 task 3b

Beitrag von #14 »

i just found this

thisJoinPoint.getSourceLocation()

maybe it will help.

i'm still open for hints and suggestions...

Mirlix_
Endlosschleifenbastler
Endlosschleifenbastler
Beiträge: 188
Registriert: 3. Mär 2006 14:57

Re: ex09 task 3b

Beitrag von Mirlix_ »

I solved this problem with cflowbelow, an important information that I missed at the beginnging was that cflow and cflowbelow can be added to the aspect and to the advice cflow and cflowbelow both can take the pointcut as a parameter. With this it is possible to have an advice for a call from outside the class and an advice for calls from inside the class. Hope this helps.
"If you want more effective programmers, you will discover that they should not waste their time debugging, they should not introduce the bugs to start with." Edsger W. Dijkstra

Benutzeravatar
sproksch
Computerversteher
Computerversteher
Beiträge: 346
Registriert: 15. Apr 2004 17:56

Re: ex09 task 3b

Beitrag von sproksch »

Try it with a different approach... When you are looking for good pointcuts, think about the execution in terms of a stack trace. Every control flow is just a list of called methods in this case.

In addition to this I'm not sure why you take the packages into account... possible subclasses of "Function" may be implemented in any package, so I think this does not help you at all. Instead of matching packages, you could try to reason about the control flow... is it possible to distinguish between an initial function call and subsequent ones?

#14
Mausschubser
Mausschubser
Beiträge: 80
Registriert: 7. Dez 2007 13:54
Wohnort: Darmstadt

Re: ex09 task 3b

Beitrag von #14 »

Try it with a different approach... When you are looking for good pointcuts, think about the execution in terms of a stack trace. Every control flow is just a list of called methods in this case.
i am totally aware of that.
is it possible to distinguish between an initial function call and subsequent ones?
exactly one of my questions... i'm guessing yes, but the question is how...

Benutzeravatar
sproksch
Computerversteher
Computerversteher
Beiträge: 346
Registriert: 15. Apr 2004 17:56

Re: ex09 task 3b

Beitrag von sproksch »

How does a stack trace of a nested call look like?

#14
Mausschubser
Mausschubser
Beiträge: 80
Registriert: 7. Dez 2007 13:54
Wohnort: Darmstadt

Re: ex09 task 3b

Beitrag von #14 »

it maps the internal method calling sequences of the nested call?

Benutzeravatar
sproksch
Computerversteher
Computerversteher
Beiträge: 346
Registriert: 15. Apr 2004 17:56

Re: ex09 task 3b

Beitrag von sproksch »

What do you mean with "maps the calling"?

Do you know any possibility from the lecture to create a pointcut that matches (or does not match) depending on the current control flow?

#14
Mausschubser
Mausschubser
Beiträge: 80
Registriert: 7. Dez 2007 13:54
Wohnort: Darmstadt

Re: ex09 task 3b

Beitrag von #14 »

well... i'm guessing i need something like this:

Code: Alles auswählen

after(Shape shape) returning: shapeChange(shape)
                                     && !cflowbelow(shapeChange()) {
               Display.update(shape);
}

Benutzeravatar
sproksch
Computerversteher
Computerversteher
Beiträge: 346
Registriert: 15. Apr 2004 17:56

Re: ex09 task 3b

Beitrag von sproksch »

You are guessing right ;) If you have understood the construct cflowbelow you should be able to define pointcuts for initial function calls and subsequent ones...

Senchy
Windoof-User
Windoof-User
Beiträge: 37
Registriert: 6. Okt 2010 19:14

Re: ex09 task 3b

Beitrag von Senchy »

was ist necessary for the task to use this language-feature of aspectj or does it only have to work?
Our solution is more like a "hack" around this, using different pointcuts which differ by within() where the call was executed.
The output is like the expected one in the exercise but the solution might not be as clean as if we used cflowbelow :)

Benutzeravatar
sproksch
Computerversteher
Computerversteher
Beiträge: 346
Registriert: 15. Apr 2004 17:56

Re: ex09 task 3b

Beitrag von sproksch »

To be honest, I have not used "within" before, so I think I have to look at your solution to say if your solution is ok.

Antworten

Zurück zu „Archiv“