Limit the number of bytes to copy per Unsafe.copyMemory()
Motivation: During a large memory copy, safepoint polling is diabled, hindering accurate profiling. Modifications: Only copy up to 1 MiB per Unsafe.copyMemory() Result: Potentially more reliable performance
This commit is contained in:
parent
4882377c27
commit
7252934f9b
@ -42,6 +42,13 @@ final class PlatformDependent0 {
|
||||
private static final boolean BIG_ENDIAN = ByteOrder.nativeOrder() == ByteOrder.BIG_ENDIAN;
|
||||
private static final long ADDRESS_FIELD_OFFSET;
|
||||
|
||||
/**
|
||||
* Limits the number of bytes to copy per {@link Unsafe#copyMemory(long, long, long)} to allow safepoint polling
|
||||
* during a large copy.
|
||||
*/
|
||||
private static final long UNSAFE_COPY_THRESHOLD = 1024L * 1024L;
|
||||
|
||||
|
||||
/**
|
||||
* {@code true} if and only if the platform supports unaligned access.
|
||||
*
|
||||
@ -155,11 +162,9 @@ final class PlatformDependent0 {
|
||||
}
|
||||
try {
|
||||
Cleaner cleaner = ((DirectBuffer) buffer).cleaner();
|
||||
if (cleaner == null) {
|
||||
throw new IllegalArgumentException(
|
||||
"attempted to deallocate the buffer which was allocated via JNIEnv->NewDirectByteBuffer()");
|
||||
if (cleaner != null) {
|
||||
cleaner.clean();
|
||||
}
|
||||
cleaner.clean();
|
||||
} catch (Throwable t) {
|
||||
// Nothing we can do here.
|
||||
}
|
||||
@ -308,11 +313,25 @@ final class PlatformDependent0 {
|
||||
}
|
||||
|
||||
static void copyMemory(long srcAddr, long dstAddr, long length) {
|
||||
UNSAFE.copyMemory(srcAddr, dstAddr, length);
|
||||
//UNSAFE.copyMemory(srcAddr, dstAddr, length);
|
||||
while (length > 0) {
|
||||
long size = Math.min(length, UNSAFE_COPY_THRESHOLD);
|
||||
UNSAFE.copyMemory(srcAddr, dstAddr, size);
|
||||
length -= size;
|
||||
srcAddr += size;
|
||||
dstAddr += size;
|
||||
}
|
||||
}
|
||||
|
||||
static void copyMemory(Object src, long srcOffset, Object dst, long dstOffset, long length) {
|
||||
UNSAFE.copyMemory(src, srcOffset, dst, dstOffset, length);
|
||||
//UNSAFE.copyMemory(src, srcOffset, dst, dstOffset, 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;
|
||||
}
|
||||
}
|
||||
|
||||
static <U, W> AtomicReferenceFieldUpdater<U, W> newAtomicReferenceFieldUpdater(
|
||||
|
Loading…
Reference in New Issue
Block a user