Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/micro/org/openjdk/bench/java/lang/ArrayCopyObject.java
41161 views
1
/*
2
* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
3
* Copyright (c) 2020, Arm Limited. All rights reserved.
4
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5
*
6
* This code is free software; you can redistribute it and/or modify it
7
* under the terms of the GNU General Public License version 2 only, as
8
* published by the Free Software Foundation.
9
*
10
* This code is distributed in the hope that it will be useful, but WITHOUT
11
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13
* version 2 for more details (a copy is included in the LICENSE file that
14
* accompanied this code).
15
*
16
* You should have received a copy of the GNU General Public License version
17
* 2 along with this work; if not, write to the Free Software Foundation,
18
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19
*
20
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21
* or visit www.oracle.com if you need additional information or have any
22
* questions.
23
*/
24
25
package org.openjdk.bench.vm.compiler;
26
27
import org.openjdk.jmh.annotations.Benchmark;
28
import org.openjdk.jmh.annotations.BenchmarkMode;
29
import org.openjdk.jmh.annotations.Mode;
30
import org.openjdk.jmh.annotations.OutputTimeUnit;
31
import org.openjdk.jmh.annotations.Param;
32
import org.openjdk.jmh.annotations.Scope;
33
import org.openjdk.jmh.annotations.Setup;
34
import org.openjdk.jmh.annotations.State;
35
import org.openjdk.jmh.results.Result;
36
import org.openjdk.jmh.results.RunResult;
37
import org.openjdk.jmh.runner.Runner;
38
import org.openjdk.jmh.runner.RunnerException;
39
import org.openjdk.jmh.runner.options.Options;
40
import org.openjdk.jmh.runner.options.OptionsBuilder;
41
import org.openjdk.jmh.runner.options.TimeValue;
42
43
44
45
46
import java.util.concurrent.TimeUnit;
47
import java.util.Arrays;
48
49
class MyClass {
50
public int field1;
51
public int field2;
52
public int field3;
53
54
public MyClass(int val) {
55
field1 = val;
56
field2 = val;
57
field3 = val;
58
}
59
}
60
61
@State(Scope.Benchmark)
62
@BenchmarkMode(Mode.Throughput)
63
@OutputTimeUnit(TimeUnit.MILLISECONDS)
64
public class ArrayCopyObject {
65
@Param({"31", "63", "127" , "2047" , "4095", "8191"}) private int size;
66
67
private MyClass [] src;
68
private MyClass [] dst;
69
70
@Setup
71
public void setup() {
72
src = new MyClass[size];
73
dst = new MyClass[size];
74
for (int i = 0; i < src.length ; i++) {
75
src[i] = new MyClass(i);
76
dst[i] = new MyClass(0);
77
}
78
}
79
80
@Benchmark
81
public void disjoint_micro() {
82
System.arraycopy(src, 0 , dst, 0 , size);
83
}
84
85
@Benchmark
86
public void conjoint_micro() {
87
System.arraycopy(src, 0 , src, 10 , size - 10 );
88
}
89
90
public static void main(String[] args) throws RunnerException {
91
String [] base_opts =
92
{ "-XX:+UnlockDiagnosticVMOptions ",
93
"-XX:+IgnoreUnrecognizedVMOptions ",
94
"-XX:UseAVX=3" };
95
String [] opts_str1 = {"-XX:-UseCompressedOops "};
96
String [] opts_str2 = {"-XX:+UseCompressedOops "};
97
98
Options baseOpts = new OptionsBuilder()
99
.include(ArrayCopyObject.class.getName())
100
.warmupTime(TimeValue.seconds(30))
101
.measurementTime(TimeValue.seconds(10))
102
.warmupIterations(1)
103
.measurementIterations(2)
104
.jvmArgs(base_opts)
105
.forks(1)
106
.build();
107
108
RunResult r1 = new Runner(new OptionsBuilder()
109
.parent(baseOpts)
110
.jvmArgs(opts_str1)
111
.build()).runSingle();
112
113
RunResult r2 = new Runner(new OptionsBuilder()
114
.parent(baseOpts)
115
.jvmArgs(opts_str2)
116
.build()).runSingle();
117
118
System.out.println(r1.getPrimaryResult().getScore() + r2.getPrimaryResult().getScore());
119
}
120
}
121
122
123