Skip to content

Commit 787b585

Browse files
committed
[GR-31350] [GR-32680] Migrate to profileAndReportLoopCount()
PullRequest: truffleruby/2820
2 parents 433c285 + 232ef50 commit 787b585

18 files changed

+93
-128
lines changed

src/main/.checkstyle_checks.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,14 @@
234234
<property name="format" value='Collections\.newSetFromMap\(new ConcurrentHashMap'/>
235235
<property name="message" value="Use ConcurrentHashMap.newKeySet() instead."/>
236236
</module>
237+
<module name="RegexpSinglelineJava">
238+
<property name="format" value='LoopNode\.reportLoopCount\('/>
239+
<property name="message" value="Use profileAndReportLoopCount() instead."/>
240+
</module>
241+
<module name="RegexpSinglelineJava">
242+
<property name="format" value='\.profileCounted\('/>
243+
<property name="message" value="Use profileAndReportLoopCount() instead."/>
244+
</module>
237245
<module name="IllegalType">
238246
<!-- Use PrintStream instead of PrintWriter, PrintWriter does not consistently flush, even when writing \n.-->
239247
<property name="illegalClassNames" value="TruffleObject,DynamicObject,PrintWriter"/>

src/main/java/org/truffleruby/cext/UnwrapNode.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
import com.oracle.truffle.api.dsl.Bind;
1818
import com.oracle.truffle.api.interop.InvalidArrayIndexException;
1919
import com.oracle.truffle.api.nodes.ExplodeLoop;
20-
import com.oracle.truffle.api.nodes.LoopNode;
2120
import com.oracle.truffle.api.profiles.LoopConditionProfile;
2221
import org.truffleruby.RubyContext;
2322
import org.truffleruby.RubyLanguage;
@@ -227,12 +226,15 @@ protected Object[] unwrapCArray(Object cArray,
227226
@Cached UnwrapNode unwrapNode,
228227
@Cached LoopConditionProfile loopProfile) {
229228
final Object[] store = new Object[size];
230-
loopProfile.profileCounted(size);
231-
for (int i = 0; loopProfile.inject(i < size); i++) {
232-
final Object cValue = readArrayElement(cArray, interop, i);
233-
store[i] = unwrapNode.execute(cValue);
229+
int i = 0;
230+
try {
231+
for (; loopProfile.inject(i < size); i++) {
232+
final Object cValue = readArrayElement(cArray, interop, i);
233+
store[i] = unwrapNode.execute(cValue);
234+
}
235+
} finally {
236+
profileAndReportLoopCount(loopProfile, i);
234237
}
235-
LoopNode.reportLoopCount(this, size);
236238
return store;
237239
}
238240

src/main/java/org/truffleruby/core/array/ArrayCopyCompatibleRangeNode.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
*/
1010
package org.truffleruby.core.array;
1111

12-
import com.oracle.truffle.api.nodes.LoopNode;
1312
import com.oracle.truffle.api.profiles.LoopConditionProfile;
1413
import org.truffleruby.core.array.library.ArrayStoreLibrary;
1514
import org.truffleruby.language.RubyBaseNode;
@@ -67,12 +66,11 @@ protected void copy(RubyArray dst, RubyArray src, int dstStart, int srcStart, in
6766
!isSrcShared.executeIsShared(src))) {
6867
int i = 0;
6968
try {
70-
loopProfile.profileCounted(length);
7169
for (; loopProfile.inject(i < length); ++i) {
7270
writeBarrierNode.executeWriteBarrier(stores.read(srcStore, i));
7371
}
7472
} finally {
75-
LoopNode.reportLoopCount(this, i);
73+
profileAndReportLoopCount(loopProfile, i);
7674
}
7775
}
7876
}

src/main/java/org/truffleruby/core/array/ArrayEachIteratorNode.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import com.oracle.truffle.api.dsl.ReportPolymorphism;
2020
import com.oracle.truffle.api.dsl.Specialization;
2121
import com.oracle.truffle.api.library.CachedLibrary;
22-
import com.oracle.truffle.api.nodes.LoopNode;
2322
import com.oracle.truffle.api.nodes.NodeInterface;
2423
import com.oracle.truffle.api.profiles.ConditionProfile;
2524
import com.oracle.truffle.api.profiles.LoopConditionProfile;
@@ -66,7 +65,6 @@ protected RubyArray iterateMany(RubyArray array, RubyProc block, int startAt, Ar
6665
@Cached LoopConditionProfile loopProfile,
6766
@Cached ConditionProfile strategyMatchProfile) {
6867
int i = startAt;
69-
loopProfile.profileCounted(array.size - startAt);
7068
try {
7169
for (; loopProfile.inject(i < array.size); i++) {
7270
if (strategyMatchProfile.profile(arrays.accepts(array.store))) {
@@ -77,7 +75,7 @@ protected RubyArray iterateMany(RubyArray array, RubyProc block, int startAt, Ar
7775
}
7876
}
7977
} finally {
80-
LoopNode.reportLoopCount(this, i - startAt);
78+
profileAndReportLoopCount(loopProfile, i - startAt);
8179
}
8280

8381
return array;

0 commit comments

Comments
 (0)