Skip to main content

[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 Simone,

	Sorry about the silence :) I've tried the solution, but not worked.
I'm not sure why, but finally I'm choosed a solution based on an
WeakReferences queue for instances unloading. Thanks anyway for your help.

Regards, Federico


-----Mensaje original-----
De: aspectj-users-bounces@xxxxxxxxxxx
[mailto:aspectj-users-bounces@xxxxxxxxxxx] En nombre de Simone Gianni
Enviado el: miƩrcoles, 10 de junio de 2009 14:32
Para: aspectj-users@xxxxxxxxxxx
Asunto: Re: [aspectj-users] around advice not matching with finalize method

Hi Federico,
have you tried this solution? Is it working? Is there something obvious 
I haven't considered when posting it?

Simone

Simone Gianni wrote:
> Hi Andy and Federico,
> couldn't "hasmethod" be used here?
>  
>    public static interface HandledFinalize {
>        public void finalize();
>    }
>      public void HandledFinalize.finalize() {
>        super.finalize();
>    }
>      declare parents : !hasmethod(public void finalize()) implements 
> HandledFinalize;
>      after() : execution(public void *.finalize()) {
>          }
>
> Obviously you need the -XhasMember compiler option to support 
> hasMethod and hasField.
>
> Basically you "inject" a finalize method where it is not declared, and 
> then normally advice it to give it a more useful body.
>
> Obviously, it will not work on "any class", but an any weave-able 
> class yes :)
>
> I must admit I haven't tested it, but compiles and could be a way. I 
> used something similar before, but not on finalize methods.
>
> Hope it helps,
> Simone
>
> Andy Clement wrote:
>> I see.  Yes, unless Object is woven, you won't be able to advise
>> methods within it.  And I wouldn't recommend weaving Object.
>>
>> Usually in this case you can switch to weaving the call join point -
>> but calls to finalize won't be in your control either.
>>
>> Andy
>>
>> 2009/6/8 Federico Firpo Bodner <federico@xxxxxxxxxxxx>:
>>  
>>> 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
>>>
>>> _______________________________________________
>>> 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
>>   
>
>


-- 
Simone Gianni            CEO Semeru s.r.l.           Apache Committer
http://www.simonegianni.it/

_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/aspectj-users



Back to the top