changeset 460:75e8e2c3b31f

Accept only non-final classes as implicit benchmark holders and @State-s.
author shade
date Mon, 03 Mar 2014 19:50:42 +0400
parents fda5c52fc014
children adb938a4aaca
files jmh-core/src/main/java/org/openjdk/jmh/generators/annotations/APClassInfo.java jmh-core/src/main/java/org/openjdk/jmh/generators/bytecode/ASMClassInfo.java jmh-core/src/main/java/org/openjdk/jmh/generators/core/BenchmarkGenerator.java jmh-core/src/main/java/org/openjdk/jmh/generators/reflective/RFClassInfo.java jmh-core/src/main/java/org/openjdk/jmh/generators/source/ClassInfo.java
diffstat 5 files changed, 25 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/jmh-core/src/main/java/org/openjdk/jmh/generators/annotations/APClassInfo.java	Mon Mar 03 19:05:54 2014 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/generators/annotations/APClassInfo.java	Mon Mar 03 19:50:42 2014 +0400
@@ -141,6 +141,11 @@
         return el.getModifiers().contains(Modifier.STRICTFP);
     }
 
+    @Override
+    public boolean isFinal() {
+        return el.getModifiers().contains(Modifier.FINAL);
+    }
+
     public String toString() {
         return getQualifiedName();
     }
--- a/jmh-core/src/main/java/org/openjdk/jmh/generators/bytecode/ASMClassInfo.java	Mon Mar 03 19:05:54 2014 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/generators/bytecode/ASMClassInfo.java	Mon Mar 03 19:50:42 2014 +0400
@@ -189,6 +189,11 @@
     }
 
     @Override
+    public boolean isFinal() {
+        return (access & Opcodes.ACC_FINAL) > 0;
+    }
+
+    @Override
     public String toString() {
         return qualifiedName;
     }
--- a/jmh-core/src/main/java/org/openjdk/jmh/generators/core/BenchmarkGenerator.java	Mon Mar 03 19:05:54 2014 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/generators/core/BenchmarkGenerator.java	Mon Mar 03 19:50:42 2014 +0400
@@ -209,6 +209,10 @@
             throw new GenerationException("Microbenchmark should have package other than default.", clazz);
         }
 
+        if (clazz.isFinal()) {
+            throw new GenerationException("Benchmark classes should not be final.", clazz);
+        }
+
         Collection<ClassInfo> states = new ArrayList<ClassInfo>();
 
         // validate all arguments are @State-s
@@ -246,6 +250,11 @@
                         " annotation only supports public classes.", state);
             }
 
+            if (state.isFinal()) {
+                throw new GenerationException("The " + State.class.getSimpleName() +
+                        " annotation only supports non-final classes.", state);
+            }
+
             boolean hasDefaultConstructor = false;
             for (MethodInfo constructor : state.getConstructors()) {
                 hasDefaultConstructor |= (constructor.getParameters().isEmpty() && constructor.isPublic());
--- a/jmh-core/src/main/java/org/openjdk/jmh/generators/reflective/RFClassInfo.java	Mon Mar 03 19:05:54 2014 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/generators/reflective/RFClassInfo.java	Mon Mar 03 19:50:42 2014 +0400
@@ -138,6 +138,11 @@
     }
 
     @Override
+    public boolean isFinal() {
+        return Modifier.isFinal(klass.getModifiers());
+    }
+
+    @Override
     public String toString() {
         return getQualifiedName();
     }
--- a/jmh-core/src/main/java/org/openjdk/jmh/generators/source/ClassInfo.java	Mon Mar 03 19:05:54 2014 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/generators/source/ClassInfo.java	Mon Mar 03 19:50:42 2014 +0400
@@ -56,5 +56,6 @@
 
     boolean isStrictFP();
 
+    boolean isFinal();
 }