Skip to content

Commit e4daec5

Browse files
committed
rebase into latest master
Major refactoring after fully passing the test suite fixed 2 very nasty bugs First working skeleton of a compact hash table, still lots of cleaning up and profiling required Some cleanup and style fixes Made index.length always even and exploited that for more efficient mod division No floating point div on the fast path in resizeIndexIfNeeded, index array overallocates so that it's bigger than the kvstore bug fixes, test failures now down to only 2 from 13 InlinedConditionProfile instead of ConditionProfile, more efficient getIndexPosFromHash and minor improvements Style and comments jt test fast passes fully ! Major Refactor
1 parent b4a05b5 commit e4daec5

File tree

5 files changed

+723
-22
lines changed

5 files changed

+723
-22
lines changed

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

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

12+
import org.truffleruby.core.basicobject.ReferenceEqualNode;
13+
import org.truffleruby.core.kernel.KernelNodes.SameOrEqlNode;
14+
import org.truffleruby.language.RubyBaseNode;
15+
1216
import com.oracle.truffle.api.dsl.Cached;
1317
import com.oracle.truffle.api.dsl.GenerateUncached;
1418
import com.oracle.truffle.api.dsl.Specialization;
1519
import com.oracle.truffle.api.nodes.Node;
16-
import org.truffleruby.core.basicobject.ReferenceEqualNode;
17-
import org.truffleruby.core.kernel.KernelNodes.SameOrEqlNode;
18-
import org.truffleruby.language.RubyBaseNode;
1920

2021
@GenerateUncached
2122
public abstract class CompareHashKeysNode extends RubyBaseNode {
@@ -47,4 +48,26 @@ boolean same(boolean compareByIdentity, Object key, int hashed, Object otherKey,
4748
@Cached SameOrEqlNode same) {
4849
return hashed == otherHashed && same.execute(key, otherKey);
4950
}
51+
52+
@GenerateUncached
53+
public abstract static class AssumingEqualHashes extends RubyBaseNode {
54+
55+
public static AssumingEqualHashes getUncached() {
56+
return CompareHashKeysNodeGen.AssumingEqualHashesNodeGen.getUncached();
57+
}
58+
59+
public abstract boolean execute(boolean compareByIdentity, Object key, Object otherKey);
60+
61+
@Specialization(guards = "compareByIdentity")
62+
boolean refEquals(boolean compareByIdentity, Object key, Object otherKey,
63+
@Cached ReferenceEqualNode refEqual) {
64+
return refEqual.execute(this, key, otherKey);
65+
}
66+
67+
@Specialization(guards = "!compareByIdentity")
68+
boolean same(boolean compareByIdentity, Object key, Object otherKey,
69+
@Cached SameOrEqlNode same) {
70+
return same.execute(key, otherKey);
71+
}
72+
}
5073
}

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

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

1212
import org.truffleruby.core.hash.library.BucketsHashStore;
13+
import org.truffleruby.core.hash.library.CompactHashStore;
1314
import org.truffleruby.core.hash.library.EmptyHashStore;
1415
import org.truffleruby.core.hash.library.PackedHashStoreLibrary;
1516
import org.truffleruby.core.hash.library.PackedHashStoreLibraryFactory;
@@ -28,13 +29,21 @@ protected HashLiteralNode(RubyNode[] keyValues) {
2829
this.keyValues = keyValues;
2930
}
3031

32+
private static final boolean bigHashTypeIsCompactHash;
33+
static {
34+
String type = System.getProperty("BigHashStrategy");
35+
bigHashTypeIsCompactHash = type != null && type.equalsIgnoreCase("compact");
36+
}
37+
3138
public static HashLiteralNode create(RubyNode[] keyValues) {
3239
if (keyValues.length == 0) {
3340
return new EmptyHashStore.EmptyHashLiteralNode();
3441
} else if (keyValues.length <= PackedHashStoreLibrary.MAX_ENTRIES * 2) {
3542
return PackedHashStoreLibraryFactory.SmallHashLiteralNodeGen.create(keyValues);
3643
} else {
37-
return new BucketsHashStore.GenericHashLiteralNode(keyValues);
44+
return bigHashTypeIsCompactHash
45+
? new CompactHashStore.CompactHashLiteralNode(keyValues)
46+
: new BucketsHashStore.GenericHashLiteralNode(keyValues);
3847
}
3948
}
4049

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

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,20 @@
1111

1212
import java.util.Set;
1313

14+
import org.truffleruby.RubyContext;
15+
import org.truffleruby.collections.PEBiFunction;
16+
import org.truffleruby.core.hash.library.BucketsHashStore;
17+
import org.truffleruby.core.hash.library.CompactHashStore;
18+
import org.truffleruby.core.hash.library.HashStoreLibrary;
19+
import org.truffleruby.core.klass.RubyClass;
20+
import org.truffleruby.interop.ForeignToRubyNode;
21+
import org.truffleruby.language.Nil;
22+
import org.truffleruby.language.RubyDynamicObject;
23+
import org.truffleruby.language.dispatch.DispatchNode;
24+
import org.truffleruby.language.objects.IsFrozenNode;
25+
import org.truffleruby.language.objects.ObjectGraph;
26+
import org.truffleruby.language.objects.ObjectGraphNode;
27+
1428
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
1529
import com.oracle.truffle.api.dsl.Bind;
1630
import com.oracle.truffle.api.dsl.Cached;
@@ -26,20 +40,7 @@
2640
import com.oracle.truffle.api.library.ExportMessage;
2741
import com.oracle.truffle.api.nodes.Node;
2842
import com.oracle.truffle.api.object.Shape;
29-
3043
import com.oracle.truffle.api.profiles.InlinedConditionProfile;
31-
import org.truffleruby.RubyContext;
32-
import org.truffleruby.collections.PEBiFunction;
33-
import org.truffleruby.core.hash.library.BucketsHashStore;
34-
import org.truffleruby.core.hash.library.HashStoreLibrary;
35-
import org.truffleruby.core.klass.RubyClass;
36-
import org.truffleruby.interop.ForeignToRubyNode;
37-
import org.truffleruby.language.Nil;
38-
import org.truffleruby.language.RubyDynamicObject;
39-
import org.truffleruby.language.dispatch.DispatchNode;
40-
import org.truffleruby.language.objects.IsFrozenNode;
41-
import org.truffleruby.language.objects.ObjectGraph;
42-
import org.truffleruby.language.objects.ObjectGraphNode;
4344

4445
@ExportLibrary(InteropLibrary.class)
4546
@ImportStatic(HashGuards.class)
@@ -86,6 +87,8 @@ public String toString() {
8687
public void getAdjacentObjects(Set<Object> reachable) {
8788
if (store instanceof BucketsHashStore) {
8889
((BucketsHashStore) store).getAdjacentObjects(reachable);
90+
} else if (store instanceof CompactHashStore) {
91+
((CompactHashStore) store).getAdjacentObjects(reachable);
8992
} else {
9093
ObjectGraph.addProperty(reachable, store);
9194
}

0 commit comments

Comments
 (0)