[abc-users] Question on arrayget/arrayset pointcuts

From: Richard Gomes <rgomes1997_at_yahoo.co.uk>
Date: Wed, 12 Aug 2009 14:03:24 +0100

Hi,

This is my first post to this list.
In spite I recognize interesting applications for AOP, projects I was
involved before never adopted AOP.
It means that my knowledge of it is restricted to very generic concepts.

I'd like to ask you guys some guidance. Actually, I don't know whether
my idea makes sense or not and, if makes sense, I didn't find enough
information about how it could be implemented.

Suppose a class like this:

class Matrix {
    private int rows; // number of rows
    private int cols; // number of columns
    private int length; // rows*cols

    public double doubles[]; // This is where data is
actually stored. It's initialized elsewhere.
    public final double data[][] = null; // Only used to "trap" array
access; no data actually stored here!

    /** This method maps a bi-dimensional address <i,j> into a
unidimensional address <i*cols + j> */
    private addr(int i, int j) { return i*cols + j; }

}

So, when one writes...
                         matrix.data[i][j]
... I'd like to replace the previous generated bytecode by something
generated by
                        matrix.doubles[matrix.addr(i,j)]

Can it be done somehow using arrayget/arrayset pointcuts?
Any help would be very much appreciated.

PS:
Maybe you are curious about why such a weird idea. In a nutshell:

    a. Access to double[] is faster than access to double[][]
    b. JDK7 jit optimizer will be able to avoid access checking
    instructions (which may throw ArrayIndexOutOfBoundsException) when
    array access is known to succeed, providing a performance gain of
    ~20% (according to some articles I found).
    c. Languages like C++ maps multidimensional arrays to a
    unidimensional array.

Kind Regards

-- 
Richard Gomes
http://www.jquantlib.org/index.php/User:RichardGomes
twitter: frgomes
JQuantLib is a library for Quantitative Finance written in Java.
http://www.jquantlib.org/
twitter: jquantlib
Received on Wed Aug 12 2009 - 14:07:29 BST

This archive was generated by hypermail 2.2.0 : Fri Aug 28 2009 - 20:20:10 BST