Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/micro/org/openjdk/bench/java/lang/ObjectHashCode.java
41161 views
1
/*
2
* Copyright (c) 2014, 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.java.lang;
24
25
import org.openjdk.jmh.annotations.BenchmarkMode;
26
import org.openjdk.jmh.annotations.Fork;
27
import org.openjdk.jmh.annotations.Benchmark;
28
import org.openjdk.jmh.annotations.Mode;
29
import org.openjdk.jmh.annotations.OutputTimeUnit;
30
31
import java.util.concurrent.TimeUnit;
32
33
/**
34
* This benchmark assesses different hashCode strategies in HotSpot
35
*/
36
@BenchmarkMode(Mode.AverageTime)
37
@OutputTimeUnit(TimeUnit.NANOSECONDS)
38
public class ObjectHashCode {
39
40
@Benchmark
41
@Fork
42
public int mode_default() {
43
return System.identityHashCode(new Object());
44
}
45
46
@Benchmark
47
@Fork(jvmArgsPrepend = {"-XX:+UnlockExperimentalVMOptions", "-XX:hashCode=0"})
48
public int mode_0() {
49
return System.identityHashCode(new Object());
50
}
51
52
@Benchmark
53
@Fork(jvmArgsPrepend = {"-XX:+UnlockExperimentalVMOptions", "-XX:hashCode=1"})
54
public int mode_1() {
55
return System.identityHashCode(new Object());
56
}
57
58
@Benchmark
59
@Fork(jvmArgsPrepend = {"-XX:+UnlockExperimentalVMOptions", "-XX:hashCode=2"})
60
public int mode_2() {
61
return System.identityHashCode(new Object());
62
}
63
64
@Benchmark
65
@Fork(jvmArgsPrepend = {"-XX:+UnlockExperimentalVMOptions", "-XX:hashCode=3"})
66
public int mode_3() {
67
return System.identityHashCode(new Object());
68
}
69
70
@Benchmark
71
@Fork(jvmArgsPrepend = {"-XX:+UnlockExperimentalVMOptions", "-XX:hashCode=4"})
72
public int mode_4() {
73
return System.identityHashCode(new Object());
74
}
75
76
@Benchmark
77
@Fork(jvmArgsPrepend = {"-XX:+UnlockExperimentalVMOptions", "-XX:hashCode=5"})
78
public int mode_5() {
79
return System.identityHashCode(new Object());
80
}
81
82
}
83
84