Skip to content

Commit 01c3fe7

Browse files
committed
[GR-31356] Use @cached LoopConditionProfile
PullRequest: truffleruby/2649
2 parents a28e3da + 4a0bd78 commit 01c3fe7

File tree

7 files changed

+41
-37
lines changed

7 files changed

+41
-37
lines changed

mx.truffleruby/suite.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
{
88
"name": "regex",
99
"subdir": True,
10-
"version": "d5ec6c894350b4b8c927f877f4e6994a6cd7e8b6",
10+
"version": "a5ca5bda7301447bb2c755134f8403e51621dfa4",
1111
"urls": [
1212
{"url": "https://github.com/oracle/graal.git", "kind": "git"},
1313
{"url": "https://curio.ssw.jku.at/nexus/content/repositories/snapshots", "kind": "binary"},
@@ -16,7 +16,7 @@
1616
{
1717
"name": "sulong",
1818
"subdir": True,
19-
"version": "d5ec6c894350b4b8c927f877f4e6994a6cd7e8b6",
19+
"version": "a5ca5bda7301447bb2c755134f8403e51621dfa4",
2020
"urls": [
2121
{"url": "https://github.com/oracle/graal.git", "kind": "git"},
2222
{"url": "https://curio.ssw.jku.at/nexus/content/repositories/snapshots", "kind": "binary"},

src/main/.checkstyle_checks.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,10 @@
226226
<property name="format" value='@Cached\("createBinaryProfile\(\)"\) ConditionProfile'/>
227227
<property name="message" value="Use @Cached ConditionProfile instead."/>
228228
</module>
229+
<module name="RegexpSinglelineJava">
230+
<property name="format" value='@Cached\("createCountingProfile\(\)"\) LoopConditionProfile'/>
231+
<property name="message" value="Use @Cached LoopConditionProfile instead."/>
232+
</module>
229233
<module name="IllegalType">
230234
<!-- Use PrintStream instead of PrintWriter, PrintWriter does not consistently flush, even when writing \n.-->
231235
<property name="illegalClassNames" value="TruffleObject,DynamicObject,PrintWriter"/>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ protected void copy(RubyArray dst, RubyArray src, int dstStart, int srcStart, in
5656
@Cached IsSharedNode isSrcShared,
5757
@Cached WriteBarrierNode writeBarrierNode,
5858
@Cached ConditionProfile share,
59-
@Cached("createCountingProfile()") LoopConditionProfile loopProfile) {
59+
@Cached LoopConditionProfile loopProfile) {
6060

6161
final Object srcStore = src.store;
6262
stores.copyContents(srcStore, srcStart, dst.store, dstStart, length);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ protected RubyArray iterateOne(RubyArray array, RubyProc block, int startAt, Arr
6363
limit = "storageStrategyLimit()")
6464
protected RubyArray iterateMany(RubyArray array, RubyProc block, int startAt, ArrayElementConsumerNode consumerNode,
6565
@CachedLibrary("array.store") ArrayStoreLibrary arrays,
66-
@Cached("createCountingProfile()") LoopConditionProfile loopProfile,
66+
@Cached LoopConditionProfile loopProfile,
6767
@Cached ConditionProfile strategyMatchProfile) {
6868
int i = startAt;
6969
loopProfile.profileCounted(array.size - startAt);

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

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ protected RubyArray mulZero(RubyArray array, int count) {
170170
limit = "storageStrategyLimit()")
171171
protected RubyArray mulOther(RubyArray array, int count,
172172
@CachedLibrary("array.store") ArrayStoreLibrary arrays,
173-
@Cached("createCountingProfile()") LoopConditionProfile loopProfile) {
173+
@Cached LoopConditionProfile loopProfile) {
174174

175175
final int size = array.size;
176176
final int newSize;
@@ -478,7 +478,7 @@ protected RubyArray compactPrimitive(RubyArray array,
478478
protected Object compactObjectsNonMutable(RubyArray array,
479479
@CachedLibrary("array.store") ArrayStoreLibrary stores,
480480
@Cached ArrayBuilderNode arrayBuilder,
481-
@Cached("createCountingProfile()") LoopConditionProfile loopProfile) {
481+
@Cached LoopConditionProfile loopProfile) {
482482
final int size = array.size;
483483
final Object store = array.store;
484484
BuilderState state = arrayBuilder.start(size);
@@ -514,7 +514,7 @@ protected Object compactNotObjects(RubyArray array,
514514
protected Object compactObjectsNonMutable(RubyArray array,
515515
@CachedLibrary("array.store") ArrayStoreLibrary stores,
516516
@CachedLibrary(limit = "1") ArrayStoreLibrary mutableStores,
517-
@Cached("createCountingProfile()") LoopConditionProfile loopProfile) {
517+
@Cached LoopConditionProfile loopProfile) {
518518
final int size = array.size;
519519
final Object oldStore = array.store;
520520
final Object newStore;
@@ -602,7 +602,7 @@ protected RubyArray concatManyGeneral(RubyArray array, Object first, Object[] re
602602
@Cached ArrayAppendManyNode appendManyNode,
603603
@Cached ArrayCopyOnWriteNode cowNode,
604604
@Cached ConditionProfile selfArgProfile,
605-
@Cached("createCountingProfile()") LoopConditionProfile loopProfile) {
605+
@Cached LoopConditionProfile loopProfile) {
606606
final int size = array.size;
607607
Object store = cowNode.execute(array, 0, size);
608608

@@ -633,7 +633,7 @@ public abstract static class DeleteNode extends YieldingCoreMethodNode {
633633
limit = "storageStrategyLimit()")
634634
protected Object delete(VirtualFrame frame, RubyArray array, Object value, Object maybeBlock,
635635
@CachedLibrary("array.store") ArrayStoreLibrary stores,
636-
@Cached("createCountingProfile()") LoopConditionProfile loopProfile) {
636+
@Cached LoopConditionProfile loopProfile) {
637637

638638
return delete(frame, array, value, maybeBlock, true, array.store, array.store, stores, stores, loopProfile);
639639
}
@@ -644,7 +644,7 @@ protected Object delete(VirtualFrame frame, RubyArray array, Object value, Objec
644644
protected Object delete(VirtualFrame frame, RubyArray array, Object value, Object maybeBlock,
645645
@CachedLibrary("array.store") ArrayStoreLibrary oldStores,
646646
@CachedLibrary(limit = "1") ArrayStoreLibrary newStores,
647-
@Cached("createCountingProfile()") LoopConditionProfile loopProfile) {
647+
@Cached LoopConditionProfile loopProfile) {
648648

649649
final Object oldStore = array.store;
650650
final Object newStore = oldStores.allocator(oldStore).allocate(array.size);
@@ -838,7 +838,7 @@ protected boolean equalSamePrimitiveType(RubyArray a, RubyArray b,
838838
@Cached ConditionProfile sameSizeProfile,
839839
@Cached BranchProfile trueProfile,
840840
@Cached BranchProfile falseProfile,
841-
@Cached("createCountingProfile()") LoopConditionProfile loopProfile) {
841+
@Cached LoopConditionProfile loopProfile) {
842842

843843
if (sameProfile.profile(a == b)) {
844844
return true;
@@ -906,7 +906,7 @@ protected boolean eqlSamePrimitiveType(RubyArray a, RubyArray b,
906906
@Cached ConditionProfile sameSizeProfile,
907907
@Cached BranchProfile trueProfile,
908908
@Cached BranchProfile falseProfile,
909-
@Cached("createCountingProfile()") LoopConditionProfile loopProfile) {
909+
@Cached LoopConditionProfile loopProfile) {
910910

911911
if (sameProfile.profile(a == b)) {
912912
return true;
@@ -967,7 +967,7 @@ public abstract static class FillNode extends ArrayCoreMethodNode {
967967
protected RubyArray fill(RubyArray array, Object[] args, Nil block,
968968
@CachedLibrary("array.store") ArrayStoreLibrary stores,
969969
@Cached PropagateSharingNode propagateSharingNode,
970-
@Cached("createCountingProfile()") LoopConditionProfile loopProfile) {
970+
@Cached LoopConditionProfile loopProfile) {
971971
final Object value = args[0];
972972
propagateSharingNode.executePropagate(array, value);
973973

@@ -1010,7 +1010,7 @@ protected long hash(VirtualFrame frame, RubyArray array,
10101010
@CachedLibrary("array.store") ArrayStoreLibrary stores,
10111011
@Cached DispatchNode toHashNode,
10121012
@Cached ToLongNode toLongNode,
1013-
@Cached("createCountingProfile()") LoopConditionProfile loopProfile) {
1013+
@Cached LoopConditionProfile loopProfile) {
10141014
final int size = array.size;
10151015
long h = getContext().getHashing(this).start(size);
10161016
h = Hashing.update(h, CLASS_SALT);
@@ -1037,7 +1037,7 @@ public abstract static class IncludeNode extends ArrayCoreMethodNode {
10371037
@Specialization(limit = "storageStrategyLimit()")
10381038
protected boolean include(RubyArray array, Object value,
10391039
@CachedLibrary("array.store") ArrayStoreLibrary stores,
1040-
@Cached("createCountingProfile()") LoopConditionProfile loopProfile) {
1040+
@Cached LoopConditionProfile loopProfile) {
10411041
final Object store = array.store;
10421042

10431043
loopProfile.profileCounted(array.size);
@@ -1122,7 +1122,7 @@ protected RubyArray initializeWithSizeAndValue(RubyArray array, int size, Object
11221122
@CachedLibrary(limit = "1") ArrayStoreLibrary allocatedStores,
11231123
@Cached ConditionProfile needsFill,
11241124
@Cached PropagateSharingNode propagateSharingNode,
1125-
@Cached("createCountingProfile()") LoopConditionProfile loopProfile) {
1125+
@Cached LoopConditionProfile loopProfile) {
11261126
final Object allocatedStore = stores.allocateForNewValue(array.store, fillingValue, size);
11271127
if (needsFill.profile(!allocatedStores.isDefaultValue(allocatedStore, fillingValue))) {
11281128
propagateSharingNode.executePropagate(array, fillingValue);
@@ -1148,7 +1148,7 @@ protected RubyArray initializeSizeOther(RubyArray array, Object size, Object fil
11481148
protected Object initializeBlock(RubyArray array, int size, Object unusedFillingValue, RubyProc block,
11491149
@Cached ArrayBuilderNode arrayBuilder,
11501150
@Cached PropagateSharingNode propagateSharingNode,
1151-
@Cached("createCountingProfile()") LoopConditionProfile loopProfile) {
1151+
@Cached LoopConditionProfile loopProfile) {
11521152
BuilderState state = arrayBuilder.start(size);
11531153

11541154
int n = 0;
@@ -1273,7 +1273,7 @@ protected Object injectEmptyArrayNoInitial(
12731273
limit = "storageStrategyLimit()")
12741274
protected Object injectWithInitial(RubyArray array, Object initialOrSymbol, NotProvided symbol, RubyProc block,
12751275
@CachedLibrary("array.store") ArrayStoreLibrary stores,
1276-
@Cached("createCountingProfile()") LoopConditionProfile loopProfile) {
1276+
@Cached LoopConditionProfile loopProfile) {
12771277
final Object store = array.store;
12781278
return injectBlockHelper(stores, array, block, store, initialOrSymbol, 0, loopProfile);
12791279
}
@@ -1284,7 +1284,7 @@ protected Object injectWithInitial(RubyArray array, Object initialOrSymbol, NotP
12841284
protected Object injectNoInitial(
12851285
RubyArray array, NotProvided initialOrSymbol, NotProvided symbol, RubyProc block,
12861286
@CachedLibrary("array.store") ArrayStoreLibrary stores,
1287-
@Cached("createCountingProfile()") LoopConditionProfile loopProfile) {
1287+
@Cached LoopConditionProfile loopProfile) {
12881288
final Object store = array.store;
12891289
return injectBlockHelper(stores, array, block, store, stores.read(store, 0), 1, loopProfile);
12901290
}
@@ -1330,7 +1330,7 @@ protected Object injectSymbolEmptyArrayNoInitial(
13301330
protected Object injectSymbolWithInitial(
13311331
VirtualFrame frame, RubyArray array, Object initialOrSymbol, RubySymbol symbol, Nil block,
13321332
@CachedLibrary("array.store") ArrayStoreLibrary stores,
1333-
@Cached("createCountingProfile()") LoopConditionProfile loopProfile,
1333+
@Cached LoopConditionProfile loopProfile,
13341334
@Cached ToJavaStringNode toJavaString) {
13351335
final Object store = array.store;
13361336
return injectSymbolHelper(
@@ -1350,7 +1350,7 @@ protected Object injectSymbolWithInitial(
13501350
protected Object injectSymbolNoInitial(
13511351
VirtualFrame frame, RubyArray array, RubySymbol initialOrSymbol, NotProvided symbol, Nil block,
13521352
@CachedLibrary("array.store") ArrayStoreLibrary stores,
1353-
@Cached("createCountingProfile()") LoopConditionProfile loopProfile,
1353+
@Cached LoopConditionProfile loopProfile,
13541354
@Cached ToJavaStringNode toJavaString) {
13551355
final Object store = array.store;
13561356
return injectSymbolHelper(
@@ -1392,7 +1392,7 @@ public abstract static class MapNode extends YieldingCoreMethodNode {
13921392
protected Object map(RubyArray array, RubyProc block,
13931393
@CachedLibrary("array.store") ArrayStoreLibrary stores,
13941394
@Cached ArrayBuilderNode arrayBuilder,
1395-
@Cached("createCountingProfile()") LoopConditionProfile loopProfile) {
1395+
@Cached LoopConditionProfile loopProfile) {
13961396
final Object store = array.store;
13971397
final int size = array.size;
13981398
BuilderState state = arrayBuilder.start(size);
@@ -1652,7 +1652,7 @@ protected RubyArray pushOne(RubyArray array, Object value, Object[] rest) {
16521652

16531653
@Specialization(guards = { "rest.length > 0", "wasProvided(value)" })
16541654
protected RubyArray pushMany(VirtualFrame frame, RubyArray array, Object value, Object[] rest,
1655-
@Cached("createCountingProfile()") LoopConditionProfile loopProfile) {
1655+
@Cached LoopConditionProfile loopProfile) {
16561656
// NOTE (eregon): Appending one by one here to avoid useless generalization to Object[]
16571657
// if the arguments all fit in the current storage
16581658
appendOneNode.executeAppendOne(array, value);
@@ -1675,7 +1675,7 @@ protected Object rejectOther(RubyArray array, RubyProc block,
16751675
@CachedLibrary("array.store") ArrayStoreLibrary stores,
16761676
@Cached ArrayBuilderNode arrayBuilder,
16771677
@Cached BooleanCastNode booleanCastNode,
1678-
@Cached("createCountingProfile()") LoopConditionProfile loopProfile) {
1678+
@Cached LoopConditionProfile loopProfile) {
16791679
final Object store = array.store;
16801680
final int size = array.size;
16811681

@@ -1720,8 +1720,8 @@ protected Object rejectEmpty(RubyArray array, RubyProc block) {
17201720
protected Object rejectInPlaceMutableStore(RubyArray array, RubyProc block,
17211721
@CachedLibrary("array.store") ArrayStoreLibrary stores,
17221722
@CachedLibrary(limit = "1") ArrayStoreLibrary mutablestores,
1723-
@Cached("createCountingProfile()") LoopConditionProfile loop1Profile,
1724-
@Cached("createCountingProfile()") LoopConditionProfile loop2Profile) {
1723+
@Cached LoopConditionProfile loop1Profile,
1724+
@Cached LoopConditionProfile loop2Profile) {
17251725
return rejectInPlaceInternal(array, block, mutablestores, array.store, loop1Profile, loop2Profile);
17261726
}
17271727

@@ -1731,8 +1731,8 @@ protected Object rejectInPlaceMutableStore(RubyArray array, RubyProc block,
17311731
protected Object rejectInPlaceImmutableStore(RubyArray array, RubyProc block,
17321732
@CachedLibrary("array.store") ArrayStoreLibrary stores,
17331733
@CachedLibrary(limit = "1") ArrayStoreLibrary mutablestores,
1734-
@Cached("createCountingProfile()") LoopConditionProfile loop1Profile,
1735-
@Cached("createCountingProfile()") LoopConditionProfile loop2Profile) {
1734+
@Cached LoopConditionProfile loop1Profile,
1735+
@Cached LoopConditionProfile loop2Profile) {
17361736
final Object mutableStore = stores.allocator(array.store).allocate(array.size);
17371737
stores.copyContents(array.store, 0, mutableStore, 0, array.size);
17381738
array.store = mutableStore;
@@ -1855,9 +1855,9 @@ protected RubyArray rotate(RubyArray array, int rotation,
18551855
@CachedLibrary("array.store") ArrayStoreLibrary arrays,
18561856
@Cached("createIdentityProfile()") IntValueProfile sizeProfile,
18571857
@Cached("createIdentityProfile()") IntValueProfile rotationProfile,
1858-
@Cached("createCountingProfile()") LoopConditionProfile loop1Profile,
1859-
@Cached("createCountingProfile()") LoopConditionProfile loop2Profile,
1860-
@Cached("createCountingProfile()") LoopConditionProfile loop3Profile) {
1858+
@Cached LoopConditionProfile loop1Profile,
1859+
@Cached LoopConditionProfile loop2Profile,
1860+
@Cached LoopConditionProfile loop3Profile) {
18611861
final int size = sizeProfile.profile(array.size);
18621862
rotation = rotationProfile.profile(rotation);
18631863
assert 0 < rotation && rotation < size;
@@ -1954,7 +1954,7 @@ public abstract static class SelectNode extends YieldingCoreMethodNode {
19541954
@Specialization(limit = "storageStrategyLimit()")
19551955
protected Object select(RubyArray array, RubyProc block,
19561956
@CachedLibrary("array.store") ArrayStoreLibrary stores,
1957-
@Cached("createCountingProfile()") LoopConditionProfile loopProfile,
1957+
@Cached LoopConditionProfile loopProfile,
19581958
@Cached ArrayBuilderNode arrayBuilder,
19591959
@Cached BooleanCastNode booleanCastNode) {
19601960
final Object store = array.store;
@@ -2211,7 +2211,7 @@ protected RubyArray zipToPairs(RubyArray array, RubyArray other,
22112211
@CachedLibrary("other.store") ArrayStoreLibrary bStores,
22122212
@CachedLibrary(limit = "1") ArrayStoreLibrary pairs,
22132213
@Cached ConditionProfile bNotSmallerProfile,
2214-
@Cached("createCountingProfile()") LoopConditionProfile loopProfile) {
2214+
@Cached LoopConditionProfile loopProfile) {
22152215
final Object a = array.store;
22162216
final Object b = other.store;
22172217

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ protected Object writeExtendByOne(RubyArray array, int index, Object value,
8383
protected Object writeBeyondPrimitive(RubyArray array, int index, Object value,
8484
@CachedLibrary("array.store") ArrayStoreLibrary arrays,
8585
@CachedLibrary(limit = "1") ArrayStoreLibrary newArrays,
86-
@Cached("createCountingProfile()") LoopConditionProfile loopProfile) {
86+
@Cached LoopConditionProfile loopProfile) {
8787
final int newSize = index + 1;
8888
Object store = array.store;
8989
final Object objectStore = arrays.allocateForNewValue(store, nil, newSize);
@@ -109,7 +109,7 @@ protected Object writeBeyondObject(RubyArray array, int index, Object value,
109109
@CachedLibrary("array.store") ArrayStoreLibrary arrays,
110110
@CachedLibrary(limit = "1") ArrayStoreLibrary newArrays,
111111
@Cached ArrayEnsureCapacityNode ensureCapacityNode,
112-
@Cached("createCountingProfile()") LoopConditionProfile loopProfile) {
112+
@Cached LoopConditionProfile loopProfile) {
113113
ensureCapacityNode.executeEnsureCapacity(array, index + 1);
114114
final Object store = array.store;
115115
loopProfile.profileCounted(index - array.size);

src/main/java/org/truffleruby/core/range/RangeNodes.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public abstract static class EachNode extends YieldingCoreMethodNode {
9595

9696
@Specialization
9797
protected RubyIntRange eachInt(RubyIntRange range, RubyProc block,
98-
@Cached("createCountingProfile()") LoopConditionProfile loopProfile) {
98+
@Cached LoopConditionProfile loopProfile) {
9999
int result;
100100
if (range.excludedEnd) {
101101
result = range.end;
@@ -119,7 +119,7 @@ protected RubyIntRange eachInt(RubyIntRange range, RubyProc block,
119119

120120
@Specialization
121121
protected RubyLongRange eachLong(RubyLongRange range, RubyProc block,
122-
@Cached("createCountingProfile()") LoopConditionProfile loopProfile) {
122+
@Cached LoopConditionProfile loopProfile) {
123123
long result;
124124
if (range.excludedEnd) {
125125
result = range.end;

0 commit comments

Comments
 (0)