8259398: Super word not applied to a loop with byteArrayViewVarHandle

Reviewed-by: vlivanov, thartmann, chagedorn
This commit is contained in:
Vladimir Kozlov 2021-02-01 15:48:10 +00:00
parent 80760a322b
commit 02d586e13e
2 changed files with 51 additions and 16 deletions

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2020, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -33,10 +33,14 @@
* @run main compiler.vectorization.TestBufferVectorization buffer
* @run main compiler.vectorization.TestBufferVectorization bufferHeap
* @run main compiler.vectorization.TestBufferVectorization bufferDirect
* @run main compiler.vectorization.TestBufferVectorization arrayView
*/
package compiler.vectorization;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.VarHandle;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.IntBuffer;
@ -51,6 +55,7 @@ public class TestBufferVectorization {
final static int offset = buffer.arrayOffset();
final static IntBuffer heap_buffer_byte_to_int = ByteBuffer.allocate(N * Integer.BYTES).order(ByteOrder.nativeOrder()).asIntBuffer();
final static IntBuffer direct_buffer_byte_to_int = ByteBuffer.allocateDirect(N * Integer.BYTES).order(ByteOrder.nativeOrder()).asIntBuffer();
final static VarHandle VH_arr_view = MethodHandles.byteArrayViewVarHandle(int[].class, ByteOrder.nativeOrder()).withInvokeExactBehavior();
final static String arch = System.getProperty("os.arch");
interface Test {
@ -153,9 +158,42 @@ public class TestBufferVectorization {
}
}
static class TestArrayView implements Test {
final byte[] b_arr = new byte[N * Integer.BYTES];
public void init() {
for (int k = 0; k < N; k++) {
VH_arr_view.set(b_arr, k, k);
}
}
public void run() {
for (int k = 0; k < b_arr.length; k += 4) {
int v = (int) VH_arr_view.get(b_arr, k);
VH_arr_view.set(b_arr, k, v + 1);
}
}
public void verify() {
init(); // reset
// Save initial INT values
final int[] i_arr = new int[N];
for (int k = 0; k < i_arr.length; k++) {
i_arr[k] = (int) VH_arr_view.get(b_arr, k * Integer.BYTES);
}
run(); // run compiled code
for (int k = 0; k < i_arr.length; k++) {
int v = (int) VH_arr_view.get(b_arr, k * Integer.BYTES);
if (v != (i_arr[k] + 1)) {
throw new RuntimeException(" Invalid result: VH_arr_view.get(b_arr, " + (k * Integer.BYTES) + "): " + v + " != " + (i_arr[k] + 1));
}
}
}
}
public static void main(String[] args) {
if (args.length == 0) {
throw new RuntimeException(" Missing test name: array, arrayOffset, buffer, bufferHeap, bufferDirect");
throw new RuntimeException(" Missing test name: array, arrayOffset, buffer, bufferHeap, bufferDirect, arrayView");
}
Test te;
@ -175,6 +213,9 @@ public class TestBufferVectorization {
case "bufferDirect":
te = new TestBuffer(direct_buffer_byte_to_int);
break;
case "arrayView":
te = new TestArrayView();
break;
default:
throw new RuntimeException(" Unknown test: " + args[0]);
}