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

View File

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

View File

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