Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/jdk17u
Path: blob/master/test/micro/org/openjdk/bench/vm/compiler/InterfacePrivateCalls.java
66646 views
1
/*
2
* Copyright Amazon.com Inc. 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.vm.compiler;
24
25
import org.openjdk.jmh.annotations.Benchmark;
26
import org.openjdk.jmh.annotations.BenchmarkMode;
27
import org.openjdk.jmh.annotations.Fork;
28
import org.openjdk.jmh.annotations.Level;
29
import org.openjdk.jmh.annotations.Measurement;
30
import org.openjdk.jmh.annotations.Mode;
31
import org.openjdk.jmh.annotations.OutputTimeUnit;
32
import org.openjdk.jmh.annotations.Scope;
33
import org.openjdk.jmh.annotations.Setup;
34
import org.openjdk.jmh.annotations.State;
35
36
import java.util.concurrent.TimeUnit;
37
38
@State(Scope.Benchmark)
39
public class InterfacePrivateCalls {
40
interface I {
41
private int bar() { return 0; }
42
default int foo() {
43
return bar();
44
}
45
}
46
47
static class C1 implements I {}
48
static class C2 implements I {}
49
static class C3 implements I {}
50
51
private I[] objs;
52
53
@Setup(Level.Trial)
54
public void setupTrial() {
55
objs = new I[3];
56
objs[0] = new C1();
57
objs[1] = new C2();
58
objs[2] = new C3();
59
}
60
61
@Benchmark
62
@BenchmarkMode(Mode.AverageTime)
63
@OutputTimeUnit(TimeUnit.NANOSECONDS)
64
@Fork(value=1, jvmArgsAppend={"-XX:TieredStopAtLevel=1"})
65
public void invokePrivateInterfaceMethodC1() {
66
for (int i = 0; i < objs.length; ++i) {
67
objs[i].foo();
68
}
69
}
70
71
@Benchmark
72
@BenchmarkMode(Mode.AverageTime)
73
@OutputTimeUnit(TimeUnit.NANOSECONDS)
74
@Fork(value=1)
75
public void invokePrivateInterfaceMethodC2() {
76
for (int i = 0; i < objs.length; ++i) {
77
objs[i].foo();
78
}
79
}
80
}
81
82