提交 ec7859dc 编写于 作者: A andrew

8138978: Examine usages of sun.misc.IOUtils

Reviewed-by: mbalao
上级 c56e2833
......@@ -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
......
......@@ -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() {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册