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

Commits on Jun 18, 2015

  1. Copy the full SHA
    25fa571 View commit details
  2. Copy the full SHA
    6fb42d3 View commit details
9 changes: 9 additions & 0 deletions truffle/src/main/java/org/jruby/truffle/nodes/RubyGuards.java
Original file line number Diff line number Diff line change
@@ -13,6 +13,7 @@
import org.jruby.truffle.nodes.core.*;
import org.jruby.truffle.nodes.core.hash.HashNodes;
import org.jruby.truffle.nodes.ext.BigDecimalNodes;
import org.jruby.truffle.nodes.rubinius.PointerNodes;
import org.jruby.truffle.runtime.NotProvided;
import org.jruby.truffle.runtime.ThreadLocalObject;
import org.jruby.truffle.runtime.core.*;
@@ -136,6 +137,14 @@ public static boolean isRubyBasicObject(Object value) {
return value instanceof RubyBasicObject;
}

public static boolean isRubyPointer(Object value) {
return (value instanceof RubyBasicObject) && isRubyPointer((RubyBasicObject) value);
}

public static boolean isRubyPointer(RubyBasicObject value) {
return value.getDynamicObject().getShape().getObjectType() == PointerNodes.POINTER_TYPE;
}

// Internal types

public static boolean isThreadLocal(Object value) {
Original file line number Diff line number Diff line change
@@ -12,25 +12,33 @@
import com.oracle.truffle.api.nodes.Node;
import com.oracle.truffle.api.object.*;
import jnr.ffi.Pointer;
import org.jruby.truffle.nodes.RubyGuards;
import org.jruby.truffle.nodes.objects.Allocator;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.core.RubyBasicObject;
import org.jruby.truffle.runtime.core.RubyClass;
import org.jruby.truffle.runtime.object.BasicObjectType;

import java.util.EnumSet;

public abstract class PointerNodes {

public static final Pointer NULL_POINTER = jnr.ffi.Runtime.getSystemRuntime().getMemoryManager().newOpaquePointer(0);

public static class PointerType extends BasicObjectType {

}

public static final PointerType POINTER_TYPE = new PointerType();

private static final HiddenKey POINTER_IDENTIFIER = new HiddenKey("pointer");
private static final Property POINTER_PROPERTY;
private static final DynamicObjectFactory POINTER_FACTORY;

static {
final Shape.Allocator allocator = RubyBasicObject.LAYOUT.createAllocator();
POINTER_PROPERTY = Property.create(POINTER_IDENTIFIER, allocator.locationForType(Pointer.class, EnumSet.of(LocationModifier.NonNull)), 0);
POINTER_FACTORY = RubyBasicObject.EMPTY_SHAPE.addProperty(POINTER_PROPERTY).createFactory();
POINTER_FACTORY = RubyBasicObject.LAYOUT.createShape(POINTER_TYPE).addProperty(POINTER_PROPERTY).createFactory();
}

public static class PointerAllocator implements Allocator {
@@ -49,9 +57,11 @@ public static RubyBasicObject createPointer(RubyClass rubyClass, Pointer pointer
}

public static void setPointer(RubyBasicObject pointer, Pointer newPointer) {
assert newPointer != null;
assert RubyGuards.isRubyPointer(pointer);
assert pointer.getDynamicObject().getShape().hasProperty(POINTER_IDENTIFIER);

assert newPointer != null;

try {
POINTER_PROPERTY.set(pointer.getDynamicObject(), newPointer, pointer.getDynamicObject().getShape());
} catch (IncompatibleLocationException | FinalLocationException e) {
@@ -60,6 +70,7 @@ public static void setPointer(RubyBasicObject pointer, Pointer newPointer) {
}

public static Pointer getPointer(RubyBasicObject pointer) {
assert RubyGuards.isRubyPointer(pointer);
assert pointer.getDynamicObject().getShape().hasProperty(POINTER_IDENTIFIER);
return (Pointer) POINTER_PROPERTY.get(pointer.getDynamicObject(), true);
}
Original file line number Diff line number Diff line change
@@ -180,7 +180,7 @@ public GetGroupsNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
}

@Specialization
@Specialization(guards = "isRubyPointer(pointer)")
public int getGroups(int max, RubyBasicObject pointer) {
final long[] groups = Platform.getPlatform().getGroups(null);

@@ -204,7 +204,7 @@ public GetRLimitNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
}

@Specialization
@Specialization(guards = "isRubyPointer(pointer)")
public int getrlimit(int resource, RubyBasicObject pointer) {
final int result = posix().getrlimit(resource, PointerNodes.getPointer(pointer));

@@ -239,12 +239,12 @@ public MemsetNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
}

@Specialization
@Specialization(guards = "isRubyPointer(pointer)")
public RubyBasicObject memset(RubyBasicObject pointer, int c, int length) {
return memset(pointer, c, (long) length);
}

@Specialization
@Specialization(guards = "isRubyPointer(pointer)")
public RubyBasicObject memset(RubyBasicObject pointer, int c, long length) {
PointerNodes.getPointer(pointer).setMemory(0, length, (byte) c);
return pointer;
@@ -259,7 +259,7 @@ public ReadlinkNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
}

@Specialization
@Specialization(guards = "isRubyPointer(pointer)")
public int readlink(RubyString path, RubyBasicObject pointer, int bufsize) {
final String pathString = RubyEncoding.decodeUTF8(StringNodes.getByteList(path).getUnsafeBytes(), StringNodes.getByteList(path).getBegin(), StringNodes.getByteList(path).getRealSize());

@@ -325,7 +325,7 @@ public UtimesNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
}

@Specialization
@Specialization(guards = "isRubyPointer(pointer)")
public int utimes(RubyString path, RubyBasicObject pointer) {
final String pathString = RubyEncoding.decodeUTF8(StringNodes.getByteList(path).getUnsafeBytes(), StringNodes.getByteList(path).getBegin(), StringNodes.getByteList(path).getRealSize());

@@ -467,7 +467,7 @@ public SetRLimitNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
}

@Specialization
@Specialization(guards = "isRubyPointer(pointer)")
public int setrlimit(int resource, RubyBasicObject pointer) {
final int result = posix().setrlimit(resource, PointerNodes.getPointer(pointer));

@@ -731,8 +731,6 @@ public int symlink(RubyString first, RubyString second) {

}

// TODO CS-15-May 15 we're missing a lot of guards for things like Pointer here

@CoreMethod(names = "_getaddrinfo", isModuleFunction = true, required = 4)
public abstract static class GetAddrInfoNode extends CoreMethodArrayArgumentsNode {

@@ -745,7 +743,7 @@ public int getaddrinfo(RubyBasicObject hostName, RubyString serviceName, RubyBas
return getaddrinfo((RubyString) createString("0.0.0.0"), serviceName, hintsPointer, resultsPointer);
}

@Specialization
@Specialization(guards = {"isRubyPointer(hintsPointer)", "isRubyPointer(resultsPointer)"})
public int getaddrinfo(RubyString hostName, RubyString serviceName, RubyBasicObject hintsPointer, RubyBasicObject resultsPointer) {
return nativeSockets().getaddrinfo(
StringNodes.getByteList(hostName),
@@ -763,7 +761,7 @@ public FreeAddrInfoNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
}

@Specialization
@Specialization(guards = "isRubyPointer(addrInfo)")
public RubyBasicObject freeaddrinfo(RubyBasicObject addrInfo) {
nativeSockets().freeaddrinfo(PointerNodes.getPointer(addrInfo));
return nil();
@@ -778,7 +776,7 @@ public GetNameInfoNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
}

@Specialization
@Specialization(guards = {"isRubyPointer(sa)", "isRubyPointer(host)", "isRubyPointer(serv)"})
public int getnameinfo(RubyBasicObject sa, int salen, RubyBasicObject host, int hostlen, RubyBasicObject serv, int servlen, int flags) {
return nativeSockets().getnameinfo(
PointerNodes.getPointer(sa),
@@ -813,7 +811,7 @@ public SetSockOptNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
}

@Specialization
@Specialization(guards = "isRubyPointer(optionValue)")
public int setsockopt(int socket, int level, int optionName, RubyBasicObject optionValue, int optionLength) {
return nativeSockets().setsockopt(socket, level, optionName, PointerNodes.getPointer(optionValue), optionLength);
}
@@ -827,7 +825,7 @@ public BindNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
}

@Specialization
@Specialization(guards = "isRubyPointer(address)")
public int bind(int socket, RubyBasicObject address, int addressLength) {
return nativeSockets().bind(socket, PointerNodes.getPointer(address), addressLength);
}
@@ -855,7 +853,7 @@ public GetHostNameNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
}

@Specialization
@Specialization(guards = "isRubyPointer(name)")
public int getHostName(RubyBasicObject name, int nameLength) {
return nativeSockets().gethostname(PointerNodes.getPointer(name), nameLength);
}
@@ -869,7 +867,7 @@ public GetPeerNameNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
}

@Specialization
@Specialization(guards = {"isRubyPointer(address)", "isRubyPointer(addressLength)"})
public int getPeerName(int socket, RubyBasicObject address, RubyBasicObject addressLength) {
return nativeSockets().getpeername(socket, PointerNodes.getPointer(address), PointerNodes.getPointer(addressLength));
}
@@ -883,7 +881,7 @@ public GetSockNameNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
}

@Specialization
@Specialization(guards = {"isRubyPointer(address)", "isRubyPointer(addressLength)"})
public int getSockName(int socket, RubyBasicObject address, RubyBasicObject addressLength) {
return nativeSockets().getsockname(socket, PointerNodes.getPointer(address), PointerNodes.getPointer(addressLength));
}