Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] quick little hack


 That is very cool!

Heh, if only exceptions wasn't that expensieve to create in java. Thought it mat get fixed in Java 7 if they decide to implement one of those closures specs. Wile Java 7 is still fat on a horizon, we could reuse exception instance per trampoline, per thread (i.e. storing it in ThreadLocal).

 regards,
 Eugene


Gregor Kiczales wrote:
Here's a quick little hack that Ryan Golbeck and I just wrote...

(the complete code w/ example is attached in three files)

/* * The idea here is to take a program with a dispersed iterative structure,
and
 * given the 'nonReturningCalls' (procedure calls that never return until
the
 * very end of the computation) package them up in a closure and bounce them
 * off a trampoline farther up the stack.
* * Try commenting out this aspect and then running A.main(). That will
produce a
 * stack overflow. Enable the aspect ---> No overflow, just nice iteration!
* * */
public aspect Trampolining {
	
    pointcut trampoline(): execution(void A.main(String[]));
	
    pointcut nonReturningCalls(): call(void A.a(B))
                                  || call(void B.b(A));
	
    void around(): trampoline() {
        Closure proceeder = new Closure(){
                              public void doit() { proceed(); }
                            };
        while (true) {
            try { proceeder.doit(); }
            catch(ToBounce e) { proceeder = e.getClosure(); }
        }
    }
	
    void around(): nonReturningCalls() {
        throw new ToBounce(new Closure(){
                               public void doit() { proceed(); }
                           });
    }
}
------------------------------------------------------------------------

_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/aspectj-users



Back to the top