8138978: Examine usages of sun.misc.IOUtils jdk8u242-b07

Mon, 13 Jan 2020 02:15:57 +0000

author
andrew
date
Mon, 13 Jan 2020 02:15:57 +0000
changeset 9804
8b80409d5840
parent 9803
f37db4bd396c
child 9805
7c9f6b5f8d11

8138978: Examine usages of sun.misc.IOUtils
Reviewed-by: mbalao

test/compiler/classUnloading/anonymousClass/TestAnonymousClassUnloading.java file | annotate | diff | comparison | revisions
test/runtime/8003720/VictimClassLoader.java file | annotate | diff | comparison | revisions
     1.1 --- a/test/compiler/classUnloading/anonymousClass/TestAnonymousClassUnloading.java	Tue Oct 08 10:26:17 2019 -0400
     1.2 +++ b/test/compiler/classUnloading/anonymousClass/TestAnonymousClassUnloading.java	Mon Jan 13 02:15:57 2020 +0000
     1.3 @@ -22,9 +22,10 @@
     1.4   */
     1.5  
     1.6  import sun.hotspot.WhiteBox;
     1.7 +import sun.misc.IOUtils;
     1.8  import sun.misc.Unsafe;
     1.9 -import sun.misc.IOUtils;
    1.10  
    1.11 +import java.io.IOException;
    1.12  import java.lang.reflect.Method;
    1.13  import java.net.URL;
    1.14  import java.net.URLConnection;
    1.15 @@ -108,7 +109,13 @@
    1.16          // (1) Load an anonymous version of this class using the corresponding Unsafe method
    1.17          URL classUrl = TestAnonymousClassUnloading.class.getResource("TestAnonymousClassUnloading.class");
    1.18          URLConnection connection = classUrl.openConnection();
    1.19 -        byte[] classBytes = IOUtils.readFully(connection.getInputStream(), connection.getContentLength(), true);
    1.20 +
    1.21 +        int length = connection.getContentLength();
    1.22 +        byte[] classBytes = IOUtils.readAllBytes(connection.getInputStream());
    1.23 +        if (length != -1 && classBytes.length != length) {
    1.24 +            throw new IOException("Expected:" + length + ", actual: " + classBytes.length);
    1.25 +        }
    1.26 +
    1.27          Class<?> anonymousClass = UNSAFE.defineAnonymousClass(TestAnonymousClassUnloading.class, classBytes, null);
    1.28  
    1.29          // (2) Make sure all paths of doWork are profiled and compiled
     2.1 --- a/test/runtime/8003720/VictimClassLoader.java	Tue Oct 08 10:26:17 2019 -0400
     2.2 +++ b/test/runtime/8003720/VictimClassLoader.java	Mon Jan 13 02:15:57 2020 +0000
     2.3 @@ -22,6 +22,8 @@
     2.4   *
     2.5   */
     2.6  
     2.7 +import sun.misc.IOUtils;
     2.8 +
     2.9  public class VictimClassLoader extends ClassLoader {
    2.10      public static long counter = 0;
    2.11  
    2.12 @@ -72,8 +74,10 @@
    2.13      }
    2.14  
    2.15      static byte[] readFully(java.io.InputStream in, int len) throws java.io.IOException {
    2.16 -        // Warning here:
    2.17 -        return sun.misc.IOUtils.readFully(in, len, true);
    2.18 +        byte[] b = IOUtils.readAllBytes(in);
    2.19 +        if (len != -1 && b.length != len)
    2.20 +            throw new java.io.IOException("Expected:" + len + ", actual:" + b.length);
    2.21 +        return b;
    2.22      }
    2.23  
    2.24      public void finalize() {

mercurial