Skip to content

Commit e898e9c

Browse files
committed
Merge branch 'master' into truffle-head
Conflicts: core/src/main/java/org/jruby/truffle/nodes/RubyNode.java
2 parents 432d579 + 32cdcfb commit e898e9c

30 files changed

+427
-751
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,3 +99,8 @@ core/.gitignore
9999
core/.project
100100
core/.settings
101101
core/.apt_generated
102+
103+
# Truffle findbugs
104+
truffle-findbugs-report.html
105+
findbugs-noUpdateChecks-3.0.0.tar.gz
106+
findbugs-3.0.0

.travis.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,15 @@ matrix:
6262
jdk: oraclejdk8
6363
- env: COMMAND=test/check_versions.sh
6464
jdk: oraclejdk8
65+
- env: COMMAND=tool/truffle-findbugs.sh
66+
jdk: oraclejdk8
6567
fast_finish: true
6668
allow_failures:
6769
- env: PHASE='-Pcomplete'
6870
- env: PHASE='-Prake -Dtask=spec:jrubyc'
6971
- env: PHASE='-Prake -Dtask=spec:profiler'
7072
- env: PHASE='-Ptruffle-specs-rubysl'
73+
- env: COMMAND=tool/truffle-findbugs.sh
7174

7275
branches:
7376
only:

core/src/main/java/org/jruby/RubyString.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3380,7 +3380,8 @@ public RubyBoolean include_p(ThreadContext context, IRubyObject obj) {
33803380
@JRubyMethod(name = "include?")
33813381
public RubyBoolean include_p19(ThreadContext context, IRubyObject obj) {
33823382
Ruby runtime = context.runtime;
3383-
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();
3383+
RubyString coerced = obj.convertToString();
3384+
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();
33843385
}
33853386

33863387
@JRubyMethod

core/src/main/java/org/jruby/truffle/nodes/RubyNode.java

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,15 @@
1313
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
1414
import com.oracle.truffle.api.dsl.TypeSystemReference;
1515
import com.oracle.truffle.api.frame.VirtualFrame;
16+
import com.oracle.truffle.api.instrument.Probe;
17+
import com.oracle.truffle.api.instrument.ProbeNode;
18+
import com.oracle.truffle.api.instrument.TruffleEventReceiver;
1619
import com.oracle.truffle.api.interop.TruffleObject;
1720
import com.oracle.truffle.api.nodes.Node;
1821
import com.oracle.truffle.api.nodes.UnexpectedResultException;
1922
import com.oracle.truffle.api.source.SourceSection;
2023
import org.jruby.truffle.nodes.dispatch.Dispatch;
24+
import org.jruby.truffle.nodes.instrument.RubyWrapperNode;
2125
import org.jruby.truffle.nodes.yield.YieldDispatchNode;
2226
import org.jruby.truffle.runtime.LexicalScope;
2327
import org.jruby.truffle.runtime.RubyContext;
@@ -33,7 +37,7 @@
3337
*/
3438
@TypeSystemReference(RubyTypes.class)
3539
@GenerateNodeFactory
36-
public abstract class RubyNode extends Node {
40+
public abstract class RubyNode extends Node implements ProbeNode.Instrumentable {
3741

3842
private final RubyContext context;
3943

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

232+
public RubyNode getNonWrapperNode() {
233+
return this;
234+
}
235+
236+
public Probe probe() {
237+
final Node parent = getParent();
238+
239+
if (parent == null) {
240+
throw new IllegalStateException("Cannot call probe() on a node without a parent.");
241+
}
242+
243+
if (parent instanceof RubyWrapperNode) {
244+
return ((RubyWrapperNode) parent).getProbe();
245+
}
246+
247+
// Create a new wrapper/probe with this node as its child.
248+
final RubyWrapperNode wrapper = new RubyWrapperNode(this);
249+
250+
// Connect it to a Probe
251+
final Probe probe = ProbeNode.insertProbe(wrapper);
252+
253+
// Replace this node in the AST with the wrapper
254+
this.replace(wrapper);
255+
256+
return probe;
257+
}
258+
259+
public void probeLite(TruffleEventReceiver eventReceiver) {
260+
final Node parent = getParent();
261+
262+
if (parent == null) {
263+
throw new IllegalStateException("Cannot call probeLite() on a node without a parent");
264+
}
265+
266+
if (parent instanceof RubyWrapperNode) {
267+
throw new IllegalStateException("Cannot call probeLite() on a node that already has a wrapper.");
268+
}
269+
270+
final RubyWrapperNode wrapper = new RubyWrapperNode(this);
271+
ProbeNode.insertProbeLite(wrapper, eventReceiver);
272+
273+
this.replace(wrapper);
274+
}
275+
228276
// Copied from RubyTypesGen
229277

230278
@SuppressWarnings("static-method")

core/src/main/java/org/jruby/truffle/nodes/control/AndNode.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@ public AndNode(RubyContext context, SourceSection sourceSection, RubyNode left,
3737
@Override
3838
public Object execute(VirtualFrame frame) {
3939
final Object leftValue = left.execute(frame);
40-
boolean leftBoolean = leftCast.executeBoolean(frame, leftValue);
41-
if (conditionProfile.profile(leftBoolean)) {
40+
if (conditionProfile.profile(leftCast.executeBoolean(frame, leftValue))) {
4241
// Right expression evaluated and returned if left expression returns true.
4342
return right.execute(frame);
4443
} else {

core/src/main/java/org/jruby/truffle/nodes/control/IfNode.java

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99
*/
1010
package org.jruby.truffle.nodes.control;
1111

12-
import com.oracle.truffle.api.CompilerDirectives;
1312
import com.oracle.truffle.api.frame.VirtualFrame;
1413
import com.oracle.truffle.api.source.SourceSection;
15-
import com.oracle.truffle.api.utilities.BranchProfile;
14+
import com.oracle.truffle.api.utilities.ConditionProfile;
15+
1616
import org.jruby.truffle.nodes.RubyNode;
1717
import org.jruby.truffle.nodes.cast.BooleanCastNode;
1818
import org.jruby.truffle.runtime.RubyContext;
@@ -26,12 +26,7 @@ public class IfNode extends RubyNode {
2626
@Child protected BooleanCastNode condition;
2727
@Child protected RubyNode thenBody;
2828
@Child protected RubyNode elseBody;
29-
30-
private final BranchProfile thenProfile = BranchProfile.create();
31-
private final BranchProfile elseProfile = BranchProfile.create();
32-
33-
@CompilerDirectives.CompilationFinal private int thenCount;
34-
@CompilerDirectives.CompilationFinal private int elseCount;
29+
private final ConditionProfile conditionProfile = ConditionProfile.createCountingProfile();
3530

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

4843
@Override
4944
public Object execute(VirtualFrame frame) {
50-
if (CompilerDirectives.injectBranchProbability(getBranchProbability(), condition.executeBoolean(frame))) {
51-
if (CompilerDirectives.inInterpreter()) {
52-
thenCount++;
53-
}
54-
thenProfile.enter();
45+
if (conditionProfile.profile(condition.executeBoolean(frame))) {
5546
return thenBody.execute(frame);
5647
} else {
57-
if (CompilerDirectives.inInterpreter()) {
58-
elseCount++;
59-
}
60-
elseProfile.enter();
6148
return elseBody.execute(frame);
6249
}
6350
}
64-
65-
private double getBranchProbability() {
66-
final int totalCount = thenCount + elseCount;
67-
68-
if (totalCount == 0) {
69-
return 0;
70-
} else {
71-
return (double) thenCount / (double) (thenCount + elseCount);
72-
}
73-
}
74-
7551
}

core/src/main/java/org/jruby/truffle/nodes/control/OrNode.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
*/
1010
package org.jruby.truffle.nodes.control;
1111

12+
import com.oracle.truffle.api.utilities.ConditionProfile;
1213
import com.oracle.truffle.api.frame.VirtualFrame;
1314
import com.oracle.truffle.api.source.SourceSection;
1415
import org.jruby.truffle.nodes.RubyNode;
@@ -24,6 +25,8 @@ public class OrNode extends RubyNode {
2425
@Child protected RubyNode left;
2526
@Child protected BooleanCastNode leftCast;
2627
@Child protected RubyNode right;
28+
private final ConditionProfile conditionProfile = ConditionProfile.createCountingProfile();
29+
2730

2831
public OrNode(RubyContext context, SourceSection sourceSection, RubyNode left, RubyNode right) {
2932
super(context, sourceSection);
@@ -35,12 +38,10 @@ public OrNode(RubyContext context, SourceSection sourceSection, RubyNode left, R
3538
@Override
3639
public Object execute(VirtualFrame frame) {
3740
final Object leftValue = left.execute(frame);
38-
39-
if (leftCast.executeBoolean(frame, leftValue)) {
41+
if (conditionProfile.profile(leftCast.executeBoolean(frame, leftValue))) {
4042
return leftValue;
43+
} else {
44+
return right.execute(frame);
4145
}
42-
43-
return right.execute(frame);
4446
}
45-
4647
}

core/src/main/java/org/jruby/truffle/nodes/control/TraceNode.java

Lines changed: 24 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2013, 2014 Oracle and/or its affiliates. All rights reserved. This
2+
* Copyright (c) 2013, 2015 Oracle and/or its affiliates. All rights reserved. This
33
* code is released under a tri EPL/GPL/LGPL license. You can use it,
44
* redistribute it and/or modify it under the terms of the:
55
*
@@ -13,19 +13,21 @@
1313
import com.oracle.truffle.api.CompilerDirectives;
1414
import com.oracle.truffle.api.Truffle;
1515
import com.oracle.truffle.api.frame.VirtualFrame;
16+
import com.oracle.truffle.api.instrument.KillException;
1617
import com.oracle.truffle.api.nodes.DirectCallNode;
1718
import com.oracle.truffle.api.nodes.InvalidAssumptionException;
19+
import com.oracle.truffle.api.nodes.UnexpectedResultException;
1820
import com.oracle.truffle.api.source.SourceSection;
1921
import org.jruby.truffle.nodes.RubyNode;
2022
import org.jruby.truffle.runtime.RubyArguments;
2123
import org.jruby.truffle.runtime.RubyContext;
22-
import org.jruby.truffle.runtime.core.RubyBinding;
23-
import org.jruby.truffle.runtime.core.RubyProc;
24-
import org.jruby.truffle.runtime.core.RubyString;
24+
import org.jruby.truffle.runtime.UndefinedPlaceholder;
25+
import org.jruby.truffle.runtime.core.*;
2526

26-
public class TraceNode extends WrapperNode {
27+
public class TraceNode extends RubyNode {
2728

2829
private final RubyContext context;
30+
@Child protected RubyNode child;
2931

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

3840
public TraceNode(RubyContext context, SourceSection sourceSection, RubyNode child) {
39-
super(context, sourceSection, child);
41+
super(context, sourceSection);
42+
this.child = child;
4043
this.context = context;
4144
traceAssumption = context.getTraceManager().getTraceAssumption();
4245
traceFunc = null;
@@ -47,7 +50,19 @@ public TraceNode(RubyContext context, SourceSection sourceSection, RubyNode chil
4750
}
4851

4952
@Override
50-
public void enter(VirtualFrame frame) {
53+
public Object execute(VirtualFrame frame) {
54+
trace(frame);
55+
return child.execute(frame);
56+
}
57+
58+
59+
@Override
60+
public void executeVoid(VirtualFrame frame) {
61+
trace(frame);
62+
child.executeVoid(frame);
63+
}
64+
65+
public void trace(VirtualFrame frame) {
5166
try {
5267
traceAssumption.check();
5368
} catch (InvalidAssumptionException e) {
@@ -84,30 +99,7 @@ public void enter(VirtualFrame frame) {
8499
}
85100

86101
@Override
87-
void leave(VirtualFrame frame) {
88-
}
89-
90-
@Override
91-
void leave(VirtualFrame frame, boolean result) {
92-
}
93-
94-
@Override
95-
void leave(VirtualFrame frame, int result) {
96-
}
97-
98-
@Override
99-
void leave(VirtualFrame frame, long result) {
100-
}
101-
102-
@Override
103-
void leave(VirtualFrame frame, double result) {
104-
}
105-
106-
@Override
107-
void leave(VirtualFrame frame, Object result) {
108-
}
109-
110-
@Override
111-
void leaveExceptional(VirtualFrame frame, Exception e) {
102+
public Object isDefined(VirtualFrame frame) {
103+
return child.isDefined(frame);
112104
}
113105
}

0 commit comments

Comments
 (0)