use of com.oracle.truffle.api.nodes.Node in project graal by oracle.
the class DebugStackFrame method getScope.
/**
* Get the current inner-most scope. The scope remain valid as long as the current stack frame
* remains valid.
* <p>
* Use {@link DebuggerSession#getTopScope(java.lang.String)} to get scopes with global validity.
* <p>
* This method is not thread-safe and will throw an {@link IllegalStateException} if called on
* another thread than it was created with.
*
* @return the scope, or <code>null</code> when no language is associated with this frame
* location, or when no local scope exists.
* @since 0.26
*/
public DebugScope getScope() {
verifyValidState(false);
SuspendedContext context = getContext();
RootNode root = findCurrentRoot();
if (root == null) {
return null;
}
Node node;
if (currentFrame == null) {
node = context.getInstrumentedNode();
} else {
node = currentFrame.getCallNode();
}
if (node.getRootNode().getLanguageInfo() == null) {
// no language, no scopes
return null;
}
Debugger debugger = event.getSession().getDebugger();
MaterializedFrame frame = findTruffleFrame();
Iterable<Scope> scopes = debugger.getEnv().findLocalScopes(node, frame);
Iterator<Scope> it = scopes.iterator();
if (!it.hasNext()) {
return null;
}
return new DebugScope(it.next(), it, debugger, event, frame, root);
}
use of com.oracle.truffle.api.nodes.Node 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.nodes.Node in project graal by oracle.
the class FlatNodeGenFactory method createInsertAccessor.
private CodeExecutableElement createInsertAccessor(boolean array) {
CodeTypeParameterElement tVar = new CodeTypeParameterElement("T", context.getType(Node.class));
TypeMirror type = tVar.createMirror(null, null);
if (array) {
type = new ArrayCodeTypeMirror(type);
}
CodeExecutableElement insertAccessor = new CodeExecutableElement(modifiers(FINAL), type, INSERT_ACCESSOR_NAME);
insertAccessor.getParameters().add(new CodeVariableElement(type, "node"));
insertAccessor.getTypeParameters().add(tVar);
insertAccessor.createBuilder().startReturn().string("super.insert(node)").end();
return insertAccessor;
}
use of com.oracle.truffle.api.nodes.Node in project graal by oracle.
the class NodeUtilTest method testRecursiveIterator.
@Test
public void testRecursiveIterator() {
TestRootNode root = new TestRootNode();
TestForEachNode testForEachNode = new TestForEachNode(1);
root.child0 = testForEachNode;
TestNode testNode1 = new TestNode();
testForEachNode.firstChild = testNode1;
TestNode testNode2 = new TestNode();
testForEachNode.children[0] = testNode2;
TestNode testNode3 = new TestNode();
testForEachNode.lastChild = testNode3;
root.adoptChildren();
int count = 0;
Iterable<Node> iterable = () -> NodeUtil.makeRecursiveIterator(testForEachNode);
for (Node node : iterable) {
((VisitableNode) node).visited++;
count++;
}
Assert.assertEquals(4, count);
Assert.assertEquals(1, testForEachNode.visited);
Assert.assertEquals(1, testNode1.visited);
Assert.assertEquals(1, testNode2.visited);
Assert.assertEquals(1, testNode3.visited);
}
use of com.oracle.truffle.api.nodes.Node in project graal by oracle.
the class NodeUtilTest method testChildrenArray.
@Test
public void testChildrenArray() {
// 2 children in the array
TestForEachNode test2children = new TestForEachNode(2);
TestNode both1 = new TestNode();
TestNode both2 = new TestNode();
test2children.children[0] = both1;
test2children.children[1] = both2;
int count = 0;
for (Node node : test2children.getChildren()) {
((VisitableNode) node).visited++;
count++;
}
Assert.assertEquals(2, count);
Assert.assertEquals(1, both1.visited);
Assert.assertEquals(1, both2.visited);
// First null
TestNode testChild1 = new TestNode();
test2children.children[0] = null;
test2children.children[1] = testChild1;
count = 0;
for (Node node : test2children.getChildren()) {
((VisitableNode) node).visited++;
count++;
}
Assert.assertEquals(1, count);
Assert.assertEquals(1, testChild1.visited);
// Second null
TestNode testChild2 = new TestNode();
test2children.children[0] = testChild2;
test2children.children[1] = null;
count = 0;
for (Node node : test2children.getChildren()) {
((VisitableNode) node).visited++;
count++;
}
Assert.assertEquals(1, count);
Assert.assertEquals(1, testChild2.visited);
// Both null, go to next child
TestNode otherChild = new TestNode();
test2children.children[0] = null;
test2children.children[1] = null;
test2children.lastChild = otherChild;
count = 0;
for (Node node : test2children.getChildren()) {
((VisitableNode) node).visited++;
count++;
}
Assert.assertEquals(1, count);
Assert.assertEquals(1, otherChild.visited);
}
Aggregations