40 import org.graalvm.compiler.word.Word; 41 42 import jdk.vm.ci.meta.JavaKind; 43 44 // JaCoCo Exclude 45 46 /** 47 * Substitutions for {@link CRC32}. 48 */ 49 @ClassSubstitution(CRC32.class) 50 public class CRC32Substitutions { 51 52 /** 53 * Gets the address of {@code StubRoutines::x86::_crc_table} in {@code stubRoutines_x86.hpp}. 54 */ 55 @Fold 56 static long crcTableAddress(@InjectedParameter GraalHotSpotVMConfig config) { 57 return config.crcTableAddress; 58 } 59 60 @MethodSubstitution 61 static int update(int crc, int b) { 62 final long crcTableRawAddress = GraalHotSpotVMConfigNode.crcTableAddress(); 63 64 int c = ~crc; 65 int index = (b ^ c) & 0xFF; 66 int offset = index << 2; 67 int result = Word.unsigned(crcTableRawAddress).readInt(offset); 68 result = result ^ (c >>> 8); 69 return ~result; 70 } 71 72 @MethodSubstitution 73 static int updateBytes(int crc, byte[] buf, int off, int len) { 74 Word bufAddr = Word.unsigned(ComputeObjectAddressNode.get(buf, arrayBaseOffset(JavaKind.Byte) + off)); 75 return updateBytesCRC32(UPDATE_BYTES_CRC32, crc, bufAddr, len); 76 } 77 78 /** 79 * @since 9 80 */ 81 @MethodSubstitution(optional = true) 82 static int updateBytes0(int crc, byte[] buf, int off, int len) { 83 Word bufAddr = Word.unsigned(ComputeObjectAddressNode.get(buf, arrayBaseOffset(JavaKind.Byte) + off)); 84 return updateBytesCRC32(UPDATE_BYTES_CRC32, crc, bufAddr, len); 85 } 86 87 @MethodSubstitution 88 static int updateByteBuffer(int crc, long addr, int off, int len) { 89 Word bufAddr = Word.unsigned(addr).add(off); 90 return updateBytesCRC32(UPDATE_BYTES_CRC32, crc, bufAddr, len); 91 } 92 93 /** 94 * @since 9 95 */ 96 @MethodSubstitution(optional = true) 97 static int updateByteBuffer0(int crc, long addr, int off, int len) { 98 Word bufAddr = Word.unsigned(addr).add(off); 99 return updateBytesCRC32(UPDATE_BYTES_CRC32, crc, bufAddr, len); 100 } 101 102 public static final ForeignCallDescriptor UPDATE_BYTES_CRC32 = new ForeignCallDescriptor("updateBytesCRC32", int.class, int.class, Word.class, int.class); 103 104 @NodeIntrinsic(ForeignCallNode.class) 105 public static native int updateBytesCRC32(@ConstantNodeParameter ForeignCallDescriptor descriptor, int crc, Word buf, int length); 106 } | 40 import org.graalvm.compiler.word.Word; 41 42 import jdk.vm.ci.meta.JavaKind; 43 44 // JaCoCo Exclude 45 46 /** 47 * Substitutions for {@link CRC32}. 48 */ 49 @ClassSubstitution(CRC32.class) 50 public class CRC32Substitutions { 51 52 /** 53 * Gets the address of {@code StubRoutines::x86::_crc_table} in {@code stubRoutines_x86.hpp}. 54 */ 55 @Fold 56 static long crcTableAddress(@InjectedParameter GraalHotSpotVMConfig config) { 57 return config.crcTableAddress; 58 } 59 60 @MethodSubstitution(optional = true) 61 static int update(int crc, int b) { 62 final long crcTableRawAddress = GraalHotSpotVMConfigNode.crcTableAddress(); 63 64 int c = ~crc; 65 int index = (b ^ c) & 0xFF; 66 int offset = index << 2; 67 int result = Word.unsigned(crcTableRawAddress).readInt(offset); 68 result = result ^ (c >>> 8); 69 return ~result; 70 } 71 72 @MethodSubstitution(optional = true) 73 static int updateBytes(int crc, byte[] buf, int off, int len) { 74 Word bufAddr = Word.unsigned(ComputeObjectAddressNode.get(buf, arrayBaseOffset(JavaKind.Byte) + off)); 75 return updateBytesCRC32(UPDATE_BYTES_CRC32, crc, bufAddr, len); 76 } 77 78 /** 79 * @since 9 80 */ 81 @MethodSubstitution(optional = true) 82 static int updateBytes0(int crc, byte[] buf, int off, int len) { 83 Word bufAddr = Word.unsigned(ComputeObjectAddressNode.get(buf, arrayBaseOffset(JavaKind.Byte) + off)); 84 return updateBytesCRC32(UPDATE_BYTES_CRC32, crc, bufAddr, len); 85 } 86 87 @MethodSubstitution(optional = true) 88 static int updateByteBuffer(int crc, long addr, int off, int len) { 89 Word bufAddr = Word.unsigned(addr).add(off); 90 return updateBytesCRC32(UPDATE_BYTES_CRC32, crc, bufAddr, len); 91 } 92 93 /** 94 * @since 9 95 */ 96 @MethodSubstitution(optional = true) 97 static int updateByteBuffer0(int crc, long addr, int off, int len) { 98 Word bufAddr = Word.unsigned(addr).add(off); 99 return updateBytesCRC32(UPDATE_BYTES_CRC32, crc, bufAddr, len); 100 } 101 102 public static final ForeignCallDescriptor UPDATE_BYTES_CRC32 = new ForeignCallDescriptor("updateBytesCRC32", int.class, int.class, Word.class, int.class); 103 104 @NodeIntrinsic(ForeignCallNode.class) 105 public static native int updateBytesCRC32(@ConstantNodeParameter ForeignCallDescriptor descriptor, int crc, Word buf, int length); 106 } |