Skip to content

Commit

Permalink
Clean up JoinPointImpl, e.g. use list instead of stack
Browse files Browse the repository at this point in the history
Fixes eclipse-aspectj#128.

Signed-off-by: Alexander Kriegisch <[email protected]>
  • Loading branch information
kriegaex committed Feb 26, 2022
1 parent 1584914 commit 436bf4d
Showing 1 changed file with 10 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@

package org.aspectj.runtime.reflect;

import java.util.Stack;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.Signature;
import org.aspectj.lang.reflect.SourceLocation;
import org.aspectj.runtime.internal.AroundClosure;

import java.util.ArrayList;
import java.util.List;

class JoinPointImpl implements ProceedingJoinPoint {
static class StaticPartImpl implements JoinPoint.StaticPart {
String kind;
Expand Down Expand Up @@ -137,32 +138,27 @@ public final String toLongString() {
}

// To proceed we need a closure to proceed on. Generated code
// will either be using arc or arcs but not both. arcs being non-null
// indicates it is in use (even if an empty stack)
// will either be using arc or arcs but not both.
private AroundClosure arc = null;
private final Stack<AroundClosure> arcs = new Stack<>();
private int currentArcIndex = -1;
private final List<AroundClosure> arcs = new ArrayList<>();
private int currentArcIndex = -1;

public void set$AroundClosure(AroundClosure arc) {
this.arc = arc;
}

public synchronized void stack$AroundClosure(AroundClosure arc) {
public synchronized void stack$AroundClosure(AroundClosure arc) {
// If input parameter arc is null this is the 'unlink' call from AroundClosure
if (arc != null) {
this.arcs.push(arc);
this.arcs.add(arc);
currentArcIndex++;
}
}

public synchronized Object proceed() throws Throwable {
// when called from a before advice, but be a no-op
if (currentArcIndex < 0) {
if (arc == null) {
return null;
} else {
return arc.run(arc.getState());
}
return arc == null ? null : arc.run(arc.getState());
} else {
final AroundClosure ac = arcs.get(currentArcIndex--);
final Object result = ac.run(ac.getState());
Expand All @@ -173,12 +169,7 @@ public synchronized Object proceed() throws Throwable {

public synchronized Object proceed(Object[] adviceBindings) throws Throwable {
// when called from a before advice, but be a no-op
AroundClosure ac = null;
if (currentArcIndex < 0) {
ac = arc;
} else {
ac = arcs.get(currentArcIndex);
}
AroundClosure ac = currentArcIndex < 0 ? arc : arcs.get(currentArcIndex);

if (ac == null) {
return null;
Expand Down

0 comments on commit 436bf4d

Please sign in to comment.