mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 06:45:07 +02:00
8300236: Use VarHandle access in Data(Input | Output)Stream classes
Reviewed-by: rriggs, alanb
This commit is contained in:
parent
a5d8e12872
commit
74e1a8bfa8
11 changed files with 869 additions and 364 deletions
|
@ -32,6 +32,8 @@ import java.util.Arrays;
|
|||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.StringJoiner;
|
||||
|
||||
import jdk.internal.util.ByteArray;
|
||||
import sun.reflect.misc.ReflectUtil;
|
||||
|
||||
/**
|
||||
|
@ -1638,7 +1640,7 @@ public class ObjectOutputStream
|
|||
}
|
||||
|
||||
public void put(String name, boolean val) {
|
||||
Bits.putBoolean(primVals, getFieldOffset(name, Boolean.TYPE), val);
|
||||
ByteArray.setBoolean(primVals, getFieldOffset(name, Boolean.TYPE), val);
|
||||
}
|
||||
|
||||
public void put(String name, byte val) {
|
||||
|
@ -1646,27 +1648,27 @@ public class ObjectOutputStream
|
|||
}
|
||||
|
||||
public void put(String name, char val) {
|
||||
Bits.putChar(primVals, getFieldOffset(name, Character.TYPE), val);
|
||||
ByteArray.setChar(primVals, getFieldOffset(name, Character.TYPE), val);
|
||||
}
|
||||
|
||||
public void put(String name, short val) {
|
||||
Bits.putShort(primVals, getFieldOffset(name, Short.TYPE), val);
|
||||
ByteArray.setShort(primVals, getFieldOffset(name, Short.TYPE), val);
|
||||
}
|
||||
|
||||
public void put(String name, int val) {
|
||||
Bits.putInt(primVals, getFieldOffset(name, Integer.TYPE), val);
|
||||
ByteArray.setInt(primVals, getFieldOffset(name, Integer.TYPE), val);
|
||||
}
|
||||
|
||||
public void put(String name, float val) {
|
||||
Bits.putFloat(primVals, getFieldOffset(name, Float.TYPE), val);
|
||||
ByteArray.setFloat(primVals, getFieldOffset(name, Float.TYPE), val);
|
||||
}
|
||||
|
||||
public void put(String name, long val) {
|
||||
Bits.putLong(primVals, getFieldOffset(name, Long.TYPE), val);
|
||||
ByteArray.setLong(primVals, getFieldOffset(name, Long.TYPE), val);
|
||||
}
|
||||
|
||||
public void put(String name, double val) {
|
||||
Bits.putDouble(primVals, getFieldOffset(name, Double.TYPE), val);
|
||||
ByteArray.setDouble(primVals, getFieldOffset(name, Double.TYPE), val);
|
||||
}
|
||||
|
||||
public void put(String name, Object val) {
|
||||
|
@ -1908,7 +1910,7 @@ public class ObjectOutputStream
|
|||
out.write(hbuf, 0, 2);
|
||||
} else {
|
||||
hbuf[0] = TC_BLOCKDATALONG;
|
||||
Bits.putInt(hbuf, 1, len);
|
||||
ByteArray.setInt(hbuf, 1, len);
|
||||
out.write(hbuf, 0, 5);
|
||||
}
|
||||
}
|
||||
|
@ -1925,7 +1927,7 @@ public class ObjectOutputStream
|
|||
if (pos >= MAX_BLOCK_SIZE) {
|
||||
drain();
|
||||
}
|
||||
Bits.putBoolean(buf, pos++, v);
|
||||
ByteArray.setBoolean(buf, pos++, v);
|
||||
}
|
||||
|
||||
public void writeByte(int v) throws IOException {
|
||||
|
@ -1937,7 +1939,7 @@ public class ObjectOutputStream
|
|||
|
||||
public void writeChar(int v) throws IOException {
|
||||
if (pos + 2 <= MAX_BLOCK_SIZE) {
|
||||
Bits.putChar(buf, pos, (char) v);
|
||||
ByteArray.setChar(buf, pos, (char) v);
|
||||
pos += 2;
|
||||
} else {
|
||||
dout.writeChar(v);
|
||||
|
@ -1946,7 +1948,7 @@ public class ObjectOutputStream
|
|||
|
||||
public void writeShort(int v) throws IOException {
|
||||
if (pos + 2 <= MAX_BLOCK_SIZE) {
|
||||
Bits.putShort(buf, pos, (short) v);
|
||||
ByteArray.setShort(buf, pos, (short) v);
|
||||
pos += 2;
|
||||
} else {
|
||||
dout.writeShort(v);
|
||||
|
@ -1955,7 +1957,7 @@ public class ObjectOutputStream
|
|||
|
||||
public void writeInt(int v) throws IOException {
|
||||
if (pos + 4 <= MAX_BLOCK_SIZE) {
|
||||
Bits.putInt(buf, pos, v);
|
||||
ByteArray.setInt(buf, pos, v);
|
||||
pos += 4;
|
||||
} else {
|
||||
dout.writeInt(v);
|
||||
|
@ -1964,7 +1966,7 @@ public class ObjectOutputStream
|
|||
|
||||
public void writeFloat(float v) throws IOException {
|
||||
if (pos + 4 <= MAX_BLOCK_SIZE) {
|
||||
Bits.putFloat(buf, pos, v);
|
||||
ByteArray.setFloat(buf, pos, v);
|
||||
pos += 4;
|
||||
} else {
|
||||
dout.writeFloat(v);
|
||||
|
@ -1973,7 +1975,7 @@ public class ObjectOutputStream
|
|||
|
||||
public void writeLong(long v) throws IOException {
|
||||
if (pos + 8 <= MAX_BLOCK_SIZE) {
|
||||
Bits.putLong(buf, pos, v);
|
||||
ByteArray.setLong(buf, pos, v);
|
||||
pos += 8;
|
||||
} else {
|
||||
dout.writeLong(v);
|
||||
|
@ -1982,7 +1984,7 @@ public class ObjectOutputStream
|
|||
|
||||
public void writeDouble(double v) throws IOException {
|
||||
if (pos + 8 <= MAX_BLOCK_SIZE) {
|
||||
Bits.putDouble(buf, pos, v);
|
||||
ByteArray.setDouble(buf, pos, v);
|
||||
pos += 8;
|
||||
} else {
|
||||
dout.writeDouble(v);
|
||||
|
@ -2042,7 +2044,7 @@ public class ObjectOutputStream
|
|||
}
|
||||
int stop = Math.min(endoff, off + (MAX_BLOCK_SIZE - pos));
|
||||
while (off < stop) {
|
||||
Bits.putBoolean(buf, pos++, v[off++]);
|
||||
ByteArray.setBoolean(buf, pos++, v[off++]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2055,7 +2057,7 @@ public class ObjectOutputStream
|
|||
int avail = (MAX_BLOCK_SIZE - pos) >> 1;
|
||||
int stop = Math.min(endoff, off + avail);
|
||||
while (off < stop) {
|
||||
Bits.putChar(buf, pos, v[off++]);
|
||||
ByteArray.setChar(buf, pos, v[off++]);
|
||||
pos += 2;
|
||||
}
|
||||
} else {
|
||||
|
@ -2072,7 +2074,7 @@ public class ObjectOutputStream
|
|||
int avail = (MAX_BLOCK_SIZE - pos) >> 1;
|
||||
int stop = Math.min(endoff, off + avail);
|
||||
while (off < stop) {
|
||||
Bits.putShort(buf, pos, v[off++]);
|
||||
ByteArray.setShort(buf, pos, v[off++]);
|
||||
pos += 2;
|
||||
}
|
||||
} else {
|
||||
|
@ -2089,7 +2091,7 @@ public class ObjectOutputStream
|
|||
int avail = (MAX_BLOCK_SIZE - pos) >> 2;
|
||||
int stop = Math.min(endoff, off + avail);
|
||||
while (off < stop) {
|
||||
Bits.putInt(buf, pos, v[off++]);
|
||||
ByteArray.setInt(buf, pos, v[off++]);
|
||||
pos += 4;
|
||||
}
|
||||
} else {
|
||||
|
@ -2106,7 +2108,7 @@ public class ObjectOutputStream
|
|||
int avail = (MAX_BLOCK_SIZE - pos) >> 2;
|
||||
int stop = Math.min(endoff, off + avail);
|
||||
while (off < stop) {
|
||||
Bits.putFloat(buf, pos, v[off++]);
|
||||
ByteArray.setFloat(buf, pos, v[off++]);
|
||||
pos += 4;
|
||||
}
|
||||
} else {
|
||||
|
@ -2123,7 +2125,7 @@ public class ObjectOutputStream
|
|||
int avail = (MAX_BLOCK_SIZE - pos) >> 3;
|
||||
int stop = Math.min(endoff, off + avail);
|
||||
while (off < stop) {
|
||||
Bits.putLong(buf, pos, v[off++]);
|
||||
ByteArray.setLong(buf, pos, v[off++]);
|
||||
pos += 8;
|
||||
}
|
||||
} else {
|
||||
|
@ -2140,7 +2142,7 @@ public class ObjectOutputStream
|
|||
int avail = (MAX_BLOCK_SIZE - pos) >> 3;
|
||||
int stop = Math.min(endoff, off + avail);
|
||||
while (off < stop) {
|
||||
Bits.putDouble(buf, pos, v[off++]);
|
||||
ByteArray.setDouble(buf, pos, v[off++]);
|
||||
pos += 8;
|
||||
}
|
||||
} else {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue