/** *Getthevalueofaprimitivearrayentry * *@paramptrpointertothedata *@paramoffsetoffset(inbytes)ofthearrayelement,relativetothefirstelementinthearray * *@returnthearrayelement,asanunsignedlong
*/ privatelong getArrayElem(GenericPointer ptr, long offset, long elemSize) { if (ptr.isOnHeap()) {
Object o = ptr.getObject(); int index = (int)(offset / elemSize);
// Initialize the whole source buffer with a verification friendly pattern (no 0x00 bytes)
initVerificationData(src, bufSize, elemSize); if (!src.equals(dst)) {
initVerificationData(dst, bufSize, elemSize);
}
if (DEBUG) {
System.out.println("===before==="); for (int offset = 0; offset < bufSize; offset += elemSize) { long srcValue = getArrayElem(src, offset, elemSize); long dstValue = getArrayElem(dst, offset, elemSize);
if (swap) { // Copy & swap data into the middle of the destination buffer
UNSAFE.copySwapMemory(src.getObject(),
src.getOffset() + srcOffset,
dst.getObject(),
dst.getOffset() + dstOffset,
copyBytes,
elemSize);
} else { // Copy & swap data into the middle of the destination buffer
UNSAFE.copyMemory(src.getObject(),
src.getOffset() + srcOffset,
dst.getObject(),
dst.getOffset() + dstOffset,
copyBytes);
}
if (DEBUG) {
System.out.println("===after==="); for (int offset = 0; offset < bufSize; offset += elemSize) { long srcValue = getArrayElem(src, offset, elemSize); long dstValue = getArrayElem(dst, offset, elemSize);
// Verify the front padding is unchanged
verifyUnswappedData(dst, 0, 0, dstOffset);
if (swap) { // Verify swapped data
verifySwappedData(dst, srcOffset, dstOffset, copyBytes, elemSize);
} else { // Verify copied/unswapped data
verifyUnswappedData(dst, dstOffset, srcOffset, copyBytes);
}
// Verify that the back padding is unchanged long frontAndCopyBytes = dstOffset + copyBytes; long trailingBytes = bufSize - frontAndCopyBytes;
verifyUnswappedData(dst, frontAndCopyBytes, frontAndCopyBytes, trailingBytes);
}
/** *Testvariousconfigurationsofcopyingandoptionallyswappingdata * *@paramsrcthesourcebuffertocopyfrom *@paramdstthedestinationbuffertocopyto *@paramsizesize(inbytes)ofthebuffers *@paramelemSizesize(inbytes)oftheindividualelements * *@throwsRuntimeExceptionifanerrorisfound
*/ publicvoid testBufferPair(GenericPointer src, GenericPointer dst, long size, long elemSize, boolean swap) { // offset in source from which to start reading data for (long srcOffset = 0; srcOffset < size; srcOffset += (src.isOnHeap() ? elemSize : 1)) {
// offset in destination at which to start writing data for (int dstOffset = 0; dstOffset < size; dstOffset += (dst.isOnHeap() ? elemSize : 1)) {
// number of bytes to copy long maxCopyBytes = Math.min(size - srcOffset, size - dstOffset); for (long copyBytes = 0; copyBytes < maxCopyBytes; copyBytes += elemSize) { try {
testCopyGeneric(src, srcOffset, dst, dstOffset, size, copyBytes, elemSize, swap);
} catch (RuntimeException e) { // Wrap the exception in another exception to catch the relevant configuration data thrownew RuntimeException("testBufferPair: " + "src=" + src + " dst=" + dst + " elemSize=0x" + Long.toHexString(elemSize) + " copyBytes=0x" + Long.toHexString(copyBytes) + " srcOffset=0x" + Long.toHexString(srcOffset) + " dstOffset=0x" + Long.toHexString(dstOffset) + " swap=" + swap,
e);
}
}
}
}
}
buf2Raw = UNSAFE.allocateMemory(size + BASE_ALIGNMENT); long buf2 = alignUp(buf2Raw, BASE_ALIGNMENT);
GenericPointer[] buffers = { new GenericPointer(buf1), new GenericPointer(buf2), new GenericPointer(allocArray(size, elemSize)), new GenericPointer(allocArray(size, elemSize))
};
/** *Verifythatsmallcopieswork
*/ void testSmallCopy(boolean swap) { int smallBufSize = SMALL_COPY_SIZE; int minElemSize = swap ? 2 : 1; int maxElemSize = swap ? 8 : 1;
// Test various element types and heap/native combinations for (long elemSize = minElemSize; elemSize <= maxElemSize; elemSize <<= 1) {
testElemSize(smallBufSize, elemSize, swap);
}
}
/** *Verifythatlargecopieswork
*/ void testLargeCopy(boolean swap) { long size = 2 * GB + 8; long bufRaw = 0;
// Check that a large native copy succeeds try { try {
bufRaw = UNSAFE.allocateMemory(size + BASE_ALIGNMENT);
} catch (OutOfMemoryError e) { // Accept failure, skip test return;
}
¤ Diese beiden folgenden Angebotsgruppen bietet das Unternehmen0.25Angebot
(Wie Sie bei der Firma Beratungs- und Dienstleistungen beauftragen können 2026-06-10)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.