Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/jdk17u
Path: blob/master/test/micro/org/openjdk/bench/vm/compiler/LoopUnroll.java
66646 views
1
/*
2
* Copyright (C) 2021 THL A29 Limited, a Tencent company. 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
24
package org.openjdk.bench.vm.compiler;
25
26
import org.openjdk.jmh.annotations.*;
27
import org.openjdk.jmh.infra.*;
28
import java.util.concurrent.TimeUnit;
29
30
@Warmup(iterations = 3, time = 5, timeUnit = TimeUnit.SECONDS)
31
@Measurement(iterations = 4, time = 5, timeUnit = TimeUnit.SECONDS)
32
@BenchmarkMode(Mode.Throughput)
33
@OutputTimeUnit(TimeUnit.SECONDS)
34
@State(Scope.Thread)
35
@Fork(value=1)
36
public class LoopUnroll {
37
@Param({"16", "32", "64", "128", "256", "512", "1024"})
38
private int VECLEN;
39
40
private byte[][] a;
41
private byte[][] b;
42
private byte[][] c;
43
44
@Setup
45
public void init() {
46
a = new byte[VECLEN][VECLEN];
47
b = new byte[VECLEN][VECLEN];
48
c = new byte[VECLEN][VECLEN];
49
}
50
51
@CompilerControl(CompilerControl.Mode.DONT_INLINE)
52
private int run_workload1(int count, byte[][] a , byte[][] b, byte[][] c) {
53
for(int i = 0; i < a.length; i++) {
54
for (int j = 0; j < a[0].length; j++) {
55
a[i][j] = (byte)(b[i][j] + c[i][j]);
56
}
57
}
58
return a[count][count];
59
}
60
61
@Benchmark
62
public void workload1_caller(Blackhole bh) {
63
int r = 0;
64
for(int i = 0 ; i < 100; i++) {
65
r += run_workload1(i % a.length, a, b, c);
66
}
67
bh.consume(r);
68
}
69
70
@CompilerControl(CompilerControl.Mode.DONT_INLINE)
71
private int run_workload2(int count, byte[][] a , byte[][] b) {
72
for(int i = 0; i < b.length; i++) {
73
for (int j = 0; j < b[0].length; j++) {
74
a[i][j] = b[i][j];
75
}
76
}
77
return a[count][count];
78
}
79
80
@Benchmark
81
public void workload2_caller(Blackhole bh) {
82
int r = 0;
83
for(int i = 0 ; i < 100; i++) {
84
r += run_workload2(i % a.length, a, b);
85
}
86
bh.consume(r);
87
}
88
}
89
90