changeset 684:6be5a214efcd

jmh-core-it: do the tests with a bytecode generator as well.
author shade
date Mon, 26 May 2014 16:40:48 +0400
parents cdbf8209664c
children 25bc20503a46
files jmh-core-ct/pom.xml jmh-core-ct/src/test/java/org/openjdk/jmh/ct/CompileTest.java jmh-generator-bytecode/src/main/java/org/openjdk/jmh/generators/bytecode/ClassInfoRepo.java
diffstat 3 files changed, 92 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/jmh-core-ct/pom.xml	Mon May 26 15:48:52 2014 +0400
+++ b/jmh-core-ct/pom.xml	Mon May 26 16:40:48 2014 +0400
@@ -55,6 +55,11 @@
             <version>${project.version}</version>
         </dependency>
         <dependency>
+            <groupId>org.openjdk.jmh</groupId>
+            <artifactId>jmh-generator-bytecode</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <dependency>
             <groupId>com.sun</groupId>
             <artifactId>tools</artifactId>
             <scope>system</scope>
@@ -80,15 +85,6 @@
     <build>
         <plugins>
             <plugin>
-                <groupId>org.apache.maven.plugins</groupId>
-                <artifactId>maven-surefire-plugin</artifactId>
-                <version>2.14.1</version>
-                <configuration>
-                    <redirectTestOutputToFile>true</redirectTestOutputToFile>
-                </configuration>
-            </plugin>
-
-            <plugin>
                 <groupId>com.mycila.maven-license-plugin</groupId>
                 <artifactId>maven-license-plugin</artifactId>
                 <version>1.10.b1</version>
@@ -124,4 +120,43 @@
         </plugins>
     </build>
 
+    <profiles>
+        <profile>
+            <id>default</id>
+            <activation>
+                <activeByDefault>true</activeByDefault>
+            </activation>
+            <build>
+                <plugins>
+                    <plugin>
+                        <groupId>org.apache.maven.plugins</groupId>
+                        <artifactId>maven-surefire-plugin</artifactId>
+                        <version>2.14.1</version>
+                        <configuration>
+                            <redirectTestOutputToFile>true</redirectTestOutputToFile>
+                            <argLine>-Djmh.ct.generator=reflection</argLine>
+                        </configuration>
+                    </plugin>
+                </plugins>
+            </build>
+        </profile>
+
+        <profile>
+            <id>asm</id>
+            <build>
+                <plugins>
+                    <plugin>
+                        <groupId>org.apache.maven.plugins</groupId>
+                        <artifactId>maven-surefire-plugin</artifactId>
+                        <version>2.14.1</version>
+                        <configuration>
+                            <redirectTestOutputToFile>true</redirectTestOutputToFile>
+                            <argLine>-Djmh.ct.generator=bytecode</argLine>
+                        </configuration>
+                    </plugin>
+                </plugins>
+            </build>
+        </profile>
+    </profiles>
+
 </project>
--- a/jmh-core-ct/src/test/java/org/openjdk/jmh/ct/CompileTest.java	Mon May 26 15:48:52 2014 +0400
+++ b/jmh-core-ct/src/test/java/org/openjdk/jmh/ct/CompileTest.java	Mon May 26 16:40:48 2014 +0400
@@ -25,6 +25,7 @@
 package org.openjdk.jmh.ct;
 
 import junit.framework.Assert;
+import org.openjdk.jmh.generators.bytecode.ASMGeneratorSource;
 import org.openjdk.jmh.generators.core.BenchmarkGenerator;
 import org.openjdk.jmh.generators.core.GeneratorDestination;
 import org.openjdk.jmh.generators.core.MetadataInfo;
@@ -53,6 +54,8 @@
 
 public class CompileTest {
 
+    private static final String GENERATOR_TYPE = System.getProperty("jmh.ct.generator", "notset");
+
     public static void assertFail(Class<?> klass) {
         TestGeneratorDestination destination = doTest(klass);
         if (!destination.hasErrors()) {
@@ -132,10 +135,36 @@
     }
 
     private static TestGeneratorDestination doTest(Class<?> klass) {
+        if (GENERATOR_TYPE.equalsIgnoreCase("reflection")) {
+            return doTestReflection(klass);
+        }
+        if (GENERATOR_TYPE.equalsIgnoreCase("bytecode")) {
+            return doTestBytecode(klass);
+        }
+        throw new IllegalStateException("Unhandled compile test generator: " + GENERATOR_TYPE);
+    }
+
+    private static TestGeneratorDestination doTestReflection(Class<?> klass) {
         RFGeneratorSource source = new RFGeneratorSource();
         TestGeneratorDestination destination = new TestGeneratorDestination();
+        source.processClasses(klass);
 
-        source.processClasses(klass);
+        BenchmarkGenerator gen = new BenchmarkGenerator();
+        gen.generate(source, destination);
+        gen.complete(source, destination);
+        return destination;
+    }
+
+    private static TestGeneratorDestination doTestBytecode(Class<?> klass) {
+        ASMGeneratorSource source = new ASMGeneratorSource();
+        TestGeneratorDestination destination = new TestGeneratorDestination();
+
+        String name = "/" + klass.getCanonicalName().replaceAll("\\.", "/") + ".class";
+        try {
+            source.processClass(klass.getResourceAsStream(name));
+        } catch (IOException e) {
+            throw new IllegalStateException(name, e);
+        }
 
         BenchmarkGenerator gen = new BenchmarkGenerator();
         gen.generate(source, destination);
--- a/jmh-generator-bytecode/src/main/java/org/openjdk/jmh/generators/bytecode/ClassInfoRepo.java	Mon May 26 15:48:52 2014 +0400
+++ b/jmh-generator-bytecode/src/main/java/org/openjdk/jmh/generators/bytecode/ClassInfoRepo.java	Mon May 26 16:40:48 2014 +0400
@@ -42,6 +42,24 @@
             return info;
         }
 
+        if (desc.equals(boolean.class.getCanonicalName()))  return new RFClassInfo(boolean.class);
+        if (desc.equals(byte.class.getCanonicalName()))     return new RFClassInfo(byte.class);
+        if (desc.equals(char.class.getCanonicalName()))     return new RFClassInfo(char.class);
+        if (desc.equals(short.class.getCanonicalName()))    return new RFClassInfo(short.class);
+        if (desc.equals(int.class.getCanonicalName()))      return new RFClassInfo(int.class);
+        if (desc.equals(float.class.getCanonicalName()))    return new RFClassInfo(float.class);
+        if (desc.equals(long.class.getCanonicalName()))     return new RFClassInfo(long.class);
+        if (desc.equals(double.class.getCanonicalName()))   return new RFClassInfo(double.class);
+
+        if (desc.equals(boolean[].class.getCanonicalName()))  return new RFClassInfo(boolean[].class);
+        if (desc.equals(byte[].class.getCanonicalName()))     return new RFClassInfo(byte[].class);
+        if (desc.equals(char[].class.getCanonicalName()))     return new RFClassInfo(char[].class);
+        if (desc.equals(short[].class.getCanonicalName()))    return new RFClassInfo(short[].class);
+        if (desc.equals(int[].class.getCanonicalName()))      return new RFClassInfo(int[].class);
+        if (desc.equals(float[].class.getCanonicalName()))    return new RFClassInfo(float[].class);
+        if (desc.equals(long[].class.getCanonicalName()))     return new RFClassInfo(long[].class);
+        if (desc.equals(double[].class.getCanonicalName()))   return new RFClassInfo(double[].class);
+
         try {
             return new RFClassInfo(Class.forName(desc, false, Thread.currentThread().getContextClassLoader()));
         } catch (ClassNotFoundException e) {