use of com.oracle.truffle.api.dsl.Introspection.SpecializationInfo in project graal by oracle.
the class IntrospectionTest method testReflection1.
@Test
public void testReflection1() {
Introspection1Node node = Introspection1NodeGen.create();
SpecializationInfo specialization = Introspection.getSpecialization(node, "doInt");
assertSpecializationEquals(specialization, Introspection.getSpecializations(node).get(0));
assertEquals("doInt", specialization.getMethodName());
assertFalse(specialization.isActive());
assertFalse(specialization.isExcluded());
assertEquals(0, specialization.getInstances());
try {
assertEquals(0, specialization.getCachedData(0));
fail();
} catch (IllegalArgumentException e) {
}
specialization = Introspection.getSpecialization(node, "doGeneric");
assertSpecializationEquals(specialization, Introspection.getSpecializations(node).get(1));
assertEquals("doGeneric", specialization.getMethodName());
assertFalse(specialization.isActive());
assertFalse(specialization.isExcluded());
assertEquals(0, specialization.getInstances());
try {
node.execute("");
fail();
} catch (UnsupportedSpecializationException e) {
}
node.execute(1);
specialization = Introspection.getSpecialization(node, "doInt");
assertSpecializationEquals(specialization, Introspection.getSpecializations(node).get(0));
assertEquals("doInt", specialization.getMethodName());
assertTrue(specialization.isActive());
assertFalse(specialization.isExcluded());
assertEquals(1, specialization.getInstances());
assertEquals(1, specialization.getCachedData(0).get(0));
specialization = Introspection.getSpecialization(node, "doGeneric");
assertSpecializationEquals(specialization, Introspection.getSpecializations(node).get(1));
assertEquals("doGeneric", specialization.getMethodName());
assertFalse(specialization.isActive());
assertFalse(specialization.isExcluded());
assertEquals(0, specialization.getInstances());
node.execute(1);
specialization = Introspection.getSpecialization(node, "doInt");
assertSpecializationEquals(specialization, Introspection.getSpecializations(node).get(0));
assertEquals("doInt", specialization.getMethodName());
assertTrue(specialization.isActive());
assertFalse(specialization.isExcluded());
assertEquals(1, specialization.getInstances());
assertEquals(1, specialization.getCachedData(0).get(0));
specialization = Introspection.getSpecialization(node, "doGeneric");
assertSpecializationEquals(specialization, Introspection.getSpecializations(node).get(1));
assertEquals("doGeneric", specialization.getMethodName());
assertFalse(specialization.isActive());
assertFalse(specialization.isExcluded());
assertEquals(0, specialization.getInstances());
node.execute(2);
specialization = Introspection.getSpecialization(node, "doInt");
assertSpecializationEquals(specialization, Introspection.getSpecializations(node).get(0));
assertEquals("doInt", specialization.getMethodName());
assertTrue(specialization.isActive());
assertFalse(specialization.isExcluded());
assertEquals(2, specialization.getInstances());
assertEquals(2, specialization.getCachedData(0).get(0));
assertEquals(1, specialization.getCachedData(1).get(0));
specialization = Introspection.getSpecialization(node, "doGeneric");
assertSpecializationEquals(specialization, Introspection.getSpecializations(node).get(1));
assertEquals("doGeneric", specialization.getMethodName());
assertFalse(specialization.isActive());
assertFalse(specialization.isExcluded());
assertEquals(0, specialization.getInstances());
node.execute(3);
specialization = Introspection.getSpecialization(node, "doInt");
assertSpecializationEquals(specialization, Introspection.getSpecializations(node).get(0));
assertEquals("doInt", specialization.getMethodName());
assertTrue(specialization.isActive());
assertFalse(specialization.isExcluded());
assertEquals(3, specialization.getInstances());
assertEquals(3, specialization.getCachedData(0).get(0));
assertEquals(2, specialization.getCachedData(1).get(0));
assertEquals(1, specialization.getCachedData(2).get(0));
specialization = Introspection.getSpecialization(node, "doGeneric");
assertSpecializationEquals(specialization, Introspection.getSpecializations(node).get(1));
assertEquals("doGeneric", specialization.getMethodName());
assertFalse(specialization.isActive());
assertFalse(specialization.isExcluded());
assertEquals(0, specialization.getInstances());
node.execute(4);
specialization = Introspection.getSpecialization(node, "doInt");
assertSpecializationEquals(specialization, Introspection.getSpecializations(node).get(0));
assertEquals("doInt", specialization.getMethodName());
assertFalse(specialization.isActive());
assertTrue(specialization.isExcluded());
assertEquals(0, specialization.getInstances());
specialization = Introspection.getSpecialization(node, "doGeneric");
assertSpecializationEquals(specialization, Introspection.getSpecializations(node).get(1));
assertEquals("doGeneric", specialization.getMethodName());
assertTrue(specialization.isActive());
assertFalse(specialization.isExcluded());
assertEquals(1, specialization.getInstances());
assertEquals(0, specialization.getCachedData(0).size());
}
use of com.oracle.truffle.api.dsl.Introspection.SpecializationInfo in project graal by oracle.
the class IntrospectionTest method testUsingIntrospection.
@Test
public void testUsingIntrospection() {
NegateNode node = IntrospectionTestFactory.NegateNodeGen.create();
SpecializationInfo info;
node.execute(1);
info = Introspection.getSpecialization(node, "doInt");
assertEquals(1, info.getInstances());
node.execute(1);
info = Introspection.getSpecialization(node, "doInt");
assertEquals(1, info.getInstances());
node.execute(2);
info = Introspection.getSpecialization(node, "doInt");
assertEquals(0, info.getInstances());
info = Introspection.getSpecialization(node, "doGeneric");
assertEquals(1, info.getInstances());
}
use of com.oracle.truffle.api.dsl.Introspection.SpecializationInfo in project graal by oracle.
the class IntrospectionTest method testFallbackReflection.
@Test
public void testFallbackReflection() {
FallbackNode node = FallbackNodeGen.create();
SpecializationInfo specialization = Introspection.getSpecialization(node, "doFallback");
assertSpecializationEquals(specialization, Introspection.getSpecializations(node).get(1));
assertEquals("doFallback", specialization.getMethodName());
assertFalse(specialization.isActive());
assertFalse(specialization.isExcluded());
assertEquals(0, specialization.getInstances());
node.execute("fallback");
specialization = Introspection.getSpecialization(node, "doFallback");
assertSpecializationEquals(specialization, Introspection.getSpecializations(node).get(1));
assertEquals("doFallback", specialization.getMethodName());
assertTrue(specialization.isActive());
assertFalse(specialization.isExcluded());
assertEquals(1, specialization.getInstances());
}
use of com.oracle.truffle.api.dsl.Introspection.SpecializationInfo in project graal by oracle.
the class IntrospectionSnippets method testUsingIntrospection.
public void testUsingIntrospection() {
// NegateNodeGen.create();
NegateNode node = null;
SpecializationInfo info;
node.execute(1);
info = Introspection.getSpecialization(node, "doInt");
assert info.getInstances() == 1;
node.execute(1);
info = Introspection.getSpecialization(node, "doInt");
assert info.getInstances() == 1;
node.execute(2);
info = Introspection.getSpecialization(node, "doInt");
assert info.getInstances() == 0;
info = Introspection.getSpecialization(node, "doGeneric");
assert info.getInstances() == 1;
}
Aggregations