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: ed3c45964877
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 4fd96c7f5912
Choose a head ref
  • 2 commits
  • 3 files changed
  • 1 contributor

Commits on Nov 7, 2016

  1. Copy the full SHA
    a823ff3 View commit details
  2. Copy the full SHA
    4fd96c7 View commit details
Showing with 38 additions and 3 deletions.
  1. +6 −3 mx.jruby/mx_jruby.py
  2. +30 −0 truffle/src/main/java/org/jruby/truffle/Main.java
  3. +2 −0 truffle/src/main/java/org/jruby/truffle/RubyEngine.java
9 changes: 6 additions & 3 deletions mx.jruby/mx_jruby.py
Original file line number Diff line number Diff line change
@@ -173,6 +173,7 @@ def extractArguments(cli_args):
classpath = []
print_command = False
classic = False
main_class = "org.jruby.Main"

jruby_opts = os.environ.get('JRUBY_OPTS')
if jruby_opts:
@@ -183,6 +184,8 @@ def extractArguments(cli_args):
arg = args.pop(0)
if arg == '-X+T':
pass # Just drop it
elif arg == '-X+TM':
main_class = "org.jruby.truffle.Main"
elif arg == '-Xclassic':
classic = True
elif arg == '-J-cmd':
@@ -208,7 +211,7 @@ def extractArguments(cli_args):
rubyArgs.append(arg)
rubyArgs.extend(args)
break
return vmArgs, rubyArgs, classpath, print_command, classic
return vmArgs, rubyArgs, classpath, print_command, classic, main_class

def extractTarball(file, target_dir):
if file.endswith('tar'):
@@ -241,7 +244,7 @@ def ruby_command(args):
java = os.getenv('JAVACMD', java_home + '/bin/java')
argv0 = java

vmArgs, rubyArgs, user_classpath, print_command, classic = extractArguments(args)
vmArgs, rubyArgs, user_classpath, print_command, classic, main_class = extractArguments(args)
classpath = mx.classpath(['TRUFFLE_API', 'RUBY']).split(':')
truffle_api, classpath = classpath[0], classpath[1:]
classpath += user_classpath
@@ -251,7 +254,7 @@ def ruby_command(args):
'-Xbootclasspath/a:' + truffle_api,
'-cp', ':'.join(classpath),
] + vmArgs
vmArgs = vmArgs + ['org.jruby.Main']
vmArgs = vmArgs + [main_class]
if not classic:
vmArgs = vmArgs + ['-X+T']
allArgs = vmArgs + rubyArgs
30 changes: 30 additions & 0 deletions truffle/src/main/java/org/jruby/truffle/Main.java
Original file line number Diff line number Diff line change
@@ -45,16 +45,20 @@
package org.jruby.truffle;

import org.jruby.RubyInstanceConfig;
import org.jruby.util.cli.Options;
import org.jruby.util.cli.OutputStrings;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.lang.management.ManagementFactory;

public class Main {

public static void main(String[] args) {
printTruffleTimeMetric("before-main");

final RubyInstanceConfig config = new RubyInstanceConfig();
config.setHardExit(true);
config.processArguments(args);
@@ -71,6 +75,7 @@ public static void main(String[] args) {

final RubyEngine rubyEngine = new RubyEngine(config);

printTruffleTimeMetric("before-run");
try {
if (in == null) {
exitCode = 1;
@@ -85,13 +90,16 @@ public static void main(String[] args) {
exitCode = rubyEngine.execute(filename);
}
} finally {
printTruffleTimeMetric("after-run");
rubyEngine.dispose();
}
} else {
doPrintUsage(config, false);
exitCode = 1;
}

printTruffleTimeMetric("after-main");
printTruffleMemoryMetric();
System.exit(exitCode);
}

@@ -150,4 +158,26 @@ private static boolean checkStreamSyntax(RubyEngine engine, InputStream in, Stri
return engine.checkSyntax(in, filename);
}

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());
}
}

}
2 changes: 2 additions & 0 deletions truffle/src/main/java/org/jruby/truffle/RubyEngine.java
Original file line number Diff line number Diff line change
@@ -29,7 +29,9 @@ public RubyEngine(RubyInstanceConfig instanceConfig) {
engine = PolyglotEngine.newBuilder()
.globalSymbol(JRubyTruffleInterface.RUNTIME_SYMBOL, new InstanceConfigWrapper(instanceConfig))
.build();
Main.printTruffleTimeMetric("before-load-context");
context = engine.eval(loadSource("Truffle::Boot.context", "context")).as(RubyContext.class);
Main.printTruffleTimeMetric("after-load-context");
}

public int execute(String path) {