< prev index next >

test/micro/org/openjdk/bench/java/lang/foreign/TestAdaptVarHandles.java

Print this page

 73             INT_TO_INTBOX = MethodHandles.lookup()
 74                     .findConstructor(IntBox.class, MethodType.methodType(void.class, int.class));
 75             INTBOX_TO_INT = MethodHandles.lookup()
 76                     .findVirtual(IntBox.class, "intValue", MethodType.methodType(int.class));
 77         } catch (Throwable ex) {
 78             throw new ExceptionInInitializerError(ex);
 79         }
 80     }
 81 
 82     static final VarHandle VH_ARR_INT = MethodHandles.arrayElementVarHandle(int[].class);
 83 
 84     static final VarHandle VH_BOX_ARR_INT = MethodHandles.filterValue(VH_ARR_INT, INTBOX_TO_INT, INT_TO_INTBOX);
 85 
 86     static final VarHandle VH_BOX_INT = MethodHandles.filterValue(VH_INT, INTBOX_TO_INT, INT_TO_INTBOX);
 87 
 88     static final MethodHandle MH_INT = VH_ARR_INT.toMethodHandle(VarHandle.AccessMode.GET);
 89 
 90     static final MethodHandle MH_BOX_INT = MethodHandles.filterReturnValue(MH_INT, INT_TO_INTBOX);
 91 
 92     int[] base = new int[ELEM_SIZE];

 93     MemorySegment segment = MemorySegment.ofArray(base);
 94 
 95     @Setup
 96     public void setup() {
 97         for (int i = 0; i < ELEM_SIZE; i++) {
 98             base[i] = i;
 99         }
100     }
101 
102     @Benchmark
103     public int vh_loop() throws Throwable {
104         int sum = 0;
105         for (int i = 0; i < ELEM_SIZE; i++) {
106             sum += (int) VH_ARR_INT.get(base, i);
107         }
108         return sum;
109     }
110 
111     @Benchmark
112     public int vh_box_loop() throws Throwable {

 73             INT_TO_INTBOX = MethodHandles.lookup()
 74                     .findConstructor(IntBox.class, MethodType.methodType(void.class, int.class));
 75             INTBOX_TO_INT = MethodHandles.lookup()
 76                     .findVirtual(IntBox.class, "intValue", MethodType.methodType(int.class));
 77         } catch (Throwable ex) {
 78             throw new ExceptionInInitializerError(ex);
 79         }
 80     }
 81 
 82     static final VarHandle VH_ARR_INT = MethodHandles.arrayElementVarHandle(int[].class);
 83 
 84     static final VarHandle VH_BOX_ARR_INT = MethodHandles.filterValue(VH_ARR_INT, INTBOX_TO_INT, INT_TO_INTBOX);
 85 
 86     static final VarHandle VH_BOX_INT = MethodHandles.filterValue(VH_INT, INTBOX_TO_INT, INT_TO_INTBOX);
 87 
 88     static final MethodHandle MH_INT = VH_ARR_INT.toMethodHandle(VarHandle.AccessMode.GET);
 89 
 90     static final MethodHandle MH_BOX_INT = MethodHandles.filterReturnValue(MH_INT, INT_TO_INTBOX);
 91 
 92     int[] base = new int[ELEM_SIZE];
 93     @SuppressWarnings("initialization")
 94     MemorySegment segment = MemorySegment.ofArray(base);
 95 
 96     @Setup
 97     public void setup() {
 98         for (int i = 0; i < ELEM_SIZE; i++) {
 99             base[i] = i;
100         }
101     }
102 
103     @Benchmark
104     public int vh_loop() throws Throwable {
105         int sum = 0;
106         for (int i = 0; i < ELEM_SIZE; i++) {
107             sum += (int) VH_ARR_INT.get(base, i);
108         }
109         return sum;
110     }
111 
112     @Benchmark
113     public int vh_box_loop() throws Throwable {
< prev index next >