Skip to content

Commit

Permalink
Merge branch 'truffle-head'
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisseaton committed Dec 9, 2016
2 parents 125315f + 78d4bc7 commit b3c3613
Show file tree
Hide file tree
Showing 370 changed files with 14,589 additions and 3,236 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -23,6 +23,7 @@ Makefile
cext-output.txt
bench-results.json
bench-results-processed.json
failures

.DS_Store
.debug.properties
Expand Down
7 changes: 2 additions & 5 deletions bin/jruby.bash
Expand Up @@ -251,10 +251,6 @@ do
-X+T)
USING_TRUFFLE="true"
;;
-X+TM)
USING_TRUFFLE="true"
java_class=$JAVA_CLASS_JRUBY_TRUFFLE_MAIN
;;
# Match -Xa.b.c=d to translate to -Da.b.c=d as a java option
-X*)
val=${1:2}
Expand Down Expand Up @@ -325,7 +321,8 @@ do
done

if [[ "$USING_TRUFFLE" != "" ]]; then
JRUBY_CP="$JRUBY_CP$CP_DELIMITER$JRUBY_HOME/lib/jruby-truffle.jar"
JRUBY_CP="$JRUBY_HOME/lib/jruby-truffle.jar"
java_class=$JAVA_CLASS_JRUBY_TRUFFLE_MAIN
ruby_args=("-X+T" "${ruby_args[@]}")
fi

Expand Down
4 changes: 0 additions & 4 deletions bin/jruby.sh
Expand Up @@ -200,10 +200,6 @@ do
echo "error: -X+T isn't supported in the shell launcher"
exit 1
;;
-X+TM)
echo "error: -X+TM isn't supported in the shell launcher"
exit 1
;;
-Xclassic)
;;
# Match -Xa.b.c=d to translate to -Da.b.c=d as a java option
Expand Down
134 changes: 12 additions & 122 deletions core/src/main/java/org/jruby/Main.java
Expand Up @@ -46,7 +46,6 @@
import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.builtin.IRubyObject;
import org.jruby.util.SafePropertyAccessor;
import org.jruby.util.cli.Options;
import org.jruby.util.cli.OutputStrings;
import org.jruby.util.log.Logger;
import org.jruby.util.log.LoggerFactory;
Expand All @@ -60,7 +59,6 @@
import java.io.PrintStream;
import java.lang.management.ManagementFactory;
import java.lang.management.RuntimeMXBean;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
Expand Down Expand Up @@ -192,8 +190,6 @@ public static class Status {
* @param args command-line args, provided by the JVM.
*/
public static void main(String[] args) {
printTruffleTimeMetric("before-main");

doGCJCheck();

Main main;
Expand All @@ -207,9 +203,6 @@ public static void main(String[] args) {
try {
Status status = main.run(args);

printTruffleTimeMetric("after-main");
printTruffleMemoryMetric();

if (status.isExit()) {
System.exit(status.getStatus());
}
Expand All @@ -221,19 +214,12 @@ public static void main(String[] args) {
System.exit( handleUnexpectedJump(ex) );
}
catch (Throwable t) {
// If a Truffle exception gets this far it's a hard failure - don't try and dress it up as a Ruby exception

if (main.isTruffle()) {
System.err.println("Truffle internal error: " + t);
t.printStackTrace(System.err);
} else {
// print out as a nice Ruby backtrace
System.err.println("Unhandled Java exception: " + t);
// print out as a nice Ruby backtrace
System.err.println("Unhandled Java exception: " + t);
System.err.println(ThreadContext.createRawBacktraceStringFromThrowable(t, false));
while ((t = t.getCause()) != null) {
System.err.println("Caused by:");
System.err.println(ThreadContext.createRawBacktraceStringFromThrowable(t, false));
while ((t = t.getCause()) != null) {
System.err.println("Caused by:");
System.err.println(ThreadContext.createRawBacktraceStringFromThrowable(t, false));
}
}

System.exit(1);
Expand Down Expand Up @@ -277,16 +263,12 @@ private Status internalRun() {

Ruby _runtime;

if (isTruffle()) {
_runtime = null;
if (DripMain.DRIP_RUNTIME != null) {
// use drip's runtime, reinitializing config
_runtime = DripMain.DRIP_RUNTIME;
_runtime.reinitialize(true);
} else {
if (DripMain.DRIP_RUNTIME != null) {
// use drip's runtime, reinitializing config
_runtime = DripMain.DRIP_RUNTIME;
_runtime.reinitialize(true);
} else {
_runtime = Ruby.newInstance(config);
}
_runtime = Ruby.newInstance(config);
}

final Ruby runtime = _runtime;
Expand Down Expand Up @@ -317,35 +299,10 @@ public void run() {
throw new MainExitException(1, "jruby: no Ruby script found in input (LoadError)");
} else if (config.getShouldCheckSyntax()) {
// check syntax only and exit
if (isTruffle()) {
final TruffleRubyEngineInterface truffle = loadTruffle();

try {
final int exitCode = truffle.doCheckSyntax(in, filename);
return new Status(exitCode);
} finally {
truffle.dispose();
}
} else {
return doCheckSyntax(runtime, in, filename);
}
return doCheckSyntax(runtime, in, filename);
} else {
// proceed to run the script
if (isTruffle()) {
final TruffleRubyEngineInterface truffle = loadTruffle();

printTruffleTimeMetric("before-run");

try {
final int exitCode = truffle.execute(filename);
return new Status(exitCode);
} finally {
printTruffleTimeMetric("after-run");
truffle.dispose();
}
} else {
return doRunFromMain(runtime, in, filename);
}
return doRunFromMain(runtime, in, filename);
}
} finally {
if (runtime != null && didTeardown.compareAndSet(false, true)) {
Expand Down Expand Up @@ -612,73 +569,6 @@ else if ( ex instanceof JumpException.FlowControlException ) {
return 2;
}

private boolean isTruffle() {
return config.getCompileMode().isTruffle();
}

private TruffleRubyEngineInterface loadTruffle() {
Main.printTruffleTimeMetric("before-load-context");

String javaVersion = System.getProperty("java.version");
String[] parts = javaVersion.split("\\D+");
int firstPart = Integer.valueOf(parts[0]);
if (!(firstPart >= 9 || Integer.valueOf(parts[1]) >= 8)) {
System.err.println("JRuby+Truffle needs Java 8 to run (found " + javaVersion + ").");
System.exit(1);
}

final Class<?> truffleRubyEngineClass;

try {
truffleRubyEngineClass = Class.forName("org.jruby.truffle.RubyEngine");
} catch (Exception e) {
throw new RuntimeException("JRuby's Truffle backend not available - either it was not compiled because JRuby was built with Java 7, or it has been removed", e);
}

final TruffleRubyEngineInterface truffleEngine;

try {
final Object truffleEngineInstance = truffleRubyEngineClass.getConstructor(RubyInstanceConfig.class).newInstance(config);

truffleEngine = (TruffleRubyEngineInterface) Proxy.newProxyInstance(getClass().getClassLoader(), new Class[]{TruffleRubyEngineInterface.class}, new InvocationHandler() {

@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
return truffleRubyEngineClass.getMethod(method.getName(), method.getParameterTypes()).invoke(truffleEngineInstance, args);
}

});
} catch (Exception e) {
throw new RuntimeException("Error while calling the constructor of Truffle's RubyContext", e);
}

Main.printTruffleTimeMetric("after-load-context");

return truffleEngine;
}

public static void printTruffleTimeMetric(String id) {
if (Options.TRUFFLE_METRICS_TIME.load()) {
final long millis = System.currentTimeMillis();
System.err.printf("%s %d.%03d%n", id, millis / 1000, millis % 1000);
}
}

private static void printTruffleMemoryMetric() {
if (Options.TRUFFLE_METRICS_MEMORY_USED_ON_EXIT.load()) {
for (int n = 0; n < 10; n++) {
System.gc();
}

try {
Thread.sleep(1000);
} catch (InterruptedException e) {
}

System.err.printf("allocated %d%n", ManagementFactory.getMemoryMXBean().getHeapMemoryUsage().getUsed());
}
}

private final RubyInstanceConfig config;
}

4 changes: 0 additions & 4 deletions core/src/main/java/org/jruby/Ruby.java
Expand Up @@ -233,10 +233,6 @@ public final class Ruby implements Constantizable {
* @see org.jruby.RubyInstanceConfig
*/
private Ruby(RubyInstanceConfig config) {
if (config.getCompileMode().isTruffle()) {
throw new UnsupportedOperationException("Truffle isn't supported using a classic context - use PolyglotEngine instead.");
}

this.config = config;
this.threadService = new ThreadService(this);

Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/RubyFile.java
Expand Up @@ -657,7 +657,7 @@ public static IRubyObject dirname(ThreadContext context, IRubyObject recv, IRuby
return runtime.newString(dirname(context, jfilename)).infectBy(filename);
}

static Pattern PROTOCOL_PATTERN = Pattern.compile(URI_PREFIX_STRING + ".*");
public static Pattern PROTOCOL_PATTERN = Pattern.compile(URI_PREFIX_STRING + ".*");
public static String dirname(ThreadContext context, String jfilename) {
final Ruby runtime = context.runtime;
final String separator = runtime.getClass("File").getConstant("SEPARATOR").toString();
Expand Down
5 changes: 1 addition & 4 deletions core/src/main/java/org/jruby/RubyInstanceConfig.java
Expand Up @@ -1640,7 +1640,7 @@ public enum ProfilingMode {
}

public enum CompileMode {
JIT, FORCE, OFF, TRUFFLE;
JIT, FORCE, OFF;

public boolean shouldPrecompileCLI() {
return this == JIT || this == FORCE;
Expand All @@ -1654,9 +1654,6 @@ public boolean shouldPrecompileAll() {
return this == FORCE;
}

public boolean isTruffle() {
return this == TRUFFLE;
}
}

////////////////////////////////////////////////////////////////////////////
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/ast/IterNode.java
Expand Up @@ -48,7 +48,7 @@ public class IterNode extends Node implements DefNode {
private StaticScope scope;

/**
* Used by Truffle 'for' and by ForNode only.
* Used by ForNode only.
* This is to support 1.8-style assignments which only 'for' expressions use.
*/
public IterNode(ISourcePosition position, Node args, StaticScope scope, Node body) {
Expand Down
3 changes: 1 addition & 2 deletions core/src/main/java/org/jruby/common/IRubyWarnings.java
Expand Up @@ -99,8 +99,7 @@ public enum ID {
GC_STRESS_UNIMPLEMENTED,
GC_ENABLE_UNIMPLEMENTED,
GC_DISABLE_UNIMPLEMENTED,
TRUFFLE,
RATIONAL_OUT_OF_RANGE,; // TODO(CS): divide up the Truffle warnings
RATIONAL_OUT_OF_RANGE,;

public String getID() {
return name();
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/org/jruby/lexer/yacc/RubyLexer.java
Expand Up @@ -655,7 +655,7 @@ private int hereDocumentIdentifier() throws IOException {
}

private boolean arg_ambiguous() {
if (warnings.isVerbose() && Options.PARSER_WARN_AMBIGUOUS_ARGUMENTS.load() && !ParserSupport.skipTruffleRubiniusWarnings(this)) {
if (warnings.isVerbose() && Options.PARSER_WARN_AMBIGUOUS_ARGUMENTS.load()) {
warnings.warning(ID.AMBIGUOUS_ARGUMENT, getPosition(), "Ambiguous first argument; make sure.");
}
return true;
Expand Down Expand Up @@ -1976,7 +1976,7 @@ private int star(boolean spaceSeen) throws IOException {
default:
pushback(c);
if (isSpaceArg(c, spaceSeen)) {
if (warnings.isVerbose() && Options.PARSER_WARN_ARGUMENT_PREFIX.load() && !ParserSupport.skipTruffleRubiniusWarnings(this))
if (warnings.isVerbose() && Options.PARSER_WARN_ARGUMENT_PREFIX.load())
warnings.warning(ID.ARGUMENT_AS_PREFIX, getPosition(), "`*' interpreted as argument prefix");
c = Tokens.tSTAR;
} else if (isBEG()) {
Expand Down
5 changes: 1 addition & 4 deletions core/src/main/java/org/jruby/parser/ParserSupport.java
Expand Up @@ -1219,7 +1219,7 @@ public String shadowing_lvar(String name) {
if (current.exists(name) >= 0) yyerror("duplicated argument name");

if (current.isBlockScope() && warnings.isVerbose() && current.isDefined(name) >= 0 &&
Options.PARSER_WARN_LOCAL_SHADOWING.load() && !ParserSupport.skipTruffleRubiniusWarnings(lexer)) {
Options.PARSER_WARN_LOCAL_SHADOWING.load()) {
warnings.warning(ID.STATEMENT_NOT_REACHED, lexer.getPosition(), "shadowing outer local variable - " + name);
}

Expand Down Expand Up @@ -1478,7 +1478,4 @@ public String internalId() {
return "";
}

public static boolean skipTruffleRubiniusWarnings(RubyLexer lexer) {
return lexer.getFile().startsWith(Options.TRUFFLE_CORE_LOAD_PATH.load());
}
}
9 changes: 3 additions & 6 deletions core/src/main/java/org/jruby/util/cli/ArgumentProcessor.java
Expand Up @@ -401,11 +401,8 @@ private void processArgument() {
config.setCompileMode(RubyInstanceConfig.CompileMode.FORCE);
} else if (extendedOption.equals("classic")) {
throw new MainExitException(0, "jruby: the -Xclassic option should have been handled in the launcher");
} else if (extendedOption.equals("+T") || extendedOption.equals("+TM")) {
Options.PARSER_WARN_GROUPED_EXPRESSIONS.force(Boolean.FALSE.toString());
config.setCompileMode(RubyInstanceConfig.CompileMode.TRUFFLE);
// Make the static option consistent with the compile mode.
Options.COMPILE_MODE.force("TRUFFLE");
} else if (extendedOption.equals("+T")) {
throw new MainExitException(0, "jruby: you need to use the Truffle main to use Truffle - this should have been handled in the launcher");
} else if (extendedOption.endsWith("...")) {
Options.listPrefix(extendedOption.substring(0, extendedOption.length() - "...".length()));
config.setShouldRunInterpreter(false);
Expand Down Expand Up @@ -778,7 +775,7 @@ private String grabOptionalValue() {

private static void checkProperties() {
for (String propertyName : System.getProperties().stringPropertyNames()) {
if (propertyName.startsWith("jruby.")) {
if (propertyName.startsWith("jruby.") && !propertyName.startsWith("jruby.truffle.")) {
if (!isPropertySupported(propertyName)) {
System.err.println("jruby: warning: unknown property " + propertyName);
}
Expand Down
1 change: 0 additions & 1 deletion core/src/main/java/org/jruby/util/cli/Category.java
Expand Up @@ -38,7 +38,6 @@ public enum Category {
INVOKEDYNAMIC("invokedynamic"),
JIT("jit"),
IR("intermediate representation"),
TRUFFLE("truffle"),
NATIVE("native"),
THREADPOOL("thread pooling"),
MISCELLANEOUS("miscellaneous"),
Expand Down

0 comments on commit b3c3613

Please sign in to comment.