Skip to content

Commit

Permalink
[Truffle] Remove the Truffle compile mode.
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisseaton committed Dec 9, 2016
1 parent 80cc7f1 commit 9a9e7d5
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 185 deletions.
157 changes: 12 additions & 145 deletions core/src/main/java/org/jruby/Main.java
Expand Up @@ -190,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 @@ -205,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 @@ -219,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 @@ -275,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 @@ -315,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 @@ -610,98 +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(
String.class,
String[].class,
String[].class,
byte[].class,
String[].class,
String.class,
boolean.class,
int.class,
boolean.class,
boolean.class,
String.class,
String.class)
.newInstance(
config.getJRubyHome(),
config.getLoadPaths().toArray(new String[]{}),
config.getRequiredLibraries().toArray(new String[]{}),
config.inlineScript(),
config.getArgv(),
config.displayedFileName(),
config.isDebug(),
config.getVerbosity().ordinal(),
config.isFrozenStringLiteral(),
config.isDisableGems(),
config.getInternalEncoding(),
config.getExternalEncoding());

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 (Boolean.getBoolean("jruby.truffle.metrics.time")) {
final long millis = System.currentTimeMillis();
System.err.printf("%s %d.%03d%n", id, millis / 1000, millis % 1000);
}
}

private static void printTruffleMemoryMetric() {
if (Boolean.getBoolean("jruby.truffle.metrics.memory_used_on_exit")) {
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 @@ -238,10 +238,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
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
22 changes: 0 additions & 22 deletions core/src/main/java/org/jruby/TruffleRubyEngineInterface.java

This file was deleted.

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
5 changes: 1 addition & 4 deletions core/src/main/java/org/jruby/util/cli/ArgumentProcessor.java
Expand Up @@ -402,10 +402,7 @@ private void processArgument() {
} 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")) {
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");
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
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
3 changes: 1 addition & 2 deletions core/src/main/java/org/jruby/util/cli/OutputStrings.java
Expand Up @@ -119,8 +119,7 @@ public static String getPropertyHelp() {

public static String getVersionString() {
return String.format(
"jruby%s %s (%s) %s %s %s %s on %s%s%s [%s-%s]",
Options.COMPILE_MODE.load().isTruffle() ? "+truffle" : "",
"jruby %s (%s) %s %s %s %s on %s%s%s [%s-%s]",
Constants.VERSION,
Constants.RUBY_VERSION,
Constants.COMPILE_DATE,
Expand Down

0 comments on commit 9a9e7d5

Please sign in to comment.