Skip to content

Commit

Permalink
Showing 13 changed files with 60 additions and 28 deletions.
Original file line number Diff line number Diff line change
@@ -39,6 +39,8 @@

public class TruffleBridgeImpl implements TruffleBridge {

private static final boolean PRINT_RUNTIME = Options.TRUFFLE_PRINT_RUNTIME.load();

private final org.jruby.Ruby runtime;
private final RubyContext truffleContext;

@@ -54,7 +56,7 @@ public TruffleBridgeImpl(org.jruby.Ruby runtime) {

@Override
public void init() {
if (Options.TRUFFLE_PRINT_RUNTIME.load()) {
if (PRINT_RUNTIME) {
runtime.getInstanceConfig().getError().println("jruby: using " + Truffle.getRuntime().getName());
}

Original file line number Diff line number Diff line change
@@ -287,9 +287,9 @@ public abstract static class SendNode extends CoreMethodNode {
public SendNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);

dispatchNode = DispatchHeadNodeFactory.createMethodCall(context, true, Options.TRUFFLE_DISPATCH_METAPROGRAMMING_ALWAYS_INDIRECT.load(), MissingBehavior.CALL_METHOD_MISSING);
dispatchNode = DispatchHeadNodeFactory.createMethodCall(context, true, DispatchNode.DISPATCH_METAPROGRAMMING_ALWAYS_INDIRECT, MissingBehavior.CALL_METHOD_MISSING);

if (Options.TRUFFLE_DISPATCH_METAPROGRAMMING_ALWAYS_UNCACHED.load()) {
if (DispatchNode.DISPATCH_METAPROGRAMMING_ALWAYS_UNCACHED) {
dispatchNode.forceUncached();
}
}
Original file line number Diff line number Diff line change
@@ -1670,7 +1670,7 @@ public RespondToNode(RubyContext context, SourceSection sourceSection) {
dispatch = new DoesRespondDispatchHeadNode(context, false, false, MissingBehavior.RETURN_MISSING, null);
dispatchIgnoreVisibility = new DoesRespondDispatchHeadNode(context, true, false, MissingBehavior.RETURN_MISSING, null);

if (Options.TRUFFLE_DISPATCH_METAPROGRAMMING_ALWAYS_UNCACHED.load()) {
if (DispatchNode.DISPATCH_METAPROGRAMMING_ALWAYS_UNCACHED) {
dispatch.forceUncached();
dispatchIgnoreVisibility.forceUncached();
}
Original file line number Diff line number Diff line change
@@ -15,6 +15,7 @@
import com.oracle.truffle.api.nodes.DirectCallNode;
import com.oracle.truffle.api.nodes.IndirectCallNode;
import com.oracle.truffle.api.nodes.InvalidAssumptionException;

import org.jruby.truffle.runtime.RubyArguments;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.core.RubyBasicObject;
@@ -26,6 +27,9 @@

public class CachedBoxedMethodMissingDispatchNode extends CachedDispatchNode {

private static final boolean DISPATCH_METHODMISSING_ALWAYS_CLONED = Options.TRUFFLE_DISPATCH_METHODMISSING_ALWAYS_CLONED.load();
private static final boolean DISPATCH_METHODMISSING_ALWAYS_INLINED = Options.TRUFFLE_DISPATCH_METHODMISSING_ALWAYS_INLINED.load();

private final RubyClass expectedClass;
private final Assumption unmodifiedAssumption;
private final InternalMethod method;
@@ -59,13 +63,12 @@ public CachedBoxedMethodMissingDispatchNode(
*/

if (callNode.isCallTargetCloningAllowed()
&& (Options.TRUFFLE_DISPATCH_METHODMISSING_ALWAYS_CLONED.load()
|| method.getSharedMethodInfo().shouldAlwaysSplit())) {
&& (DISPATCH_METHODMISSING_ALWAYS_CLONED || method.getSharedMethodInfo().shouldAlwaysSplit())) {
insert(callNode);
callNode.cloneCallTarget();
}

if (callNode.isInlinable() && Options.TRUFFLE_DISPATCH_METHODMISSING_ALWAYS_INLINED.load()) {
if (callNode.isInlinable() && DISPATCH_METHODMISSING_ALWAYS_INLINED) {
insert(callNode);
callNode.forceInlining();
}
Original file line number Diff line number Diff line change
@@ -15,6 +15,7 @@
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.nodes.Node;
import com.oracle.truffle.api.nodes.NodeUtil;

import org.jruby.truffle.nodes.RubyNode;
import org.jruby.truffle.runtime.LexicalScope;
import org.jruby.truffle.runtime.ModuleOperations;
@@ -25,9 +26,14 @@
import org.jruby.truffle.runtime.core.RubyModule;
import org.jruby.truffle.runtime.core.RubyProc;
import org.jruby.truffle.runtime.methods.InternalMethod;
import org.jruby.util.cli.Options;

public abstract class DispatchNode extends RubyNode {

public static final int DISPATCH_POLYMORPHIC_MAX = Options.TRUFFLE_DISPATCH_POLYMORPHIC_MAX.load();
public static final boolean DISPATCH_METAPROGRAMMING_ALWAYS_UNCACHED = Options.TRUFFLE_DISPATCH_METAPROGRAMMING_ALWAYS_UNCACHED.load();
public static final boolean DISPATCH_METAPROGRAMMING_ALWAYS_INDIRECT = Options.TRUFFLE_DISPATCH_METAPROGRAMMING_ALWAYS_INDIRECT.load();

private final DispatchAction dispatchAction;

private static final class Missing {
Original file line number Diff line number Diff line change
@@ -12,6 +12,7 @@
import com.oracle.truffle.api.Assumption;
import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.frame.VirtualFrame;

import org.jruby.truffle.nodes.RubyNode;
import org.jruby.truffle.nodes.core.KernelNodes;
import org.jruby.truffle.nodes.core.KernelNodesFactory;
@@ -58,7 +59,7 @@ public Object executeDispatch(
Object argumentsObjects) {
CompilerDirectives.transferToInterpreterAndInvalidate();

if (depth == Options.TRUFFLE_DISPATCH_POLYMORPHIC_MAX.load()) {
if (depth == DISPATCH_POLYMORPHIC_MAX) {
return getHeadNode().getFirstDispatchNode()
.replace(new UncachedDispatchNode(getContext(), ignoreVisibility, getDispatchAction(), missingBehavior))
.executeDispatch(frame, receiverObject,
@@ -246,12 +247,12 @@ private DispatchNode createConstantMissingNode(
receiverObject.toString() + " didn't have a #const_missing", this));
}

if (Options.TRUFFLE_DISPATCH_METAPROGRAMMING_ALWAYS_UNCACHED.load()) {
if (DISPATCH_METAPROGRAMMING_ALWAYS_UNCACHED) {
return first.replace(new UncachedDispatchNode(getContext(), ignoreVisibility, getDispatchAction(), missingBehavior));
}

return first.replace(new CachedBoxedMethodMissingDispatchNode(getContext(), methodName, first,
receiverObject.getMetaClass(), method, Options.TRUFFLE_DISPATCH_METAPROGRAMMING_ALWAYS_INDIRECT.load(), getDispatchAction()));
receiverObject.getMetaClass(), method, DISPATCH_METAPROGRAMMING_ALWAYS_INDIRECT, getDispatchAction()));
}

default: {
@@ -279,12 +280,12 @@ private DispatchNode createMethodMissingNode(
receiverObject.toString() + " didn't have a #method_missing", this));
}

if (Options.TRUFFLE_DISPATCH_METAPROGRAMMING_ALWAYS_UNCACHED.load()) {
if (DISPATCH_METAPROGRAMMING_ALWAYS_UNCACHED) {
return first.replace(new UncachedDispatchNode(getContext(), ignoreVisibility, getDispatchAction(), missingBehavior));
}

return first.replace(new CachedBoxedMethodMissingDispatchNode(getContext(), methodName, first,
getContext().getCoreLibrary().getMetaClass(receiverObject), method, Options.TRUFFLE_DISPATCH_METAPROGRAMMING_ALWAYS_INDIRECT.load(), getDispatchAction()));
getContext().getCoreLibrary().getMetaClass(receiverObject), method, DISPATCH_METAPROGRAMMING_ALWAYS_INDIRECT, getDispatchAction()));
}

default: {
Original file line number Diff line number Diff line change
@@ -14,6 +14,7 @@
import com.oracle.truffle.api.nodes.DirectCallNode;
import com.oracle.truffle.api.nodes.NodeCost;
import com.oracle.truffle.api.nodes.NodeInfo;

import org.jruby.truffle.runtime.RubyArguments;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.core.RubyProc;
@@ -22,6 +23,9 @@
@NodeInfo(cost = NodeCost.POLYMORPHIC)
public class CachedYieldDispatchNode extends YieldDispatchNode {

private static final boolean INLINER_ALWAYS_CLONE_YIELD = Options.TRUFFLE_INLINER_ALWAYS_CLONE_YIELD.load();
private static final boolean INLINER_ALWAYS_INLINE_YIELD = Options.TRUFFLE_INLINER_ALWAYS_INLINE_YIELD.load();

@Child private DirectCallNode callNode;
@Child private YieldDispatchNode next;

@@ -31,11 +35,11 @@ public CachedYieldDispatchNode(RubyContext context, RubyProc block, YieldDispatc
callNode = Truffle.getRuntime().createDirectCallNode(block.getCallTargetForBlocks());
insert(callNode);

if (Options.TRUFFLE_INLINER_ALWAYS_CLONE_YIELD.load() && callNode.isCallTargetCloningAllowed()) {
if (INLINER_ALWAYS_CLONE_YIELD && callNode.isCallTargetCloningAllowed()) {
callNode.cloneCallTarget();
}

if (Options.TRUFFLE_INLINER_ALWAYS_INLINE_YIELD.load() && callNode.isInlinable()) {
if (INLINER_ALWAYS_INLINE_YIELD && callNode.isInlinable()) {
callNode.forceInlining();
}

Original file line number Diff line number Diff line change
@@ -14,6 +14,8 @@
import com.oracle.truffle.api.nodes.NodeCost;
import com.oracle.truffle.api.nodes.NodeInfo;
import com.oracle.truffle.api.nodes.NodeUtil;

import org.jruby.truffle.nodes.dispatch.DispatchNode;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.core.RubyProc;
import org.jruby.util.cli.Options;
@@ -33,7 +35,7 @@ public Object dispatch(VirtualFrame frame, RubyProc block, Object[] argumentsObj

depth++;

if (depth == Options.TRUFFLE_DISPATCH_POLYMORPHIC_MAX.load()) {
if (depth == DispatchNode.DISPATCH_POLYMORPHIC_MAX) {
final YieldDispatchHeadNode dispatchHead = (YieldDispatchHeadNode) NodeUtil.getNthParent(this, depth);
final GeneralYieldDispatchNode newGeneralYield = new GeneralYieldDispatchNode(getContext());
dispatchHead.getDispatch().replace(newGeneralYield);
@@ -51,7 +53,7 @@ public Object dispatchWithModifiedBlock(VirtualFrame frame, RubyProc block, Ruby

depth++;

if (depth == Options.TRUFFLE_DISPATCH_POLYMORPHIC_MAX.load()) {
if (depth == DispatchNode.DISPATCH_POLYMORPHIC_MAX) {
final YieldDispatchHeadNode dispatchHead = (YieldDispatchHeadNode) NodeUtil.getNthParent(this, depth);
final GeneralYieldDispatchNode newGeneralYield = new GeneralYieldDispatchNode(getContext());
dispatchHead.getDispatch().replace(newGeneralYield);
@@ -69,7 +71,7 @@ public Object dispatchWithModifiedSelf(VirtualFrame frame, RubyProc block, Objec

depth++;

if (depth == Options.TRUFFLE_DISPATCH_POLYMORPHIC_MAX.load()) {
if (depth == DispatchNode.DISPATCH_POLYMORPHIC_MAX) {
final YieldDispatchHeadNode dispatchHead = (YieldDispatchHeadNode) NodeUtil.getNthParent(this, depth);
final GeneralYieldDispatchNode newGeneralYield = new GeneralYieldDispatchNode(getContext());
dispatchHead.getDispatch().replace(newGeneralYield);
11 changes: 7 additions & 4 deletions truffle/src/main/java/org/jruby/truffle/runtime/RubyContext.java
Original file line number Diff line number Diff line change
@@ -17,8 +17,8 @@
import com.oracle.truffle.api.object.Shape;
import com.oracle.truffle.api.source.BytesDecoder;
import com.oracle.truffle.api.source.Source;

import com.oracle.truffle.api.tools.CoverageTracker;

import org.jcodings.Encoding;
import org.jcodings.specific.ASCIIEncoding;
import org.jcodings.specific.UTF8Encoding;
@@ -52,6 +52,9 @@
*/
public class RubyContext extends ExecutionContext {

private static final boolean TRUFFLE_COVERAGE = Options.TRUFFLE_COVERAGE.load();
private static final int INSTRUMENTATION_SERVER_PORT = Options.TRUFFLE_INSTRUMENTATION_SERVER_PORT.load();

private final Ruby runtime;
private final TranslatorDriver translator;
private final CoreLibrary coreLibrary;
@@ -96,7 +99,7 @@ public RubyContext(Ruby runtime) {

// TODO(CS, 28-Jan-15) this is global
// TODO(CS, 28-Jan-15) maybe not do this for core?
if (Options.TRUFFLE_COVERAGE.load()) {
if (TRUFFLE_COVERAGE) {
coverageTracker = new CoverageTracker();
} else {
coverageTracker = null;
@@ -130,8 +133,8 @@ public RubyContext(Ruby runtime) {

rubiniusPrimitiveManager = RubiniusPrimitiveManager.create();

if (Options.TRUFFLE_INSTRUMENTATION_SERVER_PORT.load() != 0) {
instrumentationServerManager = new InstrumentationServerManager(this, Options.TRUFFLE_INSTRUMENTATION_SERVER_PORT.load());
if (INSTRUMENTATION_SERVER_PORT != 0) {
instrumentationServerManager = new InstrumentationServerManager(this, INSTRUMENTATION_SERVER_PORT);
instrumentationServerManager.start();
} else {
instrumentationServerManager = null;
Original file line number Diff line number Diff line change
@@ -12,6 +12,7 @@
import com.oracle.truffle.api.frame.FrameDescriptor;
import com.oracle.truffle.api.frame.MaterializedFrame;
import com.oracle.truffle.api.source.SourceSection;

import org.jruby.truffle.nodes.CoreSourceSection;
import org.jruby.truffle.runtime.DebugOperations;
import org.jruby.truffle.runtime.RubyArguments;
@@ -25,6 +26,8 @@

public class DebugBacktraceFormatter implements BacktraceFormatter {

private static final int BACKTRACE_MAX_VALUE_LENGTH = Options.TRUFFLE_BACKTRACE_MAX_VALUE_LENGTH.load();

@Override
public String[] format(RubyContext context, RubyException exception, Backtrace backtrace) {
try {
@@ -98,10 +101,10 @@ public static String debugString(RubyContext context, Object value) {
try {
final String string = DebugOperations.inspect(context, value);

if (string.length() <= Options.TRUFFLE_BACKTRACE_MAX_VALUE_LENGTH.load()) {
if (string.length() <= BACKTRACE_MAX_VALUE_LENGTH) {
return string;
} else {
return string.substring(0, Options.TRUFFLE_BACKTRACE_MAX_VALUE_LENGTH.load()) + "…";
return string.substring(0, BACKTRACE_MAX_VALUE_LENGTH) + "…";
}
} catch (Throwable t) {
return "*error*";
Original file line number Diff line number Diff line change
@@ -49,6 +49,9 @@

public class CoreLibrary {

private static final boolean LOAD_CORE = Options.TRUFFLE_LOAD_CORE.load();
private static final String CLI_RECORD_SEPARATOR = Options.CLI_RECORD_SEPARATOR.load();

private final RubyContext context;

private final RubyClass argumentErrorClass;
@@ -376,7 +379,7 @@ private void initializeGlobalVariables() {
Object value = context.getRuntime().warningsEnabled() ? context.getRuntime().isVerbose() : nilObject;
globals.getOperations().setInstanceVariable(globals, "$VERBOSE", value);

final RubyString defaultRecordSeparator = RubyString.fromJavaString(stringClass, Options.CLI_RECORD_SEPARATOR.load());
final RubyString defaultRecordSeparator = RubyString.fromJavaString(stringClass, CLI_RECORD_SEPARATOR);
defaultRecordSeparator.freeze();

// TODO (nirvdrum 05-Feb-15) We need to support the $-0 alias as well.
@@ -470,7 +473,7 @@ public void initializeAfterMethodsAdded() {

// Load Ruby core

if (Options.TRUFFLE_LOAD_CORE.load()) {
if (LOAD_CORE) {
try {
loadRubyCore("core.rb");
} catch (RaiseException e) {
Original file line number Diff line number Diff line change
@@ -77,6 +77,8 @@
*/
public class BodyTranslator extends Translator {

private static final int PASS_A_LOT = Options.TRUFFLE_PASSALOT.load();

protected final BodyTranslator parent;
protected final TranslatorEnvironment environment;

@@ -2095,8 +2097,8 @@ public RubyNode visitNewlineNode(org.jruby.ast.NewlineNode node) {

final List<RubyNode> lineSequence = new ArrayList<>();

if (Options.TRUFFLE_PASSALOT.load() > 0) {
if (Options.TRUFFLE_PASSALOT.load() > Math.random() * 100) {
if (PASS_A_LOT > 0) {
if (PASS_A_LOT > Math.random() * 100) {
lineSequence.add(new ThreadPassNode(context, sourceSection));
}
}
Original file line number Diff line number Diff line change
@@ -12,6 +12,7 @@
import com.oracle.truffle.api.nodes.Node;
import com.oracle.truffle.api.source.Source;
import com.oracle.truffle.api.source.SourceSection;

import org.jruby.lexer.yacc.DetailedSourcePosition;
import org.jruby.lexer.yacc.InvalidSourcePosition;
import org.jruby.truffle.nodes.RubyNode;
@@ -24,6 +25,8 @@

public abstract class Translator extends org.jruby.ast.visitor.AbstractNodeVisitor<RubyNode> {

private static final boolean ALLOW_SIMPLE_SOURCE_SECTIONS = Options.TRUFFLE_ALLOW_SIMPLE_SOURCE_SECTIONS.load();

public static final Set<String> PRINT_AST_METHOD_NAMES = new HashSet<>(Arrays.asList(Options.TRUFFLE_TRANSLATOR_PRINT_AST.load().split(",")));
public static final Set<String> PRINT_FULL_AST_METHOD_NAMES = new HashSet<>(Arrays.asList(Options.TRUFFLE_TRANSLATOR_PRINT_FULL_AST.load().split(",")));
public static final Set<String> PRINT_PARSE_TREE_METHOD_NAMES = new HashSet<>(Arrays.asList(Options.TRUFFLE_TRANSLATOR_PRINT_PARSE_TREE.load().split(",")));
@@ -60,7 +63,7 @@ public SourceSection translate(Source source, org.jruby.lexer.yacc.ISourcePositi
// In some cases we still get bad offsets with the detailed source positions
return source.createSection(getIdentifier(), sourcePosition.getLine() + 1);
}
} else if (Options.TRUFFLE_ALLOW_SIMPLE_SOURCE_SECTIONS.load()) {
} else if (ALLOW_SIMPLE_SOURCE_SECTIONS) {
return source.createSection(getIdentifier(), sourcePosition.getLine() + 1);
} else {
throw new UnsupportedOperationException("Truffle needs detailed source positions unless you know what you are doing and set truffle.allow_simple_source_sections - got " + sourcePosition.getClass());

1 comment on commit 9cc74be

@chrisseaton
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good work.

Please sign in to comment.