本文整理汇总了Java中io.netty.util.internal.PlatformDependent类的典型用法代码示例。如果您正苦于以下问题:Java PlatformDependent类的具体用法?Java PlatformDependent怎么用?Java PlatformDependent使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
PlatformDependent类属于io.netty.util.internal包,在下文中一共展示了PlatformDependent类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createPooledByteBufAllocator
import io.netty.util.internal.PlatformDependent; //导入依赖的package包/类
/**
* Create a pooled ByteBuf allocator but disables the thread-local cache. Thread-local caches
* are disabled for TransportClients because the ByteBufs are allocated by the event loop thread,
* but released by the executor thread rather than the event loop thread. Those thread-local
* caches actually delay the recycling of buffers, leading to larger memory usage.
*/
public static PooledByteBufAllocator createPooledByteBufAllocator(
boolean allowDirectBufs,
boolean allowCache,
int numCores) {
if (numCores == 0) {
numCores = Runtime.getRuntime().availableProcessors();
}
return new PooledByteBufAllocator(
allowDirectBufs && PlatformDependent.directBufferPreferred(),
Math.min(getPrivateStaticField("DEFAULT_NUM_HEAP_ARENA"), numCores),
Math.min(getPrivateStaticField("DEFAULT_NUM_DIRECT_ARENA"), allowDirectBufs ? numCores : 0),
getPrivateStaticField("DEFAULT_PAGE_SIZE"),
getPrivateStaticField("DEFAULT_MAX_ORDER"),
allowCache ? getPrivateStaticField("DEFAULT_TINY_CACHE_SIZE") : 0,
allowCache ? getPrivateStaticField("DEFAULT_SMALL_CACHE_SIZE") : 0,
allowCache ? getPrivateStaticField("DEFAULT_NORMAL_CACHE_SIZE") : 0
);
}
示例2: ensureAvailableBlocks
import io.netty.util.internal.PlatformDependent; //导入依赖的package包/类
public void ensureAvailableBlocks(int count){
if(count > capacity){
final int blockWidth = this.blockWidth;
final int sizeInBytes = Numbers.nextPowerOfTwo(count * blockWidth);
final ArrowBuf oldBuf = buf;
buf = allocator.buffer(sizeInBytes);
// since blockWidth has to be a power of two and count
final long firstBlock = buf.memoryAddress() + (capacity * blockWidth);
final int maxBytes = blockWidth * count;
final long maxBlock = buf.memoryAddress() + maxBytes;
for(long l = firstBlock; l < maxBlock; l+= 8){
PlatformDependent.putLong(l, 0);
}
int remain = maxBytes % 8;
if(remain != 0){
buf.setZero(maxBytes - remain, remain);
}
PlatformDependent.copyMemory(oldBuf.memoryAddress(), buf.memoryAddress(), capacity * blockWidth);
oldBuf.release();
this.capacity = count;
}
}
示例3: handCopy
import io.netty.util.internal.PlatformDependent; //导入依赖的package包/类
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++;
}
}
示例4: memcmp
import io.netty.util.internal.PlatformDependent; //导入依赖的package包/类
private static final int memcmp(final long laddr, int lStart, int lEnd, final byte[] right, int rStart, final int rEnd) {
int lLen = lEnd - lStart;
int rLen = rEnd - rStart;
int n = Math.min(rLen, lLen);
long lPos = laddr + lStart;
int rPos = rStart;
while (n-- != 0) {
byte leftByte = PlatformDependent.getByte(lPos);
byte rightByte = right[rPos];
if (leftByte != rightByte) {
return ((leftByte & 0xFF) - (rightByte & 0xFF)) > 0 ? 1 : -1;
}
lPos++;
rPos++;
}
if (lLen == rLen) {
return 0;
}
return lLen > rLen ? 1 : -1;
}
示例5: finishRecord
import io.netty.util.internal.PlatformDependent; //导入依赖的package包/类
@Override
public void finishRecord() {
this.recordStart = characterData;
if(fieldOpen){
endField();
}
if(repeatedOffset >= repeatedOffsetMax){
expandRepeatedOffsets();
}
int newOffset = ((int) (charLengthOffset - charLengthOffsetOriginal))/4;
PlatformDependent.putInt(repeatedOffset, newOffset);
repeatedOffset += 4;
// if there were no defined fields, skip.
if(fieldIndex > -1){
batchIndex++;
recordCount++;
}
}
示例6: copy
import io.netty.util.internal.PlatformDependent; //导入依赖的package包/类
@Override
public void copy(long offsetAddr, int count) {
if(allocateAsFixed){
targetAlt.allocateNew(count);
}
final long srcAddr = source.getFieldBuffers().get(bufferOrdinal).memoryAddress();
final long dstAddr = target.getFieldBuffers().get(bufferOrdinal).memoryAddress();
final long maxAddr = offsetAddr + count * STEP_SIZE;
int targetIndex = 0;
for(; offsetAddr < maxAddr; offsetAddr += STEP_SIZE, targetIndex++){
final int recordIndex = (char) PlatformDependent.getShort(offsetAddr);
final int byteValue = PlatformDependent.getByte(srcAddr + (recordIndex >>> 3));
final int bitVal = ((byteValue >>> (recordIndex & 7)) & 1) << (targetIndex & 7);
final long addr = dstAddr + (targetIndex >>> 3);
PlatformDependent.putByte(addr, (byte) (PlatformDependent.getByte(addr) | bitVal));
}
}
示例7: setBytes
import io.netty.util.internal.PlatformDependent; //导入依赖的package包/类
public ByteBuf setBytes(int index, ByteBuffer src, int srcIndex, int length) {
if (src.isDirect()) {
checkIndex(index, length);
PlatformDependent.copyMemory(PlatformDependent.directBufferAddress(src) + srcIndex, this.memoryAddress() + index,
length);
} else {
if (srcIndex == 0 && src.capacity() == length) {
b.setBytes(index + offset, src);
} else {
ByteBuffer newBuf = src.duplicate();
newBuf.position(srcIndex);
newBuf.limit(srcIndex + length);
b.setBytes(index + offset, src);
}
}
return this;
}
示例8: doReadMessages
import io.netty.util.internal.PlatformDependent; //导入依赖的package包/类
@Override
protected int doReadMessages(List<Object> buf) throws Exception {
DatagramChannel ch = javaChannel();
ChannelConfig config = config();
RecvByteBufAllocator.Handle allocHandle = unsafe().recvBufAllocHandle();
ByteBuf data = allocHandle.allocate(config.getAllocator());
allocHandle.attemptedBytesRead(data.writableBytes());
boolean free = true;
try {
ByteBuffer nioData = data.internalNioBuffer(data.writerIndex(), data.writableBytes());
int pos = nioData.position();
int read = ch.read(nioData);
if (read <= 0) {
return read;
}
allocHandle.lastBytesRead(nioData.position() - pos);
buf.add(data.writerIndex(data.writerIndex() + allocHandle.lastBytesRead()));
free = false;
return 1;
} catch (Throwable cause) {
PlatformDependent.throwException(cause);
return -1;
} finally {
if (free) {
data.release();
}
}
}
示例9: doReadMessages
import io.netty.util.internal.PlatformDependent; //导入依赖的package包/类
@Override
protected int doReadMessages(List<Object> buf) throws Exception {
DatagramChannel ch = javaChannel();
UkcpServerChannelConfig config = config();
RecvByteBufAllocator.Handle allocHandle = unsafe().recvBufAllocHandle();
ByteBuf data = allocHandle.allocate(config.getAllocator());
allocHandle.attemptedBytesRead(data.writableBytes());
boolean free = true;
try {
ByteBuffer nioData = data.internalNioBuffer(data.writerIndex(), data.writableBytes());
int pos = nioData.position();
InetSocketAddress remoteAddress = (InetSocketAddress) ch.receive(nioData);
if (remoteAddress == null) {
return 0;
}
allocHandle.lastBytesRead(nioData.position() - pos);
buf.add(UkcpPacket.newInstance(data.writerIndex(data.writerIndex() + allocHandle.lastBytesRead()),
remoteAddress));
free = false;
return 1;
} catch (Throwable cause) {
PlatformDependent.throwException(cause);
return -1;
} finally {
if (free) {
data.release();
}
}
}
示例10: updateLengthBasedOnConstraint
import io.netty.util.internal.PlatformDependent; //导入依赖的package包/类
/**
* Checks to see if we can go over the end of our bytes constraint on the data. If so,
* adjusts so that we can only read to the last character of the first line that crosses
* the split boundary.
*/
private void updateLengthBasedOnConstraint() {
final long max = bStart + length;
for(long m = bStart + (endPos - streamPos); m < max; m++) {
for (int i = 0; i < lineSeparator.length; i++) {
long mPlus = m + i;
if (mPlus < max) {
// we found a line separator and don't need to consult the next byte.
if (lineSeparator[i] == PlatformDependent.getByte(mPlus) && i == lineSeparator.length - 1) {
length = (int) (mPlus - bStart) + 1;
endFound = true;
return;
}
} else {
// the last N characters of the read were remnant bytes. We'll hold off on dealing with these bytes until the next read.
remByte = i;
length = length - i;
return;
}
}
}
}
示例11: checkBom
import io.netty.util.internal.PlatformDependent; //导入依赖的package包/类
private final boolean checkBom(ByteOrderMark bom) {
int bomLength = bom.length();
if (bufferPtr + bomLength >= length) {
// Not enough bytes from the current position to the end of the buffer
return false;
}
if (BoundsChecking.BOUNDS_CHECKING_ENABLED) {
buffer.checkBytes(bufferPtr - 1, bufferPtr + bomLength);
}
byte[] bomBytes = bom.getBytes();
for (int i = 0; i < bomLength; i++) {
byte nextChar = PlatformDependent.getByte(bStartMinus1 + bufferPtr + i);
if (nextChar != bomBytes[i]) {
// No BOM. Position is unchanged
return false;
}
}
return true;
}
示例12: accumulate
import io.netty.util.internal.PlatformDependent; //导入依赖的package包/类
public void accumulate(final long memoryAddr, final int count) {
final long maxMemAddr = memoryAddr + count * 4;
List<ArrowBuf> buffers = getInput().getFieldBuffers();
final long incomaxgBit = buffers.get(0).memoryAddress();
final long incomaxgValue = buffers.get(1).memoryAddress();
final long[] bitAddresses = this.bitAddresses;
final long[] valueAddresses = this.valueAddresses;
int incomaxgIndex = 0;
for(long ordinalAddr = memoryAddr; ordinalAddr < maxMemAddr; ordinalAddr += 4, incomaxgIndex++){
final float newVal = Float.intBitsToFloat(PlatformDependent.getInt(incomaxgValue + (incomaxgIndex * WIDTH)));
final int tableIndex = PlatformDependent.getInt(ordinalAddr);
int chunkIndex = tableIndex >>> LBlockHashTable.BITS_IN_CHUNK;
int chunkOffset = tableIndex & LBlockHashTable.CHUNK_OFFSET_MASK;
final long maxAddr = valueAddresses[chunkIndex] + (chunkOffset) * 4;
final long bitUpdateAddr = bitAddresses[chunkIndex] + ((chunkOffset >>> 5) * 4);
final int bitVal = (PlatformDependent.getByte(incomaxgBit + ((incomaxgIndex >>> 3))) >>> (incomaxgIndex & 7)) & 1;
final int bitUpdateVal = bitVal << (chunkOffset & 31);
PlatformDependent.putInt(maxAddr, Float.floatToIntBits(max(Float.intBitsToFloat(PlatformDependent.getInt(maxAddr)), newVal, bitVal)));
PlatformDependent.putInt(bitUpdateAddr, PlatformDependent.getInt(bitUpdateAddr) | bitUpdateVal);
}
}
示例13: accumulate
import io.netty.util.internal.PlatformDependent; //导入依赖的package包/类
public void accumulate(final long memoryAddr, final int count) {
final long maxAddr = memoryAddr + count * 4;
List<ArrowBuf> buffers = getInput().getFieldBuffers();
final long incomingBit = buffers.get(0).memoryAddress();
final long incomingValue = buffers.get(1).memoryAddress();
final long[] valueAddresses = this.valueAddresses;
int incomingIndex = 0;
for(long ordinalAddr = memoryAddr; ordinalAddr < maxAddr; ordinalAddr += 4, incomingIndex++){
final int bitVal = (PlatformDependent.getByte(incomingBit + ((incomingIndex >>> 3))) >>> (incomingIndex & 7)) & 1;
final int newVal = PlatformDependent.getInt(incomingValue + (incomingIndex * WIDTH)) * bitVal;
final int tableIndex = PlatformDependent.getInt(ordinalAddr);
final long sumAddr = valueAddresses[tableIndex >>> LBlockHashTable.BITS_IN_CHUNK] + (tableIndex & LBlockHashTable.CHUNK_OFFSET_MASK) * 8;
PlatformDependent.putLong(sumAddr, PlatformDependent.getLong(sumAddr) + newVal);
}
}
示例14: accumulate
import io.netty.util.internal.PlatformDependent; //导入依赖的package包/类
public void accumulate(final long memoryAddr, final int count) {
final long maxAddr = memoryAddr + count * 4;
List<ArrowBuf> buffers = getInput().getFieldBuffers();
final long incomingBit = buffers.get(0).memoryAddress();
final long incomingValue = buffers.get(1).memoryAddress();
final long[] bitAddresses = this.bitAddresses;
final long[] valueAddresses = this.valueAddresses;
int incomingIndex = 0;
for(long ordinalAddr = memoryAddr; ordinalAddr < maxAddr; ordinalAddr += 4, incomingIndex++){
final int newVal = PlatformDependent.getInt(incomingValue + (incomingIndex * WIDTH));
final int tableIndex = PlatformDependent.getInt(ordinalAddr);
int chunkIndex = tableIndex >>> LBlockHashTable.BITS_IN_CHUNK;
int chunkOffset = tableIndex & LBlockHashTable.CHUNK_OFFSET_MASK;
final long minAddr = valueAddresses[chunkIndex] + (chunkOffset) * 4;
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.putInt(minAddr, min(PlatformDependent.getInt(minAddr), newVal, bitVal));
PlatformDependent.putInt(bitUpdateAddr, PlatformDependent.getInt(bitUpdateAddr) | bitUpdateVal);
}
}
示例15: accumulate
import io.netty.util.internal.PlatformDependent; //导入依赖的package包/类
public void accumulate(final long memoryAddr, final int count) {
final long maxAddr = memoryAddr + count * 4;
List<ArrowBuf> buffers = getInput().getFieldBuffers();
final long incomingBit = buffers.get(0).memoryAddress();
final long incomingValue = buffers.get(1).memoryAddress();
final long[] bitAddresses = this.bitAddresses;
final long[] valueAddresses = this.valueAddresses;
int incomingIndex = 0;
for(long ordinalAddr = memoryAddr; ordinalAddr < maxAddr; ordinalAddr += 4, incomingIndex++){
final int bitVal = (PlatformDependent.getByte(incomingBit + ((incomingIndex >>> 3))) >>> (incomingIndex & 7)) & 1;
final int newVal = PlatformDependent.getInt(incomingValue + (incomingIndex * WIDTH)) * bitVal;
final int tableIndex = PlatformDependent.getInt(ordinalAddr);
int chunkIndex = tableIndex >>> LBlockHashTable.BITS_IN_CHUNK;
int chunkOffset = tableIndex & LBlockHashTable.CHUNK_OFFSET_MASK;
final long sumAddr = valueAddresses[chunkIndex] + (chunkOffset) * 8;
final long bitUpdateAddr = bitAddresses[chunkIndex] + ((chunkOffset >>> 5) * 4);
final int bitUpdateVal = bitVal << (chunkOffset & 31);
PlatformDependent.putLong(sumAddr, PlatformDependent.getLong(sumAddr) + newVal);
PlatformDependent.putInt(bitUpdateAddr, PlatformDependent.getInt(bitUpdateAddr) | bitUpdateVal);
}
}