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.copy;
24 
25 import org.openjdk.bench.valhalla.array.util.StatesQOpt;
26 import org.openjdk.bench.valhalla.types.Int32;
27 import org.openjdk.bench.valhalla.types.QOpt;
28 import org.openjdk.jmh.annotations.Benchmark;
29 import org.openjdk.jmh.annotations.CompilerControl;
30 
31 public class InlineOpt extends StatesQOpt {
32 
33     @Benchmark
34     @CompilerControl(CompilerControl.Mode.DONT_INLINE)
35     public void Val_to_Val_copy(Val_as_Val s, Val_as_Val d) {
36         QOpt<Int32>[] src = s.arr;
37         QOpt<Int32>[] dst = d.arr;
38         for (int i = 0; i < src.length; i++) {
39             dst[i] = src[i];
40         }
41     }
42 
43     @Benchmark
44     @CompilerControl(CompilerControl.Mode.DONT_INLINE)
45     public void Val_to_Val_arraycopy(Val_as_Val s, Val_as_Val d) {
46         System.arraycopy(s.arr, 0, d.arr, 0, s.arr.length);
47     }
48 
49     @Benchmark
50     @CompilerControl(CompilerControl.Mode.DONT_INLINE)
51     public void Ref_to_Val_copy(Ref_as_Ref s, Val_as_Val d) {
52         QOpt<Int32>[] src = s.arr;
53         QOpt<Int32>[] dst = d.arr;
54         for (int i = 0; i < src.length; i++) {
55             dst[i] = src[i];
56         }
57     }
58 
59     @Benchmark
60     @CompilerControl(CompilerControl.Mode.DONT_INLINE)
61     public void Ref_to_Val_arraycopy(Ref_as_Ref s, Val_as_Val d) {
62         System.arraycopy(s.arr, 0, d.arr, 0, s.arr.length);
63     }
64 
65     @Benchmark
66     @CompilerControl(CompilerControl.Mode.DONT_INLINE)
67     public void Val_to_Ref_copy(Val_as_Val s, Ref_as_Ref d) {
68         QOpt<Int32>[] src = s.arr;
69         QOpt<Int32>[] dst = d.arr;
70         for (int i = 0; i < src.length; i++) {
71             dst[i] = src[i];
72         }
73     }
74 
75     @Benchmark
76     @CompilerControl(CompilerControl.Mode.DONT_INLINE)
77     public void Val_to_Ref_arraycopy(Val_as_Val s, Ref_as_Ref d) {
78         System.arraycopy(s.arr, 0, d.arr, 0, s.arr.length);
79     }
80 
81 }