Skip to content

Commit

Permalink
Showing 6 changed files with 69 additions and 2 deletions.
1 change: 1 addition & 0 deletions core/src/main/java/org/jruby/util/cli/Options.java
Original file line number Diff line number Diff line change
@@ -305,6 +305,7 @@ public class Options {
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 final Option<Boolean> TRUFFLE_CHAOS = bool(TRUFFLE, "truffle.chaos", false, "Randomly modify the representation of objects.");

public static final Option<Boolean> TRUFFLE_GRAAL_WARNING_UNLESS = bool(TRUFFLE, "truffle.graal.warn_unless", true, "Warn unless the JVM has the Graal compiler.");
public static final Option<Boolean> TRUFFLE_PERF_WARNING = bool(TRUFFLE, "truffle.perf.warn", false, "Warn when using a fature which is not optimized yet.");
Original file line number Diff line number Diff line change
@@ -45,6 +45,7 @@
import org.jruby.truffle.language.objects.SingletonClassNode;
import org.jruby.truffle.language.parser.jruby.Translator;
import org.jruby.truffle.platform.UnsafeGroup;
import org.jruby.truffle.tools.ChaosNodeGen;
import org.jruby.truffle.util.StringUtils;

import java.util.ArrayList;
@@ -258,9 +259,13 @@ private static CallTarget makeGenericMethod(RubyContext context, MethodDetails m
node = transformResult(method, node);
}

final ExceptionTranslatingNode exceptionTranslatingNode = new ExceptionTranslatingNode(context, sourceSection, node, method.unsupportedOperationBehavior());
RubyNode bodyNode = new ExceptionTranslatingNode(context, sourceSection, node, method.unsupportedOperationBehavior());

final RubyRootNode rootNode = new RubyRootNode(context, sourceSection, null, sharedMethodInfo, exceptionTranslatingNode, false);
if (context.getOptions().CHAOS) {
bodyNode = ChaosNodeGen.create(bodyNode);
}

final RubyRootNode rootNode = new RubyRootNode(context, sourceSection, null, sharedMethodInfo, bodyNode, false);

return Truffle.getRuntime().createCallTarget(rootNode);
}
5 changes: 5 additions & 0 deletions truffle/src/main/java/org/jruby/truffle/language/Options.java
Original file line number Diff line number Diff line change
@@ -20,6 +20,7 @@
import static org.jruby.util.cli.Options.TRUFFLE_BIND_CACHE;
import static org.jruby.util.cli.Options.TRUFFLE_CALL_GRAPH;
import static org.jruby.util.cli.Options.TRUFFLE_CALL_GRAPH_WRITE;
import static org.jruby.util.cli.Options.TRUFFLE_CHAOS;
import static org.jruby.util.cli.Options.TRUFFLE_CLASS_CACHE;
import static org.jruby.util.cli.Options.TRUFFLE_CONSTANT_CACHE;
import static org.jruby.util.cli.Options.TRUFFLE_CORE_ALWAYS_CLONE;
@@ -161,4 +162,8 @@ public class Options {
public final boolean CALL_GRAPH = TRUFFLE_CALL_GRAPH.load();
public final String CALL_GRAPH_WRITE = TRUFFLE_CALL_GRAPH_WRITE.load();

// Other tools

public static boolean CHAOS = TRUFFLE_CHAOS.load();

}
Original file line number Diff line number Diff line change
@@ -166,6 +166,7 @@
import org.jruby.truffle.language.yield.YieldExpressionNode;
import org.jruby.truffle.platform.graal.AssertConstantNodeGen;
import org.jruby.truffle.platform.graal.AssertNotCompiledNodeGen;
import org.jruby.truffle.tools.ChaosNodeGen;
import org.jruby.truffle.util.StringUtils;
import org.jruby.util.ByteList;
import org.jruby.util.KeyValuePair;
@@ -954,6 +955,10 @@ private ModuleBodyDefinitionNode compileClassNode(SourceSection sourceSection, S
final WriteLocalVariableNode writeSelfNode = WriteLocalVariableNode.createWriteLocalVariableNode(context, null, selfSlot, new ProfileArgumentNode(new ReadSelfNode()));
body = sequence(context, sourceSection, Arrays.asList(writeSelfNode, body));

if (context.getOptions().CHAOS) {
body = ChaosNodeGen.create(body);
}

final RubyRootNode rootNode = new RubyRootNode(context, sourceSection, environment.getFrameDescriptor(), environment.getSharedMethodInfo(), body, environment.needsDeclarationFrame());

final ModuleBodyDefinitionNode definitionNode = new ModuleBodyDefinitionNode(
Original file line number Diff line number Diff line change
@@ -56,6 +56,8 @@
import org.jruby.truffle.language.supercall.ReadZSuperArgumentsNode;
import org.jruby.truffle.language.supercall.SuperCallNode;
import org.jruby.truffle.language.supercall.ZSuperOutsideMethodNode;
import org.jruby.truffle.tools.ChaosNodeGen;

import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Deque;
@@ -137,6 +139,10 @@ public BlockDefinitionNode compileBlockNode(SourceSection sourceSection, String
}

body = translateNodeOrNil(sourceSection, bodyNode);

if (context.getOptions().CHAOS) {
body = ChaosNodeGen.create(body);
}
} finally {
parentSourceSection.pop();
}
@@ -251,6 +257,11 @@ public RubyNode doCompileMethodBody(SourceSection sourceSection, String methodNa

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

if (context.getOptions().CHAOS) {
body = ChaosNodeGen.create(body);
}

return body;
}

40 changes: 40 additions & 0 deletions truffle/src/main/java/org/jruby/truffle/tools/ChaosNode.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* 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.tools;

import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.dsl.Fallback;
import com.oracle.truffle.api.dsl.NodeChild;
import com.oracle.truffle.api.dsl.Specialization;
import org.jruby.truffle.language.RubyNode;

import java.util.Random;

@NodeChild
public abstract class ChaosNode extends RubyNode {

private static final Random random = new Random(0);

@TruffleBoundary
@Specialization
public Object chaos(int value) {
if (random.nextBoolean()) {
return (long) value;
} else {
return value;
}
}

@Fallback
public Object chaos(Object value) {
return value;
}

}

0 comments on commit 1e1c594

Please sign in to comment.