Vectorization of Unsafe.putByte()

Vladimir Kozlov vladimir.kozlov at oracle.com
Sat Feb 24 01:08:19 UTC 2018


Hi Vlad,

Vectorization in HotSpot JVM does not work with direct addresses. It only works with Java arrays where boundaries and 
element type is known. For Java arrays Unsafe access converted to normal access to array's elements and vectorization is 
working.

Regards,
Vladimir K

On 2/22/18 2:13 PM, vrozov wrote:
> 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