diff options
author | Ningsheng Jian <ningsheng.jian@linaro.org> | 2017-11-07 18:38:01 +0800 |
---|---|---|
committer | Ningsheng Jian <ningsheng.jian@linaro.org> | 2017-11-16 09:46:55 +0800 |
commit | e715fe64e96acb6131af937d0c8bba2537ea13f4 (patch) | |
tree | 702384eb404c3fd6acbbc3321261847e9fc27398 /src/main/java/org/linaro/benchmarks/jit_aot/Invoke.java | |
parent | 3811e9930ddb1d2b3a1463ad6c876af324331335 (diff) |
1. Port benchmark cases from art-testing.
2. Add some more benchmarks for basic OPs.
3. Fix some jmh result variance.
Signed-off-by: Zhongwei Yao <zhongwei.yao@linaro.org>
Signed-off-by: Yang Zhang <yang.zhang@linaro.org>
Signed-off-by: Ningsheng Jian <ningsheng.jian@linaro.org>
Change-Id: I514658696b63e468158325be3b84494553773705
Diffstat (limited to 'src/main/java/org/linaro/benchmarks/jit_aot/Invoke.java')
-rw-r--r-- | src/main/java/org/linaro/benchmarks/jit_aot/Invoke.java | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/src/main/java/org/linaro/benchmarks/jit_aot/Invoke.java b/src/main/java/org/linaro/benchmarks/jit_aot/Invoke.java new file mode 100644 index 0000000..36a4f76 --- /dev/null +++ b/src/main/java/org/linaro/benchmarks/jit_aot/Invoke.java @@ -0,0 +1,92 @@ +/* + * Copyright (C) 2016 Linaro Limited. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * This benchmark is inspired by benchmarks/caffeinemark. + * Original benchmark implements a recursion method which calls itself with invoke-virtual. + * + * This behavior can be different on JIT and AOT mode, because: + * - JIT mode can optimize invoke-virtual with inline cache mechanism. + * - AOT mode has no such optimization. + * + * This benchmark exposes such difference between ART JIT and AOT mode. + */ + +package org.linaro.benchmarks.jit_aot; + +import org.openjdk.jmh.annotations.*; +import java.util.concurrent.TimeUnit; + +@BenchmarkMode(Mode.AverageTime) +@OutputTimeUnit(TimeUnit.NANOSECONDS) +@State(Scope.Benchmark) + +public class Invoke { + + public int recursionInvokeVirtual(int i) { + if (i == 0) { + return 0; + } else { + return i + recursionInvokeVirtual(i - 1); + } + } + + public static int recursionInvokeStatic(int i) { + if (i == 0) { + return 0; + } else { + return i + recursionInvokeStatic(i - 1); + } + } + + public final int recursionInvokeFinal(int i) { + if (i == 0) { + return 0; + } else { + return i + recursionInvokeFinal(i - 1); + } + } + + private int recursionInvokePrivate(int i) { + if (i == 0) { + return 0; + } else { + return i + recursionInvokePrivate(i - 1); + } + } + + private static final int recursion_depth = 1000; + + @Benchmark + public void jmhTimeRecursionInvokeVirtual() { + recursionInvokeVirtual(recursion_depth); + } + + @Benchmark + public void jmhTimeRecursionInvokeStatic() { + recursionInvokeStatic(recursion_depth); + } + + @Benchmark + public void jmhTimeRecursionInvokeFinal() { + recursionInvokeFinal(recursion_depth); + } + + @Benchmark + public void jmhTimeRecursionInvokePrivate() { + recursionInvokePrivate(recursion_depth); + } +} |