changeset 22064:02015aac6be9

Removing IdentityValueProfile and ExactClassValueProfile classes from the API
author Jaroslav Tulach <jaroslav.tulach@oracle.com>
date Wed, 05 Aug 2015 16:47:04 +0200
parents b960accdd9b5
children 503529c65456
files truffle/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/utilities/ExactClassValueProfileTest.java truffle/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/utilities/IdentityValueProfileTest.java truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/utilities/ExactClassValueProfile.java truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/utilities/IdentityValueProfile.java
diffstat 4 files changed, 74 insertions(+), 37 deletions(-) [+]
line wrap: on
line diff
--- a/truffle/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/utilities/ExactClassValueProfileTest.java	Wed Aug 05 15:58:55 2015 +0200
+++ b/truffle/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/utilities/ExactClassValueProfileTest.java	Wed Aug 05 16:47:04 2015 +0200
@@ -30,6 +30,7 @@
 import org.junit.runner.*;
 
 import com.oracle.truffle.api.utilities.*;
+import java.lang.reflect.Method;
 
 @RunWith(Theories.class)
 public class ExactClassValueProfileTest {
@@ -40,33 +41,33 @@
     @DataPoint public static final Integer O4 = new Integer(1);
     @DataPoint public static final Integer O5 = null;
 
-    private ExactClassValueProfile profile;
+    private ValueProfile profile;
 
     @Before
     public void create() {
-        profile = (ExactClassValueProfile) ValueProfile.createClassProfile();
+        profile = ValueProfile.createClassProfile();
     }
 
     @Test
-    public void testInitial() {
-        assertThat(profile.isGeneric(), is(false));
-        assertThat(profile.isUninitialized(), is(true));
-        assertNull(profile.getCachedClass());
+    public void testInitial() throws Exception {
+        assertThat(isGeneric(profile), is(false));
+        assertThat(isUninitialized(profile), is(true));
+        assertNull(getCachedClass(profile));
         profile.toString(); // test that it is not crashing
     }
 
     @Theory
-    public void testProfileOne(Object value) {
+    public void testProfileOne(Object value) throws Exception {
         Object result = profile.profile(value);
 
         assertThat(result, is(value));
-        assertEquals(profile.getCachedClass(), expectedClass(value));
-        assertThat(profile.isUninitialized(), is(false));
+        assertEquals(getCachedClass(profile), expectedClass(value));
+        assertThat(isUninitialized(profile), is(false));
         profile.toString(); // test that it is not crashing
     }
 
     @Theory
-    public void testProfileTwo(Object value0, Object value1) {
+    public void testProfileTwo(Object value0, Object value1) throws Exception {
         Object result0 = profile.profile(value0);
         Object result1 = profile.profile(value1);
 
@@ -75,14 +76,14 @@
 
         Object expectedClass = expectedClass(value0) == expectedClass(value1) ? expectedClass(value0) : Object.class;
 
-        assertEquals(profile.getCachedClass(), expectedClass);
-        assertThat(profile.isUninitialized(), is(false));
-        assertThat(profile.isGeneric(), is(expectedClass == Object.class));
+        assertEquals(getCachedClass(profile), expectedClass);
+        assertThat(isUninitialized(profile), is(false));
+        assertThat(isGeneric(profile), is(expectedClass == Object.class));
         profile.toString(); // test that it is not crashing
     }
 
     @Theory
-    public void testProfileThree(Object value0, Object value1, Object value2) {
+    public void testProfileThree(Object value0, Object value1, Object value2) throws Exception {
         Object result0 = profile.profile(value0);
         Object result1 = profile.profile(value1);
         Object result2 = profile.profile(value2);
@@ -93,9 +94,9 @@
 
         Object expectedClass = expectedClass(value0) == expectedClass(value1) && expectedClass(value1) == expectedClass(value2) ? expectedClass(value0) : Object.class;
 
-        assertEquals(profile.getCachedClass(), expectedClass);
-        assertThat(profile.isUninitialized(), is(false));
-        assertThat(profile.isGeneric(), is(expectedClass == Object.class));
+        assertEquals(getCachedClass(profile), expectedClass);
+        assertThat(isUninitialized(profile), is(false));
+        assertThat(isGeneric(profile), is(expectedClass == Object.class));
         profile.toString(); // test that it is not crashing
     }
 
@@ -103,4 +104,21 @@
         return value == null ? Object.class : value.getClass();
     }
 
+    private static Object get(String name, ValueProfile profile) throws Exception {
+        final Method m = profile.getClass().getDeclaredMethod(name);
+        m.setAccessible(true);
+        return m.invoke(profile);
+    }
+
+    private static Object getCachedClass(ValueProfile profile) throws Exception {
+        return get("getCachedClass", profile);
+    }
+
+    private static boolean isUninitialized(ValueProfile profile) throws Exception {
+        return (Boolean) get("isUninitialized", profile);
+    }
+
+    private static boolean isGeneric(ValueProfile profile) throws Exception {
+        return (Boolean) get("isGeneric", profile);
+    }
 }
--- a/truffle/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/utilities/IdentityValueProfileTest.java	Wed Aug 05 15:58:55 2015 +0200
+++ b/truffle/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/utilities/IdentityValueProfileTest.java	Wed Aug 05 16:47:04 2015 +0200
@@ -30,6 +30,7 @@
 import org.junit.runner.*;
 
 import com.oracle.truffle.api.utilities.*;
+import java.lang.reflect.Method;
 
 @RunWith(Theories.class)
 public class IdentityValueProfileTest {
@@ -40,32 +41,32 @@
     @DataPoint public static final Integer O4 = new Integer(1);
     @DataPoint public static final Integer O5 = null;
 
-    private IdentityValueProfile profile;
+    private ValueProfile profile;
 
     @Before
     public void create() {
-        profile = (IdentityValueProfile) ValueProfile.createIdentityProfile();
+        profile = ValueProfile.createIdentityProfile();
     }
 
     @Test
-    public void testInitial() {
-        assertThat(profile.isGeneric(), is(false));
-        assertThat(profile.isUninitialized(), is(true));
+    public void testInitial() throws Exception {
+        assertThat(isGeneric(profile), is(false));
+        assertThat(isUninitialized(profile), is(true));
         profile.toString(); // test that it is not crashing
     }
 
     @Theory
-    public void testProfileOne(Object value) {
+    public void testProfileOne(Object value) throws Exception {
         Object result = profile.profile(value);
 
         assertThat(result, is(value));
-        assertEquals(profile.getCachedValue(), value);
-        assertThat(profile.isUninitialized(), is(false));
+        assertEquals(getCachedValue(profile), value);
+        assertThat(isUninitialized(profile), is(false));
         profile.toString(); // test that it is not crashing
     }
 
     @Theory
-    public void testProfileTwo(Object value0, Object value1) {
+    public void testProfileTwo(Object value0, Object value1) throws Exception {
         Object result0 = profile.profile(value0);
         Object result1 = profile.profile(value1);
 
@@ -73,17 +74,17 @@
         assertThat(result1, is(value1));
 
         if (value0 == value1) {
-            assertThat(profile.getCachedValue(), is(value0));
-            assertThat(profile.isGeneric(), is(false));
+            assertThat(getCachedValue(profile), is(value0));
+            assertThat(isGeneric(profile), is(false));
         } else {
-            assertThat(profile.isGeneric(), is(true));
+            assertThat(isGeneric(profile), is(true));
         }
-        assertThat(profile.isUninitialized(), is(false));
+        assertThat(isUninitialized(profile), is(false));
         profile.toString(); // test that it is not crashing
     }
 
     @Theory
-    public void testProfileThree(Object value0, Object value1, Object value2) {
+    public void testProfileThree(Object value0, Object value1, Object value2) throws Exception {
         Object result0 = profile.profile(value0);
         Object result1 = profile.profile(value1);
         Object result2 = profile.profile(value2);
@@ -93,12 +94,30 @@
         assertThat(result2, is(value2));
 
         if (value0 == value1 && value1 == value2) {
-            assertThat(profile.getCachedValue(), is(value0));
-            assertThat(profile.isGeneric(), is(false));
+            assertThat(getCachedValue(profile), is(value0));
+            assertThat(isGeneric(profile), is(false));
         } else {
-            assertThat(profile.isGeneric(), is(true));
+            assertThat(isGeneric(profile), is(true));
         }
-        assertThat(profile.isUninitialized(), is(false));
+        assertThat(isUninitialized(profile), is(false));
         profile.toString(); // test that it is not crashing
     }
+
+    private static Object get(String name, ValueProfile profile) throws Exception {
+        final Method m = profile.getClass().getDeclaredMethod(name);
+        m.setAccessible(true);
+        return m.invoke(profile);
+    }
+
+    private static Object getCachedValue(ValueProfile profile) throws Exception {
+        return get("getCachedValue", profile);
+    }
+
+    private static boolean isUninitialized(ValueProfile profile) throws Exception {
+        return (Boolean) get("isUninitialized", profile);
+    }
+
+    private static boolean isGeneric(ValueProfile profile) throws Exception {
+        return (Boolean) get("isGeneric", profile);
+    }
 }
--- a/truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/utilities/ExactClassValueProfile.java	Wed Aug 05 15:58:55 2015 +0200
+++ b/truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/utilities/ExactClassValueProfile.java	Wed Aug 05 16:47:04 2015 +0200
@@ -30,7 +30,7 @@
 /**
  * Represents a {@link ValueProfile} that speculates on the exact class of a value.
  */
-public final class ExactClassValueProfile extends ValueProfile {
+final class ExactClassValueProfile extends ValueProfile {
 
     @CompilationFinal protected Class<?> cachedClass;
 
--- a/truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/utilities/IdentityValueProfile.java	Wed Aug 05 15:58:55 2015 +0200
+++ b/truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/utilities/IdentityValueProfile.java	Wed Aug 05 16:47:04 2015 +0200
@@ -32,7 +32,7 @@
 /**
  * Represents a {@link ValueProfile} that speculates on the object identity of a value.
  */
-public final class IdentityValueProfile extends ValueProfile {
+final class IdentityValueProfile extends ValueProfile {
 
     private static final Object UNINITIALIZED = new Object();
     private static final Object GENERIC = new Object();