Mercurial > hg > truffle
comparison 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 |
comparison
equal
deleted
inserted
replaced
22420:5e2dd9c3fa7d | 22421:71c7a1ae8829 |
---|---|
38 } | 38 } |
39 | 39 |
40 @SuppressWarnings("unchecked") | 40 @SuppressWarnings("unchecked") |
41 @Override | 41 @Override |
42 public <T> T profile(T value) { | 42 public <T> T profile(T value) { |
43 if (cachedClass != Object.class) { | 43 Class<?> c = cachedClass; |
44 if (cachedClass != null && cachedClass.isInstance(value)) { | 44 if (c != Object.class) { |
45 return (T) cachedClass.cast(value); | 45 if (c != null && value != null && c == value.getClass()) { |
46 if (CompilerDirectives.inInterpreter()) { | |
47 return value; | |
48 } else { | |
49 return (T) c.cast(value); | |
50 } | |
46 } else { | 51 } else { |
47 CompilerDirectives.transferToInterpreterAndInvalidate(); | 52 CompilerDirectives.transferToInterpreterAndInvalidate(); |
48 if (cachedClass == null && value != null) { | 53 if (c == null && value != null) { |
49 cachedClass = value.getClass(); | 54 cachedClass = value.getClass(); |
50 } else { | 55 } else { |
51 cachedClass = Object.class; | 56 cachedClass = Object.class; |
52 } | 57 } |
53 } | 58 } |