# HG changeset patch # User Tom Rodriguez # Date 1422496134 28800 # Node ID b7797e485eb87d4af60c1b604555e53c05533140 # Parent a02ffe9e18dd3539abf5de9baaffccc51ea8d646 Make BlackholeSubstitutions work with older versions of JMH diff -r a02ffe9e18dd -r b7797e485eb8 graal/com.oracle.graal.api.replacements/src/com/oracle/graal/api/replacements/ClassSubstitution.java --- a/graal/com.oracle.graal.api.replacements/src/com/oracle/graal/api/replacements/ClassSubstitution.java Wed Jan 28 12:41:40 2015 -0800 +++ b/graal/com.oracle.graal.api.replacements/src/com/oracle/graal/api/replacements/ClassSubstitution.java Wed Jan 28 17:48:54 2015 -0800 @@ -41,7 +41,8 @@ Class value() default ClassSubstitution.class; /** - * Specifies the original class. + * Specifies the original class or classes if a single class is being used for multiple + * substitutions. *

* This method is provided for cases where the original class is not accessible (according to * Java language access control rules). @@ -49,7 +50,7 @@ * If the default value is specified for this element, then a non-default value must be given * for the {@link #value()} element. */ - String className() default ""; + String[] className() default {}; /** * Determines if the substitutions are for classes that may not be part of the runtime. diff -r a02ffe9e18dd -r b7797e485eb8 graal/com.oracle.graal.replacements.verifier/src/com/oracle/graal/replacements/verifier/AbstractVerifier.java --- a/graal/com.oracle.graal.replacements.verifier/src/com/oracle/graal/replacements/verifier/AbstractVerifier.java Wed Jan 28 12:41:40 2015 -0800 +++ b/graal/com.oracle.graal.replacements.verifier/src/com/oracle/graal/replacements/verifier/AbstractVerifier.java Wed Jan 28 17:48:54 2015 -0800 @@ -23,6 +23,8 @@ package com.oracle.graal.replacements.verifier; import java.lang.annotation.*; +import java.lang.reflect.*; +import java.util.*; import javax.annotation.processing.*; import javax.lang.model.element.*; @@ -46,6 +48,14 @@ if (value == null) { return null; } + if (expectedType.isArray()) { + ArrayList result = new ArrayList<>(); + List l = (List) value.getValue(); + for (AnnotationValue el : l) { + result.add(resolveAnnotationValue(expectedType.getComponentType(), el)); + } + return (T) result.toArray((Object[]) Array.newInstance(expectedType.getComponentType(), result.size())); + } Object unboxedValue = value.getValue(); if (unboxedValue != null) { if (expectedType == TypeMirror.class && unboxedValue instanceof String) { diff -r a02ffe9e18dd -r b7797e485eb8 graal/com.oracle.graal.replacements.verifier/src/com/oracle/graal/replacements/verifier/ClassSubstitutionVerifier.java --- a/graal/com.oracle.graal.replacements.verifier/src/com/oracle/graal/replacements/verifier/ClassSubstitutionVerifier.java Wed Jan 28 12:41:40 2015 -0800 +++ b/graal/com.oracle.graal.replacements.verifier/src/com/oracle/graal/replacements/verifier/ClassSubstitutionVerifier.java Wed Jan 28 17:48:54 2015 -0800 @@ -36,7 +36,6 @@ private static final String TYPE_VALUE = "value"; private static final String STRING_VALUE = "className"; private static final String OPTIONAL = "optional"; - private static final String STRING_VALUE_DEFAULT = ""; public ClassSubstitutionVerifier(ProcessingEnvironment env) { super(env); @@ -69,7 +68,7 @@ assert typeValue != null && stringValue != null && optionalValue != null; TypeMirror type = resolveAnnotationValue(TypeMirror.class, typeValue); - String className = resolveAnnotationValue(String.class, stringValue); + String[] classNames = resolveAnnotationValue(String[].class, stringValue); boolean optional = resolveAnnotationValue(Boolean.class, optionalValue); if (type.getKind() != TypeKind.DECLARED) { @@ -78,7 +77,7 @@ } if (!classSubstition.getAnnotationType().asElement().equals(((DeclaredType) type).asElement())) { - if (!className.equals(STRING_VALUE_DEFAULT)) { + if (classNames.length != 0) { String msg = "The usage of value and className is exclusive."; env.getMessager().printMessage(Kind.ERROR, msg, sourceElement, classSubstition, stringValue); env.getMessager().printMessage(Kind.ERROR, msg, sourceElement, classSubstition, typeValue); @@ -87,11 +86,15 @@ return (TypeElement) ((DeclaredType) type).asElement(); } - if (!className.equals(STRING_VALUE_DEFAULT)) { - TypeElement typeElement = env.getElementUtils().getTypeElement(className); - if (typeElement == null && !optional) { - env.getMessager().printMessage(Kind.ERROR, String.format("The class '%s' was not found on the classpath.", stringValue), sourceElement, classSubstition, stringValue); + if (classNames.length != 0) { + TypeElement typeElement = null; + for (String className : classNames) { + typeElement = env.getElementUtils().getTypeElement(className); + if (typeElement == null && !optional) { + env.getMessager().printMessage(Kind.ERROR, String.format("The class '%s' was not found on the classpath.", stringValue), sourceElement, classSubstition, stringValue); + } } + return typeElement; } diff -r a02ffe9e18dd -r b7797e485eb8 graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/BlackholeSubstitutions.java --- a/graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/BlackholeSubstitutions.java Wed Jan 28 12:41:40 2015 -0800 +++ b/graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/BlackholeSubstitutions.java Wed Jan 28 17:48:54 2015 -0800 @@ -25,7 +25,10 @@ import com.oracle.graal.api.replacements.*; import com.oracle.graal.replacements.nodes.*; -@ClassSubstitution(className = "org.openjdk.jmh.infra.Blackhole", optional = true) +/** + * Substitutions for both the old and new versions of JMH Blackhole helper classes. + */ +@ClassSubstitution(className = {"org.openjdk.jmh.infra.Blackhole", "org.openjdk.jmh.logic.BlackHole"}, optional = true) public class BlackholeSubstitutions { @SuppressWarnings("unused") diff -r a02ffe9e18dd -r b7797e485eb8 graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/GraalMethodSubstitutions.java --- a/graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/GraalMethodSubstitutions.java Wed Jan 28 12:41:40 2015 -0800 +++ b/graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/GraalMethodSubstitutions.java Wed Jan 28 17:48:54 2015 -0800 @@ -66,6 +66,11 @@ return "org.openjdk.jmh.infra.Blackhole"; } }, BlackholeSubstitutions.class); + replacements.registerSubstitutions(new Type() { + public String getTypeName() { + return "org.openjdk.jmh.logic.BlackHole"; + } + }, BlackholeSubstitutions.class); } } } diff -r a02ffe9e18dd -r b7797e485eb8 graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/ReplacementsImpl.java --- a/graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/ReplacementsImpl.java Wed Jan 28 12:41:40 2015 -0800 +++ b/graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/ReplacementsImpl.java Wed Jan 28 17:48:54 2015 -0800 @@ -162,7 +162,12 @@ private Executable originalMethod(ClassSubstitution classSubstitution, boolean optional, String name, JavaSignature signature) { Class originalClass = classSubstitution.value(); if (originalClass == ClassSubstitution.class) { - originalClass = resolveClass(classSubstitution.className(), classSubstitution.optional()); + for (String className : classSubstitution.className()) { + originalClass = resolveClass(className, classSubstitution.optional()); + if (originalClass != null) { + break; + } + } if (originalClass == null) { // optional class was not found return null; @@ -334,18 +339,26 @@ return null; } - private static String getOriginalInternalName(Class substitutions) { + private static boolean checkSubstitutionInternalName(Class substitutions, String internalName) { ClassSubstitution cs = substitutions.getAnnotation(ClassSubstitution.class); assert cs != null : substitutions + " must be annotated by " + ClassSubstitution.class.getSimpleName(); if (cs.value() == ClassSubstitution.class) { - return toInternalName(cs.className()); + for (String className : cs.className()) { + if (toInternalName(className).equals(internalName)) { + return true; + } + } + assert false : internalName + " not found in " + Arrays.toString(cs.className()); + } else { + String originalInternalName = toInternalName(cs.value().getName()); + assert originalInternalName.equals(internalName) : originalInternalName + " != " + internalName; } - return toInternalName(cs.value().getName()); + return true; } public void registerSubstitutions(Type original, Class substitutionClass) { String internalName = toInternalName(original.getTypeName()); - assert getOriginalInternalName(substitutionClass).equals(internalName) : getOriginalInternalName(substitutionClass) + " != " + (internalName); + assert checkSubstitutionInternalName(substitutionClass, internalName); Class[] classes = internalNameToSubstitutionClasses.get(internalName); if (classes == null) { classes = new Class[]{substitutionClass};