[armedbear-devel] AASTORE Removal - Bounds checking

logicmoo at gmail.com logicmoo at gmail.com
Thu Dec 3 22:49:27 UTC 2009


Dang.. yup and performance tests showed the same time for both:  1843/1844

The only time it doesn't do bounds check is when the  new (even multidemensional)
  array data is in the constant table.. and that cant happen with passed in args.



package ArrayTests;

public class AASTOREvsNEWARRAY {

  /**
   * @param args
   */
  public static void main(String[] args) {
    long lVectorStartTime = System.currentTimeMillis();
    testAALoad();
    long lVectorRunTime = System.currentTimeMillis() - lVectorStartTime;
    System.out.println(" time: " + lVectorRunTime);
  }

  // time: 1843
  public static void testAALoad() {
    final Object testObject = new Object();
    int iterations = Short.MAX_VALUE<<10;
    long result = 0;
    while (iterations-- > 0) {
      final Object[] accessArray = new Object[20];
      accessArray[0] = testObject;
      accessArray[1] = testObject;
      accessArray[2] = testObject;
      accessArray[3] = testObject;
      accessArray[4] = testObject;
      accessArray[5] = testObject;
      accessArray[6] = testObject;
      accessArray[7] = testObject;
      accessArray[8] = testObject;
      accessArray[9] = testObject;
      accessArray[10] = testObject;
      accessArray[11] = testObject;
      accessArray[12] = testObject;
      accessArray[13] = testObject;
      accessArray[14] = testObject;
      accessArray[15] = testObject;
      accessArray[16] = testObject;
      accessArray[17] = testObject;
      accessArray[18] = testObject;
      accessArray[19] = testObject;
      passIt(accessArray);
    }
  }

  // time: 1844
  public static void testANEWARRY() {
    final Object testObject = new Object();
    int iterations = Short.MAX_VALUE<<10;
    long result = 0;
    while (iterations-- > 0) {
      final Object[] accessArray = new Object[] { testObject, testObject, testObject, testObject, testObject,
          testObject, testObject, testObject, testObject, testObject, testObject, testObject, testObject, testObject,
          testObject, testObject, testObject, testObject, testObject, testObject };
      passIt(accessArray);
    }
  }

  static void passIt(Object[] accessArray) {
    // fake some use so no jit empty method emimination
    int i = accessArray.length;
  }

}


----- Original Message ----- 
From: "Alessio Stalla" <alessiostalla at gmail.com>
To: <dmiles at users.sourceforge.net>
Cc: "Armed Bear" <armedbear-devel at common-lisp.net>
Sent: Thursday, December 03, 2009 12:32 PM
Subject: Re: [armedbear-devel] AASTORE Removal - Bounds checking


On Thu, Dec 3, 2009 at 9:24 PM,  <logicmoo at gmail.com> wrote:
> With the execute(...) functions in Primitive.java
>
> @Override
> public LispObject execute(LispObject first, LispObject second,
> LispObject third)
>
> {
> LispObject[] args = new LispObject[3];
> args[0] = first;
> args[1] = second;
> args[2] = third;
> return execute(args);
> }
>
> Should probably be transformed to
>
> @Override
> public LispObject execute(LispObject first, LispObject second,
> LispObject third)
>
> {
> return execute(new LispObject[]{first,second,third});
> }
>
> To remove the redundant bounds checking of AASTORE

I believe that javac translates the second method to the exact same
code as the first. Bounds checking can't be eliminated in Java as far
as I know.

Alessio




More information about the armedbear-devel mailing list