< prev index next >

src/jdk.incubator.foreign/share/classes/jdk/internal/foreign/AbstractMemorySegmentImpl.java

Print this page
M AbstractMemorySegmentImpl.java


 132                 base(), min(), size);
 133     }
 134 
 135     private final static VarHandle BYTE_HANDLE = MemoryLayout.ofSequence(MemoryLayouts.JAVA_BYTE)
 136             .varHandle(byte.class, MemoryLayout.PathElement.sequenceElement());
 137 
 138     @Override
 139     public long mismatch(MemorySegment other) {
 140         AbstractMemorySegmentImpl that = (AbstractMemorySegmentImpl)other;
 141         final long thisSize = this.byteSize();
 142         final long thatSize = that.byteSize();
 143         final long length = Math.min(thisSize, thatSize);
 144         this.checkRange(0, length, false);
 145         that.checkRange(0, length, false);
 146         if (this == other) {
 147             return -1;
 148         }
 149 
 150         long i = 0;
 151         if (length > 7) {



 152             i = ArraysSupport.vectorizedMismatchLarge(
 153                     this.base(), this.min(),
 154                     that.base(), that.min(),
 155                     length, ArraysSupport.LOG2_ARRAY_BYTE_INDEX_SCALE);
 156             if (i >= 0) {
 157                 return i;
 158             }
 159             i = length - ~i;



 160         }
 161         MemoryAddress thisAddress = this.baseAddress();
 162         MemoryAddress thatAddress = that.baseAddress();
 163         for (; i < length; i++) {
 164             if ((byte) BYTE_HANDLE.get(thisAddress, i) != (byte) BYTE_HANDLE.get(thatAddress, i)) {
 165                 return i;
 166             }
 167         }
 168         return thisSize != thatSize ? length : -1;
 169     }
 170 
 171     @Override
 172     @ForceInline
 173     public final MemoryAddress baseAddress() {
 174         return new MemoryAddressImpl(this, 0);
 175     }
 176 
 177     @Override
 178     public final ByteBuffer asByteBuffer() {
 179         if (!isSet(READ)) {




 132                 base(), min(), size);
 133     }
 134 
 135     private final static VarHandle BYTE_HANDLE = MemoryLayout.ofSequence(MemoryLayouts.JAVA_BYTE)
 136             .varHandle(byte.class, MemoryLayout.PathElement.sequenceElement());
 137 
 138     @Override
 139     public long mismatch(MemorySegment other) {
 140         AbstractMemorySegmentImpl that = (AbstractMemorySegmentImpl)other;
 141         final long thisSize = this.byteSize();
 142         final long thatSize = that.byteSize();
 143         final long length = Math.min(thisSize, thatSize);
 144         this.checkRange(0, length, false);
 145         that.checkRange(0, length, false);
 146         if (this == other) {
 147             return -1;
 148         }
 149 
 150         long i = 0;
 151         if (length > 7) {
 152             if ((byte) BYTE_HANDLE.get(this.baseAddress(), 0) != (byte) BYTE_HANDLE.get(that.baseAddress(), 0)) {
 153                 return 0;
 154             }
 155             i = ArraysSupport.vectorizedMismatchLarge(
 156                     this.base(), this.min(),
 157                     that.base(), that.min(),
 158                     length, ArraysSupport.LOG2_ARRAY_BYTE_INDEX_SCALE);
 159             if (i >= 0) {
 160                 return i;
 161             }
 162             long remaining = ~i;
 163             if (remaining > 7)
 164                 throw new InternalError("remaining greater than 7: " + remaining);
 165             i = length - remaining;
 166         }
 167         MemoryAddress thisAddress = this.baseAddress();
 168         MemoryAddress thatAddress = that.baseAddress();
 169         for (; i < length; i++) {
 170             if ((byte) BYTE_HANDLE.get(thisAddress, i) != (byte) BYTE_HANDLE.get(thatAddress, i)) {
 171                 return i;
 172             }
 173         }
 174         return thisSize != thatSize ? length : -1;
 175     }
 176 
 177     @Override
 178     @ForceInline
 179     public final MemoryAddress baseAddress() {
 180         return new MemoryAddressImpl(this, 0);
 181     }
 182 
 183     @Override
 184     public final ByteBuffer asByteBuffer() {
 185         if (!isSet(READ)) {


< prev index next >