1 /*
  2  * Copyright (c) 2020, 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.R32int;
 28 import org.openjdk.bench.valhalla.types.ROpt;
 29 import org.openjdk.bench.valhalla.util.SizeBase;
 30 import org.openjdk.jmh.annotations.Setup;
 31 
 32 public class StatesROpt 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] =  ROpt.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] =  ROpt.of(new R32int(i));
 48             }
 49         }
 50     }
 51 
 52     public static abstract class RefState extends SizeState {
 53         public ROpt<Int32>[] arr;
 54         void fill() {
 55             for (int i = 0; i < arr.length; i++) {
 56                 arr[i] =  ROpt.of(new R32int(i));
 57             }
 58         }
 59     }
 60 
 61     // naming convention: <runtime array type>_as_<static array type>
 62 
 63     public static class Obj_as_Obj extends ObjState {
 64         @Setup
 65         public void setup() {
 66             arr = new Object[size];
 67             fill();
 68         }
 69     }
 70 
 71     public static class Int_as_Obj extends ObjState {
 72         @Setup
 73         public void setup() {
 74             arr = new Opt[size];
 75             fill();
 76         }
 77     }
 78 
 79     public static class Ref_as_Obj extends ObjState {
 80         @Setup
 81         public void setup() {
 82             arr = new ROpt[size];
 83             fill();
 84         }
 85     }
 86 
 87     public static class Int_as_Int extends IntState {
 88         @Setup
 89         public void setup() {
 90             arr = new Opt[size];
 91             fill();
 92         }
 93     }
 94 
 95     public static class Ref_as_Int extends IntState {
 96         @Setup
 97         public void setup() {
 98             arr = new ROpt[size];
 99             fill();
100         }
101     }
102 
103     public static class Ref_as_Ref extends RefState {
104         @Setup
105         public void setup() {
106             arr = new ROpt[size];
107             fill();
108         }
109     }
110 
111 }