Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[aspectj-users] Use Cases for Changing target and this in proceed

I am trying to understand the semantics of proceed. One interesting issue arises because AspectJ lets us change the "this" and "target" objects when proceeding from around advice. Here's a fragment that just changes the "this" object (the full code for the example is given below):

	void around(ChangeThis th) : call(* *.m()) && this(th) {
		System.out.println("first around call m: this = " + th);
proceed(new ChangeThis()); // change this, just seen in subsequent advice
		System.out.println("first around call m: this = " + th);
	}

My example isn't practical; it is just meant to demonstrate the semantic issue.

My question is about use cases for changing the target and this objects when proceeding. I can imagine wanting to change the target object: perhaps we want to wrap the original target in some wrapper object before proceeding. However, I haven't been able to come up with a realistic use case for changing the "this" object. I assume changing the "this" object would only affect join point information bound in subsequent advice. I don't see how it could change the original "this" object that called the advised code, and the advised code wouldn't typically be able to determine its original caller. (Experimentation with ajc version 1.2 bears this assumption out.) Also, it also isn't clear what it should mean to change the target object at an execution join point, because presumably the target object's stack frame has already been pushed.

My basic question is:

Are there any use cases for changing the "this" object in a proceed? Or is this capability just a result of the decision to make the arguments to proceed match the parameters of the surrounding advice?

Thanks for any insight,

Curt

----------------------------------
Curtis Clifton, PhD Candidate
Dept. of Computer Science, Iowa State University
http://www.cs.iastate.edu/~cclifton

// Full sample code
public class ChangeThis {
	private B b = new B();

	public static void main(String[] args) {
		new ChangeThis().run();
	}
	
	void run() {
		System.out.println("in run, with b = " + b);
		b.m();
		System.out.println("in run, with b = " + b);
	}
	
}

class B {
	void m() {
		System.out.println("in m, this = " + this);
	}
}

aspect Asp1 {
	void around(ChangeThis th) : call(* *.m()) && this(th) {
		System.out.println("first around call m: this = " + th);
proceed(new ChangeThis()); // change this, just seen in subsequent advice
		System.out.println("first around call m: this = " + th);
	}

	void around(ChangeThis th) : call(* *.m()) && this(th) {
		System.out.println("second around call m: this = " + th);
		proceed(th); // change this, seen in next advice?
		System.out.println("second around call m: this = " + th);
	}
}



Back to the top