# HG changeset patch # User Michael Van De Vanter # Date 1428710306 25200 # Node ID 0e647427eee4b0baca8d58e5ae7b04a7beb30672 # Parent e7ece52e1ff308547697a0fc0ff898d20d70bc6c# Parent dc41766b35e11348281b76fd70b456b6ba3cf7e9 Merge with dc41766b35e11348281b76fd70b456b6ba3cf7e9 diff -r dc41766b35e1 -r 0e647427eee4 graal/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/instrument/InstrumentationTest.java --- a/graal/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/instrument/InstrumentationTest.java Fri Apr 10 13:10:56 2015 +0200 +++ b/graal/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/instrument/InstrumentationTest.java Fri Apr 10 16:58:26 2015 -0700 @@ -157,7 +157,6 @@ // Check that the "probed" AST still executes correctly assertEquals(13, callTarget1.call()); - } @Test @@ -182,7 +181,6 @@ // Now try with the more complex flavor of listener checkCounters(probe, callTarget, rootNode, new TestASTInstrumentCounter(), new TestASTInstrumentCounter(), new TestASTInstrumentCounter()); - } private static void checkCounters(Probe probe, CallTarget callTarget, RootNode rootNode, TestCounter counterA, TestCounter counterB, TestCounter counterC) { @@ -280,12 +278,10 @@ assertEquals(counterB.leaveCount(), 8); assertEquals(counterC.enterCount(), 2); assertEquals(counterC.leaveCount(), 2); - } @Test public void testTagging() { - // Applies appropriate tags final TestASTProber astProber = new TestASTProber(); Probe.registerASTProber(astProber); @@ -341,7 +337,6 @@ assertEquals(valueCounter.count, 2); Probe.unregisterASTProber(astProber); - } private interface TestCounter { @@ -353,12 +348,10 @@ void attach(Probe probe); void dispose(); - } /** - * A counter for the number of times execution enters and leaves a probed AST node, using the - * simplest kind of listener. + * A counter for the number of times execution enters and leaves a probed AST node. */ private class TestInstrumentCounter implements TestCounter { @@ -367,42 +360,50 @@ public final Instrument instrument; public TestInstrumentCounter() { - this.instrument = Instrument.create(new SimpleInstrumentListener() { + this.instrument = Instrument.create(new InstrumentListener() { - @Override public void enter(Probe probe) { enterCount++; } - @Override - public void returnAny(Probe probe) { + public void returnVoid(Probe probe) { + leaveCount++; + } + + public void returnValue(Probe probe, Object result) { + leaveCount++; + } + + public void returnExceptional(Probe probe, Exception exception) { leaveCount++; } }, "Instrumentation Test Counter"); - } + @Override public int enterCount() { return enterCount; } + @Override public int leaveCount() { return leaveCount; } + @Override public void attach(Probe probe) { probe.attach(instrument); } + @Override public void dispose() { instrument.dispose(); } } /** - * A counter for the number of times execution enters and leaves a probed AST node, using the - * simplest kind of listener. + * A counter for the number of times execution enters and leaves a probed AST node. */ private class TestASTInstrumentCounter implements TestCounter { @@ -411,34 +412,43 @@ public final Instrument instrument; public TestASTInstrumentCounter() { - this.instrument = Instrument.create(new SimpleASTInstrumentListener() { + this.instrument = Instrument.create(new ASTInstrumentListener() { - @Override public void enter(Probe probe, Node node, VirtualFrame vFrame) { enterCount++; } - @Override - public void returnAny(Probe probe, Node node, VirtualFrame vFrame) { + public void returnVoid(Probe probe, Node node, VirtualFrame vFrame) { + leaveCount++; + } + + public void returnValue(Probe probe, Node node, VirtualFrame vFrame, Object result) { + leaveCount++; + } + + public void returnExceptional(Probe probe, Node node, VirtualFrame vFrame, Exception exception) { leaveCount++; } }, "Instrumentation Test Counter"); - } + @Override public int enterCount() { return enterCount; } + @Override public int leaveCount() { return leaveCount; } + @Override public void attach(Probe probe) { probe.attach(instrument); } + @Override public void dispose() { instrument.dispose(); } @@ -483,7 +493,6 @@ public void enter(Probe probe) { counter++; } - } /** @@ -497,7 +506,6 @@ public void enter(Probe probe, Node node, VirtualFrame vFrame) { counter++; } - } /** @@ -539,5 +547,4 @@ tagCount++; } } - } diff -r dc41766b35e1 -r 0e647427eee4 graal/com.oracle.truffle.api/src/com/oracle/truffle/api/instrument/Instrument.java --- a/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/instrument/Instrument.java Fri Apr 10 13:10:56 2015 +0200 +++ b/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/instrument/Instrument.java Fri Apr 10 16:58:26 2015 -0700 @@ -74,10 +74,6 @@ *
  • Extend one of the helper implementations: {@link DefaultInstrumentListener} or * {@link DefaultASTInstrumentListener}. These provide no-op implementation of every listener * method, so only the methods of interest need to be overridden.
  • - *
  • Extend one of the helper implementations: {@link SimpleInstrumentListener} or - * {@link SimpleASTInstrumentListener}. These re-route all execution returns to a single - * method, ignoring return values, so only two methods (for "enter" and "return") will notify all - * events.
  • * *

    *

    General guidelines for {@link ASTInstrumentListener} implementation:

    diff -r dc41766b35e1 -r 0e647427eee4 graal/com.oracle.truffle.api/src/com/oracle/truffle/api/instrument/impl/SimpleASTInstrumentListener.java --- a/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/instrument/impl/SimpleASTInstrumentListener.java Fri Apr 10 13:10:56 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,67 +0,0 @@ -/* - * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.oracle.truffle.api.instrument.impl; - -import com.oracle.truffle.api.frame.*; -import com.oracle.truffle.api.instrument.*; -import com.oracle.truffle.api.nodes.*; - -/** - * An abstract listener for AST {@linkplain ASTInstrumentListener execution events} that ignores - * return values and supports handling all events by overriding only two methods: - * - */ -public abstract class SimpleASTInstrumentListener implements ASTInstrumentListener { - - public void enter(Probe probe, Node node, VirtualFrame vFrame) { - } - - /** - * Receive notification that one of an AST Node's execute methods has just returned by any - * means: with or without a return value (ignored) or via exception (ignored). - * - * @param probe where the event originated - * @param node specific node of the event - * @param vFrame - */ - protected void returnAny(Probe probe, Node node, VirtualFrame vFrame) { - } - - public final void returnVoid(Probe probe, Node node, VirtualFrame vFrame) { - returnAny(probe, node, vFrame); - } - - public final void returnValue(Probe probe, Node node, VirtualFrame vFrame, Object result) { - returnAny(probe, node, vFrame); - } - - public final void returnExceptional(Probe probe, Node node, VirtualFrame vFrame, Exception e) { - returnAny(probe, node, vFrame); - } - -} diff -r dc41766b35e1 -r 0e647427eee4 graal/com.oracle.truffle.api/src/com/oracle/truffle/api/instrument/impl/SimpleInstrumentListener.java --- a/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/instrument/impl/SimpleInstrumentListener.java Fri Apr 10 13:10:56 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,63 +0,0 @@ -/* - * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.oracle.truffle.api.instrument.impl; - -import com.oracle.truffle.api.instrument.*; - -/** - * An abstract listener for Truffle {@linkplain InstrumentListener execution events} that ignores - * return values and supports handling all events by overriding only two methods: - * - */ -public abstract class SimpleInstrumentListener implements InstrumentListener { - - public void enter(Probe probe) { - } - - /** - * Receive notification that an execute method has just returned by any means: with or without a - * return value (ignored) or via exception (ignored). - * - * @param probe - */ - protected void returnAny(Probe probe) { - } - - public final void returnVoid(Probe probe) { - returnAny(probe); - } - - public final void returnValue(Probe probe, Object result) { - returnAny(probe); - } - - public final void returnExceptional(Probe probe, Exception e) { - returnAny(probe); - } - -}