Skip to content

Commit

Permalink
Merge branch 'master' into truffle-head
Browse files Browse the repository at this point in the history
Conflicts:
	core/src/main/java/org/jruby/truffle/nodes/RubyNode.java
  • Loading branch information
chrisseaton committed Jan 5, 2015
2 parents 432d579 + 32cdcfb commit e898e9c
Show file tree
Hide file tree
Showing 30 changed files with 427 additions and 751 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Expand Up @@ -99,3 +99,8 @@ core/.gitignore
core/.project
core/.settings
core/.apt_generated

# Truffle findbugs
truffle-findbugs-report.html
findbugs-noUpdateChecks-3.0.0.tar.gz
findbugs-3.0.0
3 changes: 3 additions & 0 deletions .travis.yml
Expand Up @@ -62,12 +62,15 @@ matrix:
jdk: oraclejdk8
- env: COMMAND=test/check_versions.sh
jdk: oraclejdk8
- env: COMMAND=tool/truffle-findbugs.sh
jdk: oraclejdk8
fast_finish: true
allow_failures:
- env: PHASE='-Pcomplete'
- env: PHASE='-Prake -Dtask=spec:jrubyc'
- env: PHASE='-Prake -Dtask=spec:profiler'
- env: PHASE='-Ptruffle-specs-rubysl'
- env: COMMAND=tool/truffle-findbugs.sh

branches:
only:
Expand Down
3 changes: 2 additions & 1 deletion core/src/main/java/org/jruby/RubyString.java
Expand Up @@ -3380,7 +3380,8 @@ public RubyBoolean include_p(ThreadContext context, IRubyObject obj) {
@JRubyMethod(name = "include?")
public RubyBoolean include_p19(ThreadContext context, IRubyObject obj) {
Ruby runtime = context.runtime;
return StringSupport.index(this, this.value, this.strLength(this.checkEncoding(obj.convertToString())), obj.convertToString(), obj.convertToString().value, obj.convertToString().strLength(this.checkEncoding(obj.convertToString())), 0, this.checkEncoding(obj.convertToString())) == -1 ? runtime.getFalse() : runtime.getTrue();
RubyString coerced = obj.convertToString();
return StringSupport.index(this, this.value, this.strLength(this.checkEncoding(coerced)), coerced, coerced.value, coerced.strLength(this.checkEncoding(coerced)), 0, this.checkEncoding(coerced)) == -1 ? runtime.getFalse() : runtime.getTrue();
}

@JRubyMethod
Expand Down
50 changes: 49 additions & 1 deletion core/src/main/java/org/jruby/truffle/nodes/RubyNode.java
Expand Up @@ -13,11 +13,15 @@
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
import com.oracle.truffle.api.dsl.TypeSystemReference;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.instrument.Probe;
import com.oracle.truffle.api.instrument.ProbeNode;
import com.oracle.truffle.api.instrument.TruffleEventReceiver;
import com.oracle.truffle.api.interop.TruffleObject;
import com.oracle.truffle.api.nodes.Node;
import com.oracle.truffle.api.nodes.UnexpectedResultException;
import com.oracle.truffle.api.source.SourceSection;
import org.jruby.truffle.nodes.dispatch.Dispatch;
import org.jruby.truffle.nodes.instrument.RubyWrapperNode;
import org.jruby.truffle.nodes.yield.YieldDispatchNode;
import org.jruby.truffle.runtime.LexicalScope;
import org.jruby.truffle.runtime.RubyContext;
Expand All @@ -33,7 +37,7 @@
*/
@TypeSystemReference(RubyTypes.class)
@GenerateNodeFactory
public abstract class RubyNode extends Node {
public abstract class RubyNode extends Node implements ProbeNode.Instrumentable {

private final RubyContext context;

Expand Down Expand Up @@ -225,6 +229,50 @@ public RubyBignum bignum(BigInteger value) {
return new RubyBignum(getContext().getCoreLibrary().getBignumClass(), value);
}

public RubyNode getNonWrapperNode() {
return this;
}

public Probe probe() {
final Node parent = getParent();

if (parent == null) {
throw new IllegalStateException("Cannot call probe() on a node without a parent.");
}

if (parent instanceof RubyWrapperNode) {
return ((RubyWrapperNode) parent).getProbe();
}

// Create a new wrapper/probe with this node as its child.
final RubyWrapperNode wrapper = new RubyWrapperNode(this);

// Connect it to a Probe
final Probe probe = ProbeNode.insertProbe(wrapper);

// Replace this node in the AST with the wrapper
this.replace(wrapper);

return probe;
}

public void probeLite(TruffleEventReceiver eventReceiver) {
final Node parent = getParent();

if (parent == null) {
throw new IllegalStateException("Cannot call probeLite() on a node without a parent");
}

if (parent instanceof RubyWrapperNode) {
throw new IllegalStateException("Cannot call probeLite() on a node that already has a wrapper.");
}

final RubyWrapperNode wrapper = new RubyWrapperNode(this);
ProbeNode.insertProbeLite(wrapper, eventReceiver);

this.replace(wrapper);
}

// Copied from RubyTypesGen

@SuppressWarnings("static-method")
Expand Down
Expand Up @@ -37,8 +37,7 @@ public AndNode(RubyContext context, SourceSection sourceSection, RubyNode left,
@Override
public Object execute(VirtualFrame frame) {
final Object leftValue = left.execute(frame);
boolean leftBoolean = leftCast.executeBoolean(frame, leftValue);
if (conditionProfile.profile(leftBoolean)) {
if (conditionProfile.profile(leftCast.executeBoolean(frame, leftValue))) {
// Right expression evaluated and returned if left expression returns true.
return right.execute(frame);
} else {
Expand Down
32 changes: 4 additions & 28 deletions core/src/main/java/org/jruby/truffle/nodes/control/IfNode.java
Expand Up @@ -9,10 +9,10 @@
*/
package org.jruby.truffle.nodes.control;

import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.source.SourceSection;
import com.oracle.truffle.api.utilities.BranchProfile;
import com.oracle.truffle.api.utilities.ConditionProfile;

import org.jruby.truffle.nodes.RubyNode;
import org.jruby.truffle.nodes.cast.BooleanCastNode;
import org.jruby.truffle.runtime.RubyContext;
Expand All @@ -26,12 +26,7 @@ public class IfNode extends RubyNode {
@Child protected BooleanCastNode condition;
@Child protected RubyNode thenBody;
@Child protected RubyNode elseBody;

private final BranchProfile thenProfile = BranchProfile.create();
private final BranchProfile elseProfile = BranchProfile.create();

@CompilerDirectives.CompilationFinal private int thenCount;
@CompilerDirectives.CompilationFinal private int elseCount;
private final ConditionProfile conditionProfile = ConditionProfile.createCountingProfile();

public IfNode(RubyContext context, SourceSection sourceSection, BooleanCastNode condition, RubyNode thenBody, RubyNode elseBody) {
super(context, sourceSection);
Expand All @@ -47,29 +42,10 @@ public IfNode(RubyContext context, SourceSection sourceSection, BooleanCastNode

@Override
public Object execute(VirtualFrame frame) {
if (CompilerDirectives.injectBranchProbability(getBranchProbability(), condition.executeBoolean(frame))) {
if (CompilerDirectives.inInterpreter()) {
thenCount++;
}
thenProfile.enter();
if (conditionProfile.profile(condition.executeBoolean(frame))) {
return thenBody.execute(frame);
} else {
if (CompilerDirectives.inInterpreter()) {
elseCount++;
}
elseProfile.enter();
return elseBody.execute(frame);
}
}

private double getBranchProbability() {
final int totalCount = thenCount + elseCount;

if (totalCount == 0) {
return 0;
} else {
return (double) thenCount / (double) (thenCount + elseCount);
}
}

}
11 changes: 6 additions & 5 deletions core/src/main/java/org/jruby/truffle/nodes/control/OrNode.java
Expand Up @@ -9,6 +9,7 @@
*/
package org.jruby.truffle.nodes.control;

import com.oracle.truffle.api.utilities.ConditionProfile;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.source.SourceSection;
import org.jruby.truffle.nodes.RubyNode;
Expand All @@ -24,6 +25,8 @@ public class OrNode extends RubyNode {
@Child protected RubyNode left;
@Child protected BooleanCastNode leftCast;
@Child protected RubyNode right;
private final ConditionProfile conditionProfile = ConditionProfile.createCountingProfile();


public OrNode(RubyContext context, SourceSection sourceSection, RubyNode left, RubyNode right) {
super(context, sourceSection);
Expand All @@ -35,12 +38,10 @@ public OrNode(RubyContext context, SourceSection sourceSection, RubyNode left, R
@Override
public Object execute(VirtualFrame frame) {
final Object leftValue = left.execute(frame);

if (leftCast.executeBoolean(frame, leftValue)) {
if (conditionProfile.profile(leftCast.executeBoolean(frame, leftValue))) {
return leftValue;
} else {
return right.execute(frame);
}

return right.execute(frame);
}

}
56 changes: 24 additions & 32 deletions core/src/main/java/org/jruby/truffle/nodes/control/TraceNode.java
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, 2014 Oracle and/or its affiliates. All rights reserved. This
* Copyright (c) 2013, 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:
*
Expand All @@ -13,19 +13,21 @@
import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.Truffle;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.instrument.KillException;
import com.oracle.truffle.api.nodes.DirectCallNode;
import com.oracle.truffle.api.nodes.InvalidAssumptionException;
import com.oracle.truffle.api.nodes.UnexpectedResultException;
import com.oracle.truffle.api.source.SourceSection;
import org.jruby.truffle.nodes.RubyNode;
import org.jruby.truffle.runtime.RubyArguments;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.core.RubyBinding;
import org.jruby.truffle.runtime.core.RubyProc;
import org.jruby.truffle.runtime.core.RubyString;
import org.jruby.truffle.runtime.UndefinedPlaceholder;
import org.jruby.truffle.runtime.core.*;

public class TraceNode extends WrapperNode {
public class TraceNode extends RubyNode {

private final RubyContext context;
@Child protected RubyNode child;

@CompilerDirectives.CompilationFinal private Assumption traceAssumption;
@CompilerDirectives.CompilationFinal private RubyProc traceFunc;
Expand All @@ -36,7 +38,8 @@ public class TraceNode extends WrapperNode {
private final int line;

public TraceNode(RubyContext context, SourceSection sourceSection, RubyNode child) {
super(context, sourceSection, child);
super(context, sourceSection);
this.child = child;
this.context = context;
traceAssumption = context.getTraceManager().getTraceAssumption();
traceFunc = null;
Expand All @@ -47,7 +50,19 @@ public TraceNode(RubyContext context, SourceSection sourceSection, RubyNode chil
}

@Override
public void enter(VirtualFrame frame) {
public Object execute(VirtualFrame frame) {
trace(frame);
return child.execute(frame);
}


@Override
public void executeVoid(VirtualFrame frame) {
trace(frame);
child.executeVoid(frame);
}

public void trace(VirtualFrame frame) {
try {
traceAssumption.check();
} catch (InvalidAssumptionException e) {
Expand Down Expand Up @@ -84,30 +99,7 @@ public void enter(VirtualFrame frame) {
}

@Override
void leave(VirtualFrame frame) {
}

@Override
void leave(VirtualFrame frame, boolean result) {
}

@Override
void leave(VirtualFrame frame, int result) {
}

@Override
void leave(VirtualFrame frame, long result) {
}

@Override
void leave(VirtualFrame frame, double result) {
}

@Override
void leave(VirtualFrame frame, Object result) {
}

@Override
void leaveExceptional(VirtualFrame frame, Exception e) {
public Object isDefined(VirtualFrame frame) {
return child.isDefined(frame);
}
}

0 comments on commit e898e9c

Please sign in to comment.