Skip to content

Commit

Permalink
[GR-21566] Instrumentation does not reach retired nodes.
Browse files Browse the repository at this point in the history
PullRequest: graal/5664
  • Loading branch information
jchalou committed Apr 9, 2020
2 parents c78d5fd + 30263f3 commit 3dad36a
Show file tree
Hide file tree
Showing 8 changed files with 1,961 additions and 222 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,16 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

import org.junit.Test;

import java.util.LinkedList;
import java.util.List;
import java.util.Set;

import org.graalvm.polyglot.Context;
import org.graalvm.polyglot.Engine;
import org.graalvm.polyglot.Instrument;
import org.graalvm.polyglot.Source;
import org.junit.Test;

import com.oracle.truffle.api.CallTarget;
import com.oracle.truffle.api.Truffle;
import com.oracle.truffle.api.TruffleLanguage;
Expand Down Expand Up @@ -82,11 +86,6 @@
import com.oracle.truffle.api.source.SourceSection;
import com.oracle.truffle.api.test.polyglot.ProxyLanguage;

import org.graalvm.polyglot.Context;
import org.graalvm.polyglot.Engine;
import org.graalvm.polyglot.Instrument;
import org.graalvm.polyglot.Source;

public class InstrumentableNodeTest extends InstrumentationEventTest {

/*
Expand Down Expand Up @@ -334,7 +333,7 @@ protected void onCreate(TruffleInstrument.Env env) {
}

@TruffleLanguage.Registration(id = MaterializationLanguage.ID, name = "Materialization Test Language", version = "1.0")
@ProvidedTags({StandardTags.StatementTag.class})
@ProvidedTags({StandardTags.RootTag.class, StandardTags.StatementTag.class})
public static class MaterializationLanguage extends ProxyLanguage {

static final String ID = "truffle-materialization-test-language";
Expand Down Expand Up @@ -397,7 +396,7 @@ static class MaterializableNode extends Node implements InstrumentableNode {
private final SourceSection sourceSection;
private final int depth;
private boolean materialized;
@Node.Children private MaterializableNode[] children;
@Node.Children protected MaterializableNode[] children;

MaterializableNode(MaterializationLanguage language, com.oracle.truffle.api.source.Source source, int depth) {
this.language = language;
Expand All @@ -407,10 +406,52 @@ static class MaterializableNode extends Node implements InstrumentableNode {
}

MaterializableNode(MaterializableNode copy) {
this(copy, createChildren(copy.language, copy.sourceSection.getSource(), copy.depth));
}

MaterializableNode(MaterializableNode copy, MaterializableNode[] children) {
this.language = copy.language;
this.depth = copy.depth;
this.materialized = copy.materialized;
this.sourceSection = copy.sourceSection;
children = createChildren(language, copy.sourceSection.getSource(), depth);
this.children = children;
}

protected MaterializableNode copyUninitialized(Set<Class<? extends Tag>> materializedTags) {
if (this instanceof InstrumentableNode.WrapperNode) {
InstrumentableNode.WrapperNode wrapperNode = (InstrumentableNode.WrapperNode) this;
return cloneUninitialized((MaterializableNode) wrapperNode.getDelegateNode(), materializedTags);
}

return new MaterializableNode(this, cloneUninitialized(children, materializedTags));
}

@SuppressWarnings("unchecked")
public static <T extends MaterializableNode> T cloneUninitialized(T node, Set<Class<? extends Tag>> materializedTags) {
if (node == null) {
return null;
} else {
T copy = node;
if (node.isInstrumentable()) {
copy = (T) node.materializeInstrumentableNodes(materializedTags);
}
if (node == copy) {
copy = (T) node.copyUninitialized(materializedTags);
}
return copy;
}
}

public static <T extends MaterializableNode> T[] cloneUninitialized(T[] nodeArray, Set<Class<? extends Tag>> materializedTags) {
if (nodeArray == null) {
return null;
} else {
T[] copy = nodeArray.clone();
for (int i = 0; i < copy.length; i++) {
copy[i] = cloneUninitialized(copy[i], materializedTags);
}
return copy;
}
}

@Override
Expand Down Expand Up @@ -449,21 +490,26 @@ public InstrumentableNode materializeInstrumentableNodes(Set<Class<? extends Tag
}
materialized = true;
language.numMaterializations++;
return new MaterializedNode(language, sourceSection.getSource(), depth);
return new MaterializedNode(this, cloneUninitialized(children, materializedTags));
}
}

@GenerateWrapper
static class MaterializedNode extends MaterializableNode {

MaterializedNode(MaterializationLanguage language, com.oracle.truffle.api.source.Source source, int depth) {
super(language, source, depth);
}

MaterializedNode(MaterializedNode copy) {
super(copy);
}

MaterializedNode(MaterializableNode copy, MaterializableNode[] children) {
super(copy, children);
}

@Override
protected MaterializableNode copyUninitialized(Set<Class<? extends Tag>> materializedTags) {
return new MaterializedNode(this, cloneUninitialized(children, materializedTags));
}

@Override
public WrapperNode createWrapper(ProbeNode probe) {
return new MaterializedNodeWrapper(this, this, probe);
Expand Down
Loading

0 comments on commit 3dad36a

Please sign in to comment.