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: d3bfd4fe15e9
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: eddd5054eb16
Choose a head ref
  • 2 commits
  • 8 files changed
  • 1 contributor

Commits on Jul 7, 2016

  1. Copy the full SHA
    1034e3b View commit details
  2. Copy the full SHA
    eddd505 View commit details
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright (c) 2013, 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.language.locals;

import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.frame.FrameSlot;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.source.SourceSection;
import org.jruby.truffle.Layouts;
import org.jruby.truffle.RubyContext;
import org.jruby.truffle.language.RubyNode;
import org.jruby.truffle.language.RubyRootNode;

public class InstrumentedWriteLocalVariableNode extends WriteLocalVariableNode {

private final String name;

public InstrumentedWriteLocalVariableNode(RubyContext context, SourceSection sourceSection, FrameSlot frameSlot, RubyNode valueNode) {
super(context, sourceSection, frameSlot, valueNode);
name = frameSlot.getIdentifier().toString();
}

@Override
public Object execute(VirtualFrame frame) {
final Object value = super.execute(frame);
recordWrite(value);
return value;
}

@TruffleBoundary
private void recordWrite(Object value) {
final String type = Layouts.CLASS.getFields(getContext().getCoreLibrary().getLogicalClass(value)).getName();
getContext().getCallGraph().recordLocalWrite((RubyRootNode) getRootNode(), name, type);
}

}
Original file line number Diff line number Diff line change
@@ -68,7 +68,7 @@ private void checkReadFrameSlotNode() {

@Override
public RubyNode makeWriteNode(RubyNode rhs) {
return new WriteLocalVariableNode(getContext(), getSourceSection(), frameSlot, rhs);
return WriteLocalVariableNode.createWriteLocalVariableNode(getContext(), getSourceSection(), frameSlot, rhs);
}

}
Original file line number Diff line number Diff line change
@@ -10,14 +10,11 @@
package org.jruby.truffle.language.locals;

import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.frame.FrameSlot;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.source.SourceSection;
import org.jruby.truffle.Layouts;
import org.jruby.truffle.RubyContext;
import org.jruby.truffle.language.RubyNode;
import org.jruby.truffle.language.RubyRootNode;

public class WriteLocalVariableNode extends RubyNode {

@@ -26,8 +23,17 @@ public class WriteLocalVariableNode extends RubyNode {
@Child private RubyNode valueNode;
@Child private WriteFrameSlotNode writeFrameSlotNode;

public WriteLocalVariableNode(RubyContext context, SourceSection sourceSection,
FrameSlot frameSlot, RubyNode valueNode) {
public static WriteLocalVariableNode createWriteLocalVariableNode(RubyContext context, SourceSection sourceSection,
FrameSlot frameSlot, RubyNode valueNode) {
if (context.getCallGraph() == null) {
return new WriteLocalVariableNode(context, sourceSection, frameSlot, valueNode);
} else {
return new InstrumentedWriteLocalVariableNode(context, sourceSection, frameSlot, valueNode);
}
}

protected WriteLocalVariableNode(RubyContext context, SourceSection sourceSection,
FrameSlot frameSlot, RubyNode valueNode) {
super(context, sourceSection);
this.frameSlot = frameSlot;
this.valueNode = valueNode;
@@ -42,21 +48,9 @@ public Object execute(VirtualFrame frame) {
}

final Object value = valueNode.execute(frame);
recordWrite(value);
return writeFrameSlotNode.executeWrite(frame, value);
}

@TruffleBoundary
private void recordWrite(Object value) {
final RubyContext context = getContext();

if (context.getCallGraph() != null) {
final String name = frameSlot.getIdentifier().toString();
final String type = Layouts.CLASS.getFields(context.getCoreLibrary().getLogicalClass(value)).getName();
context.getCallGraph().recordLocalWrite((RubyRootNode) getRootNode(), name, type);
}
}

@Override
public Object isDefined(VirtualFrame frame) {
return coreStrings().ASSIGNMENT.createInstance();
Original file line number Diff line number Diff line change
@@ -49,7 +49,6 @@
import org.jruby.truffle.core.cast.ToProcNodeGen;
import org.jruby.truffle.core.cast.ToSNode;
import org.jruby.truffle.core.cast.ToSNodeGen;
import org.jruby.truffle.core.encoding.EncodingNodes;
import org.jruby.truffle.core.hash.ConcatHashLiteralNode;
import org.jruby.truffle.core.hash.HashLiteralNode;
import org.jruby.truffle.core.hash.HashNodesFactory;
@@ -334,7 +333,7 @@ public RubyNode visitAttrAssignNode(org.jruby.ast.AttrAssignNode node) {
final org.jruby.ast.Node valueNode = argChildNodes.remove(argChildNodes.size() - 1);

// Evaluate the value and store it in a local variable
writeValue = new WriteLocalVariableNode(context, sourceSection, frameSlot, valueNode.accept(this));
writeValue = WriteLocalVariableNode.createWriteLocalVariableNode(context, sourceSection, frameSlot, valueNode.accept(this));

// Recreate the arguments array, reading that local instead of including the RHS for the last argument
argChildNodes.add(new ReadLocalDummyNode(node.getPosition(), sourceSection, frameSlot));
Original file line number Diff line number Diff line change
@@ -258,7 +258,7 @@ public RubyNode visitKeywordRestArgNode(org.jruby.ast.KeywordRestArgNode node) {
final RubyNode readNode = new ReadKeywordRestArgumentNode(context, sourceSection, required, excludedKeywords.toArray(new String[excludedKeywords.size()]));
final FrameSlot slot = methodBodyTranslator.getEnvironment().getFrameDescriptor().findOrAddFrameSlot(node.getName());

return new WriteLocalVariableNode(context, sourceSection, slot, readNode);
return WriteLocalVariableNode.createWriteLocalVariableNode(context, sourceSection, slot, readNode);
}

@Override
@@ -294,7 +294,7 @@ public RubyNode visitKeywordArgNode(org.jruby.ast.KeywordArgNode node) {

final RubyNode readNode = new ReadKeywordArgumentNode(context, sourceSection, required, name, defaultValue);

return new WriteLocalVariableNode(context, sourceSection, slot, readNode);
return WriteLocalVariableNode.createWriteLocalVariableNode(context, sourceSection, slot, readNode);
}

@Override
@@ -303,7 +303,7 @@ public RubyNode visitArgumentNode(org.jruby.ast.ArgumentNode node) {

final RubyNode readNode = readArgument(sourceSection);
final FrameSlot slot = methodBodyTranslator.getEnvironment().getFrameDescriptor().findFrameSlot(node.getName());
return new WriteLocalVariableNode(context, sourceSection, slot, readNode);
return WriteLocalVariableNode.createWriteLocalVariableNode(context, sourceSection, slot, readNode);
}

private RubyNode readArgument(SourceSection sourceSection) {
@@ -339,7 +339,7 @@ public RubyNode visitRestArgNode(org.jruby.ast.RestArgNode node) {
}

final FrameSlot slot = methodBodyTranslator.getEnvironment().getFrameDescriptor().findFrameSlot(node.getName());
return new WriteLocalVariableNode(context, sourceSection, slot, readNode);
return WriteLocalVariableNode.createWriteLocalVariableNode(context, sourceSection, slot, readNode);
}

@Override
@@ -348,7 +348,7 @@ public RubyNode visitBlockArgNode(org.jruby.ast.BlockArgNode node) {

final RubyNode readNode = new ReadBlockNode(context.getCoreLibrary().getNilObject());
final FrameSlot slot = methodBodyTranslator.getEnvironment().getFrameDescriptor().findFrameSlot(node.getName());
return new WriteLocalVariableNode(context, sourceSection, slot, readNode);
return WriteLocalVariableNode.createWriteLocalVariableNode(context, sourceSection, slot, readNode);
}

@Override
@@ -440,7 +440,7 @@ private RubyNode translateLocalAssignment(ISourcePosition sourcePosition, String
readNode = ArraySliceNodeGen.create(context, sourceSection, index, indexFromEnd, loadArray(sourceSection));
}

return new WriteLocalVariableNode(context, sourceSection, slot, readNode);
return WriteLocalVariableNode.createWriteLocalVariableNode(context, sourceSection, slot, readNode);
}

@Override
@@ -582,7 +582,7 @@ public RubyNode visitMultipleAsgnNode(MultipleAsgnNode node) {

final RubyNode nil = sequence(context, sourceSection, nilSequence);

return sequence(context, sourceSection, Arrays.asList(new WriteLocalVariableNode(context, sourceSection,
return sequence(context, sourceSection, Arrays.asList(WriteLocalVariableNode.createWriteLocalVariableNode(context, sourceSection,
arraySlot, SplatCastNodeGen.create(context, sourceSection, SplatCastNode.NilBehavior.ARRAY_WITH_NIL, true,
readArgument(sourceSection))), new IfElseNode(context, sourceSection,
new IsNilNode(context, sourceSection, new ReadLocalVariableNode(context, sourceSection, LocalVariableType.FRAME_LOCAL, arraySlot)),
Original file line number Diff line number Diff line change
@@ -99,7 +99,7 @@ public BlockDefinitionNode compileBlockNode(SourceSection sourceSection, String
final RubyNode castArrayNode = ArrayCastNodeGen.create(context, sourceSection, readArrayNode);

final FrameSlot arraySlot = environment.declareVar(environment.allocateLocalTemp("destructure"));
final RubyNode writeArrayNode = new WriteLocalVariableNode(context, sourceSection, arraySlot, castArrayNode);
final RubyNode writeArrayNode = WriteLocalVariableNode.createWriteLocalVariableNode(context, sourceSection, arraySlot, castArrayNode);

final LoadArgumentsTranslator destructureArgumentsTranslator = new LoadArgumentsTranslator(currentNode, context, source, isProc, this);
destructureArgumentsTranslator.pushArraySlot(arraySlot);
Original file line number Diff line number Diff line change
@@ -190,7 +190,7 @@ public RubyRootNode parse(RubyContext context, Source source, Encoding defaultEn
final String name = argumentNames[n];
final RubyNode readNode = new ReadPreArgumentNode(n, MissingArgumentBehavior.NIL);
final FrameSlot slot = environment.getFrameDescriptor().findFrameSlot(name);
sequence.add(new WriteLocalVariableNode(context, sourceSection, slot, readNode));
sequence.add(WriteLocalVariableNode.createWriteLocalVariableNode(context, sourceSection, slot, readNode));
}

sequence.add(truffleNode);
Original file line number Diff line number Diff line change
@@ -9,7 +9,6 @@
*/
package org.jruby.truffle.tools.callgraph;

import com.oracle.truffle.api.nodes.RootNode;
import org.jruby.truffle.language.RubyRootNode;
import org.jruby.truffle.language.methods.SharedMethodInfo;