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: b20f3ff4b695
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: af7aa6d1a937
Choose a head ref
  • 13 commits
  • 10 files changed
  • 3 contributors

Commits on Aug 27, 2015

  1. Copy the full SHA
    73224a3 View commit details
  2. Copy the full SHA
    77673b3 View commit details
  3. Copy the full SHA
    4d40c03 View commit details
  4. Copy the full SHA
    fbaa433 View commit details
  5. Merge pull request #3291 from bbelleville/canonical-filename

    [Truffle] Canonicalize input file name
    eregon committed Aug 27, 2015
    Copy the full SHA
    76c950b View commit details
  6. Copy the full SHA
    8470c9c View commit details
  7. Copy the full SHA
    d2357f3 View commit details
  8. Copy the full SHA
    c9712e8 View commit details
  9. [Truffle] Nice FoundBug.

    eregon committed Aug 27, 2015
    Copy the full SHA
    39eaddc View commit details

Commits on Aug 28, 2015

  1. Merge pull request #3290 from bbelleville/minimal-lazy

    [Truffle] Allow for lazy parsing
    eregon committed Aug 28, 2015
    Copy the full SHA
    677c3f6 View commit details
  2. Copy the full SHA
    65fdc64 View commit details
  3. Merge branch 'master' into truffle-head

    Conflicts:
    	truffle/src/main/java/org/jruby/truffle/nodes/core/ProcNodes.java
    chrisseaton committed Aug 28, 2015
    Copy the full SHA
    346a201 View commit details
  4. Copy the full SHA
    af7aa6d View commit details
2 changes: 1 addition & 1 deletion truffle/pom.rb
Original file line number Diff line number Diff line change
@@ -15,7 +15,7 @@
repository( :url => 'http://lafo.ssw.uni-linz.ac.at/nexus/content/repositories/snapshots/',
:id => 'truffle' )

truffle_version = 'f84a7663966da606b7e63b3f28a2db834894297b-SNAPSHOT'
truffle_version = '2482183730b8eb3b0cfd38ab10cf76991526c159-SNAPSHOT'
jar 'com.oracle.truffle:truffle-api:' + truffle_version
jar 'com.oracle.truffle:truffle-dsl-processor:' + truffle_version, :scope => 'provided'
jar 'com.oracle.truffle:truffle-tck:' + truffle_version, :scope => 'test'
6 changes: 3 additions & 3 deletions truffle/pom.xml
Original file line number Diff line number Diff line change
@@ -31,18 +31,18 @@ DO NOT MODIFIY - GENERATED CODE
<dependency>
<groupId>com.oracle.truffle</groupId>
<artifactId>truffle-api</artifactId>
<version>f84a7663966da606b7e63b3f28a2db834894297b-SNAPSHOT</version>
<version>2482183730b8eb3b0cfd38ab10cf76991526c159-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.oracle.truffle</groupId>
<artifactId>truffle-dsl-processor</artifactId>
<version>f84a7663966da606b7e63b3f28a2db834894297b-SNAPSHOT</version>
<version>2482183730b8eb3b0cfd38ab10cf76991526c159-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.oracle.truffle</groupId>
<artifactId>truffle-tck</artifactId>
<version>f84a7663966da606b7e63b3f28a2db834894297b-SNAPSHOT</version>
<version>2482183730b8eb3b0cfd38ab10cf76991526c159-SNAPSHOT</version>
<scope>test</scope>
</dependency>
<dependency>
10 changes: 10 additions & 0 deletions truffle/src/main/java/org/jruby/truffle/nodes/core/ProcNodes.java
Original file line number Diff line number Diff line change
@@ -19,7 +19,9 @@
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.object.DynamicObject;
import com.oracle.truffle.api.object.DynamicObjectFactory;
import com.oracle.truffle.api.object.Shape;
import com.oracle.truffle.api.source.SourceSection;

import org.jcodings.specific.UTF8Encoding;
import org.jruby.RubyString;
import org.jruby.ast.ArgsNode;
@@ -97,6 +99,9 @@ public abstract static class ProcNewNode extends CoreMethodArrayArgumentsNode {
@Child private CallDispatchHeadNode initializeNode;
@Child private AllocateObjectNode allocateObjectNode;

protected final DynamicObject PROC_CLASS = getContext().getCoreLibrary().getProcClass();
protected final Shape PROC_SHAPE = getContext().getCoreLibrary().getProcFactory().getShape();

public ProcNewNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
initializeNode = DispatchHeadNodeFactory.createMethodCallOnSelf(context);
@@ -118,6 +123,11 @@ public DynamicObject proc(VirtualFrame frame, DynamicObject procClass, Object[]
return executeProcNew(frame, procClass, args, parentBlock);
}

@Specialization(guards = { "procClass == PROC_CLASS", "block.getShape() == PROC_SHAPE" })
public DynamicObject procNormalOptimized(DynamicObject procClass, Object[] args, DynamicObject block) {
return block;
}

@Specialization(guards = "procClass == metaClass(block)")
public DynamicObject procNormal(DynamicObject procClass, Object[] args, DynamicObject block) {
return block;
Original file line number Diff line number Diff line change
@@ -25,7 +25,6 @@
import org.jruby.truffle.runtime.signal.Signal;
import org.jruby.truffle.runtime.signal.SignalOperations;

@SuppressWarnings("restriction")
@CoreClass(name = "Process")
public abstract class ProcessNodes {

Original file line number Diff line number Diff line change
@@ -382,7 +382,6 @@ public DynamicObject times() {

}

@SuppressWarnings("restriction")
@RubiniusPrimitive(name = "vm_watch_signal", needsSelf = false)
public static abstract class VMWatchSignalPrimitiveNode extends RubiniusPrimitiveNode {

@@ -397,23 +396,20 @@ public boolean watchSignal(DynamicObject signalName, DynamicObject action) {
}

Signal signal = new Signal(signalName.toString());

SignalOperations.watchDefaultForSignal(signal);
return true;
}

@Specialization(guards = {"isRubyString(signalName)", "isNil(nil)"})
public boolean watchSignal(DynamicObject signalName, Object nil) {
Signal signal = new Signal(signalName.toString());

SignalOperations.watchSignal(signal, SignalOperations.IGNORE_HANDLER);
return true;
}

@Specialization(guards = {"isRubyString(signalName)", "isRubyProc(proc)"})
public boolean watchSignalProc(DynamicObject signalName, DynamicObject proc) {
Signal signal = new Signal(signalName.toString());

SignalOperations.watchSignal(signal, new ProcSignalHandler(getContext(), proc));
return true;
}
Original file line number Diff line number Diff line change
@@ -635,13 +635,12 @@ public Object execute(final org.jruby.ast.RootNode rootNode) {

String inputFile = rootNode.getPosition().getFile();

if (!inputFile.equals("-e")) {
inputFile = new File(inputFile).getAbsolutePath();
}

final Source source;

try {
if (!inputFile.equals("-e")) {
inputFile = new File(inputFile).getCanonicalPath();
}
source = sourceCache.getSource(inputFile);
} catch (IOException e) {
throw new RuntimeException(e);
Original file line number Diff line number Diff line change
@@ -17,7 +17,6 @@
import org.jruby.truffle.runtime.layouts.Layouts;
import org.jruby.truffle.runtime.subsystems.SafepointAction;

@SuppressWarnings("restriction")
public class ProcSignalHandler implements SignalHandler {

private final RubyContext context;
50 changes: 20 additions & 30 deletions truffle/src/main/java/org/jruby/truffle/runtime/signal/Signal.java
Original file line number Diff line number Diff line change
@@ -9,53 +9,43 @@
*/
package org.jruby.truffle.runtime.signal;

import java.util.Map;
import java.util.WeakHashMap;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

@SuppressWarnings("restriction")
public class Signal {

private final sun.misc.Signal signal;
private final sun.misc.Signal sunSignal;

private final static Map<sun.misc.SignalHandler, SignalHandler> handlers = new WeakHashMap<>();
private static final ConcurrentMap<sun.misc.Signal, sun.misc.SignalHandler> DEFAULT_HANDLERS = new ConcurrentHashMap<sun.misc.Signal, sun.misc.SignalHandler>();

public Signal(String name) {
signal = new sun.misc.Signal(name);
sunSignal = new sun.misc.Signal(name);
}

public static SignalHandler handle(final Signal signal, final SignalHandler newHandler) {
final sun.misc.SignalHandler wrappedNewHandler = new sun.misc.SignalHandler() {
public static void handle(final Signal signal, final SignalHandler newHandler) {
final sun.misc.SignalHandler oldSunHandler = sun.misc.Signal.handle(signal.sunSignal, wrapHandler(signal, newHandler));
DEFAULT_HANDLERS.putIfAbsent(signal.sunSignal, oldSunHandler);
}

public static void handleDefault(final Signal signal) {
final sun.misc.SignalHandler defaultHandler = DEFAULT_HANDLERS.get(signal.sunSignal);
if (defaultHandler != null) { // otherwise it is already the default signal
sun.misc.Signal.handle(signal.sunSignal, defaultHandler);
}
}

private static sun.misc.SignalHandler wrapHandler(final Signal signal, final SignalHandler newHandler) {
return new sun.misc.SignalHandler() {
@Override
public void handle(sun.misc.Signal wrappedSignal) {
newHandler.handle(signal);
}

};

synchronized (handlers) {
handlers.put(wrappedNewHandler, newHandler);

final sun.misc.SignalHandler oldWrappedHandler = sun.misc.Signal.handle(signal.signal, wrappedNewHandler);

SignalHandler oldHandler = handlers.getOrDefault(oldWrappedHandler, null);

if (oldHandler == null) {
oldHandler = new SignalHandler() {
@Override
public void handle(Signal signal) {
oldWrappedHandler.handle(signal.signal);
}
};

handlers.put(oldWrappedHandler, oldHandler);
}

return oldHandler;
}
}

public static void raise(Signal signal) {
sun.misc.Signal.raise(signal.signal);
sun.misc.Signal.raise(signal.sunSignal);
}

}
Original file line number Diff line number Diff line change
@@ -9,17 +9,12 @@
*/
package org.jruby.truffle.runtime.signal;

import org.jruby.RubySignal;

import java.util.Collections;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

@SuppressWarnings("restriction")
public class SignalOperations {
import org.jruby.RubySignal;

private static final ConcurrentMap<Signal, SignalHandler> ORIGINAL_HANDLERS = new ConcurrentHashMap<Signal, SignalHandler>();
public class SignalOperations {

public static final Map<String, Integer> SIGNALS_LIST = Collections.unmodifiableMap(RubySignal.list());

@@ -31,15 +26,11 @@ public void handle(Signal arg0) {
};

public static void watchSignal(Signal signal, SignalHandler newHandler) {
SignalHandler oldHandler = Signal.handle(signal, newHandler);
ORIGINAL_HANDLERS.putIfAbsent(signal, oldHandler);
Signal.handle(signal, newHandler);
}

public static void watchDefaultForSignal(Signal signal) {
SignalHandler defaultHandler = ORIGINAL_HANDLERS.get(signal);
if (defaultHandler != null) {
Signal.handle(signal, defaultHandler);
}
Signal.handleDefault(signal);
}

public static void raise(Signal signal) {
Original file line number Diff line number Diff line change
@@ -9,6 +9,9 @@
*/
package org.jruby.truffle.translator;

import java.util.ArrayDeque;
import java.util.Deque;

import com.oracle.truffle.api.CallTarget;
import com.oracle.truffle.api.Truffle;
import com.oracle.truffle.api.frame.FrameSlot;
@@ -34,11 +37,12 @@
import org.jruby.truffle.nodes.supercall.GeneralSuperCallNode;
import org.jruby.truffle.nodes.supercall.GeneralSuperReCallNode;
import org.jruby.truffle.nodes.supercall.ZSuperOutsideMethodNode;
import org.jruby.truffle.runtime.LexicalScope;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.methods.Arity;
import org.jruby.truffle.runtime.methods.SharedMethodInfo;

class MethodTranslator extends BodyTranslator {
public class MethodTranslator extends BodyTranslator {

private final org.jruby.ast.ArgsNode argsNode;
private boolean isBlock;
@@ -156,7 +160,16 @@ private RubyNode wrapBody(RubyNode prelude, RubyNode body) {
return body;
}

public MethodDefinitionNode compileMethodNode(SourceSection sourceSection, String methodName, org.jruby.ast.Node bodyNode, SharedMethodInfo sharedMethodInfo) {
/*
* This method exists solely to be substituted to support lazy
* method parsing. The substitution returns a node which performs
* the parsing lazily and then calls doCompileMethodBody.
*/
public RubyNode compileMethodBody(SourceSection sourceSection, String methodName, org.jruby.ast.Node bodyNode, SharedMethodInfo sharedMethodInfo) {
return doCompileMethodBody(sourceSection, methodName, bodyNode, sharedMethodInfo);
}

public RubyNode doCompileMethodBody(SourceSection sourceSection, String methodName, org.jruby.ast.Node bodyNode, SharedMethodInfo sharedMethodInfo) {
final ParameterCollector parameterCollector = declareArguments(sourceSection, methodName, sharedMethodInfo);
final Arity arity = getArity(argsNode);

@@ -194,7 +207,11 @@ public MethodDefinitionNode compileMethodNode(SourceSection sourceSection, Strin

// TODO(CS, 10-Jan-15) why do we only translate exceptions in methods and not blocks?
body = new ExceptionTranslatingNode(context, sourceSection, body);
return body;
}

public MethodDefinitionNode compileMethodNode(SourceSection sourceSection, String methodName, org.jruby.ast.Node bodyNode, SharedMethodInfo sharedMethodInfo) {
final RubyNode body = compileMethodBody(sourceSection, methodName, bodyNode, sharedMethodInfo);
final RubyRootNode rootNode = new RubyRootNode(
context, sourceSection, environment.getFrameDescriptor(), environment.getSharedMethodInfo(), body, environment.needsDeclarationFrame());

@@ -322,4 +339,29 @@ protected FlipFlopStateNode createFlipFlopState(SourceSection sourceSection, int
}
}

/*
* The following methods allow us to save and restore enough of
* the current state of the Translator to allow lazy parsing. When
* the lazy parsing is actually performed, the state is restored
* to what it would have been if the method had been parsed
* eagerly.
*/
public TranslatorState getCurrentState() {
return new TranslatorState(getEnvironment().getLexicalScope(), new ArrayDeque<SourceSection>(parentSourceSection));
}

public void restoreState(TranslatorState state) {
this.getEnvironment().getParseEnvironment().resetLexicalScope(state.scope);
this.parentSourceSection = state.parentSourceSection;
}

public static class TranslatorState {
private final LexicalScope scope;
private final Deque<SourceSection> parentSourceSection;

private TranslatorState(LexicalScope scope, Deque<SourceSection> parentSourceSection) {
this.scope = scope;
this.parentSourceSection = parentSourceSection;
}
}
}