You were right, the finalize methods are not called at all.

As a solution, I found the possibility to define shutdown hooks.

2009/10/14 Andrew Eisenberg <[email protected]>

> It may be that finalize methods are being called from native code in
> the jvm, so ajc will not be able to see them.  But, in any case, it is
> very tricky to weave into the jre (I'm not even sure it is possible
> when running in Eclipse, because you might be forced to use the
> regular jre at runtime).  If you absolutely must weave into the jre,
> then I'd suggest doing so from the command line:
>
> ajc -inpath rt.jar -outjar new_rt.jar MyAspect.java
>
> And then replacing your old rt.jar with the new one.
>
> And I believe it is entirely likely that the finalize methods are just
> not being called at all.  You can try this out by adding some println
> statements in them and seeing if they are ever printed.
>
> On Wed, Oct 14, 2009 at 4:38 AM, Christoph Kurrat
> <[email protected]> wrote:
> > Hi Andrew,
> >
> > thanks, i changed it in the suggested way.
> >
> > I've got one last question. I'm trying to capture the finalize calls of
> the
> > IO objects.
> >
> > The pointcut(s) I use are these:
> >
> > public pointcut writerFinalize() : call(void finalize())
> >             &&(target(FileWriter)||target(PrintWriter));
> > public pointcut randomAccessFileFinalize() : call(void finalize())
> >      &&target(RandomAccessFile);
> >
> > public pointcut finalizeAll() : writerFinalize() ||
> > randomAccessFileFinalize() || ...
> >
> > the advice:
> >
> >     after() : finalizeAll(){
> >         System.err.println("finalize...");
> >         close(thisJoinPoint.getTarget());
> >     }
> >
> > I added the JRE to the inpath
> >
> > Again, the warning "advice has not been applied" occurs.
> >
> > Changing the pointcuts into execution-pointcuts, the warning disappears,
> > although the advice isn't executed.
> > In addition, I tried to change the advice into before(): finalizeAll(),
> > without success.
> > Is there a possibility to capture finalize at all?
> > Or does the execution-pointcut apply and it is simply the VM that does
> not
> > call finalize?
> >
> > Christoph
> >
> >
> > 2009/10/13 Andrew Eisenberg <[email protected]>
> >>
> >> Hi Christoph,
> >>
> >> Your problem here is that for call() pointcuts, there is no target
> >> object (ie- it is always null).  The best way I can think of
> >> implementing your strategy is by using an internal map to keep track
> >> of boundTo objects.
> >>
> >> Can anyone think of a better solution?
> >>
> >> On Tue, Oct 13, 2009 at 6:55 AM, Christoph Kurrat
> >> <[email protected]> wrote:
> >> > Hi,
> >> >
> >> > I'm trying to log read and write accesses with aspectJ.
> >> > To do this, I want to capture the constructor calls, read and write
> >> > calls
> >> > and close calls of, for example, RandomAccessFile objects.
> >> > The logged data shall be saved inside the aspect. For this reason, I
> >> > want to
> >> > use pertarget to capture constructor invocations. The problem is, that
> >> > the
> >> > used pointcut doesn't seem to work; neither an aspect instance is
> >> > created,
> >> > nor the advice for the constructor is used; i get a "advice has not
> been
> >> > applied" message.
> >> >
> >> > These are the pointcuts used to capture the constructor calls.
> >> >
> >> > public pointcut randomAccessFileCreation() :
> >> > call(RandomAccessFile.new(..));
> >> > public pointcut writerCreation() : (call(FileWriter.new(..)) ||
> >> > call(PrintWriter.new(File,..)) || call(PrintWriter.new(String,..)));
> >> >
> >> > These pointcuts (and more, for example readerCreation() following the
> >> > same
> >> > principle) are joined with the newAspect() pointcut:
> >> >
> >> > public pointcut newAspect() : writerCreation() ||
> >> > randomAccessFileCreation();
> >> >
> >> >
> >> > The aspect is defined like this:
> >> > public privileged aspect loggingAspect pertarget(newAspect()){
> >> >
> >> >
> >> > The advice belonging to the newAspect() pointcut:
> >> >     after() returning(Object obj) : newAspect(){
> >> >         boundTo = obj;
> >> >         System.err.println("new Object " + boundTo);
> >> >         log.setTimeOpen(Calendar.getInstance().getTime());
> >> >         }
> >> >     }
> >> >
> >> > In the constructor of the aspect, i print a log message, too.
> >> >
> >> > None of the log messages is printed during the execution of the
> program.
> >> >
> >> > What am i doing wrong here?
> >> >
> >> > Thanks
> >> >
> >> > Christoph
> >> >
> >> > _______________________________________________
> >> > aspectj-users mailing list
> >> > [email protected]
> >> > https://dev.eclipse.org/mailman/listinfo/aspectj-users
> >> >
> >> >
> >> _______________________________________________
> >> aspectj-users mailing list
> >> [email protected]
> >> https://dev.eclipse.org/mailman/listinfo/aspectj-users
> >
> >
> > _______________________________________________
> > aspectj-users mailing list
> > [email protected]
> > https://dev.eclipse.org/mailman/listinfo/aspectj-users
> >
> >
> _______________________________________________
> aspectj-users mailing list
> [email protected]
> https://dev.eclipse.org/mailman/listinfo/aspectj-users
>
_______________________________________________
aspectj-users mailing list
[email protected]
https://dev.eclipse.org/mailman/listinfo/aspectj-users

Reply via email to