Skip to content

Commit 619dcbe

Browse files
committed
[GR-19205] Cleanups for ExplodeLoop loops.
PullRequest: truffleruby/1139
2 parents b5dabd8 + 65484b8 commit 619dcbe

File tree

8 files changed

+26
-20
lines changed

8 files changed

+26
-20
lines changed

ci.jsonnet

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ local part_definitions = {
208208
JAVA_HOME: {
209209
name: "oraclejdk",
210210
# Update the openjdk8 version too below when updating this one
211-
version: "8u231-jvmci-19.3-b04",
211+
version: "8u231-jvmci-19.3-b05",
212212
platformspecific: true,
213213
},
214214
},
@@ -219,7 +219,7 @@ local part_definitions = {
219219
downloads+: {
220220
JAVA_HOME: {
221221
name: "openjdk",
222-
version: "8u232-jvmci-19.3-b04",
222+
version: "8u232-jvmci-19.3-b05",
223223
platformspecific: true,
224224
},
225225
},
@@ -229,7 +229,7 @@ local part_definitions = {
229229
downloads+: {
230230
JAVA_HOME: {
231231
name: "labsjdk",
232-
version: "ce-11.0.5+10-jvmci-19.3-b04",
232+
version: "ce-11.0.5+10-jvmci-19.3-b05",
233233
platformspecific: true,
234234
},
235235
},

mx.truffleruby/suite.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"name": "tools",
1010
"subdir": True,
1111
# version must always be equal to the version of the "sulong" import below
12-
"version": "aee967f1d90e1f032b266c62d10fc8c32a805fb8",
12+
"version": "17a0c2940da139f757ddc3628076e067c06da8b7",
1313
"urls": [
1414
{"url": "https://github.com/oracle/graal.git", "kind": "git"},
1515
{"url": "https://curio.ssw.jku.at/nexus/content/repositories/snapshots", "kind": "binary"},
@@ -19,7 +19,7 @@
1919
"name": "sulong",
2020
"subdir": True,
2121
# version must always be equal to the version of the "tools" import above
22-
"version": "aee967f1d90e1f032b266c62d10fc8c32a805fb8",
22+
"version": "17a0c2940da139f757ddc3628076e067c06da8b7",
2323
"urls": [
2424
{"url": "https://github.com/oracle/graal.git", "kind": "git"},
2525
{"url": "https://curio.ssw.jku.at/nexus/content/repositories/snapshots", "kind": "binary"},

src/main/java/org/truffleruby/core/hash/HashLiteralNode.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
*/
1010
package org.truffleruby.core.hash;
1111

12+
import com.oracle.truffle.api.profiles.BranchProfile;
1213
import org.truffleruby.Layouts;
1314
import org.truffleruby.RubyContext;
1415
import org.truffleruby.core.cast.BooleanCastNode;
@@ -66,6 +67,7 @@ public static class SmallHashLiteralNode extends HashLiteralNode {
6667
@Child private CallDispatchHeadNode equalNode;
6768
@Child private BooleanCastNode booleanCastNode;
6869
@Child private FreezeHashKeyIfNeededNode freezeHashKeyIfNeededNode = FreezeHashKeyIfNeededNodeGen.create();
70+
private final BranchProfile duplicateKeyProfile = BranchProfile.create();
6971

7072
public SmallHashLiteralNode(RubyNode[] keyValues) {
7173
super(keyValues);
@@ -78,26 +80,31 @@ public Object execute(VirtualFrame frame) {
7880

7981
int size = 0;
8082

81-
initializers: for (int n = 0; n < keyValues.length / 2; n++) {
83+
for (int n = 0; n < keyValues.length / 2; n++) {
8284
Object key = keyValues[n * 2].execute(frame);
8385
key = freezeHashKeyIfNeededNode.executeFreezeIfNeeded(key, false);
8486

8587
final int hashed = hash(key);
8688

8789
final Object value = keyValues[n * 2 + 1].execute(frame);
90+
boolean duplicateKey = false;
8891

8992
for (int i = 0; i < n; i++) {
9093
if (i < size &&
9194
hashed == PackedArrayStrategy.getHashed(store, i) &&
9295
callEqual(key, PackedArrayStrategy.getKey(store, i))) {
96+
duplicateKeyProfile.enter();
9397
PackedArrayStrategy.setKey(store, i, key);
9498
PackedArrayStrategy.setValue(store, i, value);
95-
continue initializers;
99+
duplicateKey = true;
100+
break;
96101
}
97102
}
98103

99-
PackedArrayStrategy.setHashedKeyValue(store, size, hashed, key, value);
100-
size++;
104+
if (!duplicateKey) {
105+
PackedArrayStrategy.setHashedKeyValue(store, size, hashed, key, value);
106+
size++;
107+
}
101108
}
102109

103110
return coreLibrary()

src/main/java/org/truffleruby/core/hash/HashNodes.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
import java.util.Arrays;
1313

14+
import com.oracle.truffle.api.nodes.ExplodeLoop.LoopExplosionKind;
1415
import org.truffleruby.Layouts;
1516
import org.truffleruby.builtins.CoreModule;
1617
import org.truffleruby.builtins.CoreMethod;
@@ -71,7 +72,7 @@ public abstract static class ConstructNode extends CoreMethodArrayArgumentsNode
7172
@Child private AllocateObjectNode allocateObjectNode = AllocateObjectNode.create();
7273
@Child private CallDispatchHeadNode fallbackNode = CallDispatchHeadNode.createPrivate();
7374

74-
@ExplodeLoop
75+
@ExplodeLoop(kind = LoopExplosionKind.FULL_UNROLL)
7576
@Specialization(guards = "isSmallArrayOfPairs(args)")
7677
protected Object construct(DynamicObject hashClass, Object[] args) {
7778
final DynamicObject array = (DynamicObject) args[0];
@@ -93,11 +94,7 @@ protected Object construct(DynamicObject hashClass, Object[] args) {
9394
final DynamicObject pairArray = (DynamicObject) pair;
9495
final Object pairStore = Layouts.ARRAY.getStore(pairArray);
9596

96-
if (pairStore != null && pairStore.getClass() != Object[].class) {
97-
return fallbackNode.call(hashClass, "_constructor_fallback", args);
98-
}
99-
100-
if (Layouts.ARRAY.getSize(pairArray) != 2) {
97+
if (pairStore.getClass() != Object[].class || Layouts.ARRAY.getSize(pairArray) != 2) {
10198
return fallbackNode.call(hashClass, "_constructor_fallback", args);
10299
}
103100

src/main/java/org/truffleruby/core/hash/LookupPackedEntryNode.java

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

12+
import com.oracle.truffle.api.nodes.ExplodeLoop.LoopExplosionKind;
1213
import org.truffleruby.Layouts;
1314
import org.truffleruby.collections.BiFunctionNode;
1415
import org.truffleruby.language.RubyBaseNode;
@@ -87,7 +88,7 @@ protected int getSize(DynamicObject hash) {
8788
return Layouts.HASH.getSize(hash);
8889
}
8990

90-
@ExplodeLoop
91+
@ExplodeLoop(kind = LoopExplosionKind.FULL_UNROLL_UNTIL_RETURN)
9192
@Specialization(replaces = "getConstantIndexPackedArray")
9293
protected Object getPackedArray(VirtualFrame frame, DynamicObject hash, Object key, int hashed,
9394
BiFunctionNode defaultValueNode,
@@ -110,7 +111,6 @@ protected Object getPackedArray(VirtualFrame frame, DynamicObject hash, Object k
110111

111112
notInHashProfile.enter();
112113
return defaultValueNode.accept(frame, hash, key);
113-
114114
}
115115

116116
protected boolean equalKeys(boolean compareByIdentity, Object key, int hashed, Object otherKey, int otherHashed) {

src/main/java/org/truffleruby/core/hash/SetNode.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
*/
1010
package org.truffleruby.core.hash;
1111

12+
import com.oracle.truffle.api.nodes.ExplodeLoop.LoopExplosionKind;
1213
import org.truffleruby.Layouts;
1314
import org.truffleruby.language.RubyBaseNode;
1415
import org.truffleruby.language.objects.shared.PropagateSharingNode;
@@ -59,7 +60,7 @@ protected Object setNull(DynamicObject hash, Object originalKey, Object value, b
5960
return value;
6061
}
6162

62-
@ExplodeLoop
63+
@ExplodeLoop(kind = LoopExplosionKind.FULL_UNROLL_UNTIL_RETURN)
6364
@Specialization(guards = "isPackedHash(hash)")
6465
protected Object setPackedArray(DynamicObject hash, Object originalKey, Object value, boolean byIdentity,
6566
@Cached("createBinaryProfile()") ConditionProfile strategyProfile) {

src/main/java/org/truffleruby/core/numeric/IntegerNodes.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
import java.math.BigInteger;
1313

14+
import com.oracle.truffle.api.nodes.ExplodeLoop.LoopExplosionKind;
1415
import org.jcodings.specific.USASCIIEncoding;
1516
import org.truffleruby.Layouts;
1617
import org.truffleruby.builtins.CoreModule;
@@ -1627,7 +1628,7 @@ protected long powTwoLong(int base, int exponent) {
16271628
return 1L << exponent;
16281629
}
16291630

1630-
@ExplodeLoop
1631+
@ExplodeLoop(kind = LoopExplosionKind.FULL_UNROLL)
16311632
@Specialization(
16321633
guards = {
16331634
"isIntOrLong(base)",

src/main/java/org/truffleruby/language/exceptions/TryNode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public Object execute(VirtualFrame frame) {
7878
}
7979
}
8080

81-
@ExplodeLoop(kind = LoopExplosionKind.FULL_EXPLODE_UNTIL_RETURN)
81+
@ExplodeLoop(kind = LoopExplosionKind.FULL_UNROLL_UNTIL_RETURN)
8282
private Object handleException(VirtualFrame frame, RaiseException exception) {
8383
for (RescueNode rescue : rescueParts) {
8484
if (rescue.canHandle(frame, exception.getException())) {

0 commit comments

Comments
 (0)