Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-dev] Array access


Christian,

>However, for my application it is crucial
>to find out what kind of access (read or write of an array cell) happened.
>Is there a way to do so?


No, because unfortunately you cannot advise the array element get/set only the field itself. Before you can access an array element you must first access the field. In the example the statement "ints[0] = 999;" actually comprises 2 join points of which only the first, accessing the "ints" field, is currently part of the AspectJ language.

I have added a comment to https://bugs.eclipse.org/bugs/show_bug.cgi?id=157031.

Matthew Webster
AOSD Project
Java Technology Centre, MP146
IBM Hursley Park, Winchester,  SO21 2JN, England
Telephone: +44 196 2816139 (external) 246139 (internal)
Email: Matthew Webster/UK/IBM @ IBMGB, matthew_webster@xxxxxxxxxx
http://w3.hursley.ibm.com/~websterm/



Christian Hammer <chammer@xxxxxxxxxx>
Sent by: aspectj-dev-bounces@xxxxxxxxxxx

13/09/2006 15:08

Please respond to
AspectJ developer discussions <aspectj-dev@xxxxxxxxxxx>

To
AspectJ developer discussions <aspectj-dev@xxxxxxxxxxx>
cc
Subject
Re: [aspectj-dev] Array access





Thanks Matthew.

Actually, the index is not my priority. Currently, both array get and array
set bytecodes (accessing only one cell) are captured by the get pointcut in
the last advice in your example. However, for my application it is crucial
to find out what kind of access (read or write of an array cell) happened.
Is there a way to do so?




                                                                         
            Matthew Webster                                              
            <matthew_webster@                                            
            uk.ibm.com>                                                To
            Sent by:                  wes@xxxxxxxxxxxxxx, AspectJ        
            aspectj-dev-bounc         developer discussions              
            es@xxxxxxxxxxx            <aspectj-dev@xxxxxxxxxxx>          
                                                                       cc
                                                                         
            09/13/2006 06:14                                      Subject
            AM                        Re: [aspectj-dev] Array access      
                                                                         
                                                                         
            Please respond to                                            
            AspectJ developer                                            
               discussions                                                
            <aspectj-dev@ecli                                            
                pse.org>                                                  
                                                                         
                                                                         





Christian,

You can advise array constructions (
https://bugs.eclipse.org/bugs/show_bug.cgi?id=77166) and access.
Unfortunately you cannot (yet) determine the index used when access and
array or the identity of the element. In the example below the object
traced is the array itself:

public class Test {

       private static int[] ints;

       public static void main(String[] args) {
               ints = new int[1];
               ints[0] = 999;
               System.out.println("Test.main() ints[0]=" + ints);
       }

}

public aspect Aspect {

       after() returning(Object ret): call(int[].new(..)) {
               System.out.println("Aspect.afterReturning() " +
thisJoinPoint + ", ret=" + ret);
       }

       before (Object arg) : set(int[] *) && args(arg){
               System.out.println("Aspect.before() " + thisJoinPoint + ",
arg=" + arg);
       }

       after () returning(Object ret) : get(int[] *) {
               System.out.println("Aspect.after() " + thisJoinPoint + ",
ret=" + ret);
       }
}



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


Back to the top