[9] RFR of 8065556: (bf) Buffer.position and other methods should include detail in IAE

Brian Burkhalter brian.burkhalter at oracle.com
Fri Apr 24 18:52:32 UTC 2015


On Apr 23, 2015, at 9:38 AM, Alan Bateman <Alan.Bateman at oracle.com> wrote:

> The approach looks okay to me. It would have been interesting to have done micro benchmarks to see it matches Martin's observation/bug as that was news to me.

Here are some results using JMH with my local JDK9 fastdebug builds. 

Ubuntu 12.04-x86 VM, 1 fork, 20 warmup iterations, 25 benchmark iterations

Benchmark                                       Mode  Cnt       Score      Error  Units
MyBenchmark.createAndThrowException            thrpt   25  726912.251 ± 4290.454  ops/s
MyBenchmark.createAndThrowExceptionWithParams  thrpt   25  636919.265 ± 3861.024  ops/s
MyBenchmark.throwReturnedException             thrpt   25  739061.398 ± 3653.874  ops/s
MyBenchmark.throwReturnedExceptionWithParams   thrpt   25  642605.571 ± 3602.519  ops/s

Mac OS 10.9.5 native, 2 forks, 20 warmup iterations, 25 benchmark iterations

Benchmark                                       Mode  Cnt      Score      Error  Units
MyBenchmark.createAndThrowException            thrpt   50  80054.822 ±  257.876  ops/s
MyBenchmark.createAndThrowExceptionWithParams  thrpt   50  60709.551 ±  198.745  ops/s
MyBenchmark.throwReturnedException             thrpt   50  65792.276 ± 2750.755  ops/s
MyBenchmark.throwReturnedExceptionWithParams   thrpt   50  75005.831 ± 2048.279  ops/s

The benchmark source is included below.

These results look to me to be rather ambiguous on OS X. On Linux there is no significant difference between the invoked failure method throwing the exception directly versus the calling method throwing the exception returned by a method although the mean value for the latter approach is slightly faster.

I am not particularly a “performance guy” so if you’ve any suggestions regarding these benchmarks please don’t hesitate to educate me a little.

> In Buffer then it would be nice to reduce the method names a bit so that the declarations don't spill over two lines. I realize it's just nit picking but it's good to keep the code consistent when you can.

Please see the updated patch at:

http://cr.openjdk.java.net/~bpb/8065556/webrev.05/

Summary: Changed IllegalArgumentException-returning method names to shorter versions all of the form createXYZException() so as to eliminate line wrapping.

Thanks,

Brian

— Benchmark Source —

    static IllegalArgumentException createIAE() {
        return new IllegalArgumentException("You passed in a lame parameter, dude!");
    }

    static void throwIAE() {
        throw new IllegalArgumentException("You passed in a lame parameter, dude!");
    }

    static IllegalArgumentException createIAEWithParams(int p1, int p2) {
        return new IllegalArgumentException("Bad param 1 " + p1
                                            + " bad param 2 " + p2);
    }

    static void throwIAEWithParams(int p1, int p2) {
        throw new IllegalArgumentException("Bad param 1 " + p1
                                           + " bad param 2 " + p2);
    }

    @Benchmark
    public IllegalArgumentException throwReturnedException() {
        try {
            throw createIAE();
        } catch (IllegalArgumentException e) {
            return e;
        }
    }

    @Benchmark
    public IllegalArgumentException throwReturnedExceptionWithParams() {
        try {
            throw createIAEWithParams(42, 666);
        } catch (IllegalArgumentException e) {
            return e;
        }
    }

    @Benchmark
    public IllegalArgumentException createAndThrowException() {
        try {
            throwIAE();
        } catch (IllegalArgumentException e) {
            return e;
        }
        return null;
    }

    @Benchmark
    public IllegalArgumentException createAndThrowExceptionWithParams() {
        try {
            throwIAEWithParams(42, 666);
        } catch (IllegalArgumentException e) {
            return e;
        }
        return null;
    }
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.openjdk.java.net/pipermail/nio-dev/attachments/20150424/9eb315cb/attachment.html>


More information about the nio-dev mailing list