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

Commits on Sep 27, 2016

  1. Copy the full SHA
    f20c60b View commit details
  2. Copy the full SHA
    a0e2b1f View commit details
  3. 4
    Copy the full SHA
    ffa06d3 View commit details
3 changes: 2 additions & 1 deletion truffle/src/main/java/org/jruby/truffle/RubyContext.java
Original file line number Diff line number Diff line change
@@ -68,7 +68,7 @@ public class RubyContext extends ExecutionContext {
private final Options options = new Options();
private final RopeTable ropeTable = new RopeTable();
private final PrimitiveManager primitiveManager = new PrimitiveManager();
private final JRubyInterop jrubyInterop = new JRubyInterop(this);
private final JRubyInterop jrubyInterop;
private final SafepointManager safepointManager = new SafepointManager(this);
private final SymbolTable symbolTable;
private final InteropManager interopManager = new InteropManager(this);
@@ -105,6 +105,7 @@ public RubyContext(Ruby jrubyRuntime, TruffleLanguage.Env env) {
latestInstance = this;

this.jrubyRuntime = jrubyRuntime;
this.jrubyInterop = new JRubyInterop(this, jrubyRuntime);
this.env = env;

if (options.CALL_GRAPH) {
52 changes: 45 additions & 7 deletions truffle/src/main/java/org/jruby/truffle/interop/JRubyInterop.java
Original file line number Diff line number Diff line change
@@ -11,22 +11,60 @@

import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.object.DynamicObject;

import org.jruby.Ruby;
import org.jruby.runtime.builtin.IRubyObject;
import org.jruby.truffle.RubyContext;
import org.jruby.truffle.language.RubyNode;
import org.jruby.truffle.language.control.JavaException;
import org.jruby.truffle.language.loader.SourceLoader;

import java.io.File;
import java.net.URISyntaxException;
import java.security.CodeSource;
import java.util.ArrayList;
import java.util.List;

public class JRubyInterop {

private RubyContext context;
private final Ruby jrubyRuntime;
private final RubyContext context;

private String originalInputFile;
private final String jrubyHome;

public JRubyInterop(RubyContext context) {
public JRubyInterop(RubyContext context, Ruby jrubyRuntime) {
this.context = context;
this.jrubyRuntime = jrubyRuntime;
this.jrubyHome = findJRubyHome();
}

public String getJRubyHome() {
return jrubyHome;
}

private String findJRubyHome() {
if (System.getenv("JRUBY_HOME") == null && System.getProperty("jruby.home") == null) {
// Set JRuby home automatically for GraalVM
final CodeSource codeSource = Ruby.class.getProtectionDomain().getCodeSource();
if (codeSource != null) {
final File currentJarFile;
try {
currentJarFile = new File(codeSource.getLocation().toURI());
} catch (URISyntaxException e) {
throw new JavaException(e);
}

if (currentJarFile.toString().endsWith("/ruby.jar")) {
String jarDir = currentJarFile.getParent();
if (new File(jarDir, "lib").isDirectory()) {
return jarDir;
}
}
}
}

return context.getJRubyRuntime().getJRubyHome();
}

@TruffleBoundary
@@ -43,11 +81,11 @@ public DynamicObject toTruffle(org.jruby.RubyException jrubyException, RubyNode

@TruffleBoundary
public String getArg0() {
return context.getJRubyRuntime().getGlobalVariables().get("$0").toString();
return jrubyRuntime.getGlobalVariables().get("$0").toString();
}

public String[] getArgv() {
final IRubyObject[] jrubyStrings = ((org.jruby.RubyArray) context.getJRubyRuntime().getObject().getConstant("ARGV")).toJavaArray();
final IRubyObject[] jrubyStrings = ((org.jruby.RubyArray) jrubyRuntime.getObject().getConstant("ARGV")).toJavaArray();
final String[] strings = new String[jrubyStrings.length];

for (int n = 0; n < strings.length; n++) {
@@ -60,7 +98,7 @@ public String[] getArgv() {
public String[] getOriginalLoadPath() {
final List<String> loadPath = new ArrayList<>();

for (IRubyObject path : ((org.jruby.RubyArray) context.getJRubyRuntime().getLoadService().getLoadPath()).toJavaArray()) {
for (IRubyObject path : ((org.jruby.RubyArray) jrubyRuntime.getLoadService().getLoadPath()).toJavaArray()) {
String pathString = path.toString();

if (!(pathString.endsWith("lib/ruby/2.2/site_ruby")
@@ -79,11 +117,11 @@ public String[] getOriginalLoadPath() {
}

public void setVerbose(boolean verbose) {
context.getJRubyRuntime().setVerbose(context.getJRubyRuntime().newBoolean(verbose));
jrubyRuntime.setVerbose(jrubyRuntime.newBoolean(verbose));
}

public void setVerboseNil() {
context.getJRubyRuntime().setVerbose(context.getJRubyRuntime().getNil());
jrubyRuntime.setVerbose(jrubyRuntime.getNil());
}

public void setOriginalInputFile(String originalInputFile) {
Original file line number Diff line number Diff line change
@@ -45,7 +45,7 @@ public abstract static class JRubyHomeDirectoryNode extends CoreMethodNode {
@TruffleBoundary
@Specialization
public DynamicObject jrubyHomeDirectory() {
return createString(StringOperations.encodeRope(getContext().getJRubyRuntime().getJRubyHome(), UTF8Encoding.INSTANCE));
return createString(StringOperations.encodeRope(getContext().getJRubyInterop().getJRubyHome(), UTF8Encoding.INSTANCE));
}

}
@@ -56,7 +56,7 @@ public abstract static class JRubyHomeDirectoryProtocolNode extends CoreMethodNo
@TruffleBoundary
@Specialization
public DynamicObject jrubyHomeDirectoryProtocol() {
String home = getContext().getJRubyRuntime().getJRubyHome();
String home = getContext().getJRubyInterop().getJRubyHome();

if (home.startsWith("uri:classloader:")) {
home = home.substring("uri:classloader:".length());
Original file line number Diff line number Diff line change
@@ -145,7 +145,7 @@ public void ensureCExtImplementationLoaded(VirtualFrame frame, IndirectCallNode

@TruffleBoundary
private CallTarget getCExtLibRuby() {
final String path = context.getJRubyRuntime().getJRubyHome() + "/lib/ruby/truffle/cext/ruby.su";
final String path = context.getJRubyInterop().getJRubyHome() + "/lib/ruby/truffle/cext/ruby.su";

if (!new File(path).exists()) {
throw new RaiseException(context.getCoreExceptions().internalError("This JRuby distribution does not have the C extension implementation file ruby.su", null));