Skip to main content

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

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(); }
                           });
    }
}

Attachment: Trampolining.aj
Description: Binary data

Attachment: A.java
Description: Binary data

Attachment: B.java
Description: Binary data


Back to the top