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

The following examples show how to use io.netty.util.internal.PlatformDependent#putLong() . 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: Copier.java    From dremio-oss with Apache License 2.0 6 votes vote down vote up
public static final void handCopy(final long src, final long dst, int len) {
  int n = len;
  long lPos = src;
  long rPos = dst;

  while (n > 7) {
    PlatformDependent.putLong(rPos, PlatformDependent.getLong(lPos));
    lPos += 8;
    rPos += 8;
    n -= 8;
  }
  while (n > 3) {
    PlatformDependent.putInt(rPos, PlatformDependent.getInt(lPos));
    lPos += 4;
    rPos += 4;
    n -= 4;
  }
  while (n-- != 0) {
    PlatformDependent.putByte(rPos, PlatformDependent.getByte(lPos));
    lPos++;
    rPos++;
  }
}
 
Example 2
Source File: MultiDestCopier.java    From dremio-oss with Apache License 2.0 6 votes vote down vote up
@Override
public void copy(long compoundAddr, final int srcStart, final int count) {
  copyWatch.start();

  final long[] dstAddrs = this.dstAddrs;

  long srcAddr = source.getDataBufferAddress() + srcStart * SIZE;

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

    final long dstAddr = dstAddrs[batchIdx] + rowIdx * SIZE;
    PlatformDependent.putLong(dstAddr, PlatformDependent.getLong(srcAddr));
    PlatformDependent.putLong(dstAddr + 8, PlatformDependent.getLong(srcAddr + 8));
  }

  copyWatch.stop();
}
 
Example 3
Source File: SumZeroAccumulators.java    From dremio-oss with Apache License 2.0 6 votes vote down vote up
public void accumulate(final long memoryAddr, final int count,
                       final int bitsInChunk, final int chunkOffsetMask) {
  final long maxAddr = memoryAddr + count * PARTITIONINDEX_HTORDINAL_WIDTH;
  final long incomingBit = getInput().getValidityBufferAddress();
  final long incomingValue =  getInput().getDataBufferAddress();
  final long[] valueAddresses = this.valueAddresses;
  final int maxValuesPerBatch = super.maxValuesPerBatch;

  for (long partitionAndOrdinalAddr = memoryAddr; partitionAndOrdinalAddr < maxAddr; partitionAndOrdinalAddr += PARTITIONINDEX_HTORDINAL_WIDTH) {
    /* get the hash table ordinal */
    final int tableIndex = PlatformDependent.getInt(partitionAndOrdinalAddr + HTORDINAL_OFFSET);
    /* get the index of data in input vector */
    final int incomingIndex = PlatformDependent.getInt(partitionAndOrdinalAddr + KEYINDEX_OFFSET);
    /* get the corresponding data from input vector -- source data for accumulation */
    final int bitVal = (PlatformDependent.getByte(incomingBit + ((incomingIndex >>> 3))) >>> (incomingIndex & 7)) & 1;
    final int newVal = PlatformDependent.getInt(incomingValue + (incomingIndex * WIDTH_INPUT)) * bitVal;
    /* get the hash table batch index */
    final int chunkIndex = tableIndex >>> bitsInChunk;
    final int chunkOffset = tableIndex & chunkOffsetMask;
    /* get the target address of accumulation vector */
    final long sumAddr = valueAddresses[chunkIndex] + (chunkOffset) * WIDTH_ACCUMULATOR;
    /* store the accumulated values at the target location of accumulation vector */
    PlatformDependent.putLong(sumAddr, PlatformDependent.getLong(sumAddr) + newVal);
  }
}
 
Example 4
Source File: MaxAccumulatorsNoSpill.java    From dremio-oss with Apache License 2.0 6 votes vote down vote up
public void accumulate(final long memoryAddr, final int count) {
  final long maxMemAddr = memoryAddr + count * WIDTH_ORDINAL;
  FieldVector inputVector = getInput();
  final long incomingBit = inputVector.getValidityBufferAddress();
  final long incomingValue = inputVector.getDataBufferAddress();
  final long[] bitAddresses = this.bitAddresses;
  final long[] valueAddresses = this.valueAddresses;
  final int scale = ((DecimalVector)inputVector).getScale();

  int incomingIndex = 0;
  for(long ordinalAddr = memoryAddr; ordinalAddr < maxMemAddr; ordinalAddr += WIDTH_ORDINAL, incomingIndex++){
    java.math.BigDecimal newVal = DecimalAccumulatorUtilsNoSpill.getBigDecimal(incomingValue + (incomingIndex * WIDTH_INPUT), valBuf, scale);
    final int tableIndex = PlatformDependent.getInt(ordinalAddr);
    int chunkIndex = tableIndex >>> LBlockHashTableNoSpill.BITS_IN_CHUNK;
    int chunkOffset = tableIndex & LBlockHashTableNoSpill.CHUNK_OFFSET_MASK;
    final long maxAddr = valueAddresses[chunkIndex] + (chunkOffset) * WIDTH_ACCUMULATOR;
    final long bitUpdateAddr = bitAddresses[chunkIndex] + ((chunkOffset >>> 5) * 4);
    final int bitVal = (PlatformDependent.getByte(incomingBit + ((incomingIndex >>> 3))) >>> (incomingIndex & 7)) & 1;
    final int bitUpdateVal = bitVal << (chunkOffset & 31);
    PlatformDependent.putLong(maxAddr, Double.doubleToLongBits(max(Double.longBitsToDouble(PlatformDependent.getLong(maxAddr)), newVal.doubleValue(), bitVal)));
    PlatformDependent.putInt(bitUpdateAddr, PlatformDependent.getInt(bitUpdateAddr) | bitUpdateVal);
  }
}
 
Example 5
Source File: MinAccumulatorsNoSpill.java    From dremio-oss with Apache License 2.0 6 votes vote down vote up
public void accumulate(final long memoryAddr, final int count) {
  final long maxAddr = memoryAddr + count * WIDTH_ORDINAL;
  FieldVector inputVector = getInput();
  final long incomingBit = inputVector.getValidityBufferAddress();
  final long incomingValue = inputVector.getDataBufferAddress();
  final long[] bitAddresses = this.bitAddresses;
  final long[] valueAddresses = this.valueAddresses;
  final int scale = ((DecimalVector)inputVector).getScale();

  int incomingIndex = 0;
  for (long ordinalAddr = memoryAddr; ordinalAddr < maxAddr; ordinalAddr += WIDTH_ORDINAL, incomingIndex++) {
    java.math.BigDecimal newVal = DecimalAccumulatorUtilsNoSpill.getBigDecimal(incomingValue + (incomingIndex * WIDTH_INPUT), valBuf, scale);
    final int tableIndex = PlatformDependent.getInt(ordinalAddr);
    int chunkIndex = tableIndex >>> LBlockHashTableNoSpill.BITS_IN_CHUNK;
    int chunkOffset = tableIndex & LBlockHashTableNoSpill.CHUNK_OFFSET_MASK;
    final long minAddr = valueAddresses[chunkIndex] + (chunkOffset) * WIDTH_ACCUMULATOR;
    final long bitUpdateAddr = bitAddresses[chunkIndex] + ((chunkOffset >>> 5) * 4);
    final int bitVal = (PlatformDependent.getByte(incomingBit + ((incomingIndex >>> 3))) >>> (incomingIndex & 7)) & 1;
    final int bitUpdateVal = bitVal << (chunkOffset & 31);
    PlatformDependent.putLong(minAddr, Double.doubleToLongBits(min(Double.longBitsToDouble(PlatformDependent.getLong(minAddr)), newVal.doubleValue(), bitVal)));
    PlatformDependent.putInt(bitUpdateAddr, PlatformDependent.getInt(bitUpdateAddr) | bitUpdateVal);
  }
}
 
Example 6
Source File: UnsafeByteBufUtil.java    From netty-4.1.22 with Apache License 2.0 5 votes vote down vote up
static void setLongLE(long address, long value) {
    if (UNALIGNED) {
        PlatformDependent.putLong(address, BIG_ENDIAN_NATIVE_ORDER ? Long.reverseBytes(value) : value);
    } else {
        PlatformDependent.putByte(address, (byte) value);
        PlatformDependent.putByte(address + 1, (byte) (value >>> 8));
        PlatformDependent.putByte(address + 2, (byte) (value >>> 16));
        PlatformDependent.putByte(address + 3, (byte) (value >>> 24));
        PlatformDependent.putByte(address + 4, (byte) (value >>> 32));
        PlatformDependent.putByte(address + 5, (byte) (value >>> 40));
        PlatformDependent.putByte(address + 6, (byte) (value >>> 48));
        PlatformDependent.putByte(address + 7, (byte) (value >>> 56));
    }
}
 
Example 7
Source File: QBlockHashTable.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
private void internalInit(final int capacity) {
  initTimer.start();
  this.capacity = capacity;
  this.maxSize = !QHashCapacities.isMaxCapacity(capacity, false) ? config.maxSize(capacity) : capacity - 1;
  this.batches = (int) Math.ceil( capacity / (MAX_VALUES_PER_BATCH * 1.0d) );
  final ControlBlock[] newControlBlocks = new ControlBlock[batches];
  tableControlAddresses = new long[batches];

  try(RollbackCloseable rollbackable = new RollbackCloseable()) {

    for(int i =0; i < batches; i++){
      newControlBlocks[i] = new ControlBlock(allocator, MAX_VALUES_PER_BATCH);
      rollbackable.add(newControlBlocks[i]);
      tableControlAddresses[i] = newControlBlocks[i].getMemoryAddress();

      final long addr = newControlBlocks[i].getMemoryAddress();
      final long max = addr + MAX_VALUES_PER_BATCH * CONTROL_WIDTH;
      for(long l = addr; l < max; l+= QBlockHashTable.CONTROL_WIDTH){
        PlatformDependent.putLong(l, QBlockHashTable.LFREE);
      }
    }

    this.controlBlocks = newControlBlocks;
    rollbackable.commit();
  } catch (Exception e) {
    throw Throwables.propagate(e);
  }
  initTimer.stop();
}
 
Example 8
Source File: SumZeroAccumulators.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
public void accumulate(final long memoryAddr, final int count,
                       final int bitsInChunk, final int chunkOffsetMask) {
  final long maxAddr = memoryAddr + count * PARTITIONINDEX_HTORDINAL_WIDTH;
  FieldVector inputVector = getInput();
  final long incomingBit = inputVector.getValidityBufferAddress();
  final long incomingValue = inputVector.getDataBufferAddress();
  final long[] valueAddresses = this.valueAddresses;
  final int scale = ((DecimalVector)inputVector).getScale();
  final int maxValuesPerBatch = super.maxValuesPerBatch;

  for (long partitionAndOrdinalAddr = memoryAddr; partitionAndOrdinalAddr < maxAddr; partitionAndOrdinalAddr += PARTITIONINDEX_HTORDINAL_WIDTH) {
    /* get the hash table ordinal */
    final int tableIndex = PlatformDependent.getInt(partitionAndOrdinalAddr + HTORDINAL_OFFSET);
    /* get the index of data in input vector */
    final int incomingIndex = PlatformDependent.getInt(partitionAndOrdinalAddr + KEYINDEX_OFFSET);
    /* get the corresponding data from input vector -- source data for accumulation */
    final int bitVal = (PlatformDependent.getByte(incomingBit + ((incomingIndex >>> 3))) >>> (incomingIndex & 7)) & 1;
    java.math.BigDecimal newVal = DecimalUtils.getBigDecimalFromLEBytes(incomingValue + (incomingIndex * WIDTH_INPUT), valBuf, scale);
    /* get the hash table batch index */
    final int chunkIndex = tableIndex >>> bitsInChunk;
    final int chunkOffset = tableIndex & chunkOffsetMask;
    /* get the target address of accumulation vector */
    final long sumAddr = valueAddresses[chunkIndex] + (chunkOffset) * WIDTH_ACCUMULATOR;
    /* store the accumulated values at the target location of accumulation vector */
    PlatformDependent.putLong(sumAddr, Double.doubleToLongBits(Double.longBitsToDouble(PlatformDependent.getLong(sumAddr)) + newVal.doubleValue() * bitVal));
  }
}
 
Example 9
Source File: MatchBitSet.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
/**
 * Creates MatchBitSet, allocates the buffer and initialized values to 0
 * @param numBits       the number of bits
 * @param allocator     the allocator used to allocate direct memory
 */
public MatchBitSet(final int numBits, final BufferAllocator allocator) {
  Preconditions.checkArgument(numBits >= 0, "bits count in constructor of BitSet is invalid");

  this.allocator = allocator;
  this.numBits = numBits;
  numWords = bitsToWords(this.numBits);
  buffer = allocator.buffer(numWords * BYTES_PER_WORD);
  bufferAddr = buffer.memoryAddress();
  long maxBufferAddr = bufferAddr + numWords * BYTES_PER_WORD;
  for (long wordAddr = bufferAddr; wordAddr < maxBufferAddr; wordAddr += BYTES_PER_WORD) {
    PlatformDependent.putLong(wordAddr, 0);
  }
}
 
Example 10
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) {
  targetAlt.allocateNew(count);
  final long max = offsetAddr + count * BUILD_RECORD_LINK_SIZE;
  final long[] srcAddrs = this.srcAddrs;
  long dstAddr = target.getDataBufferAddress();
  for(long addr = offsetAddr; addr < max; addr += BUILD_RECORD_LINK_SIZE, dstAddr += SIZE){
    final int batchIndex = PlatformDependent.getInt(addr);
    final int batchOffset = Short.toUnsignedInt(PlatformDependent.getShort(addr + 4));
    final long src = srcAddrs[batchIndex] + batchOffset * SIZE;
    PlatformDependent.putLong(dstAddr, PlatformDependent.getLong(src));
    PlatformDependent.putLong(dstAddr+8, PlatformDependent.getLong(src + 8));
  }
}
 
Example 11
Source File: CountOneAccumulatorNoSpill.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
public void accumulate(final long offsetAddr, final int count){
  final long maxAddr = offsetAddr + count * 4;
  final long[] valueAddresses = this.valueAddresses;
  for(long ordinalAddr = offsetAddr; ordinalAddr < maxAddr; ordinalAddr += 4){
    final int tableIndex = PlatformDependent.getInt(ordinalAddr);
    final long countAddr = valueAddresses[tableIndex >>> LBlockHashTableNoSpill.BITS_IN_CHUNK] + (tableIndex & LBlockHashTableNoSpill.CHUNK_OFFSET_MASK) * 8;
    PlatformDependent.putLong(countAddr, PlatformDependent.getLong(countAddr) + 1);
  }

}
 
Example 12
Source File: UnsafeByteBufUtil.java    From netty-4.1.22 with Apache License 2.0 5 votes vote down vote up
static void setLongLE(byte[] array, int index, long value) {
    if (UNALIGNED) {
        PlatformDependent.putLong(array, index, BIG_ENDIAN_NATIVE_ORDER ? Long.reverseBytes(value) : value);
    } else {
        PlatformDependent.putByte(array, index, (byte) value);
        PlatformDependent.putByte(array, index + 1, (byte) (value >>> 8));
        PlatformDependent.putByte(array, index + 2, (byte) (value >>> 16));
        PlatformDependent.putByte(array, index + 3, (byte) (value >>> 24));
        PlatformDependent.putByte(array, index + 4, (byte) (value >>> 32));
        PlatformDependent.putByte(array, index + 5, (byte) (value >>> 40));
        PlatformDependent.putByte(array, index + 6, (byte) (value >>> 48));
        PlatformDependent.putByte(array, index + 7, (byte) (value >>> 56));
    }
}
 
Example 13
Source File: HashComputation.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
/**
 * Used for hash computation by EightByteInnerLeftProbeOff in Vectorized Hash Join
 * @param hashValueAddress starting address of the buffer that stores the hashvalues.
 * @param srcDataAddr starting address of the source data (keys).
 * @param count number of records
 */
public static final void computeHash(long hashValueAddress, long srcDataAddr, final int count) {
  final long maxDataAddr = srcDataAddr + (count * EIGHT_BYTES);
  for (long keyAddr = srcDataAddr; keyAddr < maxDataAddr; keyAddr += EIGHT_BYTES, hashValueAddress += EIGHT_BYTES) {
    final long key = PlatformDependent.getLong(keyAddr);
    final long keyHash = computeHash(key);
    PlatformDependent.putLong(hashValueAddress, keyHash);
  }
}
 
Example 14
Source File: SumAccumulators.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
public void accumulate(final long memoryAddr, final int count,
                       final int bitsInChunk, final int chunkOffsetMask) {
  final long maxAddr = memoryAddr + count * PARTITIONINDEX_HTORDINAL_WIDTH;
  FieldVector inputVector = getInput();
  final long incomingBit = inputVector.getValidityBufferAddress();
  final long incomingValue = inputVector.getDataBufferAddress();
  final long[] bitAddresses = this.bitAddresses;
  final long[] valueAddresses = this.valueAddresses;
  final int scale = ((DecimalVector) inputVector).getScale();
  final int maxValuesPerBatch = super.maxValuesPerBatch;

  for (long partitionAndOrdinalAddr = memoryAddr; partitionAndOrdinalAddr < maxAddr; partitionAndOrdinalAddr += PARTITIONINDEX_HTORDINAL_WIDTH) {
    /* get the hash table ordinal */
    final int tableIndex = PlatformDependent.getInt(partitionAndOrdinalAddr + HTORDINAL_OFFSET);
    /* get the index of data in input vector */
    final int incomingIndex = PlatformDependent.getInt(partitionAndOrdinalAddr + KEYINDEX_OFFSET);
    /* get the corresponding data from input vector -- source data for accumulation */
    final int bitVal = (PlatformDependent.getByte(incomingBit + ((incomingIndex >>> 3))) >>> (incomingIndex & 7)) & 1;
    java.math.BigDecimal newVal = DecimalUtils.getBigDecimalFromLEBytes(incomingValue + (incomingIndex * WIDTH_INPUT), valBuf, scale);
    /* get the hash table batch index */
    final int chunkIndex = tableIndex >>> bitsInChunk;
    final int chunkOffset = tableIndex & chunkOffsetMask;
    /* get the target addresses of accumulation vector */
    final long sumAddr = valueAddresses[chunkIndex] + (chunkOffset) * WIDTH_ACCUMULATOR;
    final long bitUpdateAddr = bitAddresses[chunkIndex] + ((chunkOffset >>> 5) * 4);
    final int bitUpdateVal = bitVal << (chunkOffset & 31);
    /* store the accumulated values at the target location of accumulation vector */
    PlatformDependent.putLong(sumAddr, Double.doubleToLongBits(Double.longBitsToDouble(PlatformDependent.getLong(sumAddr)) + newVal.doubleValue() * bitVal));
    PlatformDependent.putInt(bitUpdateAddr, PlatformDependent.getInt(bitUpdateAddr) | bitUpdateVal);
  }
}
 
Example 15
Source File: ConditionalFieldBufferCopier6.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
@Override
public void copy(long offsetAddr, int count) {
  targetAlt.allocateNew(count);
  final long max = offsetAddr + count * BUILD_RECORD_LINK_SIZE;
  final long[] srcAddrs = this.srcAddrs;
  long dstAddr = target.getDataBufferAddress();
  for(long addr = offsetAddr; addr < max; addr += BUILD_RECORD_LINK_SIZE, dstAddr += SIZE){
    final int batchIndex = PlatformDependent.getInt(addr);
    if(batchIndex != SKIP){
      final int batchOffset = Short.toUnsignedInt(PlatformDependent.getShort(addr + 4));
      final long srcAddr = srcAddrs[batchIndex] + batchOffset * SIZE;
      PlatformDependent.putLong(dstAddr, PlatformDependent.getLong(srcAddr));
    }
  }
}
 
Example 16
Source File: DrillBuf.java    From Bats with Apache License 2.0 5 votes vote down vote up
@Override
public ByteBuf writeLong(long value) {
  BoundsChecking.ensureWritable(this, 8);
  PlatformDependent.putLong(addr(writerIndex), value);
  writerIndex += 8;
  return this;
}
 
Example 17
Source File: QBlockHashTable.java    From dremio-oss with Apache License 2.0 4 votes vote down vote up
private final void rehash(int newCapacity) {

    // grab old references.
    final ControlBlock[] oldControlBlocks = this.controlBlocks;
    final long[] oldControlAddrs = this.tableControlAddresses;

    try(RollbackCloseable closer = new RollbackCloseable()){ // Close old control blocks when done rehashing.
      for(ControlBlock cb : oldControlBlocks){
        closer.add(cb);
      }

      internalInit(newCapacity);

      final int capacity = this.capacity;
      final long[] controlAddrs = this.tableControlAddresses;

      // loop through backwards.

      for(int batch =0; batch < oldControlAddrs.length; batch++){
        long addr = oldControlAddrs[batch];
        final long max = addr + MAX_VALUES_PER_BATCH * CONTROL_WIDTH;
        for(long oldControlAddr = addr; oldControlAddr < max; oldControlAddr += CONTROL_WIDTH){
          long oldControl = PlatformDependent.getLong(oldControlAddr);

          if(oldControl != LFREE){

            int index = ((int) (oldControl >>> 32)) % capacity; // get previously computed hash and mod it.
            int newChunkIndex = index >>> BITS_IN_CHUNK;
            long controlAddr = controlAddrs[newChunkIndex] + ((index & CHUNK_OFFSET_MASK) * CONTROL_WIDTH);

            if (PlatformDependent.getInt(controlAddr) != FREE) {
              int backIndex = index, forwardIndex = index, step = 1;
              while (true) {
                if ((backIndex -= step) < 0) {
                  backIndex += capacity;
                }

                newChunkIndex = backIndex >>> BITS_IN_CHUNK;
                controlAddr = controlAddrs[newChunkIndex] + ((backIndex & CHUNK_OFFSET_MASK) * CONTROL_WIDTH);

                if (PlatformDependent.getInt(controlAddr) == FREE) {
                  break;
                }
                int t;
                if ((t = (forwardIndex += step) - capacity) >= 0) {
                  forwardIndex = t;
                }

                newChunkIndex = forwardIndex >>> BITS_IN_CHUNK;
                controlAddr = controlAddrs[newChunkIndex] + ((forwardIndex & CHUNK_OFFSET_MASK) * CONTROL_WIDTH);

                if (PlatformDependent.getInt(controlAddr) == FREE) {
                  break;
                }
                step += 2;

              }
            }
            PlatformDependent.putLong(controlAddr, oldControl);
          }
        }
      }


    } catch (Exception e) {
      throw Throwables.propagate(e);
    }
  }
 
Example 18
Source File: LBlockHashTable.java    From dremio-oss with Apache License 2.0 4 votes vote down vote up
private final void rehash(int newCapacity) {
  // grab old references.
  final ControlBlock[] oldControlBlocks = this.controlBlocks;
  final long[] oldControlAddrs = this.tableControlAddresses;

  try {
    /* this is the only step that allocates memory during rehash, if the method fails the state is unchanged */
    internalInit(newCapacity);

    final long[] controlAddrs = this.tableControlAddresses;

    // loop through backwards.

    final int capacity = this.capacity;
    for(int batch =0; batch < oldControlAddrs.length; batch++){
      long addr = oldControlAddrs[batch];
      final long max = addr + MAX_VALUES_PER_BATCH * CONTROL_WIDTH;
      for(long oldControlAddr = addr; oldControlAddr < max; oldControlAddr += CONTROL_WIDTH){
        long oldControl = PlatformDependent.getLong(oldControlAddr);

        if(oldControl != LFREE){
          int index = ((int) (oldControl >>> 32)) & (capacity - 1); // get previously computed hash and slice it.
          int newChunkIndex = index >>> BITS_IN_CHUNK;
          int offetInChunk = index & CHUNK_OFFSET_MASK;
          long controlAddr = controlAddrs[newChunkIndex] + (offetInChunk * CONTROL_WIDTH);
          if (PlatformDependent.getInt(controlAddr) != FREE) {
            while (true) {
              index = (index - 1) & (capacity - 1);
              newChunkIndex = index >>> BITS_IN_CHUNK;
              offetInChunk = index & CHUNK_OFFSET_MASK;
              controlAddr = controlAddrs[newChunkIndex] + (offetInChunk * CONTROL_WIDTH);
              if (PlatformDependent.getInt(controlAddr) == FREE) {
                break;
              }
            }
          }
          PlatformDependent.putLong(controlAddr, oldControl);
        }
      }
    }

    // Release existing control blocks only after rehashing is successful.
    AutoCloseables.close(asList(oldControlBlocks));
  } catch (Exception e) {
    logger.debug("ERROR: failed to rehash, exception: ", e);
    /* VectorizedHashAggOperator inserts data into hashtable  and will handle (if OOM) this exception */
    throw Throwables.propagate(e);
  }
}
 
Example 19
Source File: DrillBuf.java    From Bats with Apache License 2.0 4 votes vote down vote up
@Override
public ByteBuf setDouble(int index, double value) {
  chk(index, 8);
  PlatformDependent.putLong(addr(index), Double.doubleToRawLongBits(value));
  return this;
}
 
Example 20
Source File: DrillBuf.java    From Bats with Apache License 2.0 3 votes vote down vote up
/**
 * Read a long at position src+srcIndex and copy it to the dest+destIndex
 *
 * @param src source byte array
 * @param srcIndex source index
 * @param dest destination byte array
 * @param destIndex destination index
 */
public static void putLong(byte[] src, int srcIndex, byte[] dest, int destIndex) {
  check(srcIndex, LONG_NUM_BYTES, src.length);
  check(destIndex,LONG_NUM_BYTES, dest.length);

  long value = PlatformDependent.getLong(src, srcIndex);
  PlatformDependent.putLong(dest, destIndex, value);
}