RFR JDK-6321472: Add CRC-32C API

Peter Levart peter.levart at gmail.com
Fri Oct 17 23:09:06 UTC 2014

On 10/17/2014 08:58 PM, Staffan Friberg wrote:
> Here is a new webrev with the updates from Alan's and Peter's 
> suggestions.
> http://cr.openjdk.java.net/~sfriberg/JDK-6321472/webrev.01 

Hi Staffan,

A few more comments...

  217                 if (Unsafe.ADDRESS_SIZE == 4) {
  218                     // On 32 bit platforms read two ints instead of a single 64bit long

When you're reading from byte[] using Unsafe (updateBytes), you have the 
option of reading 64bit values on 64bit platforms. When you're reading 
from DirectByteBuffer memory (updateDirectByteBuffer), you're only using 
32bit reads.

Also, in updateBytes, the usage of 
array sounds a little scary. To be ultra portable you could check that 
ARRAY_BYTE_INDEX_SCALE == 1 first and refuse to use Unsafe for byte 
arrays if it is not 1. Then use Integer.BYTES/Long.BYTES to manipulate 
'offsets' instead. In updateDirectByteBuffer it would be more 
appropriate to use Integer.BYTES/Long.BYTES too.

  225                         firstHalf = (int) (value & 0xFFFFFFFF);
  226                         secondHalf = (int) (value >>> 32);
  227                     } else { // ByteOrder.BIG_ENDIAN
  228                         firstHalf = (int) (value >>> 32);
  229                         secondHalf = (int) (value & 0xFFFFFFFF);

firstHalf = (int) value; // this is equivalent for line 225
secondHalf = (int) value; // this is equivalent for line 229

Regards, Peter

More information about the core-libs-dev mailing list