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

Commits on Jul 18, 2016

  1. Copy the full SHA
    977a8ad View commit details
  2. Copy the full SHA
    840ed0d View commit details
Showing with 22 additions and 14 deletions.
  1. +9 −5 truffle/src/main/java/org/jruby/truffle/core/hash/HashNodes.java
  2. +13 −9 truffle/src/main/java/org/jruby/truffle/core/regexp/MatchDataNodes.java
14 changes: 9 additions & 5 deletions truffle/src/main/java/org/jruby/truffle/core/hash/HashNodes.java
Original file line number Diff line number Diff line change
@@ -460,8 +460,9 @@ public boolean compareByIdentity(DynamicObject hash) {
public abstract static class DefaultProcNode extends CoreMethodArrayArgumentsNode {

@Specialization
public Object defaultProc(DynamicObject hash) {
if (Layouts.HASH.getDefaultBlock(hash) == null) {
public Object defaultProc(DynamicObject hash,
@Cached("createBinaryProfile()") ConditionProfile defaultBlockNullProfile) {
if (defaultBlockNullProfile.profile(Layouts.HASH.getDefaultBlock(hash) == null)) {
return nil();
} else {
return Layouts.HASH.getDefaultBlock(hash);
@@ -1417,7 +1418,7 @@ public InternalDefaultValueNode(RubyContext context, SourceSection sourceSection

@Specialization
public Object internalDefaultValue(DynamicObject hash) {
return defaultValueNode.defaultValue(hash);
return defaultValueNode.executeDefaultValue(hash);
}

}
@@ -1426,11 +1427,14 @@ public Object internalDefaultValue(DynamicObject hash) {
@NodeChild(type = RubyNode.class, value = "self")
public abstract static class DefaultValueNode extends CoreMethodNode {

public abstract Object executeDefaultValue(DynamicObject hash);

@Specialization
public Object defaultValue(DynamicObject hash) {
public Object defaultValue(DynamicObject hash,
@Cached("createBinaryProfile()") ConditionProfile nullValueProfile) {
final Object value = Layouts.HASH.getDefaultValue(hash);

if (value == null) {
if (nullValueProfile.profile(value == null)) {
return nil();
} else {
return value;
Original file line number Diff line number Diff line change
@@ -17,6 +17,7 @@
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.profiles.ConditionProfile;
import com.oracle.truffle.api.source.SourceSection;
import java.util.Arrays;
import org.jcodings.Encoding;
@@ -171,13 +172,13 @@ public abstract static class GetIndexNode extends CoreMethodArrayArgumentsNode {

@Child private ToIntNode toIntNode;

@TruffleBoundary
@Specialization
public Object getIndex(DynamicObject matchData, int index, NotProvided length) {
public Object getIndex(DynamicObject matchData, int index, NotProvided length,
@Cached("createBinaryProfile()") ConditionProfile indexOutOfBoundsProfile) {
final Object[] values = Layouts.MATCH_DATA.getValues(matchData);
final int normalizedIndex = ArrayOperations.normalizeIndex(values.length, index);

if ((normalizedIndex < 0) || (normalizedIndex >= values.length)) {
if (indexOutOfBoundsProfile.profile((normalizedIndex < 0) || (normalizedIndex >= values.length))) {
return nil();
} else {
return values[normalizedIndex];
@@ -197,12 +198,13 @@ public Object getIndex(DynamicObject matchData, int index, int length) {
@TruffleBoundary(throwsControlFlowException = true)
@Specialization(guards = "isRubySymbol(index)")
public Object getIndexSymbol(DynamicObject matchData, DynamicObject index, NotProvided length,
@Cached("create()") BranchProfile errorProfile) {
@Cached("create()") BranchProfile errorProfile,
@Cached("createBinaryProfile()") ConditionProfile indexOutOfBoundsProfile) {
try {
final Rope value = Layouts.SYMBOL.getRope(index);
final int i = Layouts.REGEXP.getRegex(Layouts.MATCH_DATA.getRegexp(matchData)).nameToBackrefNumber(value.getBytes(), 0, value.byteLength(), Layouts.MATCH_DATA.getRegion(matchData));

return getIndex(matchData, i, NotProvided.INSTANCE);
return getIndex(matchData, i, NotProvided.INSTANCE, indexOutOfBoundsProfile);
} catch (final ValueException e) {
throw new RaiseException(
coreExceptions().indexError(String.format("undefined group name reference: %s", Layouts.SYMBOL.getString(index)), this));
@@ -211,12 +213,13 @@ public Object getIndexSymbol(DynamicObject matchData, DynamicObject index, NotPr

@TruffleBoundary(throwsControlFlowException = true)
@Specialization(guards = "isRubyString(index)")
public Object getIndexString(DynamicObject matchData, DynamicObject index, NotProvided length) {
public Object getIndexString(DynamicObject matchData, DynamicObject index, NotProvided length,
@Cached("createBinaryProfile()") ConditionProfile indexOutOfBoundsProfile) {
try {
final Rope value = StringOperations.rope(index);
final int i = Layouts.REGEXP.getRegex(Layouts.MATCH_DATA.getRegexp(matchData)).nameToBackrefNumber(value.getBytes(), 0, value.byteLength(), Layouts.MATCH_DATA.getRegion(matchData));

return getIndex(matchData, i, NotProvided.INSTANCE);
return getIndex(matchData, i, NotProvided.INSTANCE, indexOutOfBoundsProfile);
}
catch (final ValueException e) {
throw new RaiseException(
@@ -225,13 +228,14 @@ public Object getIndexString(DynamicObject matchData, DynamicObject index, NotPr
}

@Specialization(guards = { "!isRubySymbol(index)", "!isRubyString(index)", "!isIntRange(index)" })
public Object getIndex(VirtualFrame frame, DynamicObject matchData, Object index, NotProvided length) {
public Object getIndex(VirtualFrame frame, DynamicObject matchData, Object index, NotProvided length,
@Cached("createBinaryProfile()") ConditionProfile indexOutOfBoundsProfile) {
if (toIntNode == null) {
CompilerDirectives.transferToInterpreterAndInvalidate();
toIntNode = insert(ToIntNode.create());
}

return getIndex(matchData, toIntNode.doInt(frame, index), NotProvided.INSTANCE);
return getIndex(matchData, toIntNode.doInt(frame, index), NotProvided.INSTANCE, indexOutOfBoundsProfile);
}

@TruffleBoundary