# HG changeset patch # User Thomas Wuerthinger # Date 1448667745 -3600 # Node ID 71c7a1ae8829ac39877d2403745b66aafe1ddccd # Parent 5e2dd9c3fa7dcb321a98e6edf55ed29e57a12dc8 In ExactClassValueProfile: Perform direct class check, make profile thread-safe, avoid cast in the interpreter, add documentation. diff -r 5e2dd9c3fa7d -r 71c7a1ae8829 truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/utilities/ExactClassValueProfile.java --- a/truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/utilities/ExactClassValueProfile.java Thu Nov 26 14:22:48 2015 +0100 +++ b/truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/utilities/ExactClassValueProfile.java Sat Nov 28 00:42:25 2015 +0100 @@ -40,12 +40,17 @@ @SuppressWarnings("unchecked") @Override public T profile(T value) { - if (cachedClass != Object.class) { - if (cachedClass != null && cachedClass.isInstance(value)) { - return (T) cachedClass.cast(value); + Class c = cachedClass; + if (c != Object.class) { + if (c != null && value != null && c == value.getClass()) { + if (CompilerDirectives.inInterpreter()) { + return value; + } else { + return (T) c.cast(value); + } } else { CompilerDirectives.transferToInterpreterAndInvalidate(); - if (cachedClass == null && value != null) { + if (c == null && value != null) { cachedClass = value.getClass(); } else { cachedClass = Object.class; diff -r 5e2dd9c3fa7d -r 71c7a1ae8829 truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/utilities/ValueProfile.java --- a/truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/utilities/ValueProfile.java Thu Nov 26 14:22:48 2015 +0100 +++ b/truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/utilities/ValueProfile.java Sat Nov 28 00:42:25 2015 +0100 @@ -57,7 +57,13 @@ } /** - * Returns a {@link ValueProfile} that speculates on the exact class of a value. + * Returns a {@link ValueProfile} that speculates on the exact class of a value. It will check + * the class of the profiled value and provide additional information to the compiler if only + * non-null values of exactly one concrete Java class are passed as a parameter to the + * {@link ValueProfile#profile} method. This can be beneficial if subsequent code can take + * advantage of knowing the concrete class of the value. The profile will degrade to the generic + * case if a null value or if at least two instances of two different Java classes are + * registered. */ public static ValueProfile createClassProfile() { return new ExactClassValueProfile();