Mercurial > hg > graal-compiler
comparison graal/com.oracle.truffle.api/src/com/oracle/truffle/api/debug/DefaultDebugManager.java @ 14094:3f27e57439ed
Truffle/Instrumentation: significant rearrangement (including moved class) and extension of the Truffle Instrumentation Framework. New interfaces include DebugContext (which can be attached to the ExecutionContext), through which access is provided to possibly language-specific (a) node instrumentation, (b) debug services manager, (c) notification when programs halt, (d) display of language values, and (e) display of variable identifiers.
author | Michael Van De Vanter <michael.van.de.vanter@oracle.com> |
---|---|
date | Mon, 03 Feb 2014 20:58:23 -0800 |
parents | graal/com.oracle.truffle.api/src/com/oracle/truffle/api/impl/DefaultDebugManager.java@4d47e9c0df23 |
children | f3a5036cc13c |
comparison
equal
deleted
inserted
replaced
13736:64fa70319890 | 14094:3f27e57439ed |
---|---|
1 /* | |
2 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. | |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | |
4 * | |
5 * This code is free software; you can redistribute it and/or modify it | |
6 * under the terms of the GNU General Public License version 2 only, as | |
7 * published by the Free Software Foundation. Oracle designates this | |
8 * particular file as subject to the "Classpath" exception as provided | |
9 * by Oracle in the LICENSE file that accompanied this code. | |
10 * | |
11 * This code is distributed in the hope that it will be useful, but WITHOUT | |
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
14 * version 2 for more details (a copy is included in the LICENSE file that | |
15 * accompanied this code). | |
16 * | |
17 * You should have received a copy of the GNU General Public License version | |
18 * 2 along with this work; if not, write to the Free Software Foundation, | |
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
20 * | |
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | |
22 * or visit www.oracle.com if you need additional information or have any | |
23 * questions. | |
24 */ | |
25 package com.oracle.truffle.api.debug; | |
26 | |
27 import java.util.*; | |
28 | |
29 import com.oracle.truffle.api.*; | |
30 import com.oracle.truffle.api.frame.*; | |
31 import com.oracle.truffle.api.nodes.*; | |
32 import com.oracle.truffle.api.nodes.instrument.InstrumentationProbeNode.ProbeChain; | |
33 import com.oracle.truffle.api.source.*; | |
34 | |
35 /** | |
36 * A minimal, language-agnostic implementation that tracks loaded sources, and keeps maps describing | |
37 * what locations in the source have instrumentation available. This implementation will do nothing | |
38 * unless there are calls to it during AST construction, notably {@link #notifyStartLoading(Source)} | |
39 * and {@link #notifyFinishedLoading(Source)} <em>and</em> there are at least some AST nodes being | |
40 * instrumented. | |
41 */ | |
42 public class DefaultDebugManager implements DebugManager { | |
43 | |
44 private final Set<Source> loadedSources = new HashSet<>(); | |
45 | |
46 private Source beingLoaded = null; | |
47 | |
48 /** | |
49 * Map: SourceSection ==> probe chain associated with that source section in an AST. | |
50 */ | |
51 private final Map<SourceSection, ProbeChain> srcToProbeChain = new HashMap<>(); | |
52 | |
53 /** | |
54 * Map: Source lines ==> probe chains associated with source sections starting on the line. | |
55 */ | |
56 private final Map<SourceLineLocation, Set<ProbeChain>> lineToProbeChains = new HashMap<>(); | |
57 | |
58 private final ExecutionContext context; | |
59 | |
60 public DefaultDebugManager(ExecutionContext context) { | |
61 this.context = context; | |
62 } | |
63 | |
64 /** | |
65 * Gets the {@linkplain ProbeChain probe} associated with a particular {@link SourceSection | |
66 * source location}, creating a new one if needed. There should only be one probe associated | |
67 * with each {@linkplain SourceSection source location}. | |
68 */ | |
69 public ProbeChain getProbeChain(SourceSection sourceSection) { | |
70 assert sourceSection != null; | |
71 assert sourceSection.getSource().equals(beingLoaded); | |
72 | |
73 ProbeChain probeChain = srcToProbeChain.get(sourceSection); | |
74 | |
75 if (probeChain != null) { | |
76 return probeChain; | |
77 } | |
78 probeChain = new ProbeChain(context, sourceSection, null); | |
79 | |
80 // Register new ProbeChain by unique SourceSection | |
81 srcToProbeChain.put(sourceSection, probeChain); | |
82 | |
83 // Register new ProbeChain by source line, there may be more than one | |
84 // Create line location for map key | |
85 final SourceLineLocation lineLocation = new SourceLineLocation(sourceSection.getSource(), sourceSection.getStartLine()); | |
86 | |
87 Set<ProbeChain> probeChains = lineToProbeChains.get(lineLocation); | |
88 if (probeChains == null) { | |
89 probeChains = new HashSet<>(); | |
90 lineToProbeChains.put(lineLocation, probeChains); | |
91 } | |
92 probeChains.add(probeChain); | |
93 | |
94 return probeChain; | |
95 } | |
96 | |
97 public void notifyStartLoading(Source source) { | |
98 assert beingLoaded == null; | |
99 beingLoaded = source; | |
100 } | |
101 | |
102 public void notifyFinishedLoading(Source source) { | |
103 assert source == beingLoaded; | |
104 loadedSources.add(source); | |
105 beingLoaded = null; | |
106 } | |
107 | |
108 public void haltedAt(Node astNode, VirtualFrame frame) { | |
109 } | |
110 | |
111 } |