Missing annotations added on sub-classes, the declaring class is always used
Staffan Friberg
staffan.friberg at oracle.com
Tue May 27 19:11:27 UTC 2014
Hi,
The annotation processor is always picking up the class annotations from
the declaring class instead of sub-classes.
*Base class*
@Fork(jvmArgs = "-XX:+UseG1GC")
@Measurement(iterations = 30)
public abstract class MyAbstractBenchmark {
@GenerateMicroBenchmark
public void testMethod() {
System.gc();
}
}
*Subclass*
@Fork(jvmArgs = "-XX:+PrintGC")
@Measurement(iterations = 40)
public class MyRealBenchmark extends MyAbstractBenchmark {
}
*Run output*
java -jar target/microbenchmarks.jar
# Run progress: 0.00% complete, ETA 00:08:20
# VM invoker: /usr/lib/jvm/java-8-oracle/jre/bin/java
# VM options: -XX:+UseG1GC
# Fork: 1 of 10
# Warmup: 20 iterations, 1 s each
# Measurement: *30 iterations,* 1 s each
*Class look-up*
class BenchmarkGeneratorUtils {
...
public static <T extends Annotation> T getAnnSyntax(MethodInfo mi,
Class<T> annClass) {
T ann = mi.getAnnotation(annClass);
if (ann != null) {
return ann;
} else {
return getAnnSyntax(mi.*getDeclaringClass*(), annClass);
}
}
}
I wonder if this should rather lookup using the userName as available in
BenchmarkInfo which would be the name of the class we are actually got
the method from which might be different than the declaring class.
Cheers,
Staffan
More information about the jmh-dev
mailing list