Mercurial > hg > graal-jvmci-8
annotate graal/com.oracle.truffle.api/src/com/oracle/truffle/api/instrument/impl/LineLocationToProbeCollectionMap.java @ 17035:7b2e6171f455
LineLocationToProbeCollectionMap: add forget method
author | Gilles Duboscq <duboscq@ssw.jku.at> |
---|---|
date | Wed, 03 Sep 2014 12:01:14 +0200 |
parents | a1427e40deaf |
children | c88ab4f1f04a |
rev | line source |
---|---|
16856
7833417c8172
Changes to Instrumentation
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
1 /* |
16880
7661cc464239
Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
16857
diff
changeset
|
2 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. |
16856
7833417c8172
Changes to Instrumentation
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
7833417c8172
Changes to Instrumentation
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
4 * |
7833417c8172
Changes to Instrumentation
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
7833417c8172
Changes to Instrumentation
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
7833417c8172
Changes to Instrumentation
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
7 * published by the Free Software Foundation. Oracle designates this |
7833417c8172
Changes to Instrumentation
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
8 * particular file as subject to the "Classpath" exception as provided |
7833417c8172
Changes to Instrumentation
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
9 * by Oracle in the LICENSE file that accompanied this code. |
7833417c8172
Changes to Instrumentation
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
10 * |
7833417c8172
Changes to Instrumentation
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
11 * This code is distributed in the hope that it will be useful, but WITHOUT |
7833417c8172
Changes to Instrumentation
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
7833417c8172
Changes to Instrumentation
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
7833417c8172
Changes to Instrumentation
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
14 * version 2 for more details (a copy is included in the LICENSE file that |
7833417c8172
Changes to Instrumentation
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
15 * accompanied this code). |
7833417c8172
Changes to Instrumentation
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
16 * |
7833417c8172
Changes to Instrumentation
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
17 * You should have received a copy of the GNU General Public License version |
7833417c8172
Changes to Instrumentation
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
18 * 2 along with this work; if not, write to the Free Software Foundation, |
7833417c8172
Changes to Instrumentation
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
7833417c8172
Changes to Instrumentation
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
20 * |
7833417c8172
Changes to Instrumentation
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
7833417c8172
Changes to Instrumentation
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
22 * or visit www.oracle.com if you need additional information or have any |
7833417c8172
Changes to Instrumentation
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
23 * questions. |
7833417c8172
Changes to Instrumentation
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
24 */ |
7833417c8172
Changes to Instrumentation
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
25 package com.oracle.truffle.api.instrument.impl; |
7833417c8172
Changes to Instrumentation
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
26 |
16961
a1427e40deaf
Truffle/Instrumentation: some Javadoc revistions; minor code cleanups; remove one redundant operation; add tracing to the LineLocation maps.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16881
diff
changeset
|
27 import java.io.*; |
16856
7833417c8172
Changes to Instrumentation
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
28 import java.util.*; |
7833417c8172
Changes to Instrumentation
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
29 |
7833417c8172
Changes to Instrumentation
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
30 import com.oracle.truffle.api.instrument.*; |
7833417c8172
Changes to Instrumentation
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
31 import com.oracle.truffle.api.source.*; |
7833417c8172
Changes to Instrumentation
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
32 |
7833417c8172
Changes to Instrumentation
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
33 /** |
16857
7bfbad29d331
Truffle/Instrumentation: Javadoc cleanups and minor corrections.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16856
diff
changeset
|
34 * A mapping from {@link LineLocation} (a line number in a specific piece of {@link Source} code) to |
7bfbad29d331
Truffle/Instrumentation: Javadoc cleanups and minor corrections.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16856
diff
changeset
|
35 * a collection of {@link Probe}s whose associated {@link SourceSection} starts on that line. |
16856
7833417c8172
Changes to Instrumentation
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
36 */ |
7833417c8172
Changes to Instrumentation
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
37 public class LineLocationToProbeCollectionMap implements ProbeListener { |
16873
3ad18f453679
Truffle/Instrumentation: Javadoc
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16857
diff
changeset
|
38 |
16961
a1427e40deaf
Truffle/Instrumentation: some Javadoc revistions; minor code cleanups; remove one redundant operation; add tracing to the LineLocation maps.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16881
diff
changeset
|
39 private static final boolean TRACE = false; |
a1427e40deaf
Truffle/Instrumentation: some Javadoc revistions; minor code cleanups; remove one redundant operation; add tracing to the LineLocation maps.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16881
diff
changeset
|
40 private static final PrintStream OUT = System.out; |
a1427e40deaf
Truffle/Instrumentation: some Javadoc revistions; minor code cleanups; remove one redundant operation; add tracing to the LineLocation maps.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16881
diff
changeset
|
41 |
16856
7833417c8172
Changes to Instrumentation
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
42 /** |
7833417c8172
Changes to Instrumentation
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
43 * Map: Source line ==> probes associated with source sections starting on the line. |
7833417c8172
Changes to Instrumentation
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
44 */ |
7833417c8172
Changes to Instrumentation
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
45 private final Map<LineLocation, Collection<Probe>> lineToProbesMap = new HashMap<>(); |
7833417c8172
Changes to Instrumentation
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
46 |
7833417c8172
Changes to Instrumentation
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
47 public LineLocationToProbeCollectionMap() { |
7833417c8172
Changes to Instrumentation
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
48 } |
7833417c8172
Changes to Instrumentation
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
49 |
7833417c8172
Changes to Instrumentation
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
50 public void newProbeInserted(SourceSection source, Probe probe) { |
16961
a1427e40deaf
Truffle/Instrumentation: some Javadoc revistions; minor code cleanups; remove one redundant operation; add tracing to the LineLocation maps.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16881
diff
changeset
|
51 if (source != null && !(source instanceof NullSourceSection)) { |
a1427e40deaf
Truffle/Instrumentation: some Javadoc revistions; minor code cleanups; remove one redundant operation; add tracing to the LineLocation maps.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16881
diff
changeset
|
52 final LineLocation lineLocation = source.getLineLocation(); |
a1427e40deaf
Truffle/Instrumentation: some Javadoc revistions; minor code cleanups; remove one redundant operation; add tracing to the LineLocation maps.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16881
diff
changeset
|
53 if (TRACE) { |
a1427e40deaf
Truffle/Instrumentation: some Javadoc revistions; minor code cleanups; remove one redundant operation; add tracing to the LineLocation maps.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16881
diff
changeset
|
54 OUT.println("LineLocationToProbeCollectionMap: adding " + lineLocation + " Probe=" + probe); |
a1427e40deaf
Truffle/Instrumentation: some Javadoc revistions; minor code cleanups; remove one redundant operation; add tracing to the LineLocation maps.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16881
diff
changeset
|
55 } |
a1427e40deaf
Truffle/Instrumentation: some Javadoc revistions; minor code cleanups; remove one redundant operation; add tracing to the LineLocation maps.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16881
diff
changeset
|
56 this.addProbeToLine(lineLocation, probe); |
a1427e40deaf
Truffle/Instrumentation: some Javadoc revistions; minor code cleanups; remove one redundant operation; add tracing to the LineLocation maps.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16881
diff
changeset
|
57 } |
16856
7833417c8172
Changes to Instrumentation
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
58 } |
7833417c8172
Changes to Instrumentation
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
59 |
7833417c8172
Changes to Instrumentation
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
60 public void probeTaggedAs(Probe probe, SyntaxTag tag) { |
16857
7bfbad29d331
Truffle/Instrumentation: Javadoc cleanups and minor corrections.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16856
diff
changeset
|
61 // This map ignores tags |
16856
7833417c8172
Changes to Instrumentation
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
62 } |
7833417c8172
Changes to Instrumentation
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
63 |
7833417c8172
Changes to Instrumentation
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
64 /** |
7833417c8172
Changes to Instrumentation
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
65 * Returns the {@link Probe}, if any, associated with source that starts on a specified line; if |
16857
7bfbad29d331
Truffle/Instrumentation: Javadoc cleanups and minor corrections.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16856
diff
changeset
|
66 * there are more than one, return the one with the first starting character location. |
16856
7833417c8172
Changes to Instrumentation
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
67 */ |
7833417c8172
Changes to Instrumentation
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
68 public Probe findLineProbe(LineLocation lineLocation) { |
7833417c8172
Changes to Instrumentation
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
69 Probe probe = null; |
7833417c8172
Changes to Instrumentation
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
70 final Collection<Probe> probes = getProbesAtLine(lineLocation); |
7833417c8172
Changes to Instrumentation
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
71 for (Probe probeOnLine : probes) { |
7833417c8172
Changes to Instrumentation
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
72 if (probe == null) { |
7833417c8172
Changes to Instrumentation
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
73 probe = probeOnLine; |
7833417c8172
Changes to Instrumentation
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
74 } else if (probeOnLine.getSourceLocation().getCharIndex() < probe.getSourceLocation().getCharIndex()) { |
7833417c8172
Changes to Instrumentation
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
75 probe = probeOnLine; |
7833417c8172
Changes to Instrumentation
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
76 } |
7833417c8172
Changes to Instrumentation
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
77 } |
7833417c8172
Changes to Instrumentation
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
78 return probe; |
7833417c8172
Changes to Instrumentation
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
79 } |
7833417c8172
Changes to Instrumentation
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
80 |
7833417c8172
Changes to Instrumentation
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
81 /** |
16873
3ad18f453679
Truffle/Instrumentation: Javadoc
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16857
diff
changeset
|
82 * Records creation of a probe whose associated source starts on the given line. |
16856
7833417c8172
Changes to Instrumentation
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
83 * <p> |
7833417c8172
Changes to Instrumentation
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
84 * If the line already exists in the internal {@link #lineToProbesMap}, this probe will be added |
7833417c8172
Changes to Instrumentation
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
85 * to the existing collection. If no line already exists in the internal map, then a new key is |
7833417c8172
Changes to Instrumentation
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
86 * added along with a new collection containing the probe. |
7833417c8172
Changes to Instrumentation
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
87 * <p> |
7833417c8172
Changes to Instrumentation
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
88 * This class requires that each added line/probe pair hasn't been previously added. However, |
7833417c8172
Changes to Instrumentation
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
89 * attaching the same probe to a new line location is allowed. |
7833417c8172
Changes to Instrumentation
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
90 * |
7833417c8172
Changes to Instrumentation
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
91 * @param line The {@link LineLocation} to attach the probe to. |
7833417c8172
Changes to Instrumentation
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
92 * @param probe The {@link Probe} to attach for that line location. |
7833417c8172
Changes to Instrumentation
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
93 */ |
16880
7661cc464239
Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
16857
diff
changeset
|
94 protected void addProbeToLine(LineLocation line, Probe probe) { |
16856
7833417c8172
Changes to Instrumentation
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
95 |
7833417c8172
Changes to Instrumentation
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
96 if (!lineToProbesMap.containsKey(line)) { |
7833417c8172
Changes to Instrumentation
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
97 // Key does not exist, add new probe list |
7833417c8172
Changes to Instrumentation
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
98 final ArrayList<Probe> newProbeList = new ArrayList<>(2); |
7833417c8172
Changes to Instrumentation
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
99 newProbeList.add(probe); |
7833417c8172
Changes to Instrumentation
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
100 lineToProbesMap.put(line, newProbeList); |
7833417c8172
Changes to Instrumentation
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
101 } else { |
7833417c8172
Changes to Instrumentation
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
102 // Probe list exists, add to existing |
7833417c8172
Changes to Instrumentation
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
103 final Collection<Probe> existingProbeList = lineToProbesMap.get(line); |
7833417c8172
Changes to Instrumentation
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
104 assert !existingProbeList.contains(probe); |
7833417c8172
Changes to Instrumentation
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
105 existingProbeList.add(probe); |
7833417c8172
Changes to Instrumentation
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
106 } |
7833417c8172
Changes to Instrumentation
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
107 } |
7833417c8172
Changes to Instrumentation
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
108 |
7833417c8172
Changes to Instrumentation
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
109 /** |
16961
a1427e40deaf
Truffle/Instrumentation: some Javadoc revistions; minor code cleanups; remove one redundant operation; add tracing to the LineLocation maps.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16881
diff
changeset
|
110 * |
16881
f0e3b50c29c8
Merge to latest. Fixed conflicts in LineLocationToProbeCollection.
David Piorkowski <david.piorkowski@oracle.com>
diff
changeset
|
111 * Returns a collection of {@link Probe}s whose associated source begins at the given |
16961
a1427e40deaf
Truffle/Instrumentation: some Javadoc revistions; minor code cleanups; remove one redundant operation; add tracing to the LineLocation maps.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16881
diff
changeset
|
112 * {@link LineLocation}, an empty list if none. |
16856
7833417c8172
Changes to Instrumentation
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
113 * |
7833417c8172
Changes to Instrumentation
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
114 * @param line The line to check. |
16873
3ad18f453679
Truffle/Instrumentation: Javadoc
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16857
diff
changeset
|
115 * @return A collection of probes at the given line. |
16856
7833417c8172
Changes to Instrumentation
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
116 */ |
16880
7661cc464239
Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
16857
diff
changeset
|
117 public Collection<Probe> getProbesAtLine(LineLocation line) { |
16856
7833417c8172
Changes to Instrumentation
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
118 Collection<Probe> probeList = lineToProbesMap.get(line); |
7833417c8172
Changes to Instrumentation
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
119 |
16961
a1427e40deaf
Truffle/Instrumentation: some Javadoc revistions; minor code cleanups; remove one redundant operation; add tracing to the LineLocation maps.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16881
diff
changeset
|
120 if (probeList == null) { |
a1427e40deaf
Truffle/Instrumentation: some Javadoc revistions; minor code cleanups; remove one redundant operation; add tracing to the LineLocation maps.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16881
diff
changeset
|
121 return Collections.emptyList(); |
a1427e40deaf
Truffle/Instrumentation: some Javadoc revistions; minor code cleanups; remove one redundant operation; add tracing to the LineLocation maps.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16881
diff
changeset
|
122 } |
16856
7833417c8172
Changes to Instrumentation
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
123 return probeList; |
7833417c8172
Changes to Instrumentation
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
124 } |
16880
7661cc464239
Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
16857
diff
changeset
|
125 |
7661cc464239
Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
16857
diff
changeset
|
126 /** |
7661cc464239
Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
16857
diff
changeset
|
127 * Convenience method to get probes according to a int line number. Returns a collection of |
16961
a1427e40deaf
Truffle/Instrumentation: some Javadoc revistions; minor code cleanups; remove one redundant operation; add tracing to the LineLocation maps.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16881
diff
changeset
|
128 * {@link Probe}s at the given line number, an empty list if none. |
16880
7661cc464239
Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
16857
diff
changeset
|
129 * |
7661cc464239
Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
16857
diff
changeset
|
130 * @param lineNumber The line number to check. |
16961
a1427e40deaf
Truffle/Instrumentation: some Javadoc revistions; minor code cleanups; remove one redundant operation; add tracing to the LineLocation maps.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16881
diff
changeset
|
131 * @return A collection of probes at the given line. |
16880
7661cc464239
Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
16857
diff
changeset
|
132 */ |
7661cc464239
Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
16857
diff
changeset
|
133 public Collection<Probe> getProbesAtLineNumber(int lineNumber) { |
7661cc464239
Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
16857
diff
changeset
|
134 |
16961
a1427e40deaf
Truffle/Instrumentation: some Javadoc revistions; minor code cleanups; remove one redundant operation; add tracing to the LineLocation maps.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16881
diff
changeset
|
135 final Set<LineLocation> keySet = lineToProbesMap.keySet(); |
a1427e40deaf
Truffle/Instrumentation: some Javadoc revistions; minor code cleanups; remove one redundant operation; add tracing to the LineLocation maps.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16881
diff
changeset
|
136 if (keySet.size() == 0) { |
a1427e40deaf
Truffle/Instrumentation: some Javadoc revistions; minor code cleanups; remove one redundant operation; add tracing to the LineLocation maps.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16881
diff
changeset
|
137 return Collections.emptyList(); |
a1427e40deaf
Truffle/Instrumentation: some Javadoc revistions; minor code cleanups; remove one redundant operation; add tracing to the LineLocation maps.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16881
diff
changeset
|
138 } |
a1427e40deaf
Truffle/Instrumentation: some Javadoc revistions; minor code cleanups; remove one redundant operation; add tracing to the LineLocation maps.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16881
diff
changeset
|
139 |
a1427e40deaf
Truffle/Instrumentation: some Javadoc revistions; minor code cleanups; remove one redundant operation; add tracing to the LineLocation maps.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16881
diff
changeset
|
140 ArrayList<Probe> probes = new ArrayList<>(); |
a1427e40deaf
Truffle/Instrumentation: some Javadoc revistions; minor code cleanups; remove one redundant operation; add tracing to the LineLocation maps.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16881
diff
changeset
|
141 for (LineLocation line : keySet) { |
16880
7661cc464239
Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
16857
diff
changeset
|
142 if (line.getLineNumber() == lineNumber) |
7661cc464239
Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
16857
diff
changeset
|
143 probes.addAll(lineToProbesMap.get(line)); |
7661cc464239
Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
16857
diff
changeset
|
144 } |
7661cc464239
Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
16857
diff
changeset
|
145 |
7661cc464239
Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
16857
diff
changeset
|
146 return probes; |
7661cc464239
Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
16857
diff
changeset
|
147 } |
17035
7b2e6171f455
LineLocationToProbeCollectionMap: add forget method
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
16961
diff
changeset
|
148 |
7b2e6171f455
LineLocationToProbeCollectionMap: add forget method
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
16961
diff
changeset
|
149 public void forget(Source source) { |
7b2e6171f455
LineLocationToProbeCollectionMap: add forget method
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
16961
diff
changeset
|
150 final Set<LineLocation> mappedLines = lineToProbesMap.keySet(); |
7b2e6171f455
LineLocationToProbeCollectionMap: add forget method
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
16961
diff
changeset
|
151 if (mappedLines.size() > 0) { |
7b2e6171f455
LineLocationToProbeCollectionMap: add forget method
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
16961
diff
changeset
|
152 List<LineLocation> forgetLines = new ArrayList<>(); |
7b2e6171f455
LineLocationToProbeCollectionMap: add forget method
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
16961
diff
changeset
|
153 for (LineLocation line : mappedLines) { |
7b2e6171f455
LineLocationToProbeCollectionMap: add forget method
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
16961
diff
changeset
|
154 if (line.getSource().equals(source)) { |
7b2e6171f455
LineLocationToProbeCollectionMap: add forget method
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
16961
diff
changeset
|
155 forgetLines.add(line); |
7b2e6171f455
LineLocationToProbeCollectionMap: add forget method
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
16961
diff
changeset
|
156 } |
7b2e6171f455
LineLocationToProbeCollectionMap: add forget method
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
16961
diff
changeset
|
157 } |
7b2e6171f455
LineLocationToProbeCollectionMap: add forget method
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
16961
diff
changeset
|
158 for (LineLocation line : forgetLines) { |
7b2e6171f455
LineLocationToProbeCollectionMap: add forget method
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
16961
diff
changeset
|
159 lineToProbesMap.remove(line); |
7b2e6171f455
LineLocationToProbeCollectionMap: add forget method
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
16961
diff
changeset
|
160 } |
7b2e6171f455
LineLocationToProbeCollectionMap: add forget method
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
16961
diff
changeset
|
161 } |
7b2e6171f455
LineLocationToProbeCollectionMap: add forget method
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
16961
diff
changeset
|
162 } |
16856
7833417c8172
Changes to Instrumentation
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
163 } |