8256018: Adler32/CRC32/CRC32C missing reachabilityFence

Reviewed-by: naoto, alanb
This commit is contained in:
Lance Andersen 2020-11-11 15:34:03 +00:00
parent 436019b8bb
commit 6247736fc9
3 changed files with 22 additions and 7 deletions

View File

@ -25,6 +25,7 @@
package java.util.zip; package java.util.zip;
import java.lang.ref.Reference;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import sun.nio.ch.DirectBuffer; import sun.nio.ch.DirectBuffer;
@ -96,8 +97,12 @@ public class Adler32 implements Checksum {
int rem = limit - pos; int rem = limit - pos;
if (rem <= 0) if (rem <= 0)
return; return;
if (buffer instanceof DirectBuffer) { if (buffer.isDirect()) {
adler = updateByteBuffer(adler, ((DirectBuffer)buffer).address(), pos, rem); try {
adler = updateByteBuffer(adler, ((DirectBuffer)buffer).address(), pos, rem);
} finally {
Reference.reachabilityFence(buffer);
}
} else if (buffer.hasArray()) { } else if (buffer.hasArray()) {
adler = updateBytes(adler, buffer.array(), pos + buffer.arrayOffset(), rem); adler = updateBytes(adler, buffer.array(), pos + buffer.arrayOffset(), rem);
} else { } else {

View File

@ -25,6 +25,7 @@
package java.util.zip; package java.util.zip;
import java.lang.ref.Reference;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.util.Objects; import java.util.Objects;
@ -95,8 +96,12 @@ public class CRC32 implements Checksum {
int rem = limit - pos; int rem = limit - pos;
if (rem <= 0) if (rem <= 0)
return; return;
if (buffer instanceof DirectBuffer) { if (buffer.isDirect()) {
crc = updateByteBuffer(crc, ((DirectBuffer)buffer).address(), pos, rem); try {
crc = updateByteBuffer(crc, ((DirectBuffer)buffer).address(), pos, rem);
} finally {
Reference.reachabilityFence(buffer);
}
} else if (buffer.hasArray()) { } else if (buffer.hasArray()) {
crc = updateBytes(crc, buffer.array(), pos + buffer.arrayOffset(), rem); crc = updateBytes(crc, buffer.array(), pos + buffer.arrayOffset(), rem);
} else { } else {

View File

@ -24,6 +24,7 @@
*/ */
package java.util.zip; package java.util.zip;
import java.lang.ref.Reference;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.ByteOrder; import java.nio.ByteOrder;
@ -170,9 +171,13 @@ public final class CRC32C implements Checksum {
return; return;
} }
if (buffer instanceof DirectBuffer) { if (buffer.isDirect()) {
crc = updateDirectByteBuffer(crc, ((DirectBuffer) buffer).address(), try {
pos, limit); crc = updateDirectByteBuffer(crc, ((DirectBuffer) buffer).address(),
pos, limit);
} finally {
Reference.reachabilityFence(buffer);
}
} else if (buffer.hasArray()) { } else if (buffer.hasArray()) {
crc = updateBytes(crc, buffer.array(), pos + buffer.arrayOffset(), crc = updateBytes(crc, buffer.array(), pos + buffer.arrayOffset(),
limit + buffer.arrayOffset()); limit + buffer.arrayOffset());