From ec7859dc72e73c5ab6edcc1ddbe942e731724e89 Mon Sep 17 00:00:00 2001 From: andrew Date: Mon, 13 Jan 2020 02:15:57 +0000 Subject: [PATCH] 8138978: Examine usages of sun.misc.IOUtils Reviewed-by: mbalao --- .../anonymousClass/TestAnonymousClassUnloading.java | 11 +++++++++-- test/runtime/8003720/VictimClassLoader.java | 8 ++++++-- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/test/compiler/classUnloading/anonymousClass/TestAnonymousClassUnloading.java b/test/compiler/classUnloading/anonymousClass/TestAnonymousClassUnloading.java index 6fbaf9cef..9ff45492f 100644 --- a/test/compiler/classUnloading/anonymousClass/TestAnonymousClassUnloading.java +++ b/test/compiler/classUnloading/anonymousClass/TestAnonymousClassUnloading.java @@ -22,9 +22,10 @@ */ import sun.hotspot.WhiteBox; -import sun.misc.Unsafe; import sun.misc.IOUtils; +import sun.misc.Unsafe; +import java.io.IOException; import java.lang.reflect.Method; import java.net.URL; import java.net.URLConnection; @@ -108,7 +109,13 @@ public class TestAnonymousClassUnloading { // (1) Load an anonymous version of this class using the corresponding Unsafe method URL classUrl = TestAnonymousClassUnloading.class.getResource("TestAnonymousClassUnloading.class"); URLConnection connection = classUrl.openConnection(); - byte[] classBytes = IOUtils.readFully(connection.getInputStream(), connection.getContentLength(), true); + + int length = connection.getContentLength(); + byte[] classBytes = IOUtils.readAllBytes(connection.getInputStream()); + if (length != -1 && classBytes.length != length) { + throw new IOException("Expected:" + length + ", actual: " + classBytes.length); + } + Class anonymousClass = UNSAFE.defineAnonymousClass(TestAnonymousClassUnloading.class, classBytes, null); // (2) Make sure all paths of doWork are profiled and compiled diff --git a/test/runtime/8003720/VictimClassLoader.java b/test/runtime/8003720/VictimClassLoader.java index 3505f7832..e219fd60f 100644 --- a/test/runtime/8003720/VictimClassLoader.java +++ b/test/runtime/8003720/VictimClassLoader.java @@ -22,6 +22,8 @@ * */ +import sun.misc.IOUtils; + public class VictimClassLoader extends ClassLoader { public static long counter = 0; @@ -72,8 +74,10 @@ public class VictimClassLoader extends ClassLoader { } static byte[] readFully(java.io.InputStream in, int len) throws java.io.IOException { - // Warning here: - return sun.misc.IOUtils.readFully(in, len, true); + byte[] b = IOUtils.readAllBytes(in); + if (len != -1 && b.length != len) + throw new java.io.IOException("Expected:" + len + ", actual:" + b.length); + return b; } public void finalize() { -- GitLab