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: 2959bff54ed2
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: f9e8fa0e616f
Choose a head ref
  • 12 commits
  • 19 files changed
  • 2 contributors

Commits on Jan 5, 2016

  1. Copy the full SHA
    4254049 View commit details
  2. Copy the full SHA
    b7796a2 View commit details
  3. Copy the full SHA
    04f2ee4 View commit details
  4. Copy the full SHA
    7b7f841 View commit details
  5. [Truffle] More fixes to the mechanism to make the source section of s…

    …equence nodes close over all children.
    chrisseaton committed Jan 5, 2016
    Copy the full SHA
    99d2605 View commit details
  6. Copy the full SHA
    12fc387 View commit details
  7. [Truffle] Can't use the SourceSection from SharedMethodInfo as it is …

    …created before we translate and so can make a covering source section
    chrisseaton committed Jan 5, 2016
    Copy the full SHA
    faa9371 View commit details
  8. Copy the full SHA
    a7b1406 View commit details
  9. Copy the full SHA
    335d272 View commit details
  10. [Truffle] More fixes to the mechanism to make the source section of s…

    …equence nodes close over all children.
    chrisseaton committed Jan 5, 2016
    Copy the full SHA
    906e760 View commit details
  11. Copy the full SHA
    140b6d9 View commit details
  12. Copy the full SHA
    f9e8fa0 View commit details
2 changes: 2 additions & 0 deletions core/src/main/java/org/jruby/util/cli/Options.java
Original file line number Diff line number Diff line change
@@ -264,6 +264,8 @@ public class Options {

public static final Option<Boolean> TRUFFLE_METRICS_TIME = bool(TRUFFLE, "truffle.metrics.time", false, "Print the time at various stages of VM operation.");
public static final Option<Boolean> TRUFFLE_METRICS_MEMORY_USED_ON_EXIT = bool(TRUFFLE, "truffle.metrics.memory_used_on_exit", false, "Print the size of heap memory in use on exit.");
public static final Option<Boolean> TRUFFLE_CALL_GRAPH = bool(TRUFFLE, "truffle.callgraph", false, "Maintain a call graph.");
public static final Option<String> TRUFFLE_CALL_GRAPH_WRITE = string(TRUFFLE, "truffle.callgraph.write", "File to write the call garph to on exit.");

public static String dump() {
return "# JRuby configuration options with current values\n" +
4 changes: 2 additions & 2 deletions spec/ruby/core/module/class_variable_get_spec.rb
Original file line number Diff line number Diff line change
@@ -32,11 +32,11 @@
end

it "returns class variables defined in the metaclass and accessed by class methods" do
ModuleSpecs::CVars.meta.should == :meta
ModuleSpecs::CVars.meta.should == :metainfo
end

it "returns class variables defined in the metaclass and accessed by instance methods" do
ModuleSpecs::CVars.new.meta.should == :meta
ModuleSpecs::CVars.new.meta.should == :metainfo
end

it "returns a class variable defined in a metaclass" do
2 changes: 1 addition & 1 deletion spec/ruby/core/module/fixtures/classes.rb
Original file line number Diff line number Diff line change
@@ -325,7 +325,7 @@ def cls
@@cls
end
# This actually adds it to the parent lexical scope, class CVars
@@meta = :meta
@@meta = :metainfo
end

def self.meta
61 changes: 61 additions & 0 deletions truffle/src/main/java/org/jruby/truffle/callgraph/CallGraph.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* Copyright (c) 2016 Oracle and/or its affiliates. All rights reserved. This
* code is released under a tri EPL/GPL/LGPL license. You can use it,
* redistribute it and/or modify it under the terms of the:
*
* Eclipse Public License version 1.0
* GNU General Public License version 2
* GNU Lesser General Public License version 2.1
*/
package org.jruby.truffle.callgraph;

import org.jruby.truffle.nodes.RubyRootNode;
import org.jruby.truffle.runtime.methods.SharedMethodInfo;

import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

public class CallGraph {

private final Map<SharedMethodInfo, Method> sharedMethodInfoToMethod = new HashMap<>();
private final Map<RubyRootNode, MethodVersion> rootNodeToMethodVersion = new HashMap<>();

public synchronized void registerRootNode(RubyRootNode rootNode) {
rootNodeToMethodVersion(rootNode);
}

public Method sharedMethodInfoToMethod(SharedMethodInfo sharedMethodInfo) {
Method method = sharedMethodInfoToMethod.get(sharedMethodInfo);

if (method == null) {
method = new Method(this, sharedMethodInfo);
sharedMethodInfoToMethod.put(sharedMethodInfo, method);
}

return method;
}

public MethodVersion rootNodeToMethodVersion(RubyRootNode rootNode) {
MethodVersion methodVersion = rootNodeToMethodVersion.get(rootNode);

if (methodVersion == null) {
methodVersion = new MethodVersion(sharedMethodInfoToMethod(rootNode.getSharedMethodInfo()), rootNode);
rootNodeToMethodVersion.put(rootNode, methodVersion);
}

return methodVersion;
}

public Collection<Method> getMethods() {
return Collections.unmodifiableCollection(sharedMethodInfoToMethod.values());
}

public void resolve() {
for (MethodVersion methodVersion : rootNodeToMethodVersion.values()) {
methodVersion.resolve();
}
}

}
35 changes: 35 additions & 0 deletions truffle/src/main/java/org/jruby/truffle/callgraph/CallSite.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright (c) 2016 Oracle and/or its affiliates. All rights reserved. This
* code is released under a tri EPL/GPL/LGPL license. You can use it,
* redistribute it and/or modify it under the terms of the:
*
* Eclipse Public License version 1.0
* GNU General Public License version 2
* GNU Lesser General Public License version 2.1
*/
package org.jruby.truffle.callgraph;

import com.oracle.truffle.api.source.SourceSection;

import java.util.ArrayList;
import java.util.List;

public class CallSite {

private final Method method;
private final SourceSection sourceSection;
private final List<CallSiteVersion> versions = new ArrayList<>();

public CallSite(Method method, SourceSection sourceSection) {
this.method = method;
this.sourceSection = sourceSection;
}

public Method getMethod() {
return method;
}

public SourceSection getSourceSection() {
return sourceSection;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright (c) 2016 Oracle and/or its affiliates. All rights reserved. This
* code is released under a tri EPL/GPL/LGPL license. You can use it,
* redistribute it and/or modify it under the terms of the:
*
* Eclipse Public License version 1.0
* GNU General Public License version 2
* GNU Lesser General Public License version 2.1
*/
package org.jruby.truffle.callgraph;

import java.util.ArrayList;
import java.util.List;

public class CallSiteVersion {

private final CallSite callSite;
private final List<Calls> calls = new ArrayList<>();

public CallSiteVersion(CallSite callSite) {
this.callSite = callSite;
}

public CallSite getCallSite() {
return callSite;
}

public List<Calls> getCalls() {
return calls;
}
}
13 changes: 13 additions & 0 deletions truffle/src/main/java/org/jruby/truffle/callgraph/Calls.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
* Copyright (c) 2016 Oracle and/or its affiliates. All rights reserved. This
* code is released under a tri EPL/GPL/LGPL license. You can use it,
* redistribute it and/or modify it under the terms of the:
*
* Eclipse Public License version 1.0
* GNU General Public License version 2
* GNU Lesser General Public License version 2.1
*/
package org.jruby.truffle.callgraph;

public interface Calls {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* Copyright (c) 2016 Oracle and/or its affiliates. All rights reserved. This
* code is released under a tri EPL/GPL/LGPL license. You can use it,
* redistribute it and/or modify it under the terms of the:
*
* Eclipse Public License version 1.0
* GNU General Public License version 2
* GNU Lesser General Public License version 2.1
*/
package org.jruby.truffle.callgraph;

public class CallsForeign implements Calls {

public static final CallsForeign INSTANCE = new CallsForeign();

private CallsForeign() {
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* Copyright (c) 2016 Oracle and/or its affiliates. All rights reserved. This
* code is released under a tri EPL/GPL/LGPL license. You can use it,
* redistribute it and/or modify it under the terms of the:
*
* Eclipse Public License version 1.0
* GNU General Public License version 2
* GNU Lesser General Public License version 2.1
*/
package org.jruby.truffle.callgraph;

public class CallsMegamorphic implements Calls {

public static final CallsMegamorphic INSTANCE = new CallsMegamorphic();

private CallsMegamorphic() {
}

}
23 changes: 23 additions & 0 deletions truffle/src/main/java/org/jruby/truffle/callgraph/CallsMethod.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright (c) 2016 Oracle and/or its affiliates. All rights reserved. This
* code is released under a tri EPL/GPL/LGPL license. You can use it,
* redistribute it and/or modify it under the terms of the:
*
* Eclipse Public License version 1.0
* GNU General Public License version 2
* GNU Lesser General Public License version 2.1
*/
package org.jruby.truffle.callgraph;

public class CallsMethod implements Calls {

private final MethodVersion methodVersion;

public CallsMethod(MethodVersion methodVersion) {
this.methodVersion = methodVersion;
}

public MethodVersion getMethodVersion() {
return methodVersion;
}
}
61 changes: 61 additions & 0 deletions truffle/src/main/java/org/jruby/truffle/callgraph/Method.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* Copyright (c) 2016 Oracle and/or its affiliates. All rights reserved. This
* code is released under a tri EPL/GPL/LGPL license. You can use it,
* redistribute it and/or modify it under the terms of the:
*
* Eclipse Public License version 1.0
* GNU General Public License version 2
* GNU Lesser General Public License version 2.1
*/
package org.jruby.truffle.callgraph;

import com.oracle.truffle.api.nodes.Node;
import com.oracle.truffle.api.source.SourceSection;
import org.jruby.truffle.runtime.methods.SharedMethodInfo;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Method {

private final CallGraph callGraph;
private final SharedMethodInfo sharedInfo;
private final List<MethodVersion> versions = new ArrayList<>();
private final Map<SourceSection, CallSite> callSites = new HashMap<>();

public Method(CallGraph callGraph, SharedMethodInfo sharedInfo) {
this.callGraph = callGraph;
this.sharedInfo = sharedInfo;
}

public List<MethodVersion> getVersions() {
return versions;
}

public SharedMethodInfo getSharedInfo() {
return sharedInfo;
}

public Map<SourceSection, CallSite> getCallSites() {
return callSites;
}

public CallSite getCallSite(Node node) {
final SourceSection sourceSection = node.getEncapsulatingSourceSection();

CallSite callSite = callSites.get(sourceSection);

if (callSite == null) {
callSite = new CallSite(this, sourceSection);
callSites.put(sourceSection, callSite);
}

return callSite;
}

public CallGraph getCallGraph() {
return callGraph;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/*
* Copyright (c) 2016 Oracle and/or its affiliates. All rights reserved. This
* code is released under a tri EPL/GPL/LGPL license. You can use it,
* redistribute it and/or modify it under the terms of the:
*
* Eclipse Public License version 1.0
* GNU General Public License version 2
* GNU Lesser General Public License version 2.1
*/
package org.jruby.truffle.callgraph;

import com.oracle.truffle.api.nodes.*;
import org.jruby.truffle.nodes.RubyRootNode;

import java.util.HashMap;
import java.util.Map;

public class MethodVersion {

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

public MethodVersion(Method method, RubyRootNode rootNode) {
this.method = method;
this.rootNode = rootNode;
method.getVersions().add(this);
}

public Method getMethod() {
return method;
}

public Map<CallSite, CallSiteVersion> getCallSiteVersions() {
return callSiteVersions;
}

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

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

});
}

private void resolve(Node node) {
if (node instanceof DirectCallNode || node instanceof IndirectCallNode) {
final CallSiteVersion callSiteVersion = getCallSiteVersion(node);

final Calls calls;

if (node instanceof DirectCallNode) {
final DirectCallNode directNode = (DirectCallNode) node;
final RootNode rootNode = directNode.getCurrentRootNode();

if (rootNode instanceof RubyRootNode) {
final MethodVersion methodVersion = method.getCallGraph().rootNodeToMethodVersion((RubyRootNode) rootNode);
calls = new CallsMethod(methodVersion);
} else {
calls = CallsForeign.INSTANCE;
}
} else {
calls = CallsMegamorphic.INSTANCE;
}

callSiteVersion.getCalls().add(calls);
}
}

private CallSiteVersion getCallSiteVersion(Node node) {
final CallSite callSite = method.getCallSite(node);

CallSiteVersion callSiteVersion = callSiteVersions.get(callSite);

if (callSiteVersion == null) {
callSiteVersion = new CallSiteVersion(callSite);
callSiteVersions.put(callSite, callSiteVersion);
}

return callSiteVersion;
}

public RubyRootNode getRootNode() {
return rootNode;
}
}
Loading