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: 92e4062db513
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 260e182323ae
Choose a head ref
  • 6 commits
  • 20 files changed
  • 1 contributor

Commits on Feb 10, 2015

  1. 1
    Copy the full SHA
    3d59f20 View commit details
  2. [Truffle] Remove RubyProc's declaringModule.

    * Not used anymore and we can get the current method to achieve
      RubyCallStack.getCurrentDeclaringModule().
    eregon committed Feb 10, 2015
    Copy the full SHA
    cb4c63d View commit details
  3. Copy the full SHA
    76e9453 View commit details
  4. [Truffle] The frame method as well as RubyProc's method are now alway…

    …s InternalMethod.
    
    * Only used by super and Module.nesting which are not interested in RubyProc.
    * For backtrace, this is done separetely with the call nodes,
      so there is no influence from this change.
    eregon committed Feb 10, 2015
    2
    Copy the full SHA
    bbcf625 View commit details
  5. [Truffle] Clarify comment.

    eregon committed Feb 10, 2015
    Copy the full SHA
    fff7a6c View commit details
  6. Copy the full SHA
    260e182 View commit details
Showing with 69 additions and 152 deletions.
  1. +1 −1 truffle/src/main/java/org/jruby/truffle/nodes/cast/LambdaNode.java
  2. +1 −1 truffle/src/main/java/org/jruby/truffle/nodes/control/TraceNode.java
  3. +6 −19 truffle/src/main/java/org/jruby/truffle/nodes/core/ArrayNodes.java
  4. +4 −4 truffle/src/main/java/org/jruby/truffle/nodes/core/KernelNodes.java
  5. +1 −2 truffle/src/main/java/org/jruby/truffle/nodes/core/ModuleNodes.java
  6. +1 −2 truffle/src/main/java/org/jruby/truffle/nodes/core/ProcNodes.java
  7. +7 −15 truffle/src/main/java/org/jruby/truffle/nodes/methods/BlockDefinitionNode.java
  8. +0 −1 truffle/src/main/java/org/jruby/truffle/nodes/supercall/AbstractGeneralSuperCallNode.java
  9. +3 −3 truffle/src/main/java/org/jruby/truffle/nodes/yield/CachedYieldDispatchNode.java
  10. +6 −3 truffle/src/main/java/org/jruby/truffle/nodes/yield/GeneralYieldDispatchNode.java
  11. +4 −6 truffle/src/main/java/org/jruby/truffle/runtime/RubyArguments.java
  12. +8 −41 truffle/src/main/java/org/jruby/truffle/runtime/RubyCallStack.java
  13. +6 −2 truffle/src/main/java/org/jruby/truffle/runtime/RubyContext.java
  14. +1 −12 truffle/src/main/java/org/jruby/truffle/runtime/backtrace/ImplementationDebugBacktraceFormatter.java
  15. +12 −16 truffle/src/main/java/org/jruby/truffle/runtime/core/RubyProc.java
  16. +1 −1 truffle/src/main/java/org/jruby/truffle/runtime/core/RubySymbol.java
  17. +4 −3 truffle/src/main/java/org/jruby/truffle/runtime/methods/InternalMethod.java
  18. +0 −19 truffle/src/main/java/org/jruby/truffle/runtime/methods/MethodLike.java
  19. +1 −1 truffle/src/main/java/org/jruby/truffle/translator/BodyTranslator.java
  20. +2 −0 truffle/src/main/java/org/jruby/truffle/translator/TranslatorDriver.java
Original file line number Diff line number Diff line change
@@ -38,7 +38,7 @@ public Object execute(VirtualFrame frame) {

return new RubyProc(getContext().getCoreLibrary().getProcClass(), RubyProc.Type.LAMBDA,
method.getSharedMethodInfo(), method.getCallTarget(), method.getCallTarget(), method.getCallTarget(),
method.getDeclarationFrame(), method.getDeclaringModule(), method, RubyArguments.getSelf(frame.getArguments()), null);
method.getDeclarationFrame(), method, RubyArguments.getSelf(frame.getArguments()), null);
}

@Override
Original file line number Diff line number Diff line change
@@ -83,7 +83,7 @@ public void trace(VirtualFrame frame) {
};

try {
callNode.call(frame, RubyArguments.pack(traceFunc, traceFunc.getDeclarationFrame(), traceFunc.getSelfCapturedInScope(), traceFunc.getBlockCapturedInScope(), args));
callNode.call(frame, RubyArguments.pack(traceFunc.getMethod(), traceFunc.getDeclarationFrame(), traceFunc.getSelfCapturedInScope(), traceFunc.getBlockCapturedInScope(), args));
} finally {
context.getTraceManager().setInTraceFunc(false);
}
25 changes: 6 additions & 19 deletions truffle/src/main/java/org/jruby/truffle/nodes/core/ArrayNodes.java
Original file line number Diff line number Diff line change
@@ -44,7 +44,6 @@
import org.jruby.truffle.runtime.core.RubyRange;
import org.jruby.truffle.runtime.core.RubyString;
import org.jruby.truffle.runtime.core.RubySymbol;
import org.jruby.truffle.runtime.methods.MethodLike;
import org.jruby.truffle.runtime.methods.SharedMethodInfo;
import org.jruby.truffle.runtime.util.ArrayUtils;
import org.jruby.util.ByteList;
@@ -1736,12 +1735,12 @@ public Object max(VirtualFrame frame, RubyArray array) {

final Memo<Object> maximum = new Memo<>();

final VirtualFrame maximumClosureFrame = Truffle.getRuntime().createVirtualFrame(RubyArguments.pack(maxBlock, null, array, null, new Object[]{}), maxBlock.getFrameDescriptor());
final VirtualFrame maximumClosureFrame = Truffle.getRuntime().createVirtualFrame(RubyArguments.pack(null, null, array, null, new Object[] {}), maxBlock.getFrameDescriptor());
maximumClosureFrame.setObject(maxBlock.getFrameSlot(), maximum);

final RubyProc block = new RubyProc(getContext().getCoreLibrary().getProcClass(), RubyProc.Type.PROC,
maxBlock.getSharedMethodInfo(), maxBlock.getCallTarget(), maxBlock.getCallTarget(),
maxBlock.getCallTarget(), maximumClosureFrame.materialize(), null, null, array, null);
maxBlock.getCallTarget(), maximumClosureFrame.materialize(), null, array, null);

eachNode.call(frame, array, "each", block);

@@ -1785,7 +1784,7 @@ public RubyNilClass max(VirtualFrame frame, Object maximumObject, Object value)

}

public static class MaxBlock implements MethodLike {
public static class MaxBlock {

private final FrameDescriptor frameDescriptor;
private final FrameSlot frameSlot;
@@ -1816,16 +1815,10 @@ public FrameSlot getFrameSlot() {
return frameSlot;
}

@Override
public SharedMethodInfo getSharedMethodInfo() {
return sharedMethodInfo;
}

@Override
public RubyModule getDeclaringModule() {
throw new UnsupportedOperationException();
}

public CallTarget getCallTarget() {
return callTarget;
}
@@ -1855,12 +1848,12 @@ public Object min(VirtualFrame frame, RubyArray array) {

final Memo<Object> minimum = new Memo<>();

final VirtualFrame minimumClosureFrame = Truffle.getRuntime().createVirtualFrame(RubyArguments.pack(minBlock, null, array, null, new Object[]{}), minBlock.getFrameDescriptor());
final VirtualFrame minimumClosureFrame = Truffle.getRuntime().createVirtualFrame(RubyArguments.pack(null, null, array, null, new Object[] {}), minBlock.getFrameDescriptor());
minimumClosureFrame.setObject(minBlock.getFrameSlot(), minimum);

final RubyProc block = new RubyProc(getContext().getCoreLibrary().getProcClass(), RubyProc.Type.PROC,
minBlock.getSharedMethodInfo(), minBlock.getCallTarget(), minBlock.getCallTarget(),
minBlock.getCallTarget(), minimumClosureFrame.materialize(), null, null, array, null);
minBlock.getCallTarget(), minimumClosureFrame.materialize(), null, array, null);

eachNode.call(frame, array, "each", block);

@@ -1904,7 +1897,7 @@ public RubyNilClass min(VirtualFrame frame, Object minimumObject, Object value)

}

public static class MinBlock implements MethodLike {
public static class MinBlock {

private final FrameDescriptor frameDescriptor;
private final FrameSlot frameSlot;
@@ -1935,16 +1928,10 @@ public FrameSlot getFrameSlot() {
return frameSlot;
}

@Override
public SharedMethodInfo getSharedMethodInfo() {
return sharedMethodInfo;
}

@Override
public RubyModule getDeclaringModule() {
throw new UnsupportedOperationException();
}

public CallTarget getCallTarget() {
return callTarget;
}
Original file line number Diff line number Diff line change
@@ -1166,8 +1166,8 @@ public RubyProc proc(RubyProc block) {

return new RubyProc(getContext().getCoreLibrary().getProcClass(), RubyProc.Type.LAMBDA,
block.getSharedMethodInfo(), block.getCallTargetForMethods(), block.getCallTargetForMethods(),
block.getCallTargetForMethods(), block.getDeclarationFrame(), block.getDeclaringModule(),
block.getMethod(), block.getSelfCapturedInScope(), block.getBlockCapturedInScope());
block.getCallTargetForMethods(), block.getDeclarationFrame(), block.getMethod(),
block.getSelfCapturedInScope(), block.getBlockCapturedInScope());
}
}

@@ -1455,8 +1455,8 @@ public RubyProc proc(RubyProc block) {

return new RubyProc(getContext().getCoreLibrary().getProcClass(), RubyProc.Type.PROC,
block.getSharedMethodInfo(), block.getCallTargetForProcs(), block.getCallTargetForProcs(),
block.getCallTargetForMethods(), block.getDeclarationFrame(), block.getDeclaringModule(),
block.getMethod(), block.getSelfCapturedInScope(), block.getBlockCapturedInScope());
block.getCallTargetForMethods(), block.getDeclarationFrame(), block.getMethod(),
block.getSelfCapturedInScope(), block.getBlockCapturedInScope());
}
}

Original file line number Diff line number Diff line change
@@ -40,7 +40,6 @@
import org.jruby.truffle.runtime.core.*;
import org.jruby.truffle.runtime.methods.Arity;
import org.jruby.truffle.runtime.methods.InternalMethod;
import org.jruby.truffle.runtime.methods.MethodLike;
import org.jruby.truffle.runtime.methods.SharedMethodInfo;
import org.jruby.truffle.translator.NodeWrapper;
import org.jruby.truffle.translator.TranslatorDriver;
@@ -1026,7 +1025,7 @@ public RubyArray nesting() {

final List<RubyModule> modules = new ArrayList<>();

MethodLike method = RubyCallStack.getCallingMethod();
InternalMethod method = RubyCallStack.getCallingMethod();
LexicalScope lexicalScope = method == null ? null : method.getSharedMethodInfo().getLexicalScope();
RubyClass object = getContext().getCoreLibrary().getObjectClass();

Original file line number Diff line number Diff line change
@@ -112,8 +112,7 @@ public InitializeNode(InitializeNode prev) {
public RubyNilClass initialize(RubyProc proc, RubyProc block) {
proc.initialize(block.getSharedMethodInfo(), block.getCallTargetForProcs(),
block.getCallTargetForProcs(), block.getCallTargetForMethods(), block.getDeclarationFrame(),
block.getDeclaringModule(), block.getMethod(), block.getSelfCapturedInScope(),
block.getBlockCapturedInScope());
block.getMethod(), block.getSelfCapturedInScope(), block.getBlockCapturedInScope());

return getContext().getCoreLibrary().getNilObject();
}
Original file line number Diff line number Diff line change
@@ -18,12 +18,12 @@
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.core.RubyModule;
import org.jruby.truffle.runtime.core.RubyProc;
import org.jruby.truffle.runtime.methods.MethodLike;
import org.jruby.truffle.runtime.methods.SharedMethodInfo;

/**
* Define a block. That is, store the definition of a block and when executed produce the executable
* object that results.
* Create a RubyProc to pass as a block to the called method.
* The literal block is represented as call targets and a SharedMethodInfo.
* This is executed at the call site just before dispatch.
*/
public class BlockDefinitionNode extends RubyNode {

@@ -62,19 +62,11 @@ public Object execute(VirtualFrame frame) {
declarationFrame = null;
}

final MethodLike methodLike = RubyArguments.getMethod(frame.getArguments());

final RubyModule declaringModule;

if (methodLike == null) {
declaringModule = null;
} else {
declaringModule = methodLike.getDeclaringModule();
}

return new RubyProc(getContext().getCoreLibrary().getProcClass(), RubyProc.Type.PROC, sharedMethodInfo,
callTargetForBlocks, callTargetForProcs, callTargetForMethods, declarationFrame, declaringModule,
RubyArguments.getMethod(frame.getArguments()), RubyArguments.getSelf(frame.getArguments()),
callTargetForBlocks, callTargetForProcs, callTargetForMethods,
declarationFrame,
RubyArguments.getMethod(frame.getArguments()),
RubyArguments.getSelf(frame.getArguments()),
RubyArguments.getBlock(frame.getArguments()));
}

Original file line number Diff line number Diff line change
@@ -65,7 +65,6 @@ private void lookup(VirtualFrame frame, boolean checkIfDefined) {
currentMethod = RubyCallStack.getCurrentMethod();

String name = currentMethod.getName();
// TODO: this is wrong, we need the lexically enclosing method (or define_method)'s module
RubyModule declaringModule = currentMethod.getDeclaringModule();

selfMetaClass = getContext().getCoreLibrary().getMetaClass(RubyArguments.getSelf(frame.getArguments()));
Original file line number Diff line number Diff line change
@@ -48,7 +48,7 @@ public Object dispatch(VirtualFrame frame, RubyProc block, Object[] argumentsObj
return next.dispatch(frame, block, argumentsObjects);
}

return callNode.call(frame, RubyArguments.pack(block, block.getDeclarationFrame(), block.getSelfCapturedInScope(), block.getBlockCapturedInScope(), argumentsObjects));
return callNode.call(frame, RubyArguments.pack(block.getMethod(), block.getDeclarationFrame(), block.getSelfCapturedInScope(), block.getBlockCapturedInScope(), argumentsObjects));
}

@Override
@@ -57,7 +57,7 @@ public Object dispatchWithModifiedBlock(VirtualFrame frame, RubyProc block, Ruby
return next.dispatch(frame, block, argumentsObjects);
}

return callNode.call(frame, RubyArguments.pack(block, block.getDeclarationFrame(), block.getSelfCapturedInScope(), modifiedBlock, argumentsObjects));
return callNode.call(frame, RubyArguments.pack(block.getMethod(), block.getDeclarationFrame(), block.getSelfCapturedInScope(), modifiedBlock, argumentsObjects));
}

@Override
@@ -66,7 +66,7 @@ public Object dispatchWithModifiedSelf(VirtualFrame frame, RubyProc block, Objec
return next.dispatchWithModifiedSelf(frame, block, self, argumentsObjects);
}

return callNode.call(frame, RubyArguments.pack(block, block.getDeclarationFrame(), self, block.getBlockCapturedInScope(), argumentsObjects));
return callNode.call(frame, RubyArguments.pack(block.getMethod(), block.getDeclarationFrame(), self, block.getBlockCapturedInScope(), argumentsObjects));
}

@Override
Original file line number Diff line number Diff line change
@@ -30,17 +30,20 @@ public GeneralYieldDispatchNode(RubyContext context) {

@Override
public Object dispatch(VirtualFrame frame, RubyProc block, Object[] argumentsObjects) {
return callNode.call(frame, block.getCallTargetForBlocks(), RubyArguments.pack(block, block.getDeclarationFrame(), block.getSelfCapturedInScope(), block.getBlockCapturedInScope(), argumentsObjects));
return callNode.call(frame, block.getCallTargetForBlocks(),
RubyArguments.pack(block.getMethod(), block.getDeclarationFrame(), block.getSelfCapturedInScope(), block.getBlockCapturedInScope(), argumentsObjects));
}

@Override
public Object dispatchWithModifiedBlock(VirtualFrame frame, RubyProc block, RubyProc modifiedBlock, Object[] argumentsObjects) {
return callNode.call(frame, block.getCallTargetForBlocks(), RubyArguments.pack(block, block.getDeclarationFrame(), block.getSelfCapturedInScope(), modifiedBlock, argumentsObjects));
return callNode.call(frame, block.getCallTargetForBlocks(),
RubyArguments.pack(block.getMethod(), block.getDeclarationFrame(), block.getSelfCapturedInScope(), modifiedBlock, argumentsObjects));
}

@Override
public Object dispatchWithModifiedSelf(VirtualFrame frame, RubyProc block, Object self, Object... argumentsObjects) {
return callNode.call(frame, block.getCallTargetForBlocks(), RubyArguments.pack(block, block.getDeclarationFrame(), self, block.getBlockCapturedInScope(), argumentsObjects));
return callNode.call(frame, block.getCallTargetForBlocks(),
RubyArguments.pack(block.getMethod(), block.getDeclarationFrame(), self, block.getBlockCapturedInScope(), argumentsObjects));
}

}
Original file line number Diff line number Diff line change
@@ -15,11 +15,9 @@

import org.jruby.truffle.runtime.core.RubyHash;
import org.jruby.truffle.runtime.core.RubyProc;
import org.jruby.truffle.runtime.methods.MethodLike;
import org.jruby.truffle.runtime.methods.InternalMethod;
import org.jruby.truffle.runtime.util.ArrayUtils;

import java.util.Arrays;

/**
* Pack and unpack Ruby method arguments to and from an array of objects.
*/
@@ -31,7 +29,7 @@ public final class RubyArguments {
public static final int BLOCK_INDEX = 3;
public static final int RUNTIME_ARGUMENT_COUNT = 4;

public static Object[] pack(MethodLike method, MaterializedFrame declarationFrame, Object self, RubyProc block, Object[] arguments) {
public static Object[] pack(InternalMethod method, MaterializedFrame declarationFrame, Object self, RubyProc block, Object[] arguments) {
final Object[] packed = new Object[arguments.length + RUNTIME_ARGUMENT_COUNT];

packed[METHOD_INDEX] = method;
@@ -43,8 +41,8 @@ public static Object[] pack(MethodLike method, MaterializedFrame declarationFram
return packed;
}

public static MethodLike getMethod(Object[] arguments) {
return (MethodLike) arguments[METHOD_INDEX];
public static InternalMethod getMethod(Object[] arguments) {
return (InternalMethod) arguments[METHOD_INDEX];
}

public static Object getSelf(Object[] arguments) {
49 changes: 8 additions & 41 deletions truffle/src/main/java/org/jruby/truffle/runtime/RubyCallStack.java
Original file line number Diff line number Diff line change
@@ -18,61 +18,32 @@
import org.jruby.truffle.nodes.CoreSourceSection;
import org.jruby.truffle.runtime.backtrace.Activation;
import org.jruby.truffle.runtime.backtrace.Backtrace;
import org.jruby.truffle.runtime.core.RubyModule;
import org.jruby.truffle.runtime.core.RubyProc;
import org.jruby.truffle.runtime.methods.InternalMethod;
import org.jruby.truffle.runtime.methods.MethodLike;
import org.jruby.util.Memo;
import org.jruby.util.cli.Options;

import java.util.ArrayList;

public abstract class RubyCallStack {

/** Called "cref" in MRI. */
public static RubyModule getCurrentDeclaringModule() {
final FrameInstance currentFrame = Truffle.getRuntime().getCurrentFrame();
final MethodLike method = getMethod(currentFrame);
return method.getDeclaringModule();
}

public static InternalMethod getCurrentMethod() {
final FrameInstance currentFrame = Truffle.getRuntime().getCurrentFrame();
MethodLike methodLike = getMethod(currentFrame);
while (!(methodLike instanceof InternalMethod)) {
methodLike = ((RubyProc) methodLike).getMethod();
}
return (InternalMethod) methodLike;
return getMethod(currentFrame);
}

public static InternalMethod getCallingMethod() {
CompilerAsserts.neverPartOfCompilation();

final Memo<Boolean> seenCurrent = new Memo<Boolean>();

MethodLike method;

final FrameInstance currentFrame = Truffle.getRuntime().getCurrentFrame();

method = getMethod(currentFrame);

if (method instanceof InternalMethod) {
seenCurrent.set(true);
}
final InternalMethod currentMethod = getCurrentMethod();

return Truffle.getRuntime().iterateFrames(new FrameInstanceVisitor<InternalMethod>() {

@Override
public InternalMethod visitFrame(FrameInstance frameInstance) {
final MethodLike maybeMethod = getMethod(frameInstance);

if (maybeMethod instanceof InternalMethod) {
if (seenCurrent.get()) {
return (InternalMethod) maybeMethod;
} else {
seenCurrent.set(true);
return null;
}
final InternalMethod method = getMethod(frameInstance);
assert method != null;

if (method != currentMethod) {
return method;
} else {
return null;
}
@@ -81,13 +52,9 @@ public InternalMethod visitFrame(FrameInstance frameInstance) {
});
}

public static MethodLike getMethod(FrameInstance frame) {
public static InternalMethod getMethod(FrameInstance frame) {
CompilerAsserts.neverPartOfCompilation();

if (frame == null) {
return null;
}

return RubyArguments.getMethod(frame.getFrame(FrameInstance.FrameAccess.READ_ONLY, true).getArguments());
}

Original file line number Diff line number Diff line change
@@ -28,6 +28,8 @@
import org.jruby.truffle.nodes.rubinius.RubiniusPrimitiveManager;
import org.jruby.truffle.runtime.control.RaiseException;
import org.jruby.truffle.runtime.core.*;
import org.jruby.truffle.runtime.methods.InternalMethod;
import org.jruby.truffle.runtime.methods.SharedMethodInfo;
import org.jruby.truffle.runtime.subsystems.*;
import org.jruby.truffle.runtime.util.FileUtils;
import org.jruby.truffle.translator.NodeWrapper;
@@ -212,8 +214,10 @@ public Object execute(RubyContext context, Source source, Encoding defaultEncodi
final RubyRootNode rootNode = translator.parse(context, source, defaultEncoding, parserContext, parentFrame, ownScopeForAssignments, currentNode, wrapper);
final CallTarget callTarget = Truffle.getRuntime().createCallTarget(rootNode);

// TODO(CS): we really need a method here - it's causing problems elsewhere
return callTarget.call(RubyArguments.pack(null, parentFrame, self, null, new Object[]{}));
final InternalMethod method = new InternalMethod(rootNode.getSharedMethodInfo(), rootNode.getSharedMethodInfo().getName(),
getCoreLibrary().getObjectClass(), Visibility.PUBLIC, false, callTarget, parentFrame);

return callTarget.call(RubyArguments.pack(method, parentFrame, self, null, new Object[] {}));
}

public long getNextObjectID() {
Loading