8219876: (bf) Improve IndexOutOfBoundsException messages in $Type$Buffer classes

Brian Burkhalter brian.burkhalter at oracle.com
Thu Feb 28 21:57:49 UTC 2019


> On Feb 27, 2019, at 11:57 PM, Alan Bateman <Alan.Bateman at oracle.com> wrote:
> 
> I assume you'll run benchmarks and/or look at the generated code to make sure that the checks inline as expected. 


The benchmark output [1] shows a small improvement for a 1024-byte bulk get and a slight degradation for a 1-byte bulk get. The benchmark code is [2].

The disassembled classes [3] (from ‘javap -c’) differ in the presence of a “pop” for the new code containing Objects.checkFromIndexSize().

Thanks,

Brian

[1] Benchmark output
[A] Before

Benchmark                 Mode  Cnt          Score         Error  Units
CheckBounds.bulkGet1     thrpt    5  183273461.428 ± 1139045.897  ops/s
CheckBounds.bulkGet1024  thrpt    5   31629761.018 ±  214187.677  ops/s

[B] After

Benchmark                 Mode  Cnt          Score         Error  Units
CheckBounds.bulkGet1     thrpt    5  177589604.771 ± 6174996.093  ops/s
CheckBounds.bulkGet1024  thrpt    5   32749414.040 ±  336815.284  ops/s

[2] Benchmark snippet

public class CheckBounds {

    private static ByteBuffer buf = ByteBuffer.allocate(1024);
    private static byte[] arr = new byte[1024];
    private static int count = 0;

    static {
        buf.put(0, (byte)42);
    };

    @Benchmark
    public int bulkGet1() {
        buf.rewind();
        buf.get(arr, 0, 1);
        return count++;
    }

    @Benchmark
    public int bulkGet1024() {
        buf.rewind();
        buf.get(arr, 0, 1024);
        return count++;
    }

}

[3] Disassembled classes
[A] Before

  public java.nio.ByteBuffer get(byte[], int, int);
    Code:
       0: iload_2
       1: iload_3
       2: aload_1
       3: arraylength
       4: invokestatic  #19                 // Method checkBounds:(III)V
       7: iload_3
       8: aload_0
       9: invokevirtual #20                 // Method remaining:()I
      12: if_icmple     23
      […]

[B] After

  public java.nio.ByteBuffer get(byte[], int, int);
    Code:
       0: iload_2
       1: iload_3
       2: aload_1
       3: arraylength
       4: invokestatic  #19                 // Method java/util/Objects.checkFromIndexSize:(III)I
       7: pop
       8: iload_3
       9: aload_0
      10: invokevirtual #20                 // Method remaining:()I
      13: if_icmple     24
      […]
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.java.net/pipermail/nio-dev/attachments/20190228/83a570cf/attachment.html>


More information about the nio-dev mailing list