Vectorization of Unsafe.putByte()

vrozov vrozov at apache.org
Thu Feb 22 22:13:35 UTC 2018


Hi,

What is a reason that Unsafe.putByte(Object var1, long var2, byte var4) is
vectorized differently compared to Unsafe.putByte(long var1, byte var3)?

Below are results of JMH with Java 8 on my Mac. Results for Java 9 and 10
are similar.

DirectBufferBenchmark.testNettyDirectPutBytes  avgt       87.490         
ms/op
DirectBufferBenchmark.testNettyHeapPutBytes    avgt       23.782         
ms/op

@State(Scope.Thread)
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.MILLISECONDS)
public class DirectBufferBenchmark {
  private static final int capacity = 256 * 1024 * 1024;

  private final ByteBuffer direct_source =
ByteBuffer.allocateDirect(capacity);
  private final ByteBuffer direct_target =
ByteBuffer.allocateDirect(capacity);
  private final ByteBuffer heap_source = ByteBuffer.allocate(capacity);
  private final ByteBuffer heap_target = ByteBuffer.allocate(capacity);
  private final long direct_source_address =
PlatformDependent.directBufferAddress(direct_source);
  private final long direct_target_address =
PlatformDependent.directBufferAddress(direct_target);
  private final byte[] heap_source_array = heap_source.array();
  private final byte[] heap_target_array = heap_target.array();

  @Benchmark
  public void testNettyHeapPutBytes() {
    for (int i = 0; i < capacity; i++) {
      PlatformDependent.putByte(heap_target_array, i, (byte)0xFF);
    }
  }

  @Benchmark
  public void testNettyDirectPutBytes() {
    for (int i = 0; i < capacity; i++) {
      PlatformDependent.putByte(direct_target_address + i, (byte)0xFF);
    }
  }
}

Thank you,

Vlad



--
Sent from: http://openjdk.5641.n7.nabble.com/OpenJDK-Hotspot-Compiler-Development-List-f6935.html


More information about the hotspot-compiler-dev mailing list