Skip to content

Commit

Permalink
Showing 24 changed files with 135 additions and 90 deletions.
20 changes: 14 additions & 6 deletions truffle/src/main/java/org/jruby/truffle/core/array/ArrayNodes.java
Original file line number Diff line number Diff line change
@@ -361,6 +361,9 @@ public abstract static class IndexSetNode extends ArrayCoreMethodNode {
@Child protected ArrayReadSliceNormalizedNode readSliceNode;
@Child private ToIntNode toIntNode;

private final BranchProfile negativeIndexProfile = BranchProfile.create();
private final BranchProfile negativeLengthProfile = BranchProfile.create();

public abstract Object executeSet(VirtualFrame frame, DynamicObject array, Object index, Object length, Object value);

// array[index] = object
@@ -508,14 +511,14 @@ public Object setRange(VirtualFrame frame, DynamicObject array, DynamicObject ra

private void checkIndex(DynamicObject array, int index, int normalizedIndex) {
if (normalizedIndex < 0) {
CompilerDirectives.transferToInterpreterAndInvalidate();
negativeIndexProfile.enter();
throw new RaiseException(coreExceptions().indexTooSmallError("array", index, getSize(array), this));
}
}

public void checkLengthPositive(int length) {
if (length < 0) {
CompilerDirectives.transferToInterpreterAndInvalidate();
negativeLengthProfile.enter();
throw new RaiseException(coreExceptions().negativeLengthError(length, this));
}
}
@@ -1317,6 +1320,8 @@ public abstract static class MaxBlockNode extends CoreMethodArrayArgumentsNode {

@Child private CallDispatchHeadNode compareNode;

private final BranchProfile errorProfile = BranchProfile.create();

public MaxBlockNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
compareNode = DispatchHeadNodeFactory.createMethodCall(context);
@@ -1339,7 +1344,7 @@ public DynamicObject max(VirtualFrame frame, Object maximumObject, Object value)
maximum.set(value);
}
} else {
CompilerDirectives.transferToInterpreterAndInvalidate();
errorProfile.enter();
// Should be the actual type and object in this string - but this method should go away soon
throw new RaiseException(coreExceptions().argumentError("comparison of X with Y failed", this));
}
@@ -1437,6 +1442,8 @@ public abstract static class MinBlockNode extends CoreMethodArrayArgumentsNode {

@Child private CallDispatchHeadNode compareNode;

private final BranchProfile errorProfile = BranchProfile.create();

public MinBlockNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
compareNode = DispatchHeadNodeFactory.createMethodCall(context);
@@ -1459,7 +1466,7 @@ public DynamicObject min(VirtualFrame frame, Object minimumObject, Object value)
minimum.set(value);
}
} else {
CompilerDirectives.transferToInterpreterAndInvalidate();
errorProfile.enter();
// Should be the actual type and object in this string - but this method should go away soon
throw new RaiseException(coreExceptions().argumentError("comparison of X with Y failed", this));
}
@@ -2018,6 +2025,8 @@ public abstract static class SortNode extends ArrayCoreMethodNode {
@Child private CallDispatchHeadNode compareDispatchNode;
@Child private YieldNode yieldNode;

private final BranchProfile errorProfile = BranchProfile.create();

public SortNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
compareDispatchNode = DispatchHeadNodeFactory.createMethodCall(context);
@@ -2103,8 +2112,7 @@ private int castSortValue(Object value) {
return (int) value;
}

CompilerDirectives.transferToInterpreterAndInvalidate();

errorProfile.enter();
// TODO CS 14-Mar-15 - what's the error message here?
throw new RaiseException(coreExceptions().argumentError("expecting a Fixnum to sort", this));
}
Original file line number Diff line number Diff line change
@@ -10,6 +10,7 @@
package org.jruby.truffle.core.cast;

import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
import com.oracle.truffle.api.dsl.NodeChild;
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.source.SourceSection;
@@ -23,8 +24,8 @@ public abstract class LazyDefaultValueNode extends RubyNode {

private final Function0<Object> defaultValueProducer;

@CompilerDirectives.CompilationFinal private boolean hasDefault;
@CompilerDirectives.CompilationFinal private Object defaultValue;
@CompilationFinal private boolean hasDefault;
@CompilationFinal private Object defaultValue;

public LazyDefaultValueNode(RubyContext context, SourceSection sourceSection, Function0<Object> defaultValueProducer) {
super(context, sourceSection);
22 changes: 14 additions & 8 deletions truffle/src/main/java/org/jruby/truffle/core/cast/ToFNode.java
Original file line number Diff line number Diff line change
@@ -11,10 +11,12 @@
package org.jruby.truffle.core.cast;

import com.oracle.truffle.api.CompilerDirectives;
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.frame.VirtualFrame;
import com.oracle.truffle.api.object.DynamicObject;
import com.oracle.truffle.api.profiles.BranchProfile;
import com.oracle.truffle.api.source.SourceSection;
import org.jruby.truffle.Layouts;
import org.jruby.truffle.RubyContext;
@@ -28,6 +30,8 @@ public abstract class ToFNode extends RubyNode {

@Child private CallDispatchHeadNode toFNode;

private final BranchProfile errorProfile = BranchProfile.create();

public ToFNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
}
@@ -39,7 +43,7 @@ public double doDouble(VirtualFrame frame, Object value) {
return (double) doubleObject;
}

CompilerDirectives.transferToInterpreterAndInvalidate();
errorProfile.enter();
throw new UnsupportedOperationException("executeDouble must return a double, instead it returned a " + doubleObject.getClass().getName());
}

@@ -61,16 +65,18 @@ public double coerceDouble(double value) {
}

@Specialization
public double coerceBoolean(VirtualFrame frame, boolean value) {
return coerceObject(frame, value);
public double coerceBoolean(VirtualFrame frame, boolean value,
@Cached("create()") BranchProfile errorProfile) {
return coerceObject(frame, value, errorProfile);
}

@Specialization
public double coerceDynamicObject(VirtualFrame frame, DynamicObject object) {
return coerceObject(frame, object);
public double coerceDynamicObject(VirtualFrame frame, DynamicObject object,
@Cached("create()") BranchProfile errorProfile) {
return coerceObject(frame, object, errorProfile);
}

private double coerceObject(VirtualFrame frame, Object object) {
private double coerceObject(VirtualFrame frame, Object object, BranchProfile errorProfile) {
if (toFNode == null) {
CompilerDirectives.transferToInterpreterAndInvalidate();
toFNode = insert(DispatchHeadNodeFactory.createMethodCall(getContext(), true));
@@ -81,7 +87,7 @@ private double coerceObject(VirtualFrame frame, Object object) {
coerced = toFNode.call(frame, object, "to_f", null);
} catch (RaiseException e) {
if (Layouts.BASIC_OBJECT.getLogicalClass(e.getException()) == coreLibrary().getNoMethodErrorClass()) {
CompilerDirectives.transferToInterpreterAndInvalidate();
errorProfile.enter();
throw new RaiseException(coreExceptions().typeErrorNoImplicitConversion(object, "Float", this));
} else {
throw e;
@@ -91,7 +97,7 @@ private double coerceObject(VirtualFrame frame, Object object) {
if (coreLibrary().getLogicalClass(coerced) == coreLibrary().getFloatClass()) {
return (double) coerced;
} else {
CompilerDirectives.transferToInterpreterAndInvalidate();
errorProfile.enter();
throw new RaiseException(coreExceptions().typeErrorBadCoercion(object, "Float", "to_f", coerced, this));
}
}
Original file line number Diff line number Diff line change
@@ -37,6 +37,8 @@ public abstract class ToIntNode extends RubyNode {
private final ConditionProfile wasLong = ConditionProfile.createBinaryProfile();
private final ConditionProfile wasLongInRange = ConditionProfile.createBinaryProfile();

private final BranchProfile errorProfile = BranchProfile.create();

public static ToIntNode create() {
return ToIntNodeGen.create(null);
}
@@ -58,7 +60,7 @@ public int doInt(VirtualFrame frame, Object object) {
}
}

CompilerDirectives.transferToInterpreterAndInvalidate();
errorProfile.enter();
if (RubyGuards.isRubyBignum(object)) {
throw new RaiseException(coreExceptions().rangeError("bignum too big to convert into `long'", this));
} else {
Original file line number Diff line number Diff line change
@@ -26,6 +26,7 @@ public static Encoding getEncoding(DynamicObject rubyEncoding) {
Encoding encoding = Layouts.ENCODING.getEncoding(rubyEncoding);

if (encoding == null) {
// Bounded by the number of encodings
CompilerDirectives.transferToInterpreterAndInvalidate();

final ByteList name = Layouts.ENCODING.getName(rubyEncoding);
Original file line number Diff line number Diff line change
@@ -13,6 +13,7 @@
import com.oracle.truffle.api.nodes.Node;
import com.oracle.truffle.api.object.DynamicObject;
import jnr.constants.platform.Errno;
import org.jcodings.Encoding;
import org.jcodings.specific.UTF8Encoding;
import org.jruby.runtime.Visibility;
import org.jruby.truffle.Layouts;
@@ -632,7 +633,7 @@ public DynamicObject regexpError(String message, Node currentNode) {
// EncodingCompatibilityError

@TruffleBoundary
public DynamicObject encodingCompatibilityErrorIncompatible(String a, String b, Node currentNode) {
public DynamicObject encodingCompatibilityErrorIncompatible(Encoding a, Encoding b, Node currentNode) {
return encodingCompatibilityError(String.format("incompatible character encodings: %s and %s", a, b), currentNode);
}

Original file line number Diff line number Diff line change
@@ -80,8 +80,7 @@ public Object backtrace(
private ReadObjectFieldNode getReadCustomBacktraceNode() {
if (readCustomBacktraceNode == null) {
CompilerDirectives.transferToInterpreterAndInvalidate();
readCustomBacktraceNode = insert(ReadObjectFieldNodeGen.create(
"@custom_backtrace", null));
readCustomBacktraceNode = insert(ReadObjectFieldNodeGen.create("@custom_backtrace", null));
}

return readCustomBacktraceNode;
Original file line number Diff line number Diff line change
@@ -53,6 +53,7 @@ private Object[] ensureCapacity(VirtualFrame frame, Object[] output, int length)
return output;
}

// If we ran out of output byte[], deoptimize and next time we'll allocate more
CompilerDirectives.transferToInterpreterAndInvalidate();

final Object[] newOutput = new Object[ArrayUtils.capacity(getContext(), output.length, neededLength)];
Original file line number Diff line number Diff line change
@@ -9,13 +9,14 @@
*/
package org.jruby.truffle.core.hash;

import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.nodes.ExplodeLoop;
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.RubyContext;
import org.jruby.truffle.language.RubyNode;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@@ -31,21 +32,34 @@ public ConcatHashLiteralNode(RubyContext context, SourceSection sourceSection, R

@Override
public Object execute(VirtualFrame frame) {
CompilerDirectives.transferToInterpreterAndInvalidate();
return buildHash(executeChildren(frame));
}

@TruffleBoundary
private Object buildHash(DynamicObject[] parts) {
final List<Map.Entry<Object, Object>> keyValues = new ArrayList<>();

for (RubyNode child : children) {
try {
for (Map.Entry<Object, Object> keyValue : HashOperations.iterableKeyValues(child.executeDynamicObject(frame))) {
keyValues.add(keyValue);
}
} catch (UnexpectedResultException e) {
throw new UnsupportedOperationException(child.getClass() + " " + e.getResult().getClass());
for (int i = 0; i < parts.length; i++) {
for (Map.Entry<Object, Object> keyValue : HashOperations.iterableKeyValues(parts[i])) {
keyValues.add(keyValue);
}
}

return BucketsStrategy.create(getContext(), keyValues, false);
}

@ExplodeLoop
protected DynamicObject[] executeChildren(VirtualFrame frame) {
DynamicObject[] values = new DynamicObject[children.length];
for (int i = 0; i < children.length; i++) {
try {
DynamicObject hash = children[i].executeDynamicObject(frame);
values[i] = hash;
} catch (UnexpectedResultException e) {
throw new UnsupportedOperationException(children[i].getClass() + " " + e.getResult().getClass());
}
}
return values;
}

}
Original file line number Diff line number Diff line change
@@ -703,13 +703,7 @@ public Object exec(VirtualFrame frame, Object command, Object[] args) {
toHashNode = insert(DispatchHeadNodeFactory.createMethodCall(getContext()));
}

CompilerDirectives.transferToInterpreterAndInvalidate();

final String[] commandLine = new String[1 + args.length];
commandLine[0] = command.toString();
for (int n = 0; n < args.length; n++) {
commandLine[1 + n] = args[n].toString();
}
final String[] commandLine = buildCommandLine(command, args);

final DynamicObject env = coreLibrary().getENV();
final DynamicObject envAsHash = (DynamicObject) toHashNode.call(frame, env, "to_hash", null);
@@ -719,6 +713,16 @@ public Object exec(VirtualFrame frame, Object command, Object[] args) {
return null;
}

@TruffleBoundary
private String[] buildCommandLine(Object command, Object[] args) {
final String[] commandLine = new String[1 + args.length];
commandLine[0] = command.toString();
for (int n = 0; n < args.length; n++) {
commandLine[1 + n] = args[n].toString();
}
return commandLine;
}

@TruffleBoundary
private void exec(RubyContext context, DynamicObject envAsHash, String[] commandLine) {
final ProcessBuilder builder = new ProcessBuilder(commandLine);
@@ -1078,9 +1082,9 @@ public DynamicObject lambda(NotProvided block) {
final DynamicObject parentBlock = RubyArguments.getBlock(parentFrame);

if (parentBlock == null) {
CompilerDirectives.transferToInterpreterAndInvalidate();
throw new RaiseException(coreExceptions().argumentError("tried to create Proc object without a block", this));
}

return lambda(parentBlock);
}

@@ -1449,7 +1453,6 @@ private String getFullPath(final String featureString) {
final String sourcePath = result;

if (sourcePath == null) {
CompilerDirectives.transferToInterpreterAndInvalidate();
throw new RaiseException(coreExceptions().loadError("cannot infer basepath", featureString, this));
}

Original file line number Diff line number Diff line change
@@ -885,8 +885,6 @@ private Object getConstant(VirtualFrame frame, Object module, String name) {
}

private Object getConstantNoInherit(VirtualFrame frame, DynamicObject module, String name, Node currentNode) {
CompilerDirectives.transferToInterpreterAndInvalidate();

RubyConstant constant = ModuleOperations.lookupConstantWithInherit(getContext(), module, name, false, currentNode);
if (constant == null) {
// Call const_missing
Original file line number Diff line number Diff line change
@@ -183,18 +183,17 @@ public static RubyConstant lookupScopedConstant(RubyContext context, DynamicObje

final String lastSegment = fullName.substring(start);
if (!IdUtil.isValidConstantName19(lastSegment)) {
CompilerDirectives.transferToInterpreterAndInvalidate();
throw new RaiseException(context.getCoreExceptions().nameError(String.format("wrong constant name %s", fullName), fullName, currentNode));
}

return lookupConstantWithInherit(context, module, lastSegment, inherit, currentNode);
}

@TruffleBoundary(throwsControlFlowException = true)
public static RubyConstant lookupConstantWithInherit(RubyContext context, DynamicObject module, String name, boolean inherit, Node currentNode) {
assert RubyGuards.isRubyModule(module);

if (!IdUtil.isValidConstantName19(name)) {
CompilerDirectives.transferToInterpreterAndInvalidate();
throw new RaiseException(context.getCoreExceptions().nameError(String.format("wrong constant name %s", name), name, currentNode));
}

Original file line number Diff line number Diff line change
@@ -235,7 +235,8 @@ public Object div(VirtualFrame frame, double a, Object b) {
public abstract static class ModNode extends CoreMethodArrayArgumentsNode {

private final ConditionProfile lessThanZeroProfile = ConditionProfile.createBinaryProfile();

private final BranchProfile zeroProfile = BranchProfile.create();

@Specialization
public double mod(double a, long b) {
return mod(a, (double) b);
@@ -244,7 +245,7 @@ public double mod(double a, long b) {
@Specialization
public double mod(double a, double b) {
if (b == 0) {
CompilerDirectives.transferToInterpreterAndInvalidate();
zeroProfile.enter();
throw new RaiseException(coreExceptions().zeroDivisionError(this));
}

Original file line number Diff line number Diff line change
@@ -1354,8 +1354,7 @@ public Object insertPrepend(DynamicObject string, int index, DynamicObject other

if (compatibleEncoding == null) {
CompilerDirectives.transferToInterpreterAndInvalidate();
throw new RaiseException(coreExceptions().encodingCompatibilityError(
String.format("incompatible encodings: %s and %s", left.getEncoding(), right.getEncoding()), this));
throw new RaiseException(coreExceptions().encodingCompatibilityErrorIncompatible(left.getEncoding(), right.getEncoding(), this));
}

if (prependMakeConcatNode == null) {
@@ -1395,8 +1394,7 @@ public Object insert(VirtualFrame frame, DynamicObject string, int index, Dynami

if (compatibleEncoding == null) {
CompilerDirectives.transferToInterpreterAndInvalidate();
throw new RaiseException(coreExceptions().encodingCompatibilityError(
String.format("incompatible encodings: %s and %s", source.getEncoding(), insert.getEncoding()), this));
throw new RaiseException(coreExceptions().encodingCompatibilityErrorIncompatible(source.getEncoding(), insert.getEncoding(), this));
}

final int stringLength = source.characterLength();
@@ -2663,16 +2661,16 @@ public StringAppendPrimitiveNode(RubyContext context, SourceSection sourceSectio
public abstract DynamicObject executeStringAppend(DynamicObject string, DynamicObject other);

@Specialization(guards = "isRubyString(other)")
public DynamicObject stringAppend(DynamicObject string, DynamicObject other) {
public DynamicObject stringAppend(DynamicObject string, DynamicObject other,
@Cached("create()") BranchProfile errorProfile) {
final Rope left = rope(string);
final Rope right = rope(other);

final Encoding compatibleEncoding = EncodingNodes.CompatibleQueryNode.compatibleEncodingForStrings(string, other);

if (compatibleEncoding == null) {
CompilerDirectives.transferToInterpreterAndInvalidate();
throw new RaiseException(coreExceptions().encodingCompatibilityError(
String.format("incompatible encodings: %s and %s", left.getEncoding(), right.getEncoding()), this));
errorProfile.enter();
throw new RaiseException(coreExceptions().encodingCompatibilityErrorIncompatible(left.getEncoding(), right.getEncoding(), this));
}

StringOperations.setRope(string, makeConcatNode.executeMake(left, right, compatibleEncoding));
Original file line number Diff line number Diff line change
@@ -161,15 +161,13 @@ public static int clampExclusiveIndex(DynamicObject string, int index) {
return ArrayOperations.clampExclusiveIndex(StringOperations.rope(string).byteLength(), index);
}

@TruffleBoundary
public static Encoding checkEncoding(RubyContext context, DynamicObject string, DynamicObject other, Node node) {
final Encoding encoding = EncodingNodes.CompatibleQueryNode.compatibleEncodingForStrings(string, other);

if (encoding == null) {
CompilerDirectives.transferToInterpreterAndInvalidate();
throw new RaiseException(context.getCoreExceptions().encodingCompatibilityErrorIncompatible(
rope(string).getEncoding().toString(),
rope(other).getEncoding().toString(),
node));
rope(string).getEncoding(), rope(other).getEncoding(), node));
}

return encoding;
Original file line number Diff line number Diff line change
@@ -10,11 +10,13 @@
package org.jruby.truffle.core.thread;

import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.nodes.Node;
import com.oracle.truffle.api.object.DynamicObject;
import com.oracle.truffle.api.profiles.BranchProfile;
import com.oracle.truffle.api.source.SourceSection;
import org.jruby.RubyThread.Status;
import org.jruby.runtime.Visibility;
@@ -36,9 +38,7 @@
import org.jruby.truffle.language.control.RaiseException;
import org.jruby.truffle.platform.UnsafeGroup;
import org.jruby.util.Memo;

import java.util.concurrent.TimeUnit;

import static org.jruby.RubyThread.RUBY_MAX_THREAD_PRIORITY;
import static org.jruby.RubyThread.RUBY_MIN_THREAD_PRIORITY;
import static org.jruby.RubyThread.javaPriorityToRubyPriority;
@@ -130,9 +130,11 @@ public void run(DynamicObject currentThread, Node currentNode) {
@CoreMethod(names = "handle_interrupt", required = 2, needsBlock = true, visibility = Visibility.PRIVATE, unsafe = UnsafeGroup.THREADS)
public abstract static class HandleInterruptNode extends YieldingCoreMethodNode {

@CompilerDirectives.CompilationFinal private DynamicObject immediateSymbol;
@CompilerDirectives.CompilationFinal private DynamicObject onBlockingSymbol;
@CompilerDirectives.CompilationFinal private DynamicObject neverSymbol;
@CompilationFinal private DynamicObject immediateSymbol;
@CompilationFinal private DynamicObject onBlockingSymbol;
@CompilationFinal private DynamicObject neverSymbol;

private final BranchProfile errorProfile = BranchProfile.create();

@Specialization(guards = { "isRubyClass(exceptionClass)", "isRubySymbol(timing)" })
public Object handle_interrupt(VirtualFrame frame, DynamicObject self, DynamicObject exceptionClass, DynamicObject timing, DynamicObject block) {
@@ -156,7 +158,7 @@ private InterruptMode symbolToInterruptMode(DynamicObject symbol) {
} else if (symbol == getNeverSymbol()) {
return InterruptMode.NEVER;
} else {
CompilerDirectives.transferToInterpreterAndInvalidate();
errorProfile.enter();
throw new RaiseException(coreExceptions().argumentError("invalid timing symbol", this));
}
}
Original file line number Diff line number Diff line change
@@ -10,6 +10,7 @@
package org.jruby.truffle.language.constants;

import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.NodeChild;
import com.oracle.truffle.api.dsl.NodeChildren;
@@ -80,8 +81,9 @@ protected Object missingConstantCached(
}

@Specialization(guards = "constant == null")
protected Object missingConstantUncached(VirtualFrame frame, DynamicObject module, String name, Object constant, LookupConstantInterface lookupConstantNode) {
final boolean isValidConstantName = isValidConstantName(name);
protected Object missingConstantUncached(VirtualFrame frame, DynamicObject module, String name, Object constant, LookupConstantInterface lookupConstantNode,
@Cached("createBinaryProfile()") ConditionProfile validNameProfile) {
final boolean isValidConstantName = validNameProfile.profile(isValidConstantName(name));
return doMissingConstant(frame, module, name, isValidConstantName, getSymbol(name));
}

@@ -92,7 +94,6 @@ private Object doMissingConstant(
boolean isValidConstantName,
DynamicObject symbolName) {
if (!isValidConstantName) {
CompilerDirectives.transferToInterpreterAndInvalidate();
throw new RaiseException(coreExceptions().nameError(formatError(name), name, this));
}

@@ -104,6 +105,7 @@ private Object doMissingConstant(
return constMissingNode.call(frame, module, "const_missing", null, symbolName);
}

@TruffleBoundary
private String formatError(String name) {
return String.format("wrong constant name %s", name);
}
Original file line number Diff line number Diff line change
@@ -12,6 +12,7 @@
import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.object.DynamicObject;
import com.oracle.truffle.api.profiles.BranchProfile;
import org.jruby.truffle.RubyContext;
import org.jruby.truffle.core.cast.BooleanCastNode;
import org.jruby.truffle.core.cast.BooleanCastNodeGen;
@@ -21,6 +22,8 @@ public class CallDispatchHeadNode extends DispatchHeadNode {

@Child private BooleanCastNode booleanCastNode;

private final BranchProfile errorProfile = BranchProfile.create();

public static CallDispatchHeadNode createMethodCall() {
return new CallDispatchHeadNode(
null,
@@ -79,7 +82,7 @@ public double callFloat(
return (double) value;
}

CompilerDirectives.transferToInterpreterAndInvalidate();
errorProfile.enter();
if (value == DispatchNode.MISSING) {
throw new RaiseException(context.getCoreExceptions().typeErrorCantConvertInto(receiverObject, "Float", this));
} else {
@@ -103,7 +106,7 @@ public long callLongFixnum(
return (long) value;
}

CompilerDirectives.transferToInterpreterAndInvalidate();
errorProfile.enter();
if (value == DispatchNode.MISSING) {
throw new RaiseException(context.getCoreExceptions().typeErrorCantConvertInto(receiverObject, "Fixnum", this));
} else {
Original file line number Diff line number Diff line change
@@ -9,8 +9,8 @@
*/
package org.jruby.truffle.language.dispatch;

import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.Truffle;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.nodes.IndirectCallNode;
import com.oracle.truffle.api.object.DynamicObject;
@@ -38,6 +38,7 @@ public class UncachedDispatchNode extends DispatchNode {
@Child private MetaClassNode metaClassNode;

private final BranchProfile methodMissingProfile = BranchProfile.create();
private final BranchProfile methodMissingNotFoundProfile = BranchProfile.create();

public UncachedDispatchNode(RubyContext context, boolean ignoreVisibility, DispatchAction dispatchAction, MissingBehavior missingBehavior) {
super(context, dispatchAction);
@@ -90,9 +91,8 @@ public Object executeDispatch(
if (dispatchAction == DispatchAction.RESPOND_TO_METHOD) {
return false;
} else {
CompilerDirectives.transferToInterpreterAndInvalidate();
throw new RaiseException(coreExceptions().runtimeError(
receiverObject.toString() + " didn't have a #method_missing", this));
methodMissingNotFoundProfile.enter();
throw new RaiseException(methodMissingNotFound(receiverObject));
}
}

@@ -115,4 +115,9 @@ private Object call(VirtualFrame frame, InternalMethod method, Object receiverOb
RubyArguments.pack(null, null, method, DeclarationContext.METHOD, null, receiverObject, blockObject, argumentsObjects));
}

@TruffleBoundary
private DynamicObject methodMissingNotFound(Object receiverObject) {
return coreExceptions().runtimeError(receiverObject.toString() + " didn't have a #method_missing", this);
}

}
Original file line number Diff line number Diff line change
@@ -9,8 +9,8 @@
*/
package org.jruby.truffle.language.methods;

import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.frame.Frame;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.object.DynamicObject;
import org.jruby.runtime.Visibility;
import org.jruby.truffle.RubyContext;
@@ -70,16 +70,16 @@ private DeclarationContext withVisibility(Visibility visibility) {
return new DeclarationContext(visibility, defaultDefinee);
}

public DynamicObject getModuleToDefineMethods(VirtualFrame frame, RubyContext context, SingletonClassNode singletonClassNode) {
public DynamicObject getModuleToDefineMethods(Object self, InternalMethod method, RubyContext context, SingletonClassNode singletonClassNode) {
switch (defaultDefinee) {
case LEXICAL_SCOPE:
return RubyArguments.getMethod(frame).getSharedMethodInfo().getLexicalScope().getLiveModule();
return method.getSharedMethodInfo().getLexicalScope().getLiveModule();
case SINGLETON_CLASS:
final Object self = RubyArguments.getSelf(frame);
return singletonClassNode.executeSingletonClass(self);
case SELF:
return (DynamicObject) RubyArguments.getSelf(frame);
return (DynamicObject) self;
default:
CompilerDirectives.transferToInterpreterAndInvalidate();
throw new UnsupportedOperationException();
}
}
Original file line number Diff line number Diff line change
@@ -9,7 +9,6 @@
*/
package org.jruby.truffle.language.methods;

import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.dsl.UnsupportedSpecializationException;
import com.oracle.truffle.api.frame.VirtualFrame;
@@ -33,6 +32,7 @@ public class ExceptionTranslatingNode extends RubyNode {
private final BranchProfile controlProfile = BranchProfile.create();
private final BranchProfile arithmeticProfile = BranchProfile.create();
private final BranchProfile unsupportedProfile = BranchProfile.create();
private final BranchProfile errorProfile = BranchProfile.create();

public ExceptionTranslatingNode(RubyContext context, SourceSection sourceSection, RubyNode child,
UnsupportedOperationBehavior unsupportedOperationBehavior) {
@@ -55,16 +55,16 @@ public Object execute(VirtualFrame frame) {
unsupportedProfile.enter();
throw new RaiseException(translate(exception));
} catch (TruffleFatalException exception) {
CompilerDirectives.transferToInterpreterAndInvalidate();
errorProfile.enter();
throw exception;
} catch (org.jruby.exceptions.RaiseException e) {
CompilerDirectives.transferToInterpreterAndInvalidate();
errorProfile.enter();
throw new RaiseException(getContext().getJRubyInterop().toTruffle(e.getException(), this));
} catch (StackOverflowError error) {
CompilerDirectives.transferToInterpreterAndInvalidate();
errorProfile.enter();
throw new RaiseException(translate(error));
} catch (Throwable exception) {
CompilerDirectives.transferToInterpreterAndInvalidate();
errorProfile.enter();
throw new RaiseException(translate(exception));
}
}
@@ -78,6 +78,7 @@ private DynamicObject translate(ArithmeticException exception) {
return coreExceptions().zeroDivisionError(this, exception);
}

@TruffleBoundary
private DynamicObject translate(StackOverflowError error) {
if (getContext().getOptions().EXCEPTIONS_PRINT_JAVA) {
error.printStackTrace();
@@ -154,6 +155,7 @@ private DynamicObject translate(UnsupportedSpecializationException exception) {
}
}

@TruffleBoundary
public DynamicObject translate(Throwable throwable) {
if (getContext().getOptions().EXCEPTIONS_PRINT_JAVA
|| getContext().getOptions().EXCEPTIONS_PRINT_UNCAUGHT_JAVA) {
Original file line number Diff line number Diff line change
@@ -9,7 +9,6 @@
*/
package org.jruby.truffle.language.methods;

import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.object.DynamicObject;
import com.oracle.truffle.api.source.SourceSection;
@@ -30,14 +29,15 @@ public GetDefaultDefineeNode(RubyContext context, SourceSection sourceSection) {

@Override
public DynamicObject execute(VirtualFrame frame) {
CompilerDirectives.transferToInterpreterAndInvalidate();

final DynamicObject capturedDefaultDefinee = RubyArguments.getMethod(frame).getCapturedDefaultDefinee();
final InternalMethod method = RubyArguments.getMethod(frame);
final DynamicObject capturedDefaultDefinee = method.getCapturedDefaultDefinee();

if (capturedDefaultDefinee != null) {
return capturedDefaultDefinee;
}

return RubyArguments.getDeclarationContext(frame).getModuleToDefineMethods(frame, getContext(), singletonClassNode);
final Object self = RubyArguments.getSelf(frame);
final DeclarationContext declarationContext = RubyArguments.getDeclarationContext(frame);
return declarationContext.getModuleToDefineMethods(self, method, getContext(), singletonClassNode);
}
}
Original file line number Diff line number Diff line change
@@ -10,12 +10,12 @@

package org.jruby.truffle.language.objects;

import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
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.object.DynamicObject;
import com.oracle.truffle.api.profiles.BranchProfile;
import com.oracle.truffle.api.source.SourceSection;
import org.jruby.truffle.Layouts;
import org.jruby.truffle.RubyContext;
@@ -25,6 +25,8 @@
@NodeChild(value = "child")
public abstract class IsFrozenNode extends RubyNode {

private final BranchProfile errorProfile = BranchProfile.create();

public IsFrozenNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
}
@@ -33,7 +35,7 @@ public IsFrozenNode(RubyContext context, SourceSection sourceSection) {

public void raiseIfFrozen(Object object) {
if (executeIsFrozen(object)) {
CompilerDirectives.transferToInterpreterAndInvalidate();
errorProfile.enter();
throw new RaiseException(coreExceptions().frozenError(object, this));
}
}
Original file line number Diff line number Diff line change
@@ -645,7 +645,6 @@ public Object moduloSpecial(

if (normalNegProfile.profile(bType == BigDecimalType.NEGATIVE_ZERO
|| (bType == BigDecimalType.NORMAL && isNormalZero(b)))) {
CompilerDirectives.transferToInterpreterAndInvalidate();
throw new RaiseException(coreExceptions().zeroDivisionError(this));
}

0 comments on commit b43a285

Please sign in to comment.