This looks similar to JDK-8153870, but for arguments.
See the test:
private static final VarHandle VH_LONG = MethodHandles.byteBufferViewVarHandle(
long[].class, java.nio.ByteOrder.nativeOrder());
ByteBuffer buffer;
@Setup
public void setup() {
buffer = ByteBuffer.allocateDirect(3 * 1024).alignedSlice(8);
}
@Benchmark
public void test_int() {
for (int i = 0; i < 100; i++) {
VH_LONG.set(buffer, i, i);
}
}
@Benchmark
public void test_long() {
for (int i = 0; i < 100; i++) {
VH_LONG.set(buffer, i, (long) i);
}
}
Benchmark Mode Cnt Score Error Units
VHLongMismatch.test_int avgt 5 1370.022 ± 0.350 ns/op
VHLongMismatch.test_long avgt 5 41.471 ± 0.537 ns/op
33x performance hit.
Tests:
http://cr.openjdk.java.net/~shade/8160821/VHLongMismatch.java
http://cr.openjdk.java.net/~shade/8160821/benchmarks.jar