Mercurial > hg > truffle
diff truffle/com.oracle.truffle.tools.test/src/com/oracle/truffle/tools/test/TestNodes.java @ 22219:1c0f490984d5
Merge with f47b601edbc626dcfe8b3636933b4834c89f7779
author | Michael Van De Vanter <michael.van.de.vanter@oracle.com> |
---|---|
date | Wed, 16 Sep 2015 15:36:22 -0700 |
parents | dc83cc1f94f2 3aad794eec0e |
children | 20380d1d41f2 |
line wrap: on
line diff
--- a/truffle/com.oracle.truffle.tools.test/src/com/oracle/truffle/tools/test/TestNodes.java Wed Sep 16 12:27:08 2015 +0200 +++ b/truffle/com.oracle.truffle.tools.test/src/com/oracle/truffle/tools/test/TestNodes.java Wed Sep 16 15:36:22 2015 -0700 @@ -24,10 +24,15 @@ */ package com.oracle.truffle.tools.test; +import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + import com.oracle.truffle.api.CallTarget; import com.oracle.truffle.api.Truffle; import com.oracle.truffle.api.TruffleLanguage; import com.oracle.truffle.api.frame.VirtualFrame; +import com.oracle.truffle.api.instrument.Instrumenter; import com.oracle.truffle.api.instrument.KillException; import com.oracle.truffle.api.instrument.Probe; import com.oracle.truffle.api.instrument.ProbeNode; @@ -39,6 +44,7 @@ import com.oracle.truffle.api.source.LineLocation; import com.oracle.truffle.api.source.Source; import com.oracle.truffle.api.source.SourceSection; +import com.oracle.truffle.api.vm.TruffleVM; /** * Nodes and an {@linkplain CallTarget executable ASTs} for testing. @@ -55,21 +61,29 @@ /** * An executable addition expression that evaluates to 13. */ - static CallTarget createExpr13TestCallTarget() { - final RootNode rootNode = createExpr13TestRootNode(); + static CallTarget createExpr13TestCallTarget(Instrumenter instrumenter) { + final RootNode rootNode = createExpr13TestRootNode(instrumenter); return Truffle.getRuntime().createCallTarget(rootNode); } /** * Root holding an addition expression that evaluates to 13. */ - static RootNode createExpr13TestRootNode() { + static RootNode createExpr13TestRootNode(Instrumenter instrumenter) { final TestLanguageNode ast = createExpr13AST(); - final TestRootNode rootNode = new TestRootNode(ast); + final TestRootNode rootNode = new TestRootNode(ast, instrumenter); rootNode.adoptChildren(); return rootNode; } + static Instrumenter createInstrumenter() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException { + TruffleVM vm = TruffleVM.newVM().build(); + final Field field = TruffleVM.class.getDeclaredField("instrumenter"); + field.setAccessible(true); + final Instrumenter instrument = (Instrumenter) field.get(vm); + return instrument; + } + /** * Addition expression that evaluates to 13, with faked source attribution. */ @@ -165,13 +179,16 @@ static class TestRootNode extends RootNode { @Child private TestLanguageNode body; + private final Instrumenter instrumenter; + /** * This constructor emulates the global machinery that applies registered probers to every * newly created AST. Global registry is not used, since that would interfere with other * tests run in the same environment. */ - public TestRootNode(TestLanguageNode body) { + public TestRootNode(TestLanguageNode body, Instrumenter instrumenter) { super(TruffleLanguage.class, null, null); + this.instrumenter = instrumenter; this.body = body; } @@ -187,7 +204,14 @@ @Override public void applyInstrumentation() { - Probe.applyASTProbers(body); + Method method; + try { + method = Instrumenter.class.getDeclaredMethod("applyInstrumentation", Node.class); + method.setAccessible(true); + method.invoke(instrumenter, body); + } catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { + throw new RuntimeException("TestNodes"); + } } }