8300864: Declare some fields in java.io as final

Reviewed-by: rriggs, lancea
This commit is contained in:
Per Minborg 2023-01-23 17:40:13 +00:00
parent a56598f5a5
commit 079255e312
8 changed files with 112 additions and 112 deletions

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 1996, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1996, 2023, 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
@ -1905,7 +1905,7 @@ public final class ObjectStreamClass implements Serializable {
private static class FieldReflector {
/** handle for performing unsafe operations */
private static final Unsafe unsafe = Unsafe.getUnsafe();
private static final Unsafe UNSAFE = Unsafe.getUnsafe();
/** fields to operate on */
private final ObjectStreamField[] fields;
@ -1944,7 +1944,7 @@ public final class ObjectStreamClass implements Serializable {
ObjectStreamField f = fields[i];
Field rf = f.getField();
long key = (rf != null) ?
unsafe.objectFieldOffset(rf) : Unsafe.INVALID_FIELD_OFFSET;
UNSAFE.objectFieldOffset(rf) : Unsafe.INVALID_FIELD_OFFSET;
readKeys[i] = key;
writeKeys[i] = usedKeys.add(key) ?
key : Unsafe.INVALID_FIELD_OFFSET;
@ -1986,14 +1986,14 @@ public final class ObjectStreamClass implements Serializable {
long key = readKeys[i];
int off = offsets[i];
switch (typeCodes[i]) {
case 'Z' -> Bits.putBoolean(buf, off, unsafe.getBoolean(obj, key));
case 'B' -> buf[off] = unsafe.getByte(obj, key);
case 'C' -> Bits.putChar(buf, off, unsafe.getChar(obj, key));
case 'S' -> Bits.putShort(buf, off, unsafe.getShort(obj, key));
case 'I' -> Bits.putInt(buf, off, unsafe.getInt(obj, key));
case 'F' -> Bits.putFloat(buf, off, unsafe.getFloat(obj, key));
case 'J' -> Bits.putLong(buf, off, unsafe.getLong(obj, key));
case 'D' -> Bits.putDouble(buf, off, unsafe.getDouble(obj, key));
case 'Z' -> Bits.putBoolean(buf, off, UNSAFE.getBoolean(obj, key));
case 'B' -> buf[off] = UNSAFE.getByte(obj, key);
case 'C' -> Bits.putChar(buf, off, UNSAFE.getChar(obj, key));
case 'S' -> Bits.putShort(buf, off, UNSAFE.getShort(obj, key));
case 'I' -> Bits.putInt(buf, off, UNSAFE.getInt(obj, key));
case 'F' -> Bits.putFloat(buf, off, UNSAFE.getFloat(obj, key));
case 'J' -> Bits.putLong(buf, off, UNSAFE.getLong(obj, key));
case 'D' -> Bits.putDouble(buf, off, UNSAFE.getDouble(obj, key));
default -> throw new InternalError();
}
}
@ -2015,14 +2015,14 @@ public final class ObjectStreamClass implements Serializable {
}
int off = offsets[i];
switch (typeCodes[i]) {
case 'Z' -> unsafe.putBoolean(obj, key, Bits.getBoolean(buf, off));
case 'B' -> unsafe.putByte(obj, key, buf[off]);
case 'C' -> unsafe.putChar(obj, key, Bits.getChar(buf, off));
case 'S' -> unsafe.putShort(obj, key, Bits.getShort(buf, off));
case 'I' -> unsafe.putInt(obj, key, Bits.getInt(buf, off));
case 'F' -> unsafe.putFloat(obj, key, Bits.getFloat(buf, off));
case 'J' -> unsafe.putLong(obj, key, Bits.getLong(buf, off));
case 'D' -> unsafe.putDouble(obj, key, Bits.getDouble(buf, off));
case 'Z' -> UNSAFE.putBoolean(obj, key, Bits.getBoolean(buf, off));
case 'B' -> UNSAFE.putByte(obj, key, buf[off]);
case 'C' -> UNSAFE.putChar(obj, key, Bits.getChar(buf, off));
case 'S' -> UNSAFE.putShort(obj, key, Bits.getShort(buf, off));
case 'I' -> UNSAFE.putInt(obj, key, Bits.getInt(buf, off));
case 'F' -> UNSAFE.putFloat(obj, key, Bits.getFloat(buf, off));
case 'J' -> UNSAFE.putLong(obj, key, Bits.getLong(buf, off));
case 'D' -> UNSAFE.putDouble(obj, key, Bits.getDouble(buf, off));
default -> throw new InternalError();
}
}
@ -2043,7 +2043,7 @@ public final class ObjectStreamClass implements Serializable {
*/
for (int i = numPrimFields; i < fields.length; i++) {
vals[offsets[i]] = switch (typeCodes[i]) {
case 'L', '[' -> unsafe.getReference(obj, readKeys[i]);
case 'L', '[' -> UNSAFE.getReference(obj, readKeys[i]);
default -> throw new InternalError();
};
}
@ -2094,7 +2094,7 @@ public final class ObjectStreamClass implements Serializable {
obj.getClass().getName());
}
if (!dryRun)
unsafe.putReference(obj, key, val);
UNSAFE.putReference(obj, key, val);
}
default -> throw new InternalError();
}