The SLOTS case is a little surprising, in that the call should have
been quickly inlined and reduced to the array addressing case.  The
array-addressing case is also a bit surprising -- a good JIT should
have been able to pull the array bounds check out of the loop,
reducing the loop body to the equivalent of the getfield case.

I'm not sure what you were trying to test with the exception case --
exceptions only become a factor if they prevent some JIT optimization,
and nothing there that would do that.

A good JIT can flatten the invokeinterface case pretty well, though in
more complex scenarios there might have to be a check that the actual
class is the same as last time.  (A little surprised that the JIT you
used did so well on this case but not so well on the array case.)

On Nov 1, 7:48 pm, [email protected] wrote:
> ABCL,
>   For implementing MOP-like objects these times are something to consider.
>
>   What I draw from it is when not messing with arrays (array bounds checking).
>    Every case is better than.
>
> JVM-L,
>    Do these tests with times make sense?
>
> package ArrayTests;
>
> public class ArrayVsClass {
>
>  public static void main(String[] args) {
>   long lVectorStartTime = System.currentTimeMillis();
>   int iterations = Integer.MAX_VALUE;
>   while (iterations-- > 0) {
>   // int iterations2 = 10;
>    //while (iterations2-- > 0)
>    {
>        //testArray(); // ARRAY
>     // vs
>     //testGETFIELD(); // GETFIELD
>     // vs
>     testIBean(); // INVOKE INTERFACE
>     // vs
>     //testBean(); // INVOKE VIRTUAL
>     // vs
>     //testABean(); // INVOKE VIRTUAL POSSIBLY THROW
>     // vs
>     //testSlots(); // INVOKE FOR AVALUE
>    }
>   }
>   long lVectorRunTime = System.currentTimeMillis() - lVectorStartTime;
>   System.out.println("Bench time: " + lVectorRunTime);
>
>  }
>
>  // SLOTS time: 33157,33250,33156
>  public static void testSlots() {
>   ClassWithSlots oneSlot = new ClassWithSlots(6);
>
>   int iterations = Integer.MAX_VALUE;
>   long result = 0;
>   while (iterations-- > 0) {
>    result += oneSlot.getValue();
>   }
>  }
>
>  // Array time: 18438,18437,18422
>  public static void testArray() {
>   final long[] accessArray = new long[] { 6 };
>   int iterations = Integer.MAX_VALUE;
>   long result = 0;
>   while (iterations-- > 0) {
>    result += accessArray[0];
>   }
>  }
>
>  // GETFIELD time: 14688,14531,14453
>  public static void testGETFIELD() {
>   ClassWithOneSlot oneSlot = new ClassWithOneSlot(6);
>
>   int iterations = Integer.MAX_VALUE;
>   long result = 0;
>   while (iterations-- > 0) {
>    result += oneSlot.slot;
>   }
>  }
>
>  // INVOKE VIRTUAL time: 14750,14594,14719
>  public static void testBean() {
>   ClassWithOneSlot oneSlot = new ClassWithOneSlot(6);
>
>   int iterations = Integer.MAX_VALUE;
>   long result = 0;
>   while (iterations-- > 0) {
>    result += oneSlot.getValue();
>   }
>  }
>
>  // INVOKE INTERFACE time: 14469,14610,14859
>  public static void testIBean() {
>   IBeanWithOneSlot oneSlot = new ClassWithOneSlot(6);
>
>   int iterations = Integer.MAX_VALUE;
>   long result = 0;
>   while (iterations-- > 0) {
>    result += oneSlot.getValue();
>   }
>  }
>
>  // INVOKE VIRTUAL POSSIBLY THROW time: 14641,14594,14547
>  public static void testABean() {
>   AClassWithOneSlot oneSlot = new ClassWithOneSlot(6);
>
>   int iterations = Integer.MAX_VALUE;
>   long result = 0;
>   while (iterations-- > 0) {
>    result += oneSlot.getValue();
>   }
>  }
>
>  static interface IBeanWithOneSlot {
>   public long getValue();
>  }
>
>  static class ClassWithOneSlot extends AClassWithOneSlot implements 
> IBeanWithOneSlot {
>   final public long slot;
>
>   ClassWithOneSlot(long s) {
>    slot = s;
>   }
>
>   @Override
>   final public long getValue() {
>    return slot;
>   }
>  }
>
>  static class ClassWithSlots  {
>   final public long[] slots = new long[1];
>
>   ClassWithSlots(long s) {
>    slots[0] = s;
>   }
>
>   final public long getValue() {
>    return slots[0];
>   }
>  }
>
>  static abstract class AClassWithOneSlot implements IBeanWithOneSlot {
>
>   @Override
>   public long getValue() {
>    throw new NullPointerException();
>   }
>
>  }
>
> }

--

You received this message because you are subscribed to the Google Groups "JVM 
Languages" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/jvm-languages?hl=.


Reply via email to