mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 14:54:52 +02:00
8138978: Examine usages of sun.misc.IOUtils
Reviewed-by: alanb, mullan, psandoz, rriggs, weijun
This commit is contained in:
parent
d12b5c154b
commit
1a83e59745
2 changed files with 12 additions and 4 deletions
|
@ -23,8 +23,8 @@
|
||||||
|
|
||||||
import sun.hotspot.WhiteBox;
|
import sun.hotspot.WhiteBox;
|
||||||
import sun.misc.Unsafe;
|
import sun.misc.Unsafe;
|
||||||
import sun.misc.IOUtils;
|
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.net.URLConnection;
|
import java.net.URLConnection;
|
||||||
|
@ -109,7 +109,13 @@ public class TestAnonymousClassUnloading {
|
||||||
// (1) Load an anonymous version of this class using the corresponding Unsafe method
|
// (1) Load an anonymous version of this class using the corresponding Unsafe method
|
||||||
URL classUrl = TestAnonymousClassUnloading.class.getResource("TestAnonymousClassUnloading.class");
|
URL classUrl = TestAnonymousClassUnloading.class.getResource("TestAnonymousClassUnloading.class");
|
||||||
URLConnection connection = classUrl.openConnection();
|
URLConnection connection = classUrl.openConnection();
|
||||||
byte[] classBytes = IOUtils.readFully(connection.getInputStream(), connection.getContentLength(), true);
|
|
||||||
|
int length = connection.getContentLength();
|
||||||
|
byte[] classBytes = connection.getInputStream().readAllBytes();
|
||||||
|
if (length != -1 && classBytes.length != length) {
|
||||||
|
throw new IOException("Expected:" + length + ", actual: " + classBytes.length);
|
||||||
|
}
|
||||||
|
|
||||||
Class<?> anonymousClass = UNSAFE.defineAnonymousClass(TestAnonymousClassUnloading.class, classBytes, null);
|
Class<?> anonymousClass = UNSAFE.defineAnonymousClass(TestAnonymousClassUnloading.class, classBytes, null);
|
||||||
|
|
||||||
// (2) Make sure all paths of doWork are profiled and compiled
|
// (2) Make sure all paths of doWork are profiled and compiled
|
||||||
|
|
|
@ -72,8 +72,10 @@ public class VictimClassLoader extends ClassLoader {
|
||||||
}
|
}
|
||||||
|
|
||||||
static byte[] readFully(java.io.InputStream in, int len) throws java.io.IOException {
|
static byte[] readFully(java.io.InputStream in, int len) throws java.io.IOException {
|
||||||
// Warning here:
|
byte[] b = in.readAllBytes();
|
||||||
return sun.misc.IOUtils.readFully(in, len, true);
|
if (len != -1 && b.length != len)
|
||||||
|
throw new java.io.IOException("Expected:" + len + ", actual:" + b.length);
|
||||||
|
return b;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void finalize() {
|
public void finalize() {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue