Java Code Examples for io.netty.util.internal.PlatformDependent#putByte()

The following examples show how to use io.netty.util.internal.PlatformDependent#putByte() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: UTF8Util.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
private static int unsafeOnHeapWriteUTF(final CharSequence str, final byte[] bytes, final int index, final int length) {
   int charCount = index;
   for (int i = 0; i < length; i++) {
      char charAtPos = str.charAt(i);
      if (charAtPos <= 0x7f) {
         PlatformDependent.putByte(bytes, charCount++, (byte) charAtPos);
      } else if (charAtPos >= 0x800) {
         PlatformDependent.putByte(bytes, charCount++, (byte) (0xE0 | charAtPos >> 12 & 0x0F));
         PlatformDependent.putByte(bytes, charCount++, (byte) (0x80 | charAtPos >> 6 & 0x3F));
         PlatformDependent.putByte(bytes, charCount++, (byte) (0x80 | charAtPos >> 0 & 0x3F));
      } else {
         PlatformDependent.putByte(bytes, charCount++, (byte) (0xC0 | charAtPos >> 6 & 0x1F));
         PlatformDependent.putByte(bytes, charCount++, (byte) (0x80 | charAtPos >> 0 & 0x3F));
      }
   }

   final int writtenBytes = (charCount - index);
   return writtenBytes;
}
 
Example 2
Source File: BaseSingleAccumulatorNoSpill.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
public static void writeWordwise(long addr, long length, long value) {
  if (length == 0) {
    return;
  }

  long nLong = length >>> 3;
  int nBytes = (int) length & 7;
  for (long i = nLong; i > 0; i--) {
    PlatformDependent.putLong(addr, value);
    addr += 8;
  }
  if (nBytes == 4) {
    PlatformDependent.putInt(addr, (int) value);
    addr += 4;
  } else if (nBytes < 4) {
    for (int i = nBytes; i > 0; i--) {
      PlatformDependent.putByte(addr, (byte) value);
      addr++;
    }
  } else {
    PlatformDependent.putInt(addr, (int) value);
    addr += 4;
    for (int i = nBytes - 4; i > 0; i--) {
      PlatformDependent.putByte(addr, (byte) value);
      addr++;
    }
  }
}
 
Example 3
Source File: UnsafeByteBufUtil.java    From netty-4.1.22 with Apache License 2.0 5 votes vote down vote up
static void setInt(byte[] array, int index, int value) {
    if (UNALIGNED) {
        PlatformDependent.putInt(array, index, BIG_ENDIAN_NATIVE_ORDER ? value : Integer.reverseBytes(value));
    } else {
        PlatformDependent.putByte(array, index, (byte) (value >>> 24));
        PlatformDependent.putByte(array, index + 1, (byte) (value >>> 16));
        PlatformDependent.putByte(array, index + 2, (byte) (value >>> 8));
        PlatformDependent.putByte(array, index + 3, (byte) value);
    }
}
 
Example 4
Source File: UnpooledUnsafeDirectByteBuf.java    From netty4.0.27Learn with Apache License 2.0 5 votes vote down vote up
@Override
protected void _setMedium(int index, int value) {
    long addr = addr(index);
    PlatformDependent.putByte(addr, (byte) (value >>> 16));
    PlatformDependent.putByte(addr + 1, (byte) (value >>> 8));
    PlatformDependent.putByte(addr + 2, (byte) value);
}
 
Example 5
Source File: UnsafeByteBufUtil.java    From netty-4.1.22 with Apache License 2.0 5 votes vote down vote up
static void setLong(byte[] array, int index, long value) {
    if (UNALIGNED) {
        PlatformDependent.putLong(array, index, BIG_ENDIAN_NATIVE_ORDER ? value : Long.reverseBytes(value));
    } else {
        PlatformDependent.putByte(array, index, (byte) (value >>> 56));
        PlatformDependent.putByte(array, index + 1, (byte) (value >>> 48));
        PlatformDependent.putByte(array, index + 2, (byte) (value >>> 40));
        PlatformDependent.putByte(array, index + 3, (byte) (value >>> 32));
        PlatformDependent.putByte(array, index + 4, (byte) (value >>> 24));
        PlatformDependent.putByte(array, index + 5, (byte) (value >>> 16));
        PlatformDependent.putByte(array, index + 6, (byte) (value >>> 8));
        PlatformDependent.putByte(array, index + 7, (byte) value);
    }
}
 
Example 6
Source File: UnsafeByteBufUtil.java    From netty-4.1.22 with Apache License 2.0 5 votes vote down vote up
static void setShort(byte[] array, int index, int value) {
    if (UNALIGNED) {
        PlatformDependent.putShort(array, index,
                                   BIG_ENDIAN_NATIVE_ORDER ? (short) value : Short.reverseBytes((short) value));
    } else {
        PlatformDependent.putByte(array, index, (byte) (value >>> 8));
        PlatformDependent.putByte(array, index + 1, (byte) value);
    }
}
 
Example 7
Source File: OffHeapRowWriter.java    From tajo with Apache License 2.0 5 votes vote down vote up
@Override
public void putBool(boolean val) {
  ensureSize(SizeOf.SIZE_OF_BOOL);
  long addr = currentAddr();

  PlatformDependent.putByte(addr, (byte) (val ? 0x01 : 0x00));
  putFieldHeader(addr, curOffset);
  forwardField(SizeOf.SIZE_OF_BOOL);
}
 
Example 8
Source File: MultiDestCopier.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
@Override
public void copy(long compoundAddr, int srcStart, final int count) {
  copyWatch.start();

  final long[] dstAddrs = this.dstAddrs;

  // skip bytes, but make sure to account for the remaining bits too
  final long srcAddr;
  switch (bufferOrdinal) {
    case NULL_BUFFER_ORDINAL:
      srcAddr = source.getValidityBufferAddress();
      break;
    case VALUE_BUFFER_ORDINAL:
      srcAddr = source.getDataBufferAddress();
      break;
    default:
      throw new UnsupportedOperationException("unexpected buffer offset");
  }

  final long max = compoundAddr + count * OFFSET_SIZE;
  for(; compoundAddr < max; compoundAddr +=OFFSET_SIZE, srcStart++){
    final int compoundIdx = PlatformDependent.getInt(compoundAddr);
    final int batchIdx = compoundIdx >>> 16;
    final int rowIdx = compoundIdx & 65535;

    final int byteValue = PlatformDependent.getByte(srcAddr + (srcStart >>> 3));
    final int bitVal = ((byteValue >>> (srcStart & 7)) & 1) << (rowIdx & 7);
    final long dstAddr = dstAddrs[batchIdx] + (rowIdx >>> 3);
    PlatformDependent.putByte(dstAddr, (byte) (PlatformDependent.getByte(dstAddr) | bitVal));
  }

  copyWatch.stop();
}
 
Example 9
Source File: FixedBlockVector.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
private void fillZeros(long startAddr, int length) {
  long c = startAddr;
  final long endAddr = startAddr + length;
  while(c < endAddr) {
    PlatformDependent.putLong(c, 0);
    c += 8;
  }

  int remain = length % 8;
  if(remain != 0){
    for(int i = 0; i < remain ; i++) {
      PlatformDependent.putByte(endAddr - i, (byte)0);
    }
  }
}
 
Example 10
Source File: UnsafeByteBufUtil.java    From netty-4.1.22 with Apache License 2.0 5 votes vote down vote up
static void setMediumLE(long address, int value) {
    PlatformDependent.putByte(address, (byte) value);
    if (UNALIGNED) {
        PlatformDependent.putShort(address + 1, BIG_ENDIAN_NATIVE_ORDER ? Short.reverseBytes((short) (value >>> 8))
                                                                        : (short) (value >>> 8));
    } else {
        PlatformDependent.putByte(address + 1, (byte) (value >>> 8));
        PlatformDependent.putByte(address + 2, (byte) (value >>> 16));
    }
}
 
Example 11
Source File: FieldBufferCopier6.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
@Override
public void copy(long offsetAddr, int count) {
  if(allocateAsFixed){
    targetAlt.allocateNew(count);
  }
  final long[] srcAddr = this.srcAddrs;
  final long dstAddr;
  switch (bufferOrdinal) {
    case NULL_BUFFER_ORDINAL:
      dstAddr = target.getValidityBufferAddress();
      break;
    case VALUE_BUFFER_ORDINAL:
      dstAddr = target.getDataBufferAddress();
      break;
    default:
      throw new UnsupportedOperationException("unexpected buffer offset");
  }

  final long maxAddr = offsetAddr + count * BUILD_RECORD_LINK_SIZE;
  int targetIndex = 0;
  for(; offsetAddr < maxAddr; offsetAddr += BUILD_RECORD_LINK_SIZE, targetIndex++){
    final int batchIndex = PlatformDependent.getInt(offsetAddr);
    final int batchOffset = Short.toUnsignedInt(PlatformDependent.getShort(offsetAddr + 4));
    final int byteValue = PlatformDependent.getByte(srcAddr[batchIndex] + (batchOffset >>> 3));
    final int bitVal = ((byteValue >>> (batchOffset & 7)) & 1) << (targetIndex & 7);
    final long addr = dstAddr + (targetIndex >>> 3);
    PlatformDependent.putByte(addr, (byte) (PlatformDependent.getByte(addr) | bitVal));
  }
}
 
Example 12
Source File: UnsafeByteBufUtil.java    From netty-4.1.22 with Apache License 2.0 5 votes vote down vote up
static void setShortLE(long address, int value) {
    if (UNALIGNED) {
        PlatformDependent.putShort(
            address, BIG_ENDIAN_NATIVE_ORDER ? Short.reverseBytes((short) value) : (short) value);
    } else {
        PlatformDependent.putByte(address, (byte) value);
        PlatformDependent.putByte(address + 1, (byte) (value >>> 8));
    }
}
 
Example 13
Source File: UnsafeByteBufUtil.java    From netty-4.1.22 with Apache License 2.0 5 votes vote down vote up
static void setShort(long address, int value) {
    if (UNALIGNED) {
        PlatformDependent.putShort(
                address, BIG_ENDIAN_NATIVE_ORDER ? (short) value : Short.reverseBytes((short) value));
    } else {
        PlatformDependent.putByte(address, (byte) (value >>> 8));
        PlatformDependent.putByte(address + 1, (byte) value);
    }
}
 
Example 14
Source File: CompactRowBlockWriter.java    From tajo with Apache License 2.0 5 votes vote down vote up
@Override
public void putByte(byte val) {
  ensureSize(SizeOf.SIZE_OF_BYTE);
  long addr = currentAddr();

  PlatformDependent.putByte(addr, val);
  curFieldIdx++;
  forwardField(SizeOf.SIZE_OF_BYTE);
}
 
Example 15
Source File: BaseSingleAccumulator.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
public static void writeWordwise(long addr, long length, long value) {
  if (length == 0) {
    return;
  }

  long nLong = length >>> 3;
  int nBytes = (int) length & 7;
  for (long i = nLong; i > 0; i--) {
    PlatformDependent.putLong(addr, value);
    addr += 8;
  }
  if (nBytes == 4) {
    PlatformDependent.putInt(addr, (int) value);
    addr += 4;
  } else if (nBytes < 4) {
    for (int i = nBytes; i > 0; i--) {
      PlatformDependent.putByte(addr, (byte) value);
      addr++;
    }
  } else {
    PlatformDependent.putInt(addr, (int) value);
    addr += 4;
    for (int i = nBytes - 4; i > 0; i--) {
      PlatformDependent.putByte(addr, (byte) value);
      addr++;
    }
  }
}
 
Example 16
Source File: PooledUnsafeDirectByteBuf.java    From netty4.0.27Learn with Apache License 2.0 4 votes vote down vote up
@Override
protected void _setByte(int index, int value) {
    PlatformDependent.putByte(addr(index), (byte) value);
}
 
Example 17
Source File: TestPreallocation.java    From dremio-oss with Apache License 2.0 4 votes vote down vote up
private void insertAndAccumulateForAllPartitions(final BufferAllocator allocator,
                                                 final int records,
                                                 final PivotDef pivot,
                                                 final LBlockHashTable hashTable,
                                                 final AccumulatorSet accumulator,
                                                 final int[] expectedOrdinals) {
  try (final FixedBlockVector fbv = new FixedBlockVector(allocator, pivot.getBlockWidth());
       final VariableBlockVector var = new VariableBlockVector(allocator, pivot.getVariableCount());
       final ArrowBuf offsets = allocator.buffer(records * VectorizedHashAggOperator.PARTITIONINDEX_HTORDINAL_WIDTH);
       final SimpleBigIntVector hashValues = new SimpleBigIntVector("hashvalues", allocator)) {

    /* pivot the data into temporary space */
    Pivots.pivot(pivot, records, fbv, var);

    final long keyFixedVectorAddr = fbv.getMemoryAddress();
    final long keyVarVectorAddr = var.getMemoryAddress();
    int[] actualOrdinals = new int[expectedOrdinals.length];
    final boolean fixedOnly = pivot.getVariableCount() == 0;

    /* compute hash on the pivoted data */
    hashValues.allocateNew(records);
    final BlockChunk blockChunk = new BlockChunk(keyFixedVectorAddr, keyVarVectorAddr, fixedOnly,
      pivot.getBlockWidth(), records, hashValues.getBufferAddress(), 0);
    HashComputation.computeHash(blockChunk);

    /* insert */
    long offsetAddr = offsets.memoryAddress();
    for (int keyIndex = 0; keyIndex < records; keyIndex++, offsetAddr += VectorizedHashAggOperator.PARTITIONINDEX_HTORDINAL_WIDTH) {
      final int keyHash = (int)hashValues.get(keyIndex);
      actualOrdinals[keyIndex] = hashTable.add(keyFixedVectorAddr, keyVarVectorAddr, keyIndex, keyHash);
      PlatformDependent.putByte(offsetAddr, (byte)0);
      PlatformDependent.putInt(offsetAddr + VectorizedHashAggOperator.HTORDINAL_OFFSET, actualOrdinals[keyIndex]);
      PlatformDependent.putInt(offsetAddr + VectorizedHashAggOperator.KEYINDEX_OFFSET, keyIndex);
    }

    assertArrayEquals(expectedOrdinals, actualOrdinals);

    /* accumulate */
    accumulator.accumulate(offsets.memoryAddress(), records, hashTable.getBitsInChunk(), hashTable.getChunkOffsetMask());
  }
}
 
Example 18
Source File: UnsafeDirectLittleEndian.java    From Bats with Apache License 2.0 4 votes vote down vote up
@Override
public ByteBuf setByte(int index, int value) {
  PlatformDependent.putByte(addr(index), (byte) value);
  return this;
}
 
Example 19
Source File: DrillBuf.java    From Bats with Apache License 2.0 4 votes vote down vote up
public void writeByteUnsafe(byte b) {
  PlatformDependent.putByte(addr(readerIndex), b);
  readerIndex++;
}
 
Example 20
Source File: TestVectorizedHashAggPartitionSpillHandler.java    From dremio-oss with Apache License 2.0 4 votes vote down vote up
private void insertAndAccumulateForAllPartitions(final BufferAllocator allocator,
                                                 final int records,
                                                 final PivotDef pivot,
                                                 final VectorizedHashAggPartition[] partitions,
                                                 final int[] expectedOrdinals) {
  try (final FixedBlockVector fbv = new FixedBlockVector(allocator, pivot.getBlockWidth());
       final VariableBlockVector var = new VariableBlockVector(allocator, pivot.getVariableCount());
       final ArrowBuf offsets = allocator.buffer(records * VectorizedHashAggOperator.PARTITIONINDEX_HTORDINAL_WIDTH);
       final SimpleBigIntVector hashValues = new SimpleBigIntVector("hashvalues", allocator)) {

    /* pivot the data into temporary space */
    Pivots.pivot(pivot, records, fbv, var);

    final long keyFixedVectorAddr = fbv.getMemoryAddress();
    final long keyVarVectorAddr = var.getMemoryAddress();
    int[] actualOrdinals = new int[expectedOrdinals.length];
    final boolean fixedOnly = pivot.getVariableCount() == 0;

    /* compute hash on the pivoted data */
    hashValues.allocateNew(records);
    final BlockChunk blockChunk = new BlockChunk(keyFixedVectorAddr, keyVarVectorAddr, fixedOnly,
      pivot.getBlockWidth(), records, hashValues.getBufferAddress(), 0);
    HashComputation.computeHash(blockChunk);

    /* since we are mocking partitions to test spill handler,
     * just insert same data into all partitions
     */
    int hashPartitionIndex = 0;
    for (int i = 0; i < partitions.length; i++) {

      /* insert */
      long offsetAddr = offsets.memoryAddress();
      LBlockHashTable hashTable = null;
      for (int keyIndex = 0; keyIndex < records; keyIndex++, offsetAddr += VectorizedHashAggOperator.PARTITIONINDEX_HTORDINAL_WIDTH) {
        final int keyHash = (int)hashValues.get(keyIndex);
        hashTable = partitions[i].getHashTable();
        actualOrdinals[keyIndex] = hashTable.add(keyFixedVectorAddr, keyVarVectorAddr, keyIndex, keyHash);
        PlatformDependent.putByte(offsetAddr, (byte)hashPartitionIndex);
        PlatformDependent.putInt(offsetAddr + VectorizedHashAggOperator.HTORDINAL_OFFSET, actualOrdinals[keyIndex]);
        PlatformDependent.putInt(offsetAddr + VectorizedHashAggOperator.KEYINDEX_OFFSET, keyIndex);
      }

      /* accumulate */
      partitions[i].getAccumulator().accumulate(offsets.memoryAddress(), records,
                                                partitions[0].getHashTable().getBitsInChunk(),
                                                partitions[0].getHashTable().getChunkOffsetMask());

      /* check hashtable */
      assertArrayEquals(expectedOrdinals, actualOrdinals);
      assertEquals(1, hashTable.getFixedBlockBuffers().size());
      assertEquals(1, hashTable.getFixedBlockBuffers().size());
    }
  }
}