Mercurial > hg > graal-compiler
annotate graal/com.oracle.truffle.ruby.parser/src/com/oracle/truffle/ruby/parser/DefaultRubyNodeInstrumenter.java @ 14014:ac599fff18dc
Substitution methods for injecting fake profiling data into unit tests.
author | Roland Schatz <roland.schatz@oracle.com> |
---|---|
date | Tue, 25 Feb 2014 11:24:17 +0100 |
parents | 22bf5a8ba9eb |
children |
rev | line source |
---|---|
13735
2c1c805153e6
Ruby: refactor low level instrumentation services
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
1 /* |
2c1c805153e6
Ruby: refactor low level instrumentation services
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
2 * Copyright (c) 2014 Oracle and/or its affiliates. All rights reserved. This |
2c1c805153e6
Ruby: refactor low level instrumentation services
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
3 * code is released under a tri EPL/GPL/LGPL license. You can use it, |
2c1c805153e6
Ruby: refactor low level instrumentation services
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
4 * redistribute it and/or modify it under the terms of the: |
2c1c805153e6
Ruby: refactor low level instrumentation services
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
5 * |
2c1c805153e6
Ruby: refactor low level instrumentation services
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
6 * Eclipse Public License version 1.0 |
2c1c805153e6
Ruby: refactor low level instrumentation services
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
7 * GNU General Public License version 2 |
2c1c805153e6
Ruby: refactor low level instrumentation services
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
8 * GNU Lesser General Public License version 2.1 |
2c1c805153e6
Ruby: refactor low level instrumentation services
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
9 */ |
2c1c805153e6
Ruby: refactor low level instrumentation services
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
10 package com.oracle.truffle.ruby.parser; |
2c1c805153e6
Ruby: refactor low level instrumentation services
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
11 |
13918
22bf5a8ba9eb
Ruby: restore prototype debugger.
Chris Seaton <chris.seaton@oracle.com>
parents:
13735
diff
changeset
|
12 import com.oracle.truffle.api.*; |
13735
2c1c805153e6
Ruby: refactor low level instrumentation services
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
13 import com.oracle.truffle.api.nodes.instrument.*; |
13918
22bf5a8ba9eb
Ruby: restore prototype debugger.
Chris Seaton <chris.seaton@oracle.com>
parents:
13735
diff
changeset
|
14 import com.oracle.truffle.api.source.*; |
13735
2c1c805153e6
Ruby: refactor low level instrumentation services
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
15 import com.oracle.truffle.ruby.nodes.*; |
2c1c805153e6
Ruby: refactor low level instrumentation services
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
16 import com.oracle.truffle.ruby.nodes.debug.*; |
2c1c805153e6
Ruby: refactor low level instrumentation services
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
17 import com.oracle.truffle.ruby.runtime.*; |
2c1c805153e6
Ruby: refactor low level instrumentation services
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
18 import com.oracle.truffle.ruby.runtime.debug.*; |
2c1c805153e6
Ruby: refactor low level instrumentation services
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
19 import com.oracle.truffle.ruby.runtime.methods.*; |
2c1c805153e6
Ruby: refactor low level instrumentation services
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
20 |
2c1c805153e6
Ruby: refactor low level instrumentation services
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
21 /** |
2c1c805153e6
Ruby: refactor low level instrumentation services
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
22 * Utility for instrumenting Ruby AST nodes to support the language's built-in <A |
2c1c805153e6
Ruby: refactor low level instrumentation services
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
23 * href="http://www.ruby-doc.org/core-2.0.0/Kernel.html#method-i-set_trace_func">tracing |
2c1c805153e6
Ruby: refactor low level instrumentation services
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
24 * facility</A>. It ignores nodes other than {@linkplain NodePhylum#STATEMENT statements}. |
2c1c805153e6
Ruby: refactor low level instrumentation services
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
25 */ |
2c1c805153e6
Ruby: refactor low level instrumentation services
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
26 final class DefaultRubyNodeInstrumenter implements RubyNodeInstrumenter { |
2c1c805153e6
Ruby: refactor low level instrumentation services
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
27 |
2c1c805153e6
Ruby: refactor low level instrumentation services
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
28 public DefaultRubyNodeInstrumenter() { |
2c1c805153e6
Ruby: refactor low level instrumentation services
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
29 } |
2c1c805153e6
Ruby: refactor low level instrumentation services
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
30 |
13918
22bf5a8ba9eb
Ruby: restore prototype debugger.
Chris Seaton <chris.seaton@oracle.com>
parents:
13735
diff
changeset
|
31 public RubyNode instrumentAsStatement(RubyNode node) { |
22bf5a8ba9eb
Ruby: restore prototype debugger.
Chris Seaton <chris.seaton@oracle.com>
parents:
13735
diff
changeset
|
32 assert node != null; |
22bf5a8ba9eb
Ruby: restore prototype debugger.
Chris Seaton <chris.seaton@oracle.com>
parents:
13735
diff
changeset
|
33 |
22bf5a8ba9eb
Ruby: restore prototype debugger.
Chris Seaton <chris.seaton@oracle.com>
parents:
13735
diff
changeset
|
34 final RubyContext context = node.getContext(); |
22bf5a8ba9eb
Ruby: restore prototype debugger.
Chris Seaton <chris.seaton@oracle.com>
parents:
13735
diff
changeset
|
35 |
22bf5a8ba9eb
Ruby: restore prototype debugger.
Chris Seaton <chris.seaton@oracle.com>
parents:
13735
diff
changeset
|
36 RubyProxyNode proxy; |
22bf5a8ba9eb
Ruby: restore prototype debugger.
Chris Seaton <chris.seaton@oracle.com>
parents:
13735
diff
changeset
|
37 |
22bf5a8ba9eb
Ruby: restore prototype debugger.
Chris Seaton <chris.seaton@oracle.com>
parents:
13735
diff
changeset
|
38 if (node instanceof RubyProxyNode) { |
22bf5a8ba9eb
Ruby: restore prototype debugger.
Chris Seaton <chris.seaton@oracle.com>
parents:
13735
diff
changeset
|
39 proxy = (RubyProxyNode) node; |
22bf5a8ba9eb
Ruby: restore prototype debugger.
Chris Seaton <chris.seaton@oracle.com>
parents:
13735
diff
changeset
|
40 } else { |
22bf5a8ba9eb
Ruby: restore prototype debugger.
Chris Seaton <chris.seaton@oracle.com>
parents:
13735
diff
changeset
|
41 proxy = new RubyProxyNode(node.getContext(), node); |
22bf5a8ba9eb
Ruby: restore prototype debugger.
Chris Seaton <chris.seaton@oracle.com>
parents:
13735
diff
changeset
|
42 proxy.markAs(NodePhylum.STATEMENT); |
22bf5a8ba9eb
Ruby: restore prototype debugger.
Chris Seaton <chris.seaton@oracle.com>
parents:
13735
diff
changeset
|
43 proxy.clearSourceSection(); |
22bf5a8ba9eb
Ruby: restore prototype debugger.
Chris Seaton <chris.seaton@oracle.com>
parents:
13735
diff
changeset
|
44 proxy.assignSourceSection(node.getSourceSection()); |
22bf5a8ba9eb
Ruby: restore prototype debugger.
Chris Seaton <chris.seaton@oracle.com>
parents:
13735
diff
changeset
|
45 } |
22bf5a8ba9eb
Ruby: restore prototype debugger.
Chris Seaton <chris.seaton@oracle.com>
parents:
13735
diff
changeset
|
46 |
13735
2c1c805153e6
Ruby: refactor low level instrumentation services
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
47 if (context.getConfiguration().getTrace()) { |
2c1c805153e6
Ruby: refactor low level instrumentation services
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
48 proxy.getProbeChain().appendProbe(new RubyTraceProbe(context)); |
2c1c805153e6
Ruby: refactor low level instrumentation services
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
49 } |
13918
22bf5a8ba9eb
Ruby: restore prototype debugger.
Chris Seaton <chris.seaton@oracle.com>
parents:
13735
diff
changeset
|
50 |
22bf5a8ba9eb
Ruby: restore prototype debugger.
Chris Seaton <chris.seaton@oracle.com>
parents:
13735
diff
changeset
|
51 if (context.getConfiguration().getDebug()) { |
22bf5a8ba9eb
Ruby: restore prototype debugger.
Chris Seaton <chris.seaton@oracle.com>
parents:
13735
diff
changeset
|
52 final SourceSection sourceSection = proxy.getChild().getSourceSection(); |
22bf5a8ba9eb
Ruby: restore prototype debugger.
Chris Seaton <chris.seaton@oracle.com>
parents:
13735
diff
changeset
|
53 final SourceLineLocation sourceLine = new SourceLineLocation(sourceSection.getSource(), sourceSection.getStartLine()); |
22bf5a8ba9eb
Ruby: restore prototype debugger.
Chris Seaton <chris.seaton@oracle.com>
parents:
13735
diff
changeset
|
54 proxy.getProbeChain().appendProbe(new InactiveLineDebugProbe(context, sourceLine, context.getRubyDebugManager().getAssumption(sourceLine))); |
22bf5a8ba9eb
Ruby: restore prototype debugger.
Chris Seaton <chris.seaton@oracle.com>
parents:
13735
diff
changeset
|
55 } |
22bf5a8ba9eb
Ruby: restore prototype debugger.
Chris Seaton <chris.seaton@oracle.com>
parents:
13735
diff
changeset
|
56 |
22bf5a8ba9eb
Ruby: restore prototype debugger.
Chris Seaton <chris.seaton@oracle.com>
parents:
13735
diff
changeset
|
57 return proxy; |
13735
2c1c805153e6
Ruby: refactor low level instrumentation services
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
58 } |
2c1c805153e6
Ruby: refactor low level instrumentation services
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
59 |
2c1c805153e6
Ruby: refactor low level instrumentation services
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
60 public RubyNode instrumentAsCall(RubyNode node, String callName) { |
2c1c805153e6
Ruby: refactor low level instrumentation services
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
61 return node; |
2c1c805153e6
Ruby: refactor low level instrumentation services
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
62 } |
2c1c805153e6
Ruby: refactor low level instrumentation services
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
63 |
2c1c805153e6
Ruby: refactor low level instrumentation services
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
64 public RubyNode instrumentAsLocalAssignment(RubyNode node, UniqueMethodIdentifier methodIdentifier, String localName) { |
13918
22bf5a8ba9eb
Ruby: restore prototype debugger.
Chris Seaton <chris.seaton@oracle.com>
parents:
13735
diff
changeset
|
65 assert node != null; |
22bf5a8ba9eb
Ruby: restore prototype debugger.
Chris Seaton <chris.seaton@oracle.com>
parents:
13735
diff
changeset
|
66 |
22bf5a8ba9eb
Ruby: restore prototype debugger.
Chris Seaton <chris.seaton@oracle.com>
parents:
13735
diff
changeset
|
67 final RubyContext context = node.getContext(); |
22bf5a8ba9eb
Ruby: restore prototype debugger.
Chris Seaton <chris.seaton@oracle.com>
parents:
13735
diff
changeset
|
68 |
22bf5a8ba9eb
Ruby: restore prototype debugger.
Chris Seaton <chris.seaton@oracle.com>
parents:
13735
diff
changeset
|
69 RubyProxyNode proxy; |
22bf5a8ba9eb
Ruby: restore prototype debugger.
Chris Seaton <chris.seaton@oracle.com>
parents:
13735
diff
changeset
|
70 |
22bf5a8ba9eb
Ruby: restore prototype debugger.
Chris Seaton <chris.seaton@oracle.com>
parents:
13735
diff
changeset
|
71 if (node instanceof RubyProxyNode) { |
22bf5a8ba9eb
Ruby: restore prototype debugger.
Chris Seaton <chris.seaton@oracle.com>
parents:
13735
diff
changeset
|
72 proxy = (RubyProxyNode) node; |
22bf5a8ba9eb
Ruby: restore prototype debugger.
Chris Seaton <chris.seaton@oracle.com>
parents:
13735
diff
changeset
|
73 } else { |
22bf5a8ba9eb
Ruby: restore prototype debugger.
Chris Seaton <chris.seaton@oracle.com>
parents:
13735
diff
changeset
|
74 proxy = new RubyProxyNode(node.getContext(), node); |
22bf5a8ba9eb
Ruby: restore prototype debugger.
Chris Seaton <chris.seaton@oracle.com>
parents:
13735
diff
changeset
|
75 proxy.markAs(NodePhylum.STATEMENT); |
22bf5a8ba9eb
Ruby: restore prototype debugger.
Chris Seaton <chris.seaton@oracle.com>
parents:
13735
diff
changeset
|
76 proxy.clearSourceSection(); |
22bf5a8ba9eb
Ruby: restore prototype debugger.
Chris Seaton <chris.seaton@oracle.com>
parents:
13735
diff
changeset
|
77 proxy.assignSourceSection(node.getSourceSection()); |
22bf5a8ba9eb
Ruby: restore prototype debugger.
Chris Seaton <chris.seaton@oracle.com>
parents:
13735
diff
changeset
|
78 } |
22bf5a8ba9eb
Ruby: restore prototype debugger.
Chris Seaton <chris.seaton@oracle.com>
parents:
13735
diff
changeset
|
79 |
22bf5a8ba9eb
Ruby: restore prototype debugger.
Chris Seaton <chris.seaton@oracle.com>
parents:
13735
diff
changeset
|
80 if (context.getConfiguration().getDebug()) { |
22bf5a8ba9eb
Ruby: restore prototype debugger.
Chris Seaton <chris.seaton@oracle.com>
parents:
13735
diff
changeset
|
81 final MethodLocal methodLocal = new MethodLocal(methodIdentifier, localName); |
22bf5a8ba9eb
Ruby: restore prototype debugger.
Chris Seaton <chris.seaton@oracle.com>
parents:
13735
diff
changeset
|
82 proxy.getProbeChain().appendProbe(new InactiveLocalDebugProbe(context, methodLocal, context.getRubyDebugManager().getAssumption(methodLocal))); |
22bf5a8ba9eb
Ruby: restore prototype debugger.
Chris Seaton <chris.seaton@oracle.com>
parents:
13735
diff
changeset
|
83 } |
22bf5a8ba9eb
Ruby: restore prototype debugger.
Chris Seaton <chris.seaton@oracle.com>
parents:
13735
diff
changeset
|
84 |
22bf5a8ba9eb
Ruby: restore prototype debugger.
Chris Seaton <chris.seaton@oracle.com>
parents:
13735
diff
changeset
|
85 return proxy; |
13735
2c1c805153e6
Ruby: refactor low level instrumentation services
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
86 } |
2c1c805153e6
Ruby: refactor low level instrumentation services
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
87 |
2c1c805153e6
Ruby: refactor low level instrumentation services
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
88 } |