Skip to content

Commit

Permalink
Only use manual safepoint polling in PlatformDependent0.copyMemory(..…
Browse files Browse the repository at this point in the history
….) when using java <= 8 (netty#8124)

Motivation:

Java9 and later does the safepoint polling by itself so there is not need for us to do it.

Modifications:

Check for java version before doing manual safepoint polling.

Result:

Less custom code and less overhead when using java9 and later. Fixes netty#8122.
  • Loading branch information
normanmaurer authored Aug 18, 2018
1 parent 7854737 commit 182ffda
Showing 1 changed file with 21 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,16 @@ static void putLong(byte[] data, int index, long value) {
}

static void copyMemory(long srcAddr, long dstAddr, long length) {
//UNSAFE.copyMemory(srcAddr, dstAddr, 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);
}
}

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);
Expand All @@ -561,7 +570,17 @@ static void copyMemory(long srcAddr, long dstAddr, long length) {
}

static void copyMemory(Object src, long srcOffset, Object dst, long dstOffset, long length) {
//UNSAFE.copyMemory(src, srcOffset, dst, dstOffset, 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);
}
}

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);
Expand Down

0 comments on commit 182ffda

Please sign in to comment.