Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Synchronise JoinPointImpl methods dealing with Stack<AroundClosure> #129

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,48 +138,38 @@ 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 Stack<AroundClosure> arcs = null;
private final List<AroundClosure> arcs = new ArrayList<>();
private int currentArcIndex = -1;

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

public 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 (arcs == null) {
arcs = new Stack<>();
}
if (arc==null) {
this.arcs.pop();
} else {
this.arcs.push(arc);
if (arc != null) {
this.arcs.add(arc);
currentArcIndex++;
}
}
}

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

public Object proceed(Object[] adviceBindings) 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 (arcs == null) {
ac = arc;
} else {
ac = arcs.peek();
}
AroundClosure ac = currentArcIndex < 0 ? arc : arcs.get(currentArcIndex);

if (ac == null) {
return null;
Expand Down Expand Up @@ -254,7 +245,10 @@ public Object proceed(Object[] adviceBindings) throws Throwable {
// state[i] = adviceBindings[formalIndex];
// }
// }
return ac.run(state);
currentArcIndex--;
final Object result = ac.run(state);
currentArcIndex++;
return result;
}
}

Expand Down