Mercurial > hg > truffle
diff truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/debug/LineToProbesMap.java @ 22266:0d36601f233e
Merge revised Instrumentation framework into the Polyglot API
- Required language implementation support now in TruffleLanguage
- Instrumentation services provided by the new Instrumenter class
- Reduced public API exposure; communication with other components via Accessor
- Several methods removed from the Node class
- Many test rewritten or using a new "test mode" because of limited access to Engine services
Merge with c66f520ad8562b906a878e9b3293aaf54270db90
author | Michael Van De Vanter <michael.van.de.vanter@oracle.com> |
---|---|
date | Wed, 30 Sep 2015 16:33:56 -0700 |
parents | 1348cc2e084e |
children |
line wrap: on
line diff
--- a/truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/debug/LineToProbesMap.java Tue Sep 29 18:04:11 2015 +0200 +++ b/truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/debug/LineToProbesMap.java Wed Sep 30 16:33:56 2015 -0700 @@ -24,13 +24,6 @@ */ package com.oracle.truffle.api.debug; -import com.oracle.truffle.api.instrument.InstrumentationTool; -import com.oracle.truffle.api.instrument.Probe; -import com.oracle.truffle.api.instrument.ProbeListener; -import com.oracle.truffle.api.instrument.impl.DefaultProbeListener; -import com.oracle.truffle.api.source.LineLocation; -import com.oracle.truffle.api.source.Source; -import com.oracle.truffle.api.source.SourceSection; import java.io.PrintStream; import java.util.ArrayList; import java.util.Collection; @@ -38,11 +31,19 @@ import java.util.HashMap; import java.util.Map; +import com.oracle.truffle.api.instrument.Instrumenter; +import com.oracle.truffle.api.instrument.Probe; +import com.oracle.truffle.api.instrument.ProbeListener; +import com.oracle.truffle.api.instrument.impl.DefaultProbeListener; +import com.oracle.truffle.api.source.LineLocation; +import com.oracle.truffle.api.source.Source; +import com.oracle.truffle.api.source.SourceSection; + /** - * An {@link InstrumentationTool} that builds a map of every {@link Probe} attached to some AST, - * indexed by {@link Source} and line number. + * An {@linkplain Instrumenter.Tool Instrumentation-based Tool} that builds a map of every + * {@link Probe} attached to some AST, indexed by {@link Source} and line number. */ -final class LineToProbesMap extends InstrumentationTool { +final class LineToProbesMap extends Instrumenter.Tool { private static final boolean TRACE = false; private static final PrintStream OUT = System.out; @@ -68,7 +69,11 @@ @Override protected boolean internalInstall() { - Probe.addProbeListener(probeListener); + final Instrumenter instrumenter = getInstrumenter(); + for (Probe probe : instrumenter.findProbesTaggedAs(null)) { + addMapEntry(probe); + } + instrumenter.addProbeListener(probeListener); return true; } @@ -79,7 +84,7 @@ @Override protected void internalDispose() { - Probe.removeProbeListener(probeListener); + getInstrumenter().removeProbeListener(probeListener); } /** @@ -115,21 +120,25 @@ @Override public void newProbeInserted(Probe probe) { - final SourceSection sourceSection = probe.getProbedSourceSection(); - if (sourceSection != null && sourceSection.getSource() != null) { - final LineLocation lineLocation = sourceSection.getLineLocation(); - if (TRACE) { - trace("ADD " + lineLocation.getShortDescription() + " ==> " + probe.getShortDescription()); - } - Collection<Probe> probes = lineToProbesMap.get(lineLocation); - if (probes == null) { - probes = new ArrayList<>(2); - lineToProbesMap.put(lineLocation, probes); - } else { - assert !probes.contains(probe); - } - probes.add(probe); + addMapEntry(probe); + } + } + + private void addMapEntry(Probe probe) { + final SourceSection sourceSection = probe.getProbedSourceSection(); + if (sourceSection != null && sourceSection.getSource() != null) { + final LineLocation lineLocation = sourceSection.getLineLocation(); + if (TRACE) { + trace("ADD " + lineLocation.getShortDescription() + " ==> " + probe.getShortDescription()); } + Collection<Probe> probes = lineToProbesMap.get(lineLocation); + if (probes == null) { + probes = new ArrayList<>(2); + lineToProbesMap.put(lineLocation, probes); + } else { + assert !probes.contains(probe); + } + probes.add(probe); } } }