Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jruby/jruby
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 95208a8761bb
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 5c2bfd221687
Choose a head ref
  • 2 commits
  • 3 files changed
  • 1 contributor

Commits on Jul 6, 2016

  1. Copy the full SHA
    78fca8d View commit details
  2. Copy the full SHA
    5c2bfd2 View commit details
31 changes: 24 additions & 7 deletions tool/truffle/callgraph2html.rb
Original file line number Diff line number Diff line change
@@ -31,6 +31,10 @@ def to_s
def lines
if file == '(unknown)'
['(native)']
elsif file == '(eval)'
['(eval)']
elsif file == '(snippet)'
['(snippet)']
elsif file.start_with?('truffle:')
['(core)']
else
@@ -64,13 +68,14 @@ def reachable
end

class MethodVersion
attr_reader :id, :method, :callsite_versions, :called_from
attr_reader :id, :method, :callsite_versions, :called_from, :eval_code

def initialize(id, method)
@id = Integer(id)
@method = method
@callsite_versions = []
@called_from = []
@eval_code = []
end

def reachable
@@ -122,6 +127,10 @@ def reachable
method_version = CG::MethodVersion.new(line[2], method)
objects[method_version.id] = method_version
method.versions.push method_version
when 'eval'
method_version = objects[Integer(line[1])]
eval_code = line.drop(2).join(' ')
method_version.eval_code.push eval_code
when 'local'
when 'callsite'
method = objects[Integer(line[1])]
@@ -231,12 +240,20 @@ def annotate(method_version, offset)
<% if reachable_objects.include?(method_version) %>
<div id='method-version-<%= method_version.id %>' class='method-version'>
<% unless method_version.called_from.empty? %>
<p>Called from:</p>
<ul>
<% method_version.called_from.each do |caller| %>
<li><a href='#method-version-<%= caller.method_version.id %>'><%= h(caller.method_version.method.name) %></a></li>
<% end %>
</ul>
<p>Called from:</p>
<ul>
<% method_version.called_from.each do |caller| %>
<li><a href='#method-version-<%= caller.method_version.id %>'><%= h(caller.method_version.method.name) %></a></li>
<% end %>
</ul>
<% end %>
<% unless method_version.eval_code.empty? %>
<p>Evals:</p>
<ul>
<% method_version.eval_code.each do |eval_code| %>
<li><code><%= h(eval_code) %></code></li>
<% end %>
</ul>
<% end %>
<% method.source.lines.each_with_index do |code, offset| %>
<p class='code'>
Original file line number Diff line number Diff line change
@@ -14,16 +14,21 @@
import com.oracle.truffle.api.nodes.Node;
import com.oracle.truffle.api.nodes.NodeVisitor;
import com.oracle.truffle.api.nodes.RootNode;
import org.jruby.truffle.core.kernel.KernelNodes;
import org.jruby.truffle.language.RubyRootNode;

import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

public class MethodVersion {

private final Method method;
private final RubyRootNode rootNode;
private final Map<CallSite, CallSiteVersion> callSiteVersions = new HashMap<>();
private final Set<String> evalCode = new HashSet<>();

public MethodVersion(Method method, RubyRootNode rootNode) {
this.method = method;
@@ -40,14 +45,9 @@ public Map<CallSite, CallSiteVersion> getCallSiteVersions() {
}

public void resolve() {
rootNode.accept(new NodeVisitor() {

@Override
public boolean visit(Node node) {
resolve(node);
return true;
}

rootNode.accept(node -> {
resolve(node);
return true;
});
}

@@ -72,6 +72,14 @@ private void resolve(Node node) {
}

callSiteVersion.getCalls().add(calls);
} else if (node.getClass().getName().indexOf("EvalNoBindingCachedNode") != -1) {
try {
final Field f = node.getClass().getDeclaredField("cachedSource");
f.setAccessible(true);
evalCode.add(f.get(node).toString());
} catch (IllegalAccessException | NoSuchFieldException e) {
e.printStackTrace();
}
}
}

@@ -91,4 +99,8 @@ private CallSiteVersion getCallSiteVersion(Node node) {
public RubyRootNode getRootNode() {
return rootNode;
}

public Set<String> getEvalCode() {
return evalCode;
}
}
Original file line number Diff line number Diff line change
@@ -86,6 +86,12 @@ private void write(MethodVersion version) {
ids.getId(version.getMethod()),
ids.getId(version));

for (String evalCode : version.getEvalCode()) {
stream.printf("eval %d %s%n",
ids.getId(version),
evalCode);
}

for (CallSiteVersion callSiteVersion : version.getCallSiteVersions().values()) {
write(callSiteVersion);
}