1 /*
2 * Copyright (c) 2025, 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.jmh.annotations.Benchmark;
26 import org.openjdk.jmh.annotations.CompilerControl;
27 import org.openjdk.jmh.annotations.Fork;
28 import org.openjdk.jmh.annotations.Setup;
29
30 @Fork(value = 3, jvmArgsAppend = {"--enable-preview"})
31 public class Value128 extends SetBase {
32
33 public static class ValWrapper {
34 public ValueInt4 f;
35
36 public ValWrapper(ValueInt4 f) {
37 this.f = f;
38 }
39 }
40
41 public interface InterfaceInt {
42 public int value();
43 }
44
45 public static value class ValueInt4 implements InterfaceInt {
46
47 public final int prevalue0;
48 public final int prevalue1;
49 public final int prevalue2;
50
51 public final int value;
52
53 public ValueInt4(int value) {
54 this.prevalue0 = value;
55 this.prevalue1 = value;
56 this.prevalue2 = value;
57 this.value = value;
58 }
59
60 public int value() {
61 return value;
62 }
63
64 }
65
66 public static class RefState extends SizeState {
67 public ValWrapper[] arr;
68
69 @Setup
70 public void setup() {
71 arr = new ValWrapper[size];
72 for (int i = 0; i < size; i++) {
73 arr[i] = new ValWrapper(new ValueInt4(i));
74 }
75 }
76 }
77
78 @CompilerControl(CompilerControl.Mode.DONT_INLINE)
79 public ValueInt4 get_val(int i) {
80 return new ValueInt4(i);
81 }
82
83 @CompilerControl(CompilerControl.Mode.DONT_INLINE)
84 public void set_new(ValWrapper[] dst) {
85 for (int i = 0; i < dst.length; i++) {
86 dst[i].f = new ValueInt4(i);
87 }
88 }
89
90 @CompilerControl(CompilerControl.Mode.DONT_INLINE)
91 public void set_call(ValWrapper[] dst) {
92 for (int i = 0; i < dst.length; i++) {
93 dst[i].f = get_val(i);
94 }
95 }
96
97 @Benchmark
98 public void set_new_val(RefState st1) {
99 set_new(st1.arr);
100 }
101
102 @Benchmark
103 public void set_call_val(RefState st1) {
104 set_call(st1.arr);
105 }
106
107 }