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.array.util;
 24 
 25 import org.openjdk.bench.valhalla.types.Int32;
 26 import org.openjdk.bench.valhalla.types.Opt;
 27 import org.openjdk.bench.valhalla.types.QOpt;
 28 import org.openjdk.bench.valhalla.types.R32int;
 29 import org.openjdk.bench.valhalla.util.SizeBase;
 30 import org.openjdk.jmh.annotations.Setup;
 31 
 32 public class StatesQOpt extends SizeBase {
 33 
 34     public static abstract class ObjState extends SizeState {
 35         public Object[] arr;
 36         void fill() {
 37             for (int i = 0; i < arr.length; i++) {
 38                 arr[i] =  QOpt.of(new R32int(i));
 39             }
 40         }
 41     }
 42 
 43     public static abstract class IntState extends SizeState {
 44         public Opt<Int32>[] arr;
 45         void fill() {
 46             for (int i = 0; i < arr.length; i++) {
 47                 arr[i] =  QOpt.of(new R32int(i));
 48             }
 49         }
 50     }
 51 
 52     public static abstract class RefState extends SizeState {
 53         public QOpt<Int32>[] arr;
 54         void fill() {
 55             for (int i = 0; i < arr.length; i++) {
 56                 arr[i] =  QOpt.of(new R32int(i));
 57             }
 58         }
 59     }
 60 
 61     public static abstract class ValState extends SizeState {
 62         public QOpt<Int32>[] arr;
 63         void fill() {
 64             for (int i = 0; i < arr.length; i++) {
 65                 arr[i] =  QOpt.of(new R32int(i));
 66             }
 67         }
 68     }
 69 
 70     // naming convention: <runtime array type>_as_<static array type>
 71 
 72     public static class Obj_as_Obj extends ObjState {
 73         @Setup
 74         public void setup() {
 75             arr = new Object[size];
 76             fill();
 77         }
 78     }
 79 
 80     public static class Int_as_Obj extends ObjState {
 81         @Setup
 82         public void setup() {
 83             arr = new Opt[size];
 84             fill();
 85         }
 86     }
 87 
 88     public static class Ref_as_Obj extends ObjState {
 89         @Setup
 90         public void setup() {
 91             arr = new QOpt[size];
 92             fill();
 93         }
 94     }
 95 
 96     public static class Val_as_Obj extends ObjState {
 97         @Setup
 98         public void setup() {
 99             arr = new QOpt[size];
100             fill();
101         }
102     }
103 
104     public static class Int_as_Int extends IntState {
105         @Setup
106         public void setup() {
107             arr = new Opt[size];
108             fill();
109         }
110     }
111 
112     public static class Ref_as_Int extends IntState {
113         @Setup
114         public void setup() {
115             arr = new QOpt[size];
116             fill();
117         }
118     }
119 
120     public static class Val_as_Int extends IntState {
121         @Setup
122         public void setup() {
123             arr = new QOpt[size];
124             fill();
125         }
126     }
127 
128     public static class Ref_as_Ref extends RefState {
129         @Setup
130         public void setup() {
131             arr = new QOpt[size];
132             fill();
133         }
134     }
135 
136     public static class Val_as_Ref extends RefState {
137         @Setup
138         public void setup() {
139             arr = new QOpt[size];
140             fill();
141         }
142     }
143 
144     public static class Val_as_Val extends ValState {
145         @Setup
146         public void setup() {
147             arr = new QOpt[size];
148             fill();
149         }
150     }
151 
152 
153 }