本文整理了Java中sun.misc.Unsafe.copyMemory()
方法的一些代码示例,展示了Unsafe.copyMemory()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Unsafe.copyMemory()
方法的具体详情如下:
包路径:sun.misc.Unsafe
类名称:Unsafe
方法名:copyMemory
[英]Sets all bytes in a given block of memory to a copy of another block. This provides a single-register addressing mode, as discussed in #getInt(Object,long). Equivalent to copyMemory(null, srcAddress, null, destAddress, bytes)
.
[中]将给定内存块中的所有字节设置为另一个块的副本。这提供了一种“单寄存器”寻址模式,如#getInt(Object,long)中所述。相当于copyMemory(null, srcAddress, null, destAddress, bytes)
。
代码示例来源:origin: prestodb/presto
private static void copyMemory(Object src, long srcAddress, Object dest, long destAddress, int length)
{
// The Unsafe Javadoc specifies that the transfer size is 8 iff length % 8 == 0
// so ensure that we copy big chunks whenever possible, even at the expense of two separate copy operations
int bytesToCopy = length - (length % 8);
unsafe.copyMemory(src, srcAddress, dest, destAddress, bytesToCopy);
unsafe.copyMemory(src, srcAddress + bytesToCopy, dest, destAddress + bytesToCopy, length - bytesToCopy);
}
代码示例来源:origin: redisson/redisson
@Override
public byte[] toBytes(long startIndex, int len) {
byte res[] = new byte[len];
unsafe.copyMemory(null,baseAdress+startIndex, res, FSTUtil.bufoff, len );
return res;
}
代码示例来源:origin: redisson/redisson
@Override
public void setDouble(long byteIndex, double[] source, int elemoff, int numElems) {
unsafe.copyMemory(source,daoff+elemoff*8,null, baseAdress +byteIndex,numElems*8);
}
代码示例来源:origin: redisson/redisson
@Override
public void setChar(long byteIndex, char[] source, int elemoff, int numElems) {
unsafe.copyMemory(source,caoff+elemoff*2, null, baseAdress +byteIndex,numElems*2);
}
代码示例来源:origin: netty/netty
private static void copyMemoryWithSafePointPolling(
Object src, long srcOffset, Object dst, long dstOffset, long length) {
while (length > 0) {
long size = Math.min(length, UNSAFE_COPY_THRESHOLD);
UNSAFE.copyMemory(src, srcOffset, dst, dstOffset, size);
length -= size;
srcOffset += size;
dstOffset += size;
}
}
代码示例来源:origin: netty/netty
private static void copyMemoryWithSafePointPolling(long srcAddr, long dstAddr, long length) {
while (length > 0) {
long size = Math.min(length, UNSAFE_COPY_THRESHOLD);
UNSAFE.copyMemory(srcAddr, dstAddr, size);
length -= size;
srcAddr += size;
dstAddr += size;
}
}
代码示例来源:origin: redisson/redisson
private static void copyMemoryWithSafePointPolling(
Object src, long srcOffset, Object dst, long dstOffset, long length) {
while (length > 0) {
long size = Math.min(length, UNSAFE_COPY_THRESHOLD);
UNSAFE.copyMemory(src, srcOffset, dst, dstOffset, size);
length -= size;
srcOffset += size;
dstOffset += size;
}
}
代码示例来源:origin: redisson/redisson
private static void copyMemoryWithSafePointPolling(long srcAddr, long dstAddr, long length) {
while (length > 0) {
long size = Math.min(length, UNSAFE_COPY_THRESHOLD);
UNSAFE.copyMemory(srcAddr, dstAddr, size);
length -= size;
srcAddr += size;
dstAddr += size;
}
}
代码示例来源:origin: redisson/redisson
@Override
public void setFloat(long byteIndex, float[] source, int elemoff, int numElems) {
checkIndex(byteIndex,numElems*4);
unsafe.copyMemory(source,faoff+off-byteoff+elemoff*4,base,off+byteIndex,numElems*4);
}
代码示例来源:origin: redisson/redisson
@Override
public void setDouble(long byteIndex, double[] source, int elemoff, int numElems) {
checkIndex(byteIndex,numElems*8);
unsafe.copyMemory(source,daoff+off-byteoff+elemoff*8,base,off+byteIndex,numElems*8);
}
代码示例来源:origin: redisson/redisson
@Override
public void setLong(long byteIndex, long[] source, int elemoff, int numElems) {
checkIndex(byteIndex,numElems*8);
unsafe.copyMemory(source,laoff+off-byteoff+elemoff*8,base,off+byteIndex,numElems*8);
}
代码示例来源:origin: redisson/redisson
@Override
public void setInt(long byteIndex, int[] source, int elemoff, int numElems) {
checkIndex(byteIndex,numElems*4);
unsafe.copyMemory(source,iaoff+off-byteoff+elemoff*4,base,off+byteIndex,numElems*4);
}
代码示例来源:origin: redisson/redisson
@Override
public void setChar(long byteIndex, char[] source, int elemoff, int numElems) {
checkIndex(byteIndex,numElems*2);
unsafe.copyMemory(source,caoff+off-byteoff+elemoff*2,base,off+byteIndex,numElems*2);
}
代码示例来源:origin: redisson/redisson
@Override
public void set(long byteIndex, byte[] source, int elemoff, int numElems) {
checkIndex(byteIndex,numElems);
unsafe.copyMemory(source,off+elemoff,base,off+byteIndex,numElems);
}
代码示例来源:origin: redisson/redisson
@Override
public void setShort(long byteIndex, short[] source, int elemoff, int numElems) {
checkIndex(byteIndex,numElems*2);
unsafe.copyMemory(source,caoff+off-byteoff+elemoff*2,base,off+byteIndex,numElems*2);
}
代码示例来源:origin: netty/netty
static void copyMemory(Object src, long srcOffset, Object dst, long dstOffset, long length) {
// Manual safe-point polling is only needed prior Java9:
// See https://bugs.openjdk.java.net/browse/JDK-8149596
if (javaVersion() <= 8) {
copyMemoryWithSafePointPolling(src, srcOffset, dst, dstOffset, length);
} else {
UNSAFE.copyMemory(src, srcOffset, dst, dstOffset, length);
}
}
代码示例来源:origin: netty/netty
static void copyMemory(long srcAddr, long dstAddr, long length) {
// Manual safe-point polling is only needed prior Java9:
// See https://bugs.openjdk.java.net/browse/JDK-8149596
if (javaVersion() <= 8) {
copyMemoryWithSafePointPolling(srcAddr, dstAddr, length);
} else {
UNSAFE.copyMemory(srcAddr, dstAddr, length);
}
}
代码示例来源:origin: redisson/redisson
static void copyMemory(long srcAddr, long dstAddr, long length) {
// Manual safe-point polling is only needed prior Java9:
// See https://bugs.openjdk.java.net/browse/JDK-8149596
if (javaVersion() <= 8) {
copyMemoryWithSafePointPolling(srcAddr, dstAddr, length);
} else {
UNSAFE.copyMemory(srcAddr, dstAddr, length);
}
}
代码示例来源:origin: redisson/redisson
static void copyMemory(Object src, long srcOffset, Object dst, long dstOffset, long length) {
// Manual safe-point polling is only needed prior Java9:
// See https://bugs.openjdk.java.net/browse/JDK-8149596
if (javaVersion() <= 8) {
copyMemoryWithSafePointPolling(src, srcOffset, dst, dstOffset, length);
} else {
UNSAFE.copyMemory(src, srcOffset, dst, dstOffset, length);
}
}
代码示例来源:origin: redisson/redisson
@Override
public void copyTo(BasicBytez other, long otherByteIndex, long myByteIndex, long lenBytes) {
if ( other instanceof HeapBytez) {
HeapBytez hp = (HeapBytez) other;
unsafe.copyMemory(null,baseAdress+myByteIndex, hp.getBase(), hp.getOff()+otherByteIndex,lenBytes);
} else {
for ( long i = 0; i < lenBytes; i++ ) {
other.put(otherByteIndex+i,get(myByteIndex+i));
}
}
}
内容来源于网络,如有侵权,请联系作者删除!