use of com.oracle.truffle.api.Assumption in project graal by oracle.
the class FlatNodeGenFactory method createFields.
private void createFields(CodeTypeElement clazz) {
state.declareFields(clazz);
if (requiresExclude()) {
exclude.declareFields(clazz);
}
for (SpecializationData specialization : reachableSpecializations) {
List<CodeVariableElement> fields = new ArrayList<>();
boolean useSpecializationClass = useSpecializationClass(specialization);
for (CacheExpression cache : specialization.getCaches()) {
Parameter parameter = cache.getParameter();
String fieldName = createFieldName(specialization, parameter);
TypeMirror type = parameter.getType();
Modifier visibility = useSpecializationClass ? null : Modifier.PRIVATE;
CodeVariableElement cachedField;
if (ElementUtils.isAssignable(type, context.getType(NodeInterface.class))) {
cachedField = createNodeField(visibility, type, fieldName, Child.class);
} else if (isNodeInterfaceArray(type)) {
cachedField = createNodeField(visibility, type, fieldName, Children.class);
} else {
cachedField = createNodeField(visibility, type, fieldName, null);
setFieldCompilationFinal(cachedField, parameter.getVariableElement().getAnnotation(Cached.class).dimensions());
}
fields.add(cachedField);
}
for (AssumptionExpression assumption : specialization.getAssumptionExpressions()) {
String fieldName = createAssumptionFieldName(specialization, assumption);
TypeMirror type;
int compilationFinalDimensions;
if (assumption.getExpression().getResolvedType().getKind() == TypeKind.ARRAY) {
type = context.getType(Assumption[].class);
compilationFinalDimensions = 1;
} else {
type = context.getType(Assumption.class);
compilationFinalDimensions = -1;
}
CodeVariableElement assumptionField;
if (useSpecializationClass) {
assumptionField = createNodeField(null, type, fieldName, null);
} else {
assumptionField = createNodeField(PRIVATE, type, fieldName, null);
}
setFieldCompilationFinal(assumptionField, compilationFinalDimensions);
fields.add(assumptionField);
}
if (useSpecializationClass) {
TypeMirror baseType;
boolean useNode = specializationClassIsNode(specialization);
if (useNode) {
baseType = context.getType(Node.class);
} else {
baseType = context.getType(Object.class);
}
CodeTypeElement cacheType = GeneratorUtils.createClass(node, null, modifiers(PRIVATE, FINAL, STATIC), createSpecializationTypeName(specialization), baseType);
Class<?> annotationType;
if (useNode) {
annotationType = Child.class;
if (specialization.getMaximumNumberOfInstances() > 1) {
cacheType.add(createNodeField(null, cacheType.asType(), "next_", Child.class));
}
CodeExecutableElement getNodeCost = new CodeExecutableElement(modifiers(PUBLIC), context.getType(NodeCost.class), "getCost");
getNodeCost.createBuilder().startReturn().staticReference(context.getType(NodeCost.class), "NONE").end();
cacheType.add(getNodeCost);
} else {
annotationType = CompilationFinal.class;
if (specialization.getMaximumNumberOfInstances() > 1) {
cacheType.add(createNodeField(null, cacheType.asType(), "next_", annotationType));
}
}
cacheType.add(GeneratorUtils.createConstructorUsingFields(modifiers(), cacheType));
cacheType.getEnclosedElements().addAll(fields);
clazz.add(createNodeField(PRIVATE, cacheType.asType(), createSpecializationFieldName(specialization), annotationType));
clazz.add(cacheType);
specializationClasses.put(specialization, cacheType);
} else {
clazz.getEnclosedElements().addAll(fields);
}
}
}
use of com.oracle.truffle.api.Assumption in project graal by oracle.
the class FrameDescriptorTest method version.
@Test
public void version() {
FrameDescriptor d = new FrameDescriptor();
s1 = d.addFrameSlot("v1", "i1", FrameSlotKind.Boolean);
s2 = d.addFrameSlot("v2", "i2", FrameSlotKind.Float);
Assumption version;
version = d.getVersion();
assertTrue(version.isValid());
// add slot
s3 = d.addFrameSlot("v3", "i3", FrameSlotKind.Int);
assertEquals(3, d.getSize());
assertFalse(version.isValid());
version = d.getVersion();
assertTrue(version.isValid());
assertSame("1st slot", s1, d.getSlots().get(0));
assertSame("2nd slot", s2, d.getSlots().get(1));
assertSame("3rd slot", s3, d.getSlots().get(2));
// change kind
s3.setKind(FrameSlotKind.Object);
assertFalse(version.isValid());
version = d.getVersion();
assertTrue(version.isValid());
// remove slot
d.removeFrameSlot("v3");
assertEquals(2, d.getSize());
assertFalse(version.isValid());
version = d.getVersion();
assertTrue(version.isValid());
}
use of com.oracle.truffle.api.Assumption in project graal by oracle.
the class FrameDescriptorTest method notInFrameAssumption.
@Test
public void notInFrameAssumption() {
FrameDescriptor d = new FrameDescriptor();
Assumption[] ass = new Assumption[] { d.getNotInFrameAssumption("v1"), d.getNotInFrameAssumption("v2"), d.getNotInFrameAssumption("v3") };
assertTrue(ass[0].isValid());
assertTrue(ass[1].isValid());
assertTrue(ass[2].isValid());
s1 = d.addFrameSlot("v1", "i1", FrameSlotKind.Boolean);
assertFalse(ass[0].isValid());
assertTrue(ass[1].isValid());
assertTrue(ass[2].isValid());
s2 = d.addFrameSlot("v2", "i2", FrameSlotKind.Float);
assertFalse(ass[0].isValid());
assertFalse(ass[1].isValid());
assertTrue(ass[2].isValid());
s3 = d.addFrameSlot("v3", "i3", FrameSlotKind.Int);
assertFalse(ass[0].isValid());
assertFalse(ass[1].isValid());
assertFalse(ass[2].isValid());
for (String identifier : new String[] { "v1", "v2", "v3" }) {
try {
d.getNotInFrameAssumption(identifier);
fail("expected IllegalArgumentException");
} catch (IllegalArgumentException e) {
// expected
}
}
d.getNotInFrameAssumption("v4");
}
use of com.oracle.truffle.api.Assumption in project graal by oracle.
the class AssumptionInvalidationTest method test.
@Test
public void test() throws InterruptedException {
TruffleRuntime runtime = Truffle.getRuntime();
Assumption assumption = runtime.createAssumption("propagated assumption invalidation");
CountingNode countingNode = new CountingNode(assumption);
TestRootNode countingRootNode = new TestRootNode(countingNode);
final CallTarget countingTarget = runtime.createCallTarget(countingRootNode);
Thread thread = new Thread(new Runnable() {
public void run() {
countingTarget.call();
}
});
thread.start();
// Give a chance for CountingNode.execute to OSR compile
Thread.sleep(100);
assumption.invalidate();
thread.join(100);
assertEquals("Thread ought to be notified of invalidation in reasonable time.", false, thread.isAlive());
}
use of com.oracle.truffle.api.Assumption in project graal by oracle.
the class CyclicAssumptionTest method testInvalidate.
@Test
public void testInvalidate() {
final CyclicAssumption cyclicAssumption = new CyclicAssumption("cyclic-assumption");
final Assumption firstAssumption = cyclicAssumption.getAssumption();
assertEquals("cyclic-assumption", firstAssumption.getName());
assertTrue(firstAssumption.isValid());
cyclicAssumption.invalidate();
assertFalse(firstAssumption.isValid());
final Assumption secondAssumption = cyclicAssumption.getAssumption();
assertEquals("cyclic-assumption", secondAssumption.getName());
assertTrue(secondAssumption.isValid());
cyclicAssumption.invalidate();
assertFalse(firstAssumption.isValid());
assertFalse(secondAssumption.isValid());
}
Aggregations