diff truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/utilities/ExactClassValueProfile.java @ 22421:71c7a1ae8829

In ExactClassValueProfile: Perform direct class check, make profile thread-safe, avoid cast in the interpreter, add documentation.
author Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
date Sat, 28 Nov 2015 00:42:25 +0100
parents dc83cc1f94f2
children a63bda98cfdb
line wrap: on
line diff
--- 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> 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;