Skip to content

Commit

Permalink
[GR-18794] Instrumentation language and multiple arguments.
Browse files Browse the repository at this point in the history
PullRequest: graal/5637
  • Loading branch information
Jaroslav Tulach committed Mar 6, 2020
2 parents 186aaa2 + 3dd5549 commit ae1f1a9
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.Set;
import java.util.TreeSet;
import java.util.concurrent.CountDownLatch;
Expand Down Expand Up @@ -583,13 +584,36 @@ public void accessFrameVariables() throws Exception {
// @formatter:on

Set<String> names = new TreeSet<>();
agentAPI.on("enter", (ctx, frame) -> {
final AgentScriptAPI.OnEventHandler captureNames = (ctx, frame) -> {
assertTrue(names.isEmpty());
names.addAll(frame.keySet());
}, createConfig(true, false, false, (name) -> "mul".equals(name), null));

};
agentAPI.on("enter", captureNames, createConfig(true, false, false, (name) -> "mul".equals(name), null));
c.eval(sampleScript);
agentAPI.off("enter", captureNames);

Assert.assertArrayEquals("THIS, a and b found", new Object[]{"THIS", "a", "b"}, names.toArray());

Object[] values = {0, 0};
agentAPI.on("enter", (ctx, frame) -> {
values[0] = frame.get("a");
values[1] = frame.get("b");
}, AgentObjectFactory.createConfig(true, false, false, (name) -> "mul".equals(name), null));

Value mul = c.getBindings(InstrumentationTestLanguage.ID).getMember("mul");
assertNotNull("mul function found", mul);
assertTrue("mul function found", mul.canExecute());

Random r = new Random();
for (int i = 1; i <= 100000; i++) {
int a = r.nextInt();
int b = r.nextInt();

mul.execute(a, b);

assertEquals(i + "th: a has been read", a, values[0]);
assertEquals(i + "th: b has been read", b, values[1]);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,7 @@ private static final class Parser {
private final Source source;
private final String code;
private int current;
private int argumentIndex = 0;

Parser(InstrumentationTestLanguage lang, Source source) {
this.lang = lang;
Expand Down Expand Up @@ -365,7 +366,6 @@ private BaseNode statement() {
throw new LanguageError(String.format("Illegal tag \"%s\".", tag));
}

int argumentIndex = 0;
int numberOfIdents = 0;
if (tag.equals("DEFINE") || tag.equals("ARGUMENT") || tag.equals("CALL") || tag.equals("LOOP") || tag.equals("CONSTANT") || tag.equals("UNEXPECTED_RESULT") || tag.equals("SLEEP") ||
tag.equals("SPAWN") | tag.equals("CATCH")) {
Expand Down

0 comments on commit ae1f1a9

Please sign in to comment.