Skip to content

Commit

Permalink
Showing 316 changed files with 3,812 additions and 1,965 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -78,6 +78,8 @@ matrix:
jdk: oraclejdk8
- env: COMMAND=test/truffle/integration-tests.sh
jdk: oraclejdk8
allow_failures:
- env: PHASE='-Prake -Dtask=test:mri:fullint'
# NOTE: build seems to never start (waited for any to finish for more than a day) - probably a travis-ci bug
#- env: PHASE='-Pmain'
# sudo: required
15 changes: 15 additions & 0 deletions bin/jruby.bash
Original file line number Diff line number Diff line change
@@ -229,6 +229,21 @@ do
CP="$CP$CP_DELIMITER$2"
CLASSPATH=""
shift
elif [ "${val:0:3}" = "-G:" ]; then # Graal options
opt=${val:3}
case $opt in
+*)
opt="${opt:1}=true" ;;
-*)
opt="${opt:1}=false" ;;
esac
java_args=("${java_args[@]}" "-Djvmci.option.$opt")
elif [ "${val:0:15}" = "-Djvmci.option." ]; then # Graal options
opt=${val:15}
java_args=("${java_args[@]}" "-Djvmci.option.$opt")
elif [ "${val:0:15}" = "-Dgraal.option." ]; then # Graal options
opt=${val:15}
java_args=("${java_args[@]}" "-Djvmci.option.$opt")
else
if [ "${val:0:3}" = "-ea" ]; then
VERIFY_JRUBY="yes"
Original file line number Diff line number Diff line change
@@ -9,18 +9,12 @@
*/
package org.jruby;

public interface TruffleContextInterface {
public interface JRubyTruffleInterface {

enum BacktraceFormatter {
MRI,
DEBUG,
IMPL_DEBUG
}

void initialize();
String RUNTIME_SYMBOL = "org.jruby.truffle.runtime";

Object execute(org.jruby.ast.RootNode rootNode);

void shutdown();
void dispose();

}
30 changes: 16 additions & 14 deletions core/src/main/java/org/jruby/Ruby.java
Original file line number Diff line number Diff line change
@@ -367,10 +367,6 @@ public static boolean isGlobalRuntimeReady() {
return globalRuntime != null;
}

public static boolean isSubstrateVM() {
return false;
}

/**
* Set the global runtime to the given runtime only if it has no been set.
*
@@ -843,7 +839,7 @@ public IRubyObject runInterpreter(ThreadContext context, Node rootNode, IRubyObj
if (getInstanceConfig().getCompileMode() == CompileMode.TRUFFLE) {
assert rootNode instanceof RootNode;
assert self == getTopSelf();
final TruffleContextInterface truffleContext = getTruffleContext();
final JRubyTruffleInterface truffleContext = getTruffleContext();
Main.printTruffleTimeMetric("before-run");
truffleContext.execute((RootNode) rootNode);
Main.printTruffleTimeMetric("after-run");
@@ -884,42 +880,48 @@ public JITCompiler getJITCompiler() {
return jitCompiler;
}

public TruffleContextInterface getTruffleContext() {
public JRubyTruffleInterface getTruffleContext() {
synchronized (truffleContextMonitor) {
if (truffleContext == null) {
truffleContext = loadTruffleContext();
truffleContext = loadTruffle();
}
return truffleContext;
}
}

private TruffleContextInterface loadTruffleContext() {
private JRubyTruffleInterface loadTruffle() {
Main.printTruffleTimeMetric("before-load-truffle-context");

final Class<?> clazz;

try {
clazz = getJRubyClassLoader().loadClass("org.jruby.truffle.runtime.RubyContext");
clazz = getJRubyClassLoader().loadClass("org.jruby.truffle.JRubyTruffleImpl");
} catch (Exception e) {
throw new RuntimeException("Truffle backend not available", e);
}

final TruffleContextInterface truffleContext;
final JRubyTruffleInterface truffleContext;

try {
Constructor<?> con = clazz.getConstructor(Ruby.class);
truffleContext = (TruffleContextInterface) con.newInstance(this);
truffleContext = (JRubyTruffleInterface) con.newInstance(this);
} catch (Exception e) {
throw new RuntimeException("Error while calling the constructor of Truffle's RubyContext", e);
}

truffleContext.initialize();

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

return truffleContext;
}

public void shutdownTruffleContextIfRunning() {
synchronized (truffleContextMonitor) {
if (truffleContext != null) {
truffleContext.dispose();
}
}
}

/**
* @deprecated use #newInstance()
*/
@@ -4959,7 +4961,7 @@ public FilenoUtil getFilenoUtil() {
// Compilation
private final JITCompiler jitCompiler;

private TruffleContextInterface truffleContext;
private JRubyTruffleInterface truffleContext;
private final Object truffleContextMonitor = new Object();

// Note: this field and the following static initializer
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/RubyInstanceConfig.java
Original file line number Diff line number Diff line change
@@ -1861,7 +1861,7 @@ private static int initGlobalJavaVersion() {
return Opcodes.V1_5;
} else if (specVersion.equals("1.6")) {
return Opcodes.V1_6;
} else if (specVersion.equals("1.7") || specVersion.equals("1.8") || specVersion.equals("1.9")) {
} else if (specVersion.equals("1.7") || specVersion.equals("1.8") || specVersion.equals("1.9") || specVersion.equals("9")) {
return Opcodes.V1_7;
} else {
System.err.println("unsupported Java version \"" + specVersion + "\", defaulting to 1.5");
136 changes: 128 additions & 8 deletions core/src/main/java/org/jruby/ext/socket/RubyUNIXSocket.java
Original file line number Diff line number Diff line change
@@ -36,10 +36,15 @@
import jnr.unixsocket.UnixServerSocketChannel;
import jnr.unixsocket.UnixSocketAddress;
import jnr.unixsocket.UnixSocketChannel;
import jnr.posix.CmsgHdr;
import jnr.posix.MsgHdr;
import jnr.posix.POSIX;
import org.jruby.Ruby;
import org.jruby.RubyClass;
import org.jruby.RubyNumeric;
import org.jruby.RubyString;
import org.jruby.RubyIO;
import org.jruby.RubyFixnum;
import org.jruby.anno.JRubyClass;
import org.jruby.anno.JRubyMethod;
import org.jruby.runtime.Helpers;
@@ -49,10 +54,14 @@
import org.jruby.runtime.builtin.IRubyObject;
import org.jruby.util.ByteList;
import org.jruby.util.io.ModeFlags;
import org.jruby.util.io.OpenFile;
import org.jruby.util.io.FilenoUtil;

import java.io.File;
import java.io.IOException;
import java.nio.channels.Channel;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;


@JRubyClass(name="UNIXSocket", parent="BasicSocket")
@@ -74,6 +83,18 @@ public RubyUNIXSocket(Ruby runtime, RubyClass type) {
super(runtime, type);
}

@JRubyMethod(meta = true)
public static IRubyObject for_fd(ThreadContext context, IRubyObject recv, IRubyObject _fileno) {
Ruby runtime = context.runtime;
int fileno = (int)_fileno.convertToInteger().getLongValue();

RubyClass klass = (RubyClass)recv;
RubyUNIXSocket unixSocket = (RubyUNIXSocket)(Helpers.invoke(context, klass, "allocate"));
UnixSocketChannel channel = UnixSocketChannel.fromFD(fileno);
unixSocket.init_sock(runtime, channel);
return unixSocket;
}

@JRubyMethod(visibility = Visibility.PRIVATE)
public IRubyObject initialize(ThreadContext context, IRubyObject path) {
init_unixsock(context.runtime, path, false);
@@ -133,16 +154,115 @@ public IRubyObject recvfrom(ThreadContext context, IRubyObject[] args) {
peeraddr(context));
}

@JRubyMethod(notImplemented = true)
public IRubyObject send_io(IRubyObject path) {
//TODO: implement, won't do this now
return getRuntime().getNil();
@JRubyMethod
public IRubyObject send_io(ThreadContext context, IRubyObject arg) {
final Ruby runtime = context.runtime;
final POSIX posix = runtime.getPosix();
OpenFile fptr = getOpenFileChecked();
int fd;

if (arg.callMethod(context, "kind_of?", runtime.getIO()).isTrue()) {
fd = ((RubyIO) arg).getOpenFileChecked().getFileno();
} else if (arg.callMethod(context, "kind_of?", runtime.getFixnum()).isTrue()) {
fd = ((RubyFixnum) arg).getIntValue();
} else {
throw runtime.newTypeError("neither IO nor file descriptor");
}

if (FilenoUtil.isFake(fd)) {
throw runtime.newTypeError("file descriptor is not native");
}

byte[] dataBytes = new byte[1];
dataBytes[0] = 0;

MsgHdr outMessage = posix.allocateMsgHdr();

ByteBuffer[] outIov = new ByteBuffer[1];
outIov[0] = ByteBuffer.allocateDirect(dataBytes.length);
outIov[0].put(dataBytes);
outIov[0].flip();

outMessage.setIov(outIov);

CmsgHdr outControl = outMessage.allocateControl(4);
outControl.setLevel(SocketLevel.SOL_SOCKET.intValue());
outControl.setType(0x01);

ByteBuffer fdBuf = ByteBuffer.allocateDirect(4);
fdBuf.order(ByteOrder.nativeOrder());
fdBuf.putInt(0, fd);
outControl.setData(fdBuf);

boolean locked = fptr.lock();
try {
while (posix.sendmsg(fptr.getFileno(), outMessage, 0) == -1) {
if (!fptr.waitWritable(context)) {
throw runtime.newErrnoFromInt(posix.errno(), "sendmsg(2)");
}
}
} finally {
if (locked) fptr.unlock();
}

return runtime.getNil();
}

@JRubyMethod(rest = true, notImplemented = true)
public IRubyObject recv_io(IRubyObject[] args) {
//TODO: implement, won't do this now
return getRuntime().getNil();
@JRubyMethod(optional = 2)
public IRubyObject recv_io(ThreadContext context, IRubyObject[] args) {
final Ruby runtime = context.runtime;
final POSIX posix = runtime.getPosix();
OpenFile fptr = getOpenFileChecked();

IRubyObject klass = runtime.getIO();
IRubyObject mode = runtime.getNil();
if (args.length > 0) {
klass = args[0];
}
if (args.length > 1) {
mode = args[1];
}

MsgHdr inMessage = posix.allocateMsgHdr();
ByteBuffer[] inIov = new ByteBuffer[1];
inIov[0] = ByteBuffer.allocateDirect(1);
inMessage.setIov(inIov);

CmsgHdr inControl = inMessage.allocateControl(4);
inControl.setLevel(SocketLevel.SOL_SOCKET.intValue());
inControl.setType(0x01);

ByteBuffer fdBuf = ByteBuffer.allocateDirect(4);
fdBuf.order(ByteOrder.nativeOrder());
fdBuf.putInt(0, -1);
inControl.setData(fdBuf);

boolean locked = fptr.lock();
try {
while (posix.recvmsg(fptr.getFileno(), inMessage, 0) == -1) {
if (!fptr.waitReadable(context)) {
throw runtime.newErrnoFromInt(posix.errno(), "recvmsg(2)");
}
}
} finally {
if (locked) fptr.unlock();
}


ByteBuffer inFdBuf = inMessage.getControls()[0].getData();
inFdBuf.order(ByteOrder.nativeOrder());

IRubyObject fd = runtime.newFixnum(inFdBuf.getInt());

if (klass.isNil()) {
return fd;
} else {
if (mode.isNil()) {
return Helpers.invoke(context, klass, "for_fd", fd);
} else {
return Helpers.invoke(context, klass, "for_fd", fd, mode);
}
}
}

@JRubyMethod(name = {"socketpair", "pair"}, optional = 2, meta = true)
Loading

0 comments on commit 8701a48

Please sign in to comment.