Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] Creation of parameterized ReferenceType not thread safe

Hi Andy,

thanks for the fix. We will have a look at this.

Shall I still open a bug for this, or is it done from your side? Just give a short note.

Btw: Is there a nightly release or similar, which I can test in my environment?

Regards

Thorsten

-------- Original-Nachricht --------
> Datum: Mon, 21 Feb 2011 12:58:21 -0800
> Von: Andy Clement <andrew.clement@xxxxxxxxx>
> An: aspectj-users@xxxxxxxxxxx
> Betreff: Re: [aspectj-users] Creation of parameterized ReferenceType not thread safe

> Hi Thorsten,
> 
> Just to say I've committed some synchronization to alleviate this
> problem.  A further thing I was concerned about was multiple threads
> attempting type resolution on the same world, as that could lead to
> two entries for the same type in the world (not ideal).  So I've also
> put some synchronization code around resolution when it is building a
> type.  All the AspectJ tests pass but I have to admit I don't have any
> tests that exercise multiple threads playing around with one world.
> 
> Andy
> 
> On 19 February 2011 02:41, Thorsten Gast <gasttor@xxxxxx> wrote:
> > Hi Andy,
> >
> > thanks for the fast reposnse. I will raise a bugzille on monday. I am
> within a spring context where prototype beans are loaded via an ObjectFactory
> bean. The exception mainly occurs on the first request after starting the
> server and the system is under load.
> >
> > Thorsten
> >
> > -------- Original-Nachricht --------
> >> Datum: Fri, 18 Feb 2011 15:55:04 -0800
> >> Von: Andy Clement <andrew.clement@xxxxxxxxx>
> >> An: aspectj-users@xxxxxxxxxxx
> >> Betreff: Re: [aspectj-users] Creation of parameterized ReferenceType
> not thread safe
> >
> >> Hi Thorsten,
> >>
> >> Looks like a bug.  Can you raise a bugzilla?  My opening position
> >> would be that the AspectJ weaver is a single threaded thing. But I
> >> know ReflectionWorlds are used in instances other than just regular
> >> weaving (for example, in a spring setup) - are you in Spring by any
> >> chance when you see this issue?
> >>
> >> cheers
> >> Andy
> >>
> >> On 18 February 2011 01:45, Gast, Thorsten <thorsten.gast@xxxxxxxxxxxx>
> >> wrote:
> >> > Hi,
> >> >
> >> > I am currently struggling with an IndexOutOfBoundsException deep in
> >> aspectj.
> >> >
> >> >        at java.util.ArrayList.add(ArrayList.java:352)
> >> >        at
> >>
> org.aspectj.weaver.ReferenceType.addDependentType(ReferenceType.java:115)
> >> >        at
> >> org.aspectj.weaver.ReferenceType.<init>(ReferenceType.java:95)
> >> >        at
> >>
> org.aspectj.weaver.TypeFactory.createParameterizedType(TypeFactory.java:43)
> >> >
> >> > After taking a deeper look into the code, I found out that the usage
> of
> >> TypeFactory.createParameterizedType() and in particular the
> instantiation
> >> of ReferenceType (line 43 of TypeFactory) is not thread safe. In a
> short
> >> program (see below) I could reproduce this issue, when passing the same
> >> instance of ResolvedType.
> >> >
> >> > Is this a bug, or should this not happen when aspectj is used in a
> >> proper way?
> >> >
> >> > Regards
> >> >
> >> > Thorsten
> >> >
> >> >
> >> > --- sample program start ---
> >> > import java.util.concurrent.CountDownLatch;
> >> >
> >> > import org.aspectj.weaver.ReferenceType;
> >> > import org.aspectj.weaver.ResolvedType;
> >> > import org.aspectj.weaver.TypeFactory;
> >> > import org.aspectj.weaver.World;
> >> > import
> >> org.aspectj.weaver.reflect.Java15ReflectionBasedReferenceTypeDelegate;
> >> > import org.aspectj.weaver.reflect.ReflectionWorld;
> >> >
> >> > public class Aspectj {
> >> >
> >> >    public static void main(String[] args) {
> >> >        new Aspectj();
> >> >    }
> >> >
> >> >    static World inAWorld = new
> >> ReflectionWorld(Aspectj.class.getClassLoader());
> >> >
> >> >    static ReferenceType aBaseType;
> >> >    static {
> >> >        aBaseType = new ReferenceType("test", inAWorld);
> >> >        Java15ReflectionBasedReferenceTypeDelegate delegate = new
> >> Java15ReflectionBasedReferenceTypeDelegate();
> >> >        delegate.initialize(aBaseType, String.class,
> >> Aspectj.class.getClassLoader(), inAWorld);
> >> >        aBaseType.setDelegate(delegate);
> >> >    }
> >> >
> >> >    public Aspectj() {
> >> >        int N = 25;
> >> >        CountDownLatch startSignal = new CountDownLatch(1);
> >> >        CountDownLatch doneSignal = new CountDownLatch(N);
> >> >
> >> >        for (int i = 0; i < N; ++i)
> >> >            new Thread(new Worker(startSignal,
> >> doneSignal)).start();
> >> >
> >> >        startSignal.countDown();
> >> >        try {
> >> >            doneSignal.await();
> >> >        } catch  (InterruptedException e){
> >> >            e.printStackTrace();
> >> >        }
> >> >    }
> >> >
> >> >    class Worker implements Runnable {
> >> >        private final CountDownLatch startSignal;
> >> >        private final CountDownLatch doneSignal;
> >> >
> >> >        Worker(CountDownLatch startSignal, CountDownLatch
> doneSignal)
> >> {
> >> >            this.startSignal = startSignal;
> >> >            this.doneSignal = doneSignal;
> >> >        }
> >> >
> >> >        public void run() {
> >> >            try {
> >> >                startSignal.await();
> >> >                doWork();
> >> >                doneSignal.countDown();
> >> >            } catch (InterruptedException ex) {
> >> >                ex.printStackTrace();
> >> >            }
> >> >        }
> >> >
> >> >        void doWork() {
> >> >            for (int i = 0; i < 10; i++) {
> >> >                // using TypeFactory
> >> >                TypeFactory.createParameterizedType(aBaseType,
> >> new ResolvedType[0], inAWorld);
> >> >
> >> >                // or creating ReferenceTypes directly
> >> >                //new ReferenceType(aBaseType, new
> >> ResolvedType[0], inAWorld);
> >> >            }
> >> >        }
> >> >    }
> >> >
> >> > }
> >> > --- sample program end ---
> >> >
> >> > _______________________________________________
> >> > aspectj-users mailing list
> >> > aspectj-users@xxxxxxxxxxx
> >> > https://dev.eclipse.org/mailman/listinfo/aspectj-users
> >> >
> >> _______________________________________________
> >> aspectj-users mailing list
> >> aspectj-users@xxxxxxxxxxx
> >> https://dev.eclipse.org/mailman/listinfo/aspectj-users
> >
> > --
> > Schon gehört? GMX hat einen genialen Phishing-Filter in die
> > Toolbar eingebaut! http://www.gmx.net/de/go/toolbar
> > _______________________________________________
> > aspectj-users mailing list
> > aspectj-users@xxxxxxxxxxx
> > https://dev.eclipse.org/mailman/listinfo/aspectj-users
> >
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/aspectj-users

-- 
Empfehlen Sie GMX DSL Ihren Freunden und Bekannten und wir
belohnen Sie mit bis zu 50,- Euro! https://freundschaftswerbung.gmx.de


Back to the top