adoptium / bumblebench

A microbenchmarking test framework for Eclipse Adoptium
Apache License 2.0
22 stars 31 forks source link

sun.misc.IOUtils.readFully throws exception due to negative length argument #21

Closed mayshukla closed 4 years ago

mayshukla commented 4 years ago

When trying to run a HumbleBench using the latest adoptopenjdk openjdk8 nightly builds, I got the following exception:

Exception in thread "main" java.lang.AssertionError: java.lang.reflect.InvocationTargetException
    at net.adoptopenjdk.bumblebench.core.Util.readFully(Util.java:201)
    at net.adoptopenjdk.bumblebench.core.Util.freshlyLoadedClass(Util.java:184)
    at net.adoptopenjdk.bumblebench.core.Util.newInstanceOfPossiblyFreshlyLoadedClass(Util.java:223)
    at net.adoptopenjdk.bumblebench.core.Util.newInstanceOfFreshlyLoadedClass(Util.java:210)
    at net.adoptopenjdk.bumblebench.core.HumbleBench$DelayThread.<init>(HumbleBench.java:134)
    at net.adoptopenjdk.bumblebench.core.HumbleBench.<init>(HumbleBench.java:57)
    at CxfMessageHumbleBench.<init>(CxfMessageHumbleBench.java:7)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at java.lang.Class.newInstance(Class.java:442)
    at net.adoptopenjdk.bumblebench.core.Launcher.main(Launcher.java:55)
Caused by: java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at net.adoptopenjdk.bumblebench.core.Util.readFully(Util.java:194)
    ... 12 more
Caused by: java.io.IOException: length cannot be negative: -1
    at sun.misc.IOUtils.readFully(IOUtils.java:305)
    ... 17 more

I think the problem is here: https://github.com/AdoptOpenJDK/bumblebench/blob/master/net/adoptopenjdk/bumblebench/core/Util.java#L194

On that line, method readFully is called with a length of -1.

I also found this PR in openj9 where a similar issue was dealt with: https://github.com/eclipse/openj9/pull/8312

It looks like the fix would either be to pass Integer.MAX_VALUE to readFully or use the new IOUtils.readAllBytes method.

piyush286 commented 4 years ago

@kusumachalasani Can you please take a look when you get a chance?

kusumachalasani commented 4 years ago

Tested the fix using the examples of humble.

Sample Output screenshots of both failing and passing cases: Failed Output: (uses old code)

HumbleBench target %paused:  96.0%
HumbleBench set default batchTargetDuration to 120
Exception in thread "main" java.lang.AssertionError: java.lang.reflect.InvocationTargetException
        at net.adoptopenjdk.bumblebench.core.Util.readFully(Util.java:201)
        at net.adoptopenjdk.bumblebench.core.Util.freshlyLoadedClass(Util.java:184)
        at net.adoptopenjdk.bumblebench.core.Util.newInstanceOfPossiblyFreshlyLoadedClass(Util.java:223)
        at net.adoptopenjdk.bumblebench.core.Util.newInstanceOfFreshlyLoadedClass(Util.java:210)
        at net.adoptopenjdk.bumblebench.core.HumbleBench$DelayThread.<init>(HumbleBench.java:134)
        at net.adoptopenjdk.bumblebench.core.HumbleBench.<init>(HumbleBench.java:57)
        at net.adoptopenjdk.bumblebench.humble.DistinctStringsEqualsBench.<init>(DistinctStringsEqualsBench.java:35)
        at java.lang.J9VMInternals.newInstanceImpl(Native Method)
        at java.lang.Class.newInstance(Class.java:1852)
        at net.adoptopenjdk.bumblebench.core.Launcher.main(Launcher.java:55)
Caused by: java.lang.reflect.InvocationTargetException
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at net.adoptopenjdk.bumblebench.core.Util.readFully(Util.java:194)
        ... 9 more
Caused by: java.io.IOException: length cannot be negative: -1
        at sun.misc.IOUtils.readFully(IOUtils.java:305)
        ... 14 more

After the fix:

HumbleBench target %paused:  96.0%
HumbleBench set default batchTargetDuration to 120

-= BumbleBench series 7 version 5.10 running DistinctStringsEqualsBench  Mon Apr 13 10:16:20 UTC 2020 =-

              Target    Est     Uncert% MaxPeak Peak    Peak%   %paused
    0.0s:  >! 110       268.6K   40.0   110     110     470.0    98.3
    0.1s:  >! 322.4K    7.725M   40.0   322.4K  322.4K  1268.3   95.5
    4.4s:  <  9.270M    6.553M   24.0   322.4K  322.4K  1268.3   96.0
    6.6s:  >  5.766M    7.853M   14.4   5.766M  5.766M  1556.8   96.0
    8.7s:  >! 8.419M    12.08M   40.0   8.419M  8.419M  1594.6   96.0
   10.9s:  >! 14.50M    19.57M   40.0   14.50M  14.50M  1648.9   96.0
   13.0s:  >! 23.48M    34.53M   40.0   23.48M  23.48M  1697.2   96.0
   14.5s:  >! 41.44M    82.06M   40.0   41.44M  41.44M  1754.0   96.0
   18.4s:  <  98.48M    75.93M   24.0   41.44M  41.44M  1754.0   96.0
   20.8s:  >  66.82M    81.31M   14.4   66.82M  66.82M  1801.7   96.0
   24.0s:  <  87.17M    82.67M    8.6   66.82M  66.82M  1801.7   96.0
   26.8s:  >  79.10M    83.11M    5.2   79.10M  79.10M  1818.6   96.0