[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
RE: [aspectj-users] around advice not matching with finalize method
|
Hi Andy,
That's correct, but only because A.class are overriding the
finalize() method, but the pointcut doesn't match for any class with the
inerithed finalize from java.lang.Object. I want to advice any class when is
garbage collected, but apparently is not possible with the finalize method.
I did it implementing a Phantom References queue, which generates a lot of
memory consumption.
Thanks anyway, Federico.
-----Mensaje original-----
De: aspectj-users-bounces@xxxxxxxxxxx
[mailto:aspectj-users-bounces@xxxxxxxxxxx] En nombre de Andy Clement
Enviado el: lunes, 08 de junio de 2009 18:25
Para: aspectj-users@xxxxxxxxxxx
Asunto: Re: [aspectj-users] around advice not matching with finalize method
Hi Frederico,
I just tried it and it worked for me:
--- A.java ---
public class A {
public static void main(String[]argv) {
new A().create();
System.gc();
}
private void create() {
for (int i=0;i<1000;i++) { new A();
}
}
protected void finalize() throws Throwable {
System.err.println("Finalized");
}
}
aspect X {
before(Object o): execution(!static * finalize(..)) && this(o) {
System.out.println("("+o+")");
}
}
--- End of A.java ---
> java A
(A@9ed927)
Finalized
(A@c2a132)
Finalized
(A@1e51060)
Finalized
(A@19616c7)
Finalized
(A@b166b5)
Finalized
(A@cdfc9c)
Finalized
(A@1837697)
Finalized
(A@1decdec)
Finalized
(A@a1807c)
Finalized
(A@fa7e74)
Finalized
(A@183f74d)
Finalized
(A@e102dc)
Finalized
Have you tried enabling -showWeaveInfo to see if the method is woven?
Andy
2009/5/29 pilux <federico@xxxxxxxxxxxx>:
>
> Hi all,
>
> I'm trying to write an aspect for controlling every custom classes
> loaded. So, i've written a pointcut to exclude th system classes:
>
> public pointcut SystemExclusions() : !within(weblogic..*) &&
> !within(sun..*) && !within(org.apache..*) && !within(com.ibm..*) &&
> !within(*..*ogger*..*)
> && !within(AbstractMonitor+) && !within(glassbox..*) &&
> !within(org.aspectj..*) && !within(net.sf.hibernate..*)
> && !within(com.rsa..*) && !within(org.jboss..*) &&
> !within(org.eclipse..*) && !within(org.osgi..*) &&
> !within(com.bea.console..*)
> && !within(edu.emory.mathcs.util..*) && !within(uk.ltd.getahead.dwr..*)
> && !within(org.hsqldb..*) && !within(org.spring*..*);
>
> And another one for capturing the classes load:
>
> /* Clases */
> after() returning(Object o): call(!static Object+.new(..)) && this(*)
&&
> SystemExclusions()
> {
> //String key = findClassName(thisJoinPointStaticPart.toString());
> String key = o.getClass().getName();
> if(LocalDebug && false) System.err.println("[Pilux-Lucierna***] Se
> ha cargado una instancia de la clase: " + key);
> registerInstanceLoad(key, false);
> iterationsOcurred.increment();
> if (iterationsOcurred.getValue() >= dumpFrequency)
> reportConsoleOperations();
> }
>
> This is working fine, but for decrease the loaded classes counter, i'm
> trying to capture the finalize() execution method, with this advice:
>
> void around(Object o) : execution(!static * finalize(..)) && this(o)
> {
> String key = o.getClass().getName();
> if(LocalDebug) System.err.println("[Pilux-Lucierna***] Se ha
> descargado una instancia de la clase: " + key);
> registerInstanceLoad(key, true);
> iterationsOcurred.increment();
> if (iterationsOcurred.getValue() >= dumpFrequency)
> reportConsoleOperations();
> proceed(o);
> }
>
> I've overloaded a finalize() method from a custom class to force a
> message console when the gc() calls it, and the method is currently
running,
> but for any reason is not matching my pointcut. I'm running in an
evironment
> with several aspects running, I don't know if this matter. Somebody can
help
> me, please? I'll be very grateful!!!
>
> Thanks!
> Regards, Federico.
> --
> View this message in context:
http://www.nabble.com/around-advice-not-matching-with-finalize-method-tp2377
5987p23775987.html
> Sent from the AspectJ - users mailing list archive at Nabble.com.
>
> _______________________________________________
> 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