# HG changeset patch # User Michael Van De Vanter # Date 1442694287 25200 # Node ID c92d6117696f4c3e4f2c6dcc8a5d22df729af52c # Parent 20380d1d41f2784405022528ccf2f9d16090705a Truffle/Instrumentation: modify behavior of CoverageTracker and LineToProbesMap so that they will work on ASTs created before installation (as long as correct probes are in place) diff -r 20380d1d41f2 -r c92d6117696f truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/debug/LineToProbesMap.java --- a/truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/debug/LineToProbesMap.java Thu Sep 17 21:23:57 2015 -0700 +++ b/truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/debug/LineToProbesMap.java Sat Sep 19 13:24:47 2015 -0700 @@ -32,6 +32,7 @@ import java.util.Map; import com.oracle.truffle.api.instrument.InstrumentationTool; +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; @@ -69,7 +70,11 @@ @Override protected boolean internalInstall() { - getInstrumenter().addProbeListener(probeListener); + final Instrumenter instrumenter = getInstrumenter(); + for (Probe probe : instrumenter.findProbesTaggedAs(null)) { + addMapEntry(probe); + } + instrumenter.addProbeListener(probeListener); return true; } @@ -116,21 +121,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 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 probes = lineToProbesMap.get(lineLocation); + if (probes == null) { + probes = new ArrayList<>(2); + lineToProbesMap.put(lineLocation, probes); + } else { + assert !probes.contains(probe); + } + probes.add(probe); } } } diff -r 20380d1d41f2 -r c92d6117696f truffle/com.oracle.truffle.tools/src/com/oracle/truffle/tools/CoverageTracker.java --- a/truffle/com.oracle.truffle.tools/src/com/oracle/truffle/tools/CoverageTracker.java Thu Sep 17 21:23:57 2015 -0700 +++ b/truffle/com.oracle.truffle.tools/src/com/oracle/truffle/tools/CoverageTracker.java Sat Sep 19 13:24:47 2015 -0700 @@ -35,6 +35,7 @@ import com.oracle.truffle.api.instrument.Instrument; import com.oracle.truffle.api.instrument.InstrumentationTool; +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.SimpleInstrumentListener; @@ -116,7 +117,11 @@ @Override protected boolean internalInstall() { - getInstrumenter().addProbeListener(probeListener); + final Instrumenter instrumenter = getInstrumenter(); + for (Probe probe : instrumenter.findProbesTaggedAs(countingTag)) { + addCoverageCounter(probe); + } + instrumenter.addProbeListener(probeListener); return true; } @@ -274,34 +279,37 @@ @Override public void probeTaggedAs(Probe probe, SyntaxTag tag, Object tagValue) { if (countingTag == tag) { - - final SourceSection srcSection = probe.getProbedSourceSection(); - if (srcSection == null) { - // TODO (mlvdv) report this? - return; - } - // Get the source line where the - final LineLocation lineLocation = srcSection.getLineLocation(); - CoverageRecord record = coverageMap.get(lineLocation); - if (record != null) { - // Another node starts on same line; count only the first (textually) - if (srcSection.getCharIndex() > record.srcSection.getCharIndex()) { - // Existing record, corresponds to code earlier on line - return; - } else { - // Existing record, corresponds to code at a later position; replace it - record.instrument.dispose(); - } - } - - final CoverageRecord coverage = new CoverageRecord(srcSection); - final Instrument instrument = Instrument.create(coverage, CoverageTracker.class.getSimpleName()); - coverage.instrument = instrument; - instruments.add(instrument); - probe.attach(instrument); - coverageMap.put(lineLocation, coverage); + addCoverageCounter(probe); } } } + private void addCoverageCounter(Probe probe) { + final SourceSection srcSection = probe.getProbedSourceSection(); + if (srcSection == null) { + // TODO (mlvdv) report this? + return; + } + // Get the source line where the + final LineLocation lineLocation = srcSection.getLineLocation(); + CoverageRecord record = coverageMap.get(lineLocation); + if (record != null) { + // Another node starts on same line; count only the first (textually) + if (srcSection.getCharIndex() > record.srcSection.getCharIndex()) { + // Existing record, corresponds to code earlier on line + return; + } else { + // Existing record, corresponds to code at a later position; replace it + record.instrument.dispose(); + } + } + + final CoverageRecord coverage = new CoverageRecord(srcSection); + final Instrument instrument = Instrument.create(coverage, CoverageTracker.class.getSimpleName()); + coverage.instrument = instrument; + instruments.add(instrument); + probe.attach(instrument); + coverageMap.put(lineLocation, coverage); + } + } diff -r 20380d1d41f2 -r c92d6117696f truffle/com.oracle.truffle.tools/src/com/oracle/truffle/tools/LineToProbesMap.java --- a/truffle/com.oracle.truffle.tools/src/com/oracle/truffle/tools/LineToProbesMap.java Thu Sep 17 21:23:57 2015 -0700 +++ b/truffle/com.oracle.truffle.tools/src/com/oracle/truffle/tools/LineToProbesMap.java Sat Sep 19 13:24:47 2015 -0700 @@ -32,6 +32,7 @@ import java.util.Map; import com.oracle.truffle.api.instrument.InstrumentationTool; +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; @@ -69,7 +70,11 @@ @Override protected boolean internalInstall() { - getInstrumenter().addProbeListener(probeListener); + final Instrumenter instrumenter = getInstrumenter(); + for (Probe probe : instrumenter.findProbesTaggedAs(null)) { + addMapEntry(probe); + } + instrumenter.addProbeListener(probeListener); return true; } @@ -116,21 +121,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 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 probes = lineToProbesMap.get(lineLocation); + if (probes == null) { + probes = new ArrayList<>(2); + lineToProbesMap.put(lineLocation, probes); + } else { + assert !probes.contains(probe); + } + probes.add(probe); } } }