changeset 7:50cc9ad61a18

7902442: New JMH micro for Verifier performance Summary: Benchmark related to JDK-8059357
author ecaspole
date Tue, 26 Mar 2019 15:48:56 -0400
parents d183b6266b77
children a644f3612e8d
files micros-jdk8/pom.xml micros-jdk8/src/main/java/org/openjdk/bench/vm/runtime/VerifySignatures.java
diffstat 2 files changed, 121 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/micros-jdk8/pom.xml	Wed Feb 20 16:04:51 2019 -0500
+++ b/micros-jdk8/pom.xml	Tue Mar 26 15:48:56 2019 -0400
@@ -137,6 +137,11 @@
             <version>${jmh.version}</version>
         </dependency>
         <dependency>
+            <groupId>org.openjdk</groupId>
+            <artifactId>micros-util</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <dependency>
             <groupId>org.openjdk.jmh</groupId>
             <artifactId>jmh-generator-annprocess</artifactId>
             <version>${jmh.version}</version>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/micros-jdk8/src/main/java/org/openjdk/bench/vm/runtime/VerifySignatures.java	Tue Mar 26 15:48:56 2019 -0400
@@ -0,0 +1,116 @@
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package org.openjdk.bench.vm.runtime;
+
+import org.openjdk.bench.util.InMemoryJavaCompiler;
+
+import java.util.concurrent.TimeUnit;
+import org.openjdk.jmh.annotations.Benchmark;
+import org.openjdk.jmh.annotations.OutputTimeUnit;
+import org.openjdk.jmh.annotations.Scope;
+import org.openjdk.jmh.annotations.Setup;
+import org.openjdk.jmh.annotations.State;
+
+// This benchmark is related to JDK-8059357
+
+@State(Scope.Thread)
+public class VerifySignatures {
+
+    static final int numberOfClasses = 1;
+
+    static byte[][] compiledClasses;
+    static int index = 0;
+
+    static final String targetClassName = "VerifySignaturesTarget";
+
+    // The target class has a method with many call sites to the same methods
+    // with many parameters.
+    static final String baseString
+            = "class " + targetClassName + " {"
+            + "  byte w = 5;"
+            + "  int x = 1;"
+            + "  long y = 2;"
+            + "  short z = 3;"
+            + "  String s = \"foo\";"
+            + "  Boolean bb = false;"
+            + "  Long ll = new Long(-1);"
+            + "  Character cc = 'a';"
+            + "  Integer ii = 6;"
+            + " "
+            + "public boolean method0(byte w, int x, long y, short z, String s, Boolean bo, Long ll, Character cc, Integer ii,"
+            + "        byte bb2, int xx2, long yy2, short zz2, String ss2, Boolean bobo, Long ll2, Character cc2, Integer ii2 ) {"
+            + "    return true;"
+            + "}"
+            + " "
+            + "public boolean method1(int x, long y, short z, String s, Boolean bo, Long ll, Character cc, Integer ii,"
+            + "        byte bb2, int xx2, long yy2, short zz2, String ss2, Boolean bobo, Long ll2, Character cc2, Integer ii2 ) {"
+            + "    return true;"
+            + "}"
+            + " "
+            + "public boolean doIt( ) {"
+            + "     return "
+            + "           method0(w, x, y, z, s, bb, ll, cc, ii, w, x, y, z, s, bb, ll, cc, ii)"
+            + "           | method1(x, y, z, s, bb, ll, cc, ii, w, x, y, z, s, bb, ll, cc, ii)"
+            + "           | method0(w, x, y, z, s, bb, ll, cc, ii, w, x, y, z, s, bb, ll, cc, ii)"
+            + "           | method1(x, y, z, s, bb, ll, cc, ii, w, x, y, z, s, bb, ll, cc, ii)"
+            + "           "
+            + "           | method0(w, x, y, z, s, bb, ll, cc, ii, w, x, y, z, s, bb, ll, cc, ii)"
+            + "           | method1(x, y, z, s, bb, ll, cc, ii, w, x, y, z, s, bb, ll, cc, ii)"
+            + "           "
+            + "           | method0(w, x, y, z, s, bb, ll, cc, ii, w, x, y, z, s, bb, ll, cc, ii)"
+            + "           | method1(x, y, z, s, bb, ll, cc, ii, w, x, y, z, s, bb, ll, cc, ii)"
+            + "           "
+            + "           | method0(w, x, y, z, s, bb, ll, cc, ii, w, x, y, z, s, bb, ll, cc, ii)"
+            + "           | method1(x, y, z, s, bb, ll, cc, ii, w, x, y, z, s, bb, ll, cc, ii)"
+            + "           "
+            + "           | method0(w, x, y, z, s, bb, ll, cc, ii, w, x, y, z, s, bb, ll, cc, ii)"
+            + "           | method1(x, y, z, s, bb, ll, cc, ii, w, x, y, z, s, bb, ll, cc, ii)"
+            + "           | method0(w, x, y, z, s, bb, ll, cc, ii, w, x, y, z, s, bb, ll, cc, ii)"
+            + "           | method1(x, y, z, s, bb, ll, cc, ii, w, x, y, z, s, bb, ll, cc, ii)"
+            + "           "
+            + "           | method0(w, x, y, z, s, bb, ll, cc, ii, w, x, y, z, s, bb, ll, cc, ii)"
+            + "           | method1(x, y, z, s, bb, ll, cc, ii, w, x, y, z, s, bb, ll, cc, ii)"
+            + "           "
+            + "           | method0(w, x, y, z, s, bb, ll, cc, ii, w, x, y, z, s, bb, ll, cc, ii)"
+            + "           | method1(x, y, z, s, bb, ll, cc, ii, w, x, y, z, s, bb, ll, cc, ii)"
+            + "           "
+            + "           | method0(w, x, y, z, s, bb, ll, cc, ii, w, x, y, z, s, bb, ll, cc, ii)"
+            + "           | method1(x, y, z, s, bb, ll, cc, ii, w, x, y, z, s, bb, ll, cc, ii)"
+            + "           "
+            + "           | method0(w, x, y, z, s, bb, ll, cc, ii, w, x, y, z, s, bb, ll, cc, ii)"
+            + "           | method1(x, y, z, s, bb, ll, cc, ii, w, x, y, z, s, bb, ll, cc, ii)"
+            + "           "
+            + "           | method0(w, x, y, z, s, bb, ll, cc, ii, w, x, y, z, s, bb, ll, cc, ii)"
+            + "           | method1(x, y, z, s, bb, ll, cc, ii, w, x, y, z, s, bb, ll, cc, ii);"
+            + "}"
+            + "}";
+
+    @Setup
+    public void setupClasses() throws Exception {
+        compiledClasses = new byte[numberOfClasses][];
+        for (int i = 0; i < numberOfClasses; i++) {
+            compiledClasses[i] = InMemoryJavaCompiler.compile(targetClassName, baseString);
+        }
+    }
+
+    static class BenchLoader extends ClassLoader {
+
+        @Override
+        protected Class<?> findClass(String name) throws ClassNotFoundException {
+            assert compiledClasses[index] != null;
+            return defineClass(name, compiledClasses[index], 0, (compiledClasses[index]).length);
+        }
+    }
+
+    @Benchmark
+    @OutputTimeUnit(TimeUnit.MILLISECONDS)
+    public Class measureLoadAndVerify() throws Exception {
+        BenchLoader loader = new BenchLoader();
+        Class c = Class.forName(targetClassName, true, loader);
+        return c;
+    }
+
+}