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

Commits on May 15, 2015

  1. Copy the full SHA
    2f7f6c6 View commit details
  2. Copy the full SHA
    ced53e4 View commit details
2 changes: 1 addition & 1 deletion test/truffle/simple-server.rb
Original file line number Diff line number Diff line change
@@ -14,7 +14,7 @@
socket = server.accept

begin
request = socket.gets
request = "Hello, World from JRuby+Truffle! #{socket.gets}"

socket.print "HTTP/1.1 200 OK\r\n" +
"Content-Type: text/plain\r\n" +
24 changes: 24 additions & 0 deletions tool/truffle/translate_rubinius_config.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/usr/bin/env ruby

# Copyright (c) 2015 Oracle and/or its affiliates. All rights reserved. This
# code is released under a tri EPL/GPL/LGPL license. You can use it,
# redistribute it and/or modify it under the terms of the:
#
# Eclipse Public License version 1.0
# GNU General Public License version 2
# GNU Lesser General Public License version 2.1

puts " // Generated from tool/truffle/translate_rubinius_config.rb < ../rubinius/runtime/platform.conf"

ARGF.each do |line|
match = line.match(/(?'var'rbx(\.\w+)*) = (?'value'.+)/)
next unless match
var = match[:var]
value = match[:value]
if /.*\.(offset|size|sizeof)$/ =~ var
code = value.to_s
else
code = "context.makeString(\"#{value}\")"
end
puts " config(\"#{var}\", #{code});"
end
5 changes: 5 additions & 0 deletions truffle/src/main/java/org/jruby/truffle/nodes/RubyNode.java
Original file line number Diff line number Diff line change
@@ -25,6 +25,7 @@
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.UndefinedPlaceholder;
import org.jruby.truffle.runtime.core.*;
import org.jruby.truffle.runtime.sockets.NativeSockets;

@ImportStatic(RubyGuards.class)
public abstract class RubyNode extends Node {
@@ -240,6 +241,10 @@ protected POSIX posix() {
return getContext().getPosix();
}

protected NativeSockets nativeSockets() {
return getContext().getNativeSockets();
}

// Instrumentation

@Override
Original file line number Diff line number Diff line change
@@ -45,6 +45,7 @@
import jnr.constants.platform.Errno;
import jnr.constants.platform.Fcntl;

import jnr.ffi.byref.IntByReference;
import org.jruby.RubyEncoding;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.control.RaiseException;
@@ -53,6 +54,7 @@
import org.jruby.truffle.runtime.core.RubyString;
import org.jruby.util.ByteList;
import org.jruby.util.Dir;
import org.jruby.util.unsafe.UnsafeHolder;

import java.nio.ByteBuffer;
import java.util.Arrays;
@@ -410,4 +412,36 @@ public int seek(VirtualFrame frame, RubyBasicObject io, int amount, int whence)

}

@RubiniusPrimitive(name = "io_accept")
public abstract static class AcceptNode extends RubiniusPrimitiveNode {

public AcceptNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
}

@Specialization
public int accept(VirtualFrame frame, RubyBasicObject io) {
final int fd = (int) rubyWithSelf(frame, io, "@descriptor");

final IntByReference addressLength = new IntByReference(16);
final long address = UnsafeHolder.U.allocateMemory(addressLength.intValue());

final int newFd;

try {
newFd = nativeSockets().accept(fd, getMemoryManager().newPointer(address), addressLength);
} finally {
UnsafeHolder.U.freeMemory(address);
}

if (newFd == -1) {
System.err.println(posix().errno());
throw new UnsupportedOperationException();
}

return newFd;
}

}

}
Original file line number Diff line number Diff line change
@@ -12,30 +12,10 @@
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.source.SourceSection;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.subsystems.RubiniusConfiguration;

public abstract class NativeFunctionPrimitiveNodes {

public static final int TYPE_CHAR = 0;
public static final int TYPE_UCHAR = 1;
public static final int TYPE_BOOL = 2;
public static final int TYPE_SHORT = 3;
public static final int TYPE_USHORT = 4;
public static final int TYPE_INT = 5;
public static final int TYPE_UINT = 6;
public static final int TYPE_LONG = 7;
public static final int TYPE_ULONG = 8;
public static final int TYPE_LL = 9;
public static final int TYPE_ULL = 10;
public static final int TYPE_FLOAT = 11;
public static final int TYPE_DOUBLE = 12;
public static final int TYPE_PTR = 13;
public static final int TYPE_VOID = 14;
public static final int TYPE_STRING = 15;
public static final int TYPE_STRPTR = 16;
public static final int TYPE_CHARARR = 17;
public static final int TYPE_ENUM = 18;
public static final int TYPE_VARARGS = 19;

@RubiniusPrimitive(name = "nativefunction_type_size", needsSelf = false)
public static abstract class NativeFunctionTypeSizePrimitiveNode extends RubiniusPrimitiveNode {

@@ -46,40 +26,40 @@ public NativeFunctionTypeSizePrimitiveNode(RubyContext context, SourceSection so
@Specialization
public long typeSize(int type) {
switch (type) {
case TYPE_CHAR:
case TYPE_UCHAR:
case RubiniusConfiguration.TYPE_CHAR:
case RubiniusConfiguration.TYPE_UCHAR:
return 1;

case TYPE_SHORT:
case TYPE_USHORT:
case RubiniusConfiguration.TYPE_SHORT:
case RubiniusConfiguration.TYPE_USHORT:
return 2;

case TYPE_INT:
case TYPE_UINT:
case RubiniusConfiguration.TYPE_INT:
case RubiniusConfiguration.TYPE_UINT:
return 4;

case TYPE_LONG:
case TYPE_ULONG:
case RubiniusConfiguration.TYPE_LONG:
case RubiniusConfiguration.TYPE_ULONG:
return 8;

case TYPE_FLOAT:
case RubiniusConfiguration.TYPE_FLOAT:
return 4;

case TYPE_DOUBLE:
case RubiniusConfiguration.TYPE_DOUBLE:
return 8;

case TYPE_PTR:
case TYPE_STRPTR:
case RubiniusConfiguration.TYPE_PTR:
case RubiniusConfiguration.TYPE_STRPTR:
return 8;

case TYPE_BOOL:
case TYPE_LL:
case TYPE_ULL:
case TYPE_VOID:
case TYPE_STRING:
case TYPE_CHARARR:
case TYPE_ENUM:
case TYPE_VARARGS:
case RubiniusConfiguration.TYPE_BOOL:
case RubiniusConfiguration.TYPE_LL:
case RubiniusConfiguration.TYPE_ULL:
case RubiniusConfiguration.TYPE_VOID:
case RubiniusConfiguration.TYPE_STRING:
case RubiniusConfiguration.TYPE_CHARARR:
case RubiniusConfiguration.TYPE_ENUM:
case RubiniusConfiguration.TYPE_VARARGS:
default:
throw new UnsupportedOperationException();
}
Original file line number Diff line number Diff line change
@@ -9,6 +9,8 @@
*/
package org.jruby.truffle.nodes.rubinius;

import com.kenai.jffi.MemoryIO;
import com.oracle.truffle.api.dsl.ImportStatic;
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.nodes.Node;
import com.oracle.truffle.api.object.*;
@@ -21,6 +23,8 @@
import org.jruby.truffle.runtime.core.RubyBasicObject;
import org.jruby.truffle.runtime.core.RubyClass;
import org.jruby.truffle.runtime.core.RubyString;
import org.jruby.truffle.runtime.subsystems.RubiniusConfiguration;
import org.jruby.util.ByteList;
import org.jruby.util.unsafe.UnsafeHolder;

import java.util.EnumSet;
@@ -42,12 +46,15 @@ public abstract class PointerPrimitiveNodes {
public static class PointerAllocator implements Allocator {
@Override
public RubyBasicObject allocate(RubyContext context, RubyClass rubyClass, Node currentNode) {
return PointerPrimitiveNodes.createPointer(rubyClass, jnr.ffi.Runtime.getSystemRuntime().getMemoryManager().newOpaquePointer(0));
return PointerPrimitiveNodes.createPointer(rubyClass, NULL_POINTER);
}
}

public static RubyBasicObject createPointer(RubyClass rubyClass, Pointer pointer) {
assert pointer != null;
if (pointer == null) {
pointer = NULL_POINTER;
}

return new RubyBasicObject(rubyClass, POINTER_FACTORY.newInstance(pointer));
}

@@ -158,7 +165,7 @@ protected boolean isSigned(boolean signed) {

}

@RubiniusPrimitive(name = "pointer_read_string")
@RubiniusPrimitive(name = "pointer_read_string", lowerFixnumParameters = 0)
public static abstract class PointerReadStringPrimitiveNode extends RubiniusPrimitiveNode {

public PointerReadStringPrimitiveNode(RubyContext context, SourceSection sourceSection) {
@@ -190,16 +197,15 @@ public boolean setAutorelease(RubyBasicObject pointer, boolean autorelease) {
}

@RubiniusPrimitive(name = "pointer_set_at_offset", lowerFixnumParameters = {0, 2})
@ImportStatic(RubiniusConfiguration.class)
public static abstract class PointerSetAtOffsetPrimitiveNode extends RubiniusPrimitiveNode {

public PointerSetAtOffsetPrimitiveNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
}

@Specialization
@Specialization(guards = "type == TYPE_INT")
public int setAtOffset(RubyBasicObject pointer, int offset, int type, int value) {
assert type == 5;
// TODO CS 13-May-15 what does the type parameter do?
getPointer(pointer).putInt(offset, value);
return value;
}
@@ -215,7 +221,7 @@ public PointerReadPointerPrimitiveNode(RubyContext context, SourceSection source

@Specialization
public RubyBasicObject readPointer(RubyBasicObject pointer) {
return createPointer(pointer.getLogicalClass(), nullOrPointer(getPointer(pointer).getPointer(0)));
return createPointer(pointer.getLogicalClass(), getPointer(pointer).getPointer(0));
}

}
@@ -235,27 +241,90 @@ public long address(RubyBasicObject pointer) {
}

@RubiniusPrimitive(name = "pointer_get_at_offset")
@ImportStatic(RubiniusConfiguration.class)
public static abstract class PointerGetAtOffsetPrimitiveNode extends RubiniusPrimitiveNode {

public PointerGetAtOffsetPrimitiveNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
}

@Specialization
public int getAtOffset(RubyBasicObject pointer, int offset, int type) {
assert type == 5;
// TODO CS 13-May-15 not sure about int/long here
@Specialization(guards = "type == TYPE_UCHAR")
public int getAtOffsetUChar(RubyBasicObject pointer, int offset, int type) {
return getPointer(pointer).getByte(offset);
}

@Specialization(guards = "type == TYPE_INT")
public int getAtOffsetInt(RubyBasicObject pointer, int offset, int type) {
return getPointer(pointer).getInt(offset);
}

@Specialization(guards = "type == TYPE_SHORT")
public int getAtOffsetShort(RubyBasicObject pointer, int offset, int type) {
return getPointer(pointer).getShort(offset);
}

@Specialization(guards = "type == TYPE_LONG")
public long getAtOffsetLong(RubyBasicObject pointer, int offset, int type) {
return getPointer(pointer).getLong(offset);
}

@Specialization(guards = "type == TYPE_PTR")
public RubyBasicObject getAtOffsetPointer(RubyBasicObject pointer, int offset, int type) {
final Pointer readPointer = getPointer(pointer).getPointer(offset);

if (readPointer == null) {
return nil();
} else {
return createPointer(pointer.getLogicalClass(), readPointer);
}
}

}

private static Pointer nullOrPointer(Pointer pointer) {
if (pointer == null) {
return NULL_POINTER;
} else {
@RubiniusPrimitive(name = "pointer_write_string")
public static abstract class PointerWriteStringPrimitiveNode extends RubiniusPrimitiveNode {

public PointerWriteStringPrimitiveNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
}

@Specialization
public RubyBasicObject address(RubyBasicObject pointer, RubyString string, int maxLength) {
final ByteList bytes = string.getByteList();
final int length = Math.min(bytes.length(), maxLength);
getPointer(pointer).put(0, bytes.unsafeBytes(), bytes.begin(), length);
return pointer;
}

}

@RubiniusPrimitive(name = "pointer_read_string_to_null")
public static abstract class PointerReadStringToNullPrimitiveNode extends RubiniusPrimitiveNode {

public PointerReadStringToNullPrimitiveNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
}

@Specialization
public RubyString readStringToNull(RubyBasicObject pointer) {
return getContext().makeString(MemoryIO.getInstance().getZeroTerminatedByteArray(getPointer(pointer).address()));
}

}

@RubiniusPrimitive(name = "pointer_write_int")
public static abstract class PointerWriteIntPrimitiveNode extends RubiniusPrimitiveNode {

public PointerWriteIntPrimitiveNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
}

@Specialization
public RubyBasicObject address(RubyBasicObject pointer, int value) {
getPointer(pointer).putInt(0, value);
return pointer;
}

}

}
Loading