Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8349503: Consolidate multi-byte access into ByteArray #23478

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions src/java.base/share/classes/java/io/DataInputStream.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1994, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1994, 2025, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2024, Alibaba Group Holding Limited. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
@@ -322,7 +322,7 @@ public final int readUnsignedByte() throws IOException {
*/
public final short readShort() throws IOException {
readFully(readBuffer, 0, 2);
return ByteArray.getShort(readBuffer, 0);
return ByteArray.getShortBE(readBuffer, 0);
}

/**
@@ -344,7 +344,7 @@ public final short readShort() throws IOException {
*/
public final int readUnsignedShort() throws IOException {
readFully(readBuffer, 0, 2);
return ByteArray.getUnsignedShort(readBuffer, 0);
return ByteArray.getUnsignedShortBE(readBuffer, 0);
}

/**
@@ -366,7 +366,7 @@ public final int readUnsignedShort() throws IOException {
*/
public final char readChar() throws IOException {
readFully(readBuffer, 0, 2);
return ByteArray.getChar(readBuffer, 0);
return ByteArray.getCharBE(readBuffer, 0);
}

/**
@@ -388,7 +388,7 @@ public final char readChar() throws IOException {
*/
public final int readInt() throws IOException {
readFully(readBuffer, 0, 4);
return ByteArray.getInt(readBuffer, 0);
return ByteArray.getIntBE(readBuffer, 0);
}

/**
@@ -410,7 +410,7 @@ public final int readInt() throws IOException {
*/
public final long readLong() throws IOException {
readFully(readBuffer, 0, 8);
return ByteArray.getLong(readBuffer, 0);
return ByteArray.getLongBE(readBuffer, 0);
}

/**
@@ -433,7 +433,7 @@ public final long readLong() throws IOException {
*/
public final float readFloat() throws IOException {
readFully(readBuffer, 0, 4);
return ByteArray.getFloat(readBuffer, 0);
return ByteArray.getFloatBE(readBuffer, 0);
}

/**
@@ -456,7 +456,7 @@ public final float readFloat() throws IOException {
*/
public final double readDouble() throws IOException {
readFully(readBuffer, 0, 8);
return ByteArray.getDouble(readBuffer, 0);
return ByteArray.getDoubleBE(readBuffer, 0);
}

private char[] lineBuffer;
18 changes: 9 additions & 9 deletions src/java.base/share/classes/java/io/DataOutputStream.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1994, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1994, 2025, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2024, Alibaba Group Holding Limited. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
@@ -183,7 +183,7 @@ public final void writeByte(int v) throws IOException {
* @see java.io.FilterOutputStream#out
*/
public final void writeShort(int v) throws IOException {
ByteArray.setUnsignedShort(writeBuffer, 0, v);
ByteArray.setUnsignedShortBE(writeBuffer, 0, v);
out.write(writeBuffer, 0, 2);
incCount(2);
}
@@ -198,7 +198,7 @@ public final void writeShort(int v) throws IOException {
* @see java.io.FilterOutputStream#out
*/
public final void writeChar(int v) throws IOException {
ByteArray.setUnsignedShort(writeBuffer, 0, v);
ByteArray.setUnsignedShortBE(writeBuffer, 0, v);
out.write(writeBuffer, 0, 2);
incCount(2);
}
@@ -213,7 +213,7 @@ public final void writeChar(int v) throws IOException {
* @see java.io.FilterOutputStream#out
*/
public final void writeInt(int v) throws IOException {
ByteArray.setInt(writeBuffer, 0, v);
ByteArray.setIntBE(writeBuffer, 0, v);
out.write(writeBuffer, 0, 4);
incCount(4);
}
@@ -228,7 +228,7 @@ public final void writeInt(int v) throws IOException {
* @see java.io.FilterOutputStream#out
*/
public final void writeLong(long v) throws IOException {
ByteArray.setLong(writeBuffer, 0, v);
ByteArray.setLongBE(writeBuffer, 0, v);
out.write(writeBuffer, 0, 8);
incCount(8);
}
@@ -247,7 +247,7 @@ public final void writeLong(long v) throws IOException {
* @see java.lang.Float#floatToIntBits(float)
*/
public final void writeFloat(float v) throws IOException {
ByteArray.setFloat(writeBuffer, 0, v);
ByteArray.setFloatBE(writeBuffer, 0, v);
out.write(writeBuffer, 0, 4);
incCount(4);
}
@@ -266,7 +266,7 @@ public final void writeFloat(float v) throws IOException {
* @see java.lang.Double#doubleToLongBits(double)
*/
public final void writeDouble(double v) throws IOException {
ByteArray.setDouble(writeBuffer, 0, v);
ByteArray.setDoubleBE(writeBuffer, 0, v);
out.write(writeBuffer, 0, 8);
incCount(8);
}
@@ -306,7 +306,7 @@ public final void writeChars(String s) throws IOException {
int len = s.length();
for (int i = 0 ; i < len ; i++) {
int v = s.charAt(i);
ByteArray.setUnsignedShort(writeBuffer, 0, v);
ByteArray.setUnsignedShortBE(writeBuffer, 0, v);
out.write(writeBuffer, 0, 2);
}
incCount(len * 2);
@@ -379,7 +379,7 @@ static int writeUTF(String str, DataOutput out) throws IOException {
}

int count = 0;
ByteArray.setUnsignedShort(bytearr, count, utflen);
ByteArray.setUnsignedShortBE(bytearr, count, utflen);
count += 2;
str.getBytes(0, countNonZeroAscii, bytearr, count);
count += countNonZeroAscii;
42 changes: 21 additions & 21 deletions src/java.base/share/classes/java/io/ObjectInputStream.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1996, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1996, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -2540,32 +2540,32 @@ public byte get(String name, byte val) {

public char get(String name, char val) {
int off = getFieldOffset(name, Character.TYPE);
return (off >= 0) ? ByteArray.getChar(primValues, off) : val;
return (off >= 0) ? ByteArray.getCharBE(primValues, off) : val;
}

public short get(String name, short val) {
int off = getFieldOffset(name, Short.TYPE);
return (off >= 0) ? ByteArray.getShort(primValues, off) : val;
return (off >= 0) ? ByteArray.getShortBE(primValues, off) : val;
}

public int get(String name, int val) {
int off = getFieldOffset(name, Integer.TYPE);
return (off >= 0) ? ByteArray.getInt(primValues, off) : val;
return (off >= 0) ? ByteArray.getIntBE(primValues, off) : val;
}

public float get(String name, float val) {
int off = getFieldOffset(name, Float.TYPE);
return (off >= 0) ? ByteArray.getFloat(primValues, off) : val;
return (off >= 0) ? ByteArray.getFloatBE(primValues, off) : val;
}

public long get(String name, long val) {
int off = getFieldOffset(name, Long.TYPE);
return (off >= 0) ? ByteArray.getLong(primValues, off) : val;
return (off >= 0) ? ByteArray.getLongBE(primValues, off) : val;
}

public double get(String name, double val) {
int off = getFieldOffset(name, Double.TYPE);
return (off >= 0) ? ByteArray.getDouble(primValues, off) : val;
return (off >= 0) ? ByteArray.getDoubleBE(primValues, off) : val;
}

public Object get(String name, Object val) throws ClassNotFoundException {
@@ -3000,7 +3000,7 @@ private int readBlockHeader(boolean canBlock) throws IOException {
return HEADER_BLOCKED;
}
in.readFully(hbuf, 0, 5);
int len = ByteArray.getInt(hbuf, 1);
int len = ByteArray.getIntBE(hbuf, 1);
if (len < 0) {
throw new StreamCorruptedException(
"illegal block data header length: " +
@@ -3299,7 +3299,7 @@ public char readChar() throws IOException {
} else if (end - pos < 2) {
return din.readChar();
}
char v = ByteArray.getChar(buf, pos);
char v = ByteArray.getCharBE(buf, pos);
pos += 2;
return v;
}
@@ -3311,7 +3311,7 @@ public short readShort() throws IOException {
} else if (end - pos < 2) {
return din.readShort();
}
short v = ByteArray.getShort(buf, pos);
short v = ByteArray.getShortBE(buf, pos);
pos += 2;
return v;
}
@@ -3323,7 +3323,7 @@ public int readUnsignedShort() throws IOException {
} else if (end - pos < 2) {
return din.readUnsignedShort();
}
int v = ByteArray.getShort(buf, pos) & 0xFFFF;
int v = ByteArray.getShortBE(buf, pos) & 0xFFFF;
pos += 2;
return v;
}
@@ -3335,7 +3335,7 @@ public int readInt() throws IOException {
} else if (end - pos < 4) {
return din.readInt();
}
int v = ByteArray.getInt(buf, pos);
int v = ByteArray.getIntBE(buf, pos);
pos += 4;
return v;
}
@@ -3347,7 +3347,7 @@ public float readFloat() throws IOException {
} else if (end - pos < 4) {
return din.readFloat();
}
float v = ByteArray.getFloat(buf, pos);
float v = ByteArray.getFloatBE(buf, pos);
pos += 4;
return v;
}
@@ -3359,7 +3359,7 @@ public long readLong() throws IOException {
} else if (end - pos < 8) {
return din.readLong();
}
long v = ByteArray.getLong(buf, pos);
long v = ByteArray.getLongBE(buf, pos);
pos += 8;
return v;
}
@@ -3371,7 +3371,7 @@ public double readDouble() throws IOException {
} else if (end - pos < 8) {
return din.readDouble();
}
double v = ByteArray.getDouble(buf, pos);
double v = ByteArray.getDoubleBE(buf, pos);
pos += 8;
return v;
}
@@ -3430,7 +3430,7 @@ void readChars(char[] v, int off, int len) throws IOException {
}

while (off < stop) {
v[off++] = ByteArray.getChar(buf, pos);
v[off++] = ByteArray.getCharBE(buf, pos);
pos += 2;
}
}
@@ -3452,7 +3452,7 @@ void readShorts(short[] v, int off, int len) throws IOException {
}

while (off < stop) {
v[off++] = ByteArray.getShort(buf, pos);
v[off++] = ByteArray.getShortBE(buf, pos);
pos += 2;
}
}
@@ -3474,7 +3474,7 @@ void readInts(int[] v, int off, int len) throws IOException {
}

while (off < stop) {
v[off++] = ByteArray.getInt(buf, pos);
v[off++] = ByteArray.getIntBE(buf, pos);
pos += 4;
}
}
@@ -3496,7 +3496,7 @@ void readFloats(float[] v, int off, int len) throws IOException {
}

while (off < stop) {
v[off++] = ByteArray.getFloat(buf, pos);
v[off++] = ByteArray.getFloatBE(buf, pos);
pos += 4;
}
}
@@ -3518,7 +3518,7 @@ void readLongs(long[] v, int off, int len) throws IOException {
}

while (off < stop) {
v[off++] = ByteArray.getLong(buf, pos);
v[off++] = ByteArray.getLongBE(buf, pos);
pos += 8;
}
}
@@ -3540,7 +3540,7 @@ void readDoubles(double[] v, int off, int len) throws IOException {
}

while (off < stop) {
v[off++] = ByteArray.getDouble(buf, pos);
v[off++] = ByteArray.getDoubleBE(buf, pos);
pos += 8;
}
}
Loading