Skip to content

Commit

Permalink
Showing 6 changed files with 11 additions and 168 deletions.
Original file line number Diff line number Diff line change
@@ -15,13 +15,11 @@
import com.oracle.truffle.api.dsl.ImportStatic;
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.nodes.UnexpectedResultException;
import com.oracle.truffle.api.object.DynamicObject;
import com.oracle.truffle.api.source.SourceSection;

import org.jruby.truffle.nodes.RubyGuards;
import org.jruby.truffle.nodes.dispatch.DoesRespondDispatchHeadNode;
import org.jruby.truffle.nodes.dispatch.RespondToNode;
import org.jruby.truffle.nodes.objectstorage.ReadHeadObjectFieldNode;
import org.jruby.truffle.nodes.objectstorage.ReadHeadObjectFieldNodeGen;
import org.jruby.truffle.runtime.ModuleOperations;
@@ -69,14 +67,7 @@ public DynamicObject id2Ref(
final long id,
@Cached("createReadObjectIDNode()") ReadHeadObjectFieldNode readObjectIdNode) {
for (DynamicObject object : ObjectGraph.stopAndGetAllObjects(this, getContext())) {
final long objectID;

try {
objectID = readObjectIdNode.executeLong(object);
} catch (UnexpectedResultException e) {
throw new UnsupportedOperationException(e);
}

final long objectID = (long) readObjectIdNode.execute(object);
if (objectID == id) {
return object;
}
Original file line number Diff line number Diff line change
@@ -13,7 +13,6 @@
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.NodeChild;
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.nodes.UnexpectedResultException;
import com.oracle.truffle.api.object.DynamicObject;
import com.oracle.truffle.api.source.SourceSection;
import org.jruby.truffle.nodes.RubyNode;
@@ -69,11 +68,7 @@ public boolean isFrozenSymbol(DynamicObject symbol) {
@Specialization(guards = { "!isNil(object)", "!isRubyBignum(object)", "!isRubySymbol(object)" })
protected boolean isFrozen(DynamicObject object,
@Cached("createReadFrozenNode()") ReadHeadObjectFieldNode readFrozenNode) {
try {
return readFrozenNode.executeBoolean(object);
} catch (UnexpectedResultException e) {
throw new UnsupportedOperationException(e);
}
return (boolean) readFrozenNode.execute(object);
}

protected ReadHeadObjectFieldNode createReadFrozenNode() {
Original file line number Diff line number Diff line change
@@ -12,7 +12,6 @@
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.NodeChild;
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.nodes.UnexpectedResultException;
import com.oracle.truffle.api.object.DynamicObject;
import com.oracle.truffle.api.source.SourceSection;
import org.jruby.truffle.nodes.RubyNode;
@@ -55,11 +54,7 @@ public boolean isTainted(double object) {
@Specialization
protected boolean isTainted(DynamicObject object,
@Cached("createReadTaintedNode()") ReadHeadObjectFieldNode readTaintedNode) {
try {
return readTaintedNode.executeBoolean(object);
} catch (UnexpectedResultException e) {
throw new UnsupportedOperationException(e);
}
return (boolean) readTaintedNode.execute(object);
}

protected ReadHeadObjectFieldNode createReadTaintedNode() {
Original file line number Diff line number Diff line change
@@ -9,22 +9,17 @@
*/
package org.jruby.truffle.nodes.objects;

import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.nodes.UnexpectedResultException;
import com.oracle.truffle.api.object.DynamicObject;
import com.oracle.truffle.api.object.Property;
import com.oracle.truffle.api.object.Shape;
import com.oracle.truffle.api.source.SourceSection;
import com.oracle.truffle.api.utilities.BranchProfile;
import org.jcodings.specific.UTF8Encoding;
import org.jruby.truffle.nodes.RubyNode;
import org.jruby.truffle.nodes.objectstorage.ReadHeadObjectFieldNode;
import org.jruby.truffle.nodes.objectstorage.ReadHeadObjectFieldNodeGen;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.core.StringOperations;
import org.jruby.truffle.runtime.layouts.Layouts;
import org.jruby.util.StringSupport;

import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.object.DynamicObject;
import com.oracle.truffle.api.source.SourceSection;
import com.oracle.truffle.api.utilities.BranchProfile;

public class ReadInstanceVariableNode extends RubyNode {

@@ -39,48 +34,6 @@ public ReadInstanceVariableNode(RubyContext context, SourceSection sourceSection
readNode = ReadHeadObjectFieldNodeGen.create(name, nil());
}

@Override
public int executeInteger(VirtualFrame frame) throws UnexpectedResultException {
final Object receiverObject = receiver.execute(frame);

if (receiverObject instanceof DynamicObject) {
return readNode.executeInteger((DynamicObject) receiverObject);
} else {
// TODO(CS): need to put this onto the fast path?

CompilerDirectives.transferToInterpreter();
throw new UnexpectedResultException(nil());
}
}

@Override
public long executeLong(VirtualFrame frame) throws UnexpectedResultException {
final Object receiverObject = receiver.execute(frame);

if (receiverObject instanceof DynamicObject) {
return readNode.executeLong((DynamicObject) receiverObject);
} else {
// TODO(CS): need to put this onto the fast path?

CompilerDirectives.transferToInterpreter();
throw new UnexpectedResultException(nil());
}
}

@Override
public double executeDouble(VirtualFrame frame) throws UnexpectedResultException {
final Object receiverObject = receiver.execute(frame);

if (receiverObject instanceof DynamicObject) {
return readNode.executeDouble((DynamicObject) receiverObject);
} else {
// TODO(CS): need to put this onto the fast path?

CompilerDirectives.transferToInterpreter();
throw new UnexpectedResultException(nil());
}
}

@Override
public Object execute(VirtualFrame frame) {
final Object receiverObject = receiver.execute(frame);
Original file line number Diff line number Diff line change
@@ -13,7 +13,6 @@
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.nodes.Node;
import com.oracle.truffle.api.nodes.UnexpectedResultException;
import com.oracle.truffle.api.object.*;

import org.jruby.truffle.runtime.Options;
@@ -31,58 +30,12 @@ public Object getName() {
return name;
}

public abstract boolean executeBoolean(DynamicObject object) throws UnexpectedResultException;
public abstract int executeInteger(DynamicObject object) throws UnexpectedResultException;
public abstract long executeLong(DynamicObject object) throws UnexpectedResultException;
public abstract double executeDouble(DynamicObject object) throws UnexpectedResultException;

public abstract Object execute(DynamicObject object);

@Specialization(
guards = { "location != null", "receiver.getShape() == cachedShape" },
assumptions = "cachedShape.getValidAssumption()",
limit = "getCacheLimit()")
protected boolean readBooleanObjectFieldCached(DynamicObject receiver,
@Cached("receiver.getShape()") Shape cachedShape,
@Cached("getBooleanLocation(cachedShape)") BooleanLocation location) {
return location.getBoolean(receiver, cachedShape);
}

@Specialization(
guards = { "location != null", "receiver.getShape() == cachedShape" },
assumptions = "cachedShape.getValidAssumption()",
limit = "getCacheLimit()")
protected int readIntObjectFieldCached(DynamicObject receiver,
@Cached("receiver.getShape()") Shape cachedShape,
@Cached("getIntLocation(cachedShape)") IntLocation location) {
return location.getInt(receiver, cachedShape);
}

@Specialization(
guards = { "location != null", "receiver.getShape() == cachedShape" },
assumptions = "cachedShape.getValidAssumption()",
limit = "getCacheLimit()")
protected long readLongObjectFieldCached(DynamicObject receiver,
@Cached("receiver.getShape()") Shape cachedShape,
@Cached("getLongLocation(cachedShape)") LongLocation location) {
return location.getLong(receiver, cachedShape);
}

@Specialization(
guards = { "location != null", "receiver.getShape() == cachedShape" },
assumptions = "cachedShape.getValidAssumption()",
limit = "getCacheLimit()")
protected double readDoubleObjectFieldCached(DynamicObject receiver,
@Cached("receiver.getShape()") Shape cachedShape,
@Cached("getDoubleLocation(cachedShape)") DoubleLocation location) {
return location.getDouble(receiver, cachedShape);
}

@Specialization(
guards = "receiver.getShape() == cachedShape",
assumptions = "cachedShape.getValidAssumption()",
limit = "getCacheLimit()",
contains = { "readBooleanObjectFieldCached", "readIntObjectFieldCached", "readLongObjectFieldCached", "readDoubleObjectFieldCached" })
limit = "getCacheLimit()")
protected Object readObjectFieldCached(DynamicObject receiver,
@Cached("receiver.getShape()") Shape cachedShape,
@Cached("cachedShape.getProperty(name)") Property property) {
@@ -96,45 +49,7 @@ protected Object readObjectFieldCached(DynamicObject receiver,
@TruffleBoundary
@Specialization
protected Object readObjectFieldUncached(DynamicObject receiver) {
final Shape shape = receiver.getShape();
final Property property = shape.getProperty(name);
if (property != null) {
return property.get(receiver, shape);
} else {
return defaultValue;
}
}

protected BooleanLocation getBooleanLocation(Shape shape) {
final Property property = shape.getProperty(name);
if (property != null && property.getLocation() instanceof BooleanLocation) {
return (BooleanLocation) property.getLocation();
}
return null;
}

protected IntLocation getIntLocation(Shape shape) {
final Property property = shape.getProperty(name);
if (property != null && property.getLocation() instanceof IntLocation) {
return (IntLocation) property.getLocation();
}
return null;
}

protected LongLocation getLongLocation(Shape shape) {
final Property property = shape.getProperty(name);
if (property != null && property.getLocation() instanceof LongLocation) {
return (LongLocation) property.getLocation();
}
return null;
}

protected DoubleLocation getDoubleLocation(Shape shape) {
final Property property = shape.getProperty(name);
if (property != null && property.getLocation() instanceof DoubleLocation) {
return (DoubleLocation) property.getLocation();
}
return null;
return receiver.get(name, defaultValue);
}

protected int getCacheLimit() {
Original file line number Diff line number Diff line change
@@ -13,7 +13,6 @@
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.nodes.UnexpectedResultException;
import com.oracle.truffle.api.object.DynamicObject;
import com.oracle.truffle.api.source.SourceSection;
import com.oracle.truffle.api.utilities.ConditionProfile;
@@ -87,12 +86,7 @@ public Object objectID(double value) {
public long objectID(DynamicObject object,
@Cached("createReadObjectIDNode()") ReadHeadObjectFieldNode readObjectIdNode,
@Cached("createWriteObjectIDNode()") WriteHeadObjectFieldNode writeObjectIdNode) {
final long id;
try {
id = readObjectIdNode.executeLong(object);
} catch (UnexpectedResultException e) {
throw new UnsupportedOperationException(e);
}
final long id = (long) readObjectIdNode.execute(object);

if (id == 0) {
final long newId = getContext().getNextObjectID();

0 comments on commit 511b580

Please sign in to comment.