Skip to content

Commit f3208bf

Browse files
committed
8199424: consider removing ObjectInputStream and ObjectOutputStream native methods
Reviewed-by: bpb, rriggs, redestad
1 parent b770e9a commit f3208bf

File tree

4 files changed

+26
-408
lines changed

4 files changed

+26
-408
lines changed

src/java.base/share/classes/java/io/ObjectInputStream.java

Lines changed: 16 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2413,22 +2413,6 @@ private void handleReset() throws StreamCorruptedException {
24132413
clear();
24142414
}
24152415

2416-
/**
2417-
* Converts specified span of bytes into float values.
2418-
*/
2419-
// REMIND: remove once hotspot inlines Float.intBitsToFloat
2420-
private static native void bytesToFloats(byte[] src, int srcpos,
2421-
float[] dst, int dstpos,
2422-
int nfloats);
2423-
2424-
/**
2425-
* Converts specified span of bytes into double values.
2426-
*/
2427-
// REMIND: remove once hotspot inlines Double.longBitsToDouble
2428-
private static native void bytesToDoubles(byte[] src, int srcpos,
2429-
double[] dst, int dstpos,
2430-
int ndoubles);
2431-
24322416
/**
24332417
* Returns the first non-null and non-platform class loader (not counting
24342418
* class loaders of generated reflection implementation classes) up the
@@ -3433,22 +3417,24 @@ void readInts(int[] v, int off, int len) throws IOException {
34333417
}
34343418

34353419
void readFloats(float[] v, int off, int len) throws IOException {
3436-
int span, endoff = off + len;
3420+
int stop, endoff = off + len;
34373421
while (off < endoff) {
34383422
if (!blkmode) {
3439-
span = Math.min(endoff - off, MAX_BLOCK_SIZE >> 2);
3423+
int span = Math.min(endoff - off, MAX_BLOCK_SIZE >> 2);
34403424
in.readFully(buf, 0, span << 2);
3425+
stop = off + span;
34413426
pos = 0;
34423427
} else if (end - pos < 4) {
34433428
v[off++] = din.readFloat();
34443429
continue;
34453430
} else {
3446-
span = Math.min(endoff - off, ((end - pos) >> 2));
3431+
stop = Math.min(endoff, ((end - pos) >> 2));
34473432
}
34483433

3449-
bytesToFloats(buf, pos, v, off, span);
3450-
off += span;
3451-
pos += span << 2;
3434+
while (off < stop) {
3435+
v[off++] = Bits.getFloat(buf, pos);
3436+
pos += 4;
3437+
}
34523438
}
34533439
}
34543440

@@ -3475,22 +3461,24 @@ void readLongs(long[] v, int off, int len) throws IOException {
34753461
}
34763462

34773463
void readDoubles(double[] v, int off, int len) throws IOException {
3478-
int span, endoff = off + len;
3464+
int stop, endoff = off + len;
34793465
while (off < endoff) {
34803466
if (!blkmode) {
3481-
span = Math.min(endoff - off, MAX_BLOCK_SIZE >> 3);
3467+
int span = Math.min(endoff - off, MAX_BLOCK_SIZE >> 3);
34823468
in.readFully(buf, 0, span << 3);
3469+
stop = off + span;
34833470
pos = 0;
34843471
} else if (end - pos < 8) {
34853472
v[off++] = din.readDouble();
34863473
continue;
34873474
} else {
3488-
span = Math.min(endoff - off, ((end - pos) >> 3));
3475+
stop = Math.min(endoff - off, ((end - pos) >> 3));
34893476
}
34903477

3491-
bytesToDoubles(buf, pos, v, off, span);
3492-
off += span;
3493-
pos += span << 3;
3478+
while (off < stop) {
3479+
v[off++] = Bits.getDouble(buf, pos);
3480+
pos += 8;
3481+
}
34943482
}
34953483
}
34963484

src/java.base/share/classes/java/io/ObjectOutputStream.java

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1591,22 +1591,6 @@ private void writeFatalException(IOException ex) throws IOException {
15911591
}
15921592
}
15931593

1594-
/**
1595-
* Converts specified span of float values into byte values.
1596-
*/
1597-
// REMIND: remove once hotspot inlines Float.floatToIntBits
1598-
private static native void floatsToBytes(float[] src, int srcpos,
1599-
byte[] dst, int dstpos,
1600-
int nfloats);
1601-
1602-
/**
1603-
* Converts specified span of double values into byte values.
1604-
*/
1605-
// REMIND: remove once hotspot inlines Double.doubleToLongBits
1606-
private static native void doublesToBytes(double[] src, int srcpos,
1607-
byte[] dst, int dstpos,
1608-
int ndoubles);
1609-
16101594
/**
16111595
* Default PutField implementation.
16121596
*/
@@ -2096,10 +2080,11 @@ void writeFloats(float[] v, int off, int len) throws IOException {
20962080
while (off < endoff) {
20972081
if (pos <= limit) {
20982082
int avail = (MAX_BLOCK_SIZE - pos) >> 2;
2099-
int chunklen = Math.min(endoff - off, avail);
2100-
floatsToBytes(v, off, buf, pos, chunklen);
2101-
off += chunklen;
2102-
pos += chunklen << 2;
2083+
int stop = Math.min(endoff, off + avail);
2084+
while (off < stop) {
2085+
Bits.putFloat(buf, pos, v[off++]);
2086+
pos += 4;
2087+
}
21032088
} else {
21042089
dout.writeFloat(v[off++]);
21052090
}
@@ -2129,10 +2114,11 @@ void writeDoubles(double[] v, int off, int len) throws IOException {
21292114
while (off < endoff) {
21302115
if (pos <= limit) {
21312116
int avail = (MAX_BLOCK_SIZE - pos) >> 3;
2132-
int chunklen = Math.min(endoff - off, avail);
2133-
doublesToBytes(v, off, buf, pos, chunklen);
2134-
off += chunklen;
2135-
pos += chunklen << 3;
2117+
int stop = Math.min(endoff, off + avail);
2118+
while (off < stop) {
2119+
Bits.putDouble(buf, pos, v[off++]);
2120+
pos += 8;
2121+
}
21362122
} else {
21372123
dout.writeDouble(v[off++]);
21382124
}

src/java.base/share/native/libjava/ObjectInputStream.c

Lines changed: 0 additions & 175 deletions
This file was deleted.

0 commit comments

Comments
 (0)