1 /*
  2  * Copyright (c) 2020, 2024, Oracle and/or its affiliates. All rights reserved.
  3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  4  *
  5  * This code is free software; you can redistribute it and/or modify it
  6  * under the terms of the GNU General Public License version 2 only, as
  7  * published by the Free Software Foundation.
  8  *
  9  * This code is distributed in the hope that it will be useful, but WITHOUT
 10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 12  * version 2 for more details (a copy is included in the LICENSE file that
 13  * accompanied this code).
 14  *
 15  * You should have received a copy of the GNU General Public License version
 16  * 2 along with this work; if not, write to the Free Software Foundation,
 17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 18  *
 19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 20  * or visit www.oracle.com if you need additional information or have any
 21  * questions.
 22  */
 23 package org.openjdk.bench.valhalla.field.set;
 24 
 25 import org.openjdk.bench.valhalla.field.util.StatesQ32int;
 26 import org.openjdk.bench.valhalla.types.Q32int;
 27 import org.openjdk.jmh.annotations.Benchmark;
 28 import org.openjdk.jmh.annotations.CompilerControl;
 29 
 30 public class Inline32int extends StatesQ32int {
 31 
 32     @CompilerControl(CompilerControl.Mode.DONT_INLINE)
 33     public static Q32int getRef(int i) {
 34         return new Q32int(i);
 35     }
 36 
 37     @CompilerControl(CompilerControl.Mode.DONT_INLINE)
 38     public static Q32int getVal(int i) {
 39         return new Q32int(i);
 40     }
 41 
 42     @Benchmark
 43     @CompilerControl(CompilerControl.Mode.DONT_INLINE)
 44     public void New_to_Val_set(ValState st) {
 45         ValWrapper[] arr = st.arr;
 46         for (int i = 0; i < arr.length; i++) {
 47             arr[i].f = new Q32int(i);
 48         }
 49     }
 50 
 51     @Benchmark
 52     @CompilerControl(CompilerControl.Mode.DONT_INLINE)
 53     public void Ref_to_Val_set(ValState st) {
 54         ValWrapper[] arr = st.arr;
 55         for (int i = 0; i < arr.length; i++) {
 56             arr[i].f = getRef(i);
 57         }
 58     }
 59 
 60     @Benchmark
 61     @CompilerControl(CompilerControl.Mode.DONT_INLINE)
 62     public void Val_to_Val_set(ValState st) {
 63         ValWrapper[] arr = st.arr;
 64         for (int i = 0; i < arr.length; i++) {
 65             arr[i].f = getVal(i);
 66         }
 67     }
 68 
 69     @Benchmark
 70     @CompilerControl(CompilerControl.Mode.DONT_INLINE)
 71     public void Def_to_Val_set(ValState st) {
 72         ValWrapper[] arr = st.arr;
 73         for (int i = 0; i < arr.length; i++) {
 74             arr[i].f = new Q32int()  ;
 75         }
 76     }
 77 
 78     @Benchmark
 79     @CompilerControl(CompilerControl.Mode.DONT_INLINE)
 80     public void New_to_Ref_set(RefState st) {
 81         RefWrapper[] arr = st.arr;
 82         for (int i = 0; i < arr.length; i++) {
 83             arr[i].f = new Q32int(i);
 84         }
 85     }
 86 
 87     @Benchmark
 88     @CompilerControl(CompilerControl.Mode.DONT_INLINE)
 89     public void Ref_to_Ref_set(RefState st) {
 90         RefWrapper[] arr = st.arr;
 91         for (int i = 0; i < arr.length; i++) {
 92             arr[i].f = getRef(i);
 93         }
 94     }
 95 
 96     @Benchmark
 97     @CompilerControl(CompilerControl.Mode.DONT_INLINE)
 98     public void Val_to_Ref_set(RefState st) {
 99         RefWrapper[] arr = st.arr;
100         for (int i = 0; i < arr.length; i++) {
101             arr[i].f = getVal(i);
102         }
103     }
104 
105     @Benchmark
106     @CompilerControl(CompilerControl.Mode.DONT_INLINE)
107     public void Def_to_Ref_set(RefState st) {
108         RefWrapper[] arr = st.arr;
109         for (int i = 0; i < arr.length; i++) {
110             arr[i].f = new Q32int()  ;
111         }
112     }
113 
114 }