8199424: consider removing ObjectInputStream and ObjectOutputStream native methods

Reviewed-by: bpb, rriggs, redestad
This commit is contained in:
Joe Darcy 2019-09-20 09:32:45 -07:00
parent b770e9a6b4
commit f3208bfcd0
4 changed files with 26 additions and 408 deletions

View file

@ -2413,22 +2413,6 @@ public class ObjectInputStream
clear();
}
/**
* Converts specified span of bytes into float values.
*/
// REMIND: remove once hotspot inlines Float.intBitsToFloat
private static native void bytesToFloats(byte[] src, int srcpos,
float[] dst, int dstpos,
int nfloats);
/**
* Converts specified span of bytes into double values.
*/
// REMIND: remove once hotspot inlines Double.longBitsToDouble
private static native void bytesToDoubles(byte[] src, int srcpos,
double[] dst, int dstpos,
int ndoubles);
/**
* Returns the first non-null and non-platform class loader (not counting
* class loaders of generated reflection implementation classes) up the
@ -3433,22 +3417,24 @@ public class ObjectInputStream
}
void readFloats(float[] v, int off, int len) throws IOException {
int span, endoff = off + len;
int stop, endoff = off + len;
while (off < endoff) {
if (!blkmode) {
span = Math.min(endoff - off, MAX_BLOCK_SIZE >> 2);
int span = Math.min(endoff - off, MAX_BLOCK_SIZE >> 2);
in.readFully(buf, 0, span << 2);
stop = off + span;
pos = 0;
} else if (end - pos < 4) {
v[off++] = din.readFloat();
continue;
} else {
span = Math.min(endoff - off, ((end - pos) >> 2));
stop = Math.min(endoff, ((end - pos) >> 2));
}
bytesToFloats(buf, pos, v, off, span);
off += span;
pos += span << 2;
while (off < stop) {
v[off++] = Bits.getFloat(buf, pos);
pos += 4;
}
}
}
@ -3475,22 +3461,24 @@ public class ObjectInputStream
}
void readDoubles(double[] v, int off, int len) throws IOException {
int span, endoff = off + len;
int stop, endoff = off + len;
while (off < endoff) {
if (!blkmode) {
span = Math.min(endoff - off, MAX_BLOCK_SIZE >> 3);
int span = Math.min(endoff - off, MAX_BLOCK_SIZE >> 3);
in.readFully(buf, 0, span << 3);
stop = off + span;
pos = 0;
} else if (end - pos < 8) {
v[off++] = din.readDouble();
continue;
} else {
span = Math.min(endoff - off, ((end - pos) >> 3));
stop = Math.min(endoff - off, ((end - pos) >> 3));
}
bytesToDoubles(buf, pos, v, off, span);
off += span;
pos += span << 3;
while (off < stop) {
v[off++] = Bits.getDouble(buf, pos);
pos += 8;
}
}
}

View file

@ -1591,22 +1591,6 @@ public class ObjectOutputStream
}
}
/**
* Converts specified span of float values into byte values.
*/
// REMIND: remove once hotspot inlines Float.floatToIntBits
private static native void floatsToBytes(float[] src, int srcpos,
byte[] dst, int dstpos,
int nfloats);
/**
* Converts specified span of double values into byte values.
*/
// REMIND: remove once hotspot inlines Double.doubleToLongBits
private static native void doublesToBytes(double[] src, int srcpos,
byte[] dst, int dstpos,
int ndoubles);
/**
* Default PutField implementation.
*/
@ -2096,10 +2080,11 @@ public class ObjectOutputStream
while (off < endoff) {
if (pos <= limit) {
int avail = (MAX_BLOCK_SIZE - pos) >> 2;
int chunklen = Math.min(endoff - off, avail);
floatsToBytes(v, off, buf, pos, chunklen);
off += chunklen;
pos += chunklen << 2;
int stop = Math.min(endoff, off + avail);
while (off < stop) {
Bits.putFloat(buf, pos, v[off++]);
pos += 4;
}
} else {
dout.writeFloat(v[off++]);
}
@ -2129,10 +2114,11 @@ public class ObjectOutputStream
while (off < endoff) {
if (pos <= limit) {
int avail = (MAX_BLOCK_SIZE - pos) >> 3;
int chunklen = Math.min(endoff - off, avail);
doublesToBytes(v, off, buf, pos, chunklen);
off += chunklen;
pos += chunklen << 3;
int stop = Math.min(endoff, off + avail);
while (off < stop) {
Bits.putDouble(buf, pos, v[off++]);
pos += 8;
}
} else {
dout.writeDouble(v[off++]);
}