From 28a2ce96bf4153ef0897c4dd045115849d4cf6c7 Mon Sep 17 00:00:00 2001 From: Fabio Niephaus Date: Tue, 23 Aug 2022 00:17:50 +0200 Subject: [PATCH] Cache one class hash --- .../nodes/primitives/impl/StoragePrimitives.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/primitives/impl/StoragePrimitives.java b/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/primitives/impl/StoragePrimitives.java index 5ed623c79..bd28de486 100644 --- a/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/primitives/impl/StoragePrimitives.java +++ b/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/primitives/impl/StoragePrimitives.java @@ -566,7 +566,16 @@ protected static final Object doSlotAtPut(@SuppressWarnings("unused") final Obje @SqueakPrimitive(indices = 175) protected abstract static class PrimBehaviorHashNode extends AbstractPrimitiveNode implements UnaryPrimitiveFallback { - @Specialization + /* Cache one class hash (helps String>>#hash). */ + @SuppressWarnings("unused") + @Specialization(guards = "receiver == cachedClass", limit = "1") + protected static final long doClassCached(final ClassObject receiver, + @Cached("receiver") final ClassObject cachedClass, + @Cached("doClassUncached(receiver)") final long cachedHash) { + return cachedHash; + } + + @Specialization(replaces = "doClassCached") protected static final long doClassUncached(final ClassObject receiver) { receiver.ensureBehaviorHash(); return receiver.getSqueakHash();