From 3b556e8b5a1a2afb5c6edeed71a6e7efa1b890ba Mon Sep 17 00:00:00 2001 From: Fabio Niephaus Date: Sun, 3 Jan 2021 16:12:24 +0100 Subject: [PATCH] Cache literals in bytecode nodes This is mostly for interpreter performance, literals should not change anyway --- .../nodes/bytecodes/PushBytecodes.java | 18 +++++++++--------- .../nodes/bytecodes/StoreBytecodes.java | 10 +++++----- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/bytecodes/PushBytecodes.java b/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/bytecodes/PushBytecodes.java index 44ca6218e..8b17588de 100644 --- a/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/bytecodes/PushBytecodes.java +++ b/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/bytecodes/PushBytecodes.java @@ -374,22 +374,22 @@ protected Object getConstant() { @NodeInfo(cost = NodeCost.NONE) public static final class PushLiteralConstantNode extends AbstractPushNode { - private final int literalIndex; + private final Object literal; public PushLiteralConstantNode(final CompiledCodeObject code, final int index, final int numBytecodes, final int literalIndex) { super(code, index, numBytecodes); - this.literalIndex = literalIndex; + literal = code.getLiteral(literalIndex); } @Override public void executeVoid(final VirtualFrame frame) { - pushNode.execute(frame, code.getLiteral(literalIndex)); + pushNode.execute(frame, literal); } @Override public String toString() { CompilerAsserts.neverPartOfCompilation(); - return "pushConstant: " + code.getLiteral(literalIndex); + return "pushConstant: " + literal; } } @@ -397,23 +397,23 @@ public String toString() { public static final class PushLiteralVariableNode extends AbstractPushNode { @Child private SqueakObjectAt0Node at0Node = SqueakObjectAt0Node.create(); private final SqueakProfile valueProfile; - private final int literalIndex; + private final Object literal; public PushLiteralVariableNode(final CompiledCodeObject code, final int index, final int numBytecodes, final int literalIndex) { super(code, index, numBytecodes); - this.literalIndex = literalIndex; - valueProfile = SqueakProfile.createLiteralProfile(code.getLiteral(literalIndex)); + literal = code.getLiteral(literalIndex); + valueProfile = SqueakProfile.createLiteralProfile(literal); } @Override public void executeVoid(final VirtualFrame frame) { - pushNode.execute(frame, valueProfile.profile(at0Node.execute(code.getLiteral(literalIndex), ASSOCIATION.VALUE))); + pushNode.execute(frame, valueProfile.profile(at0Node.execute(literal, ASSOCIATION.VALUE))); } @Override public String toString() { CompilerAsserts.neverPartOfCompilation(); - return "pushLitVar: " + code.getLiteral(literalIndex); + return "pushLitVar: " + literal; } } diff --git a/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/bytecodes/StoreBytecodes.java b/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/bytecodes/StoreBytecodes.java index 9c4351f81..86838c12b 100644 --- a/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/bytecodes/StoreBytecodes.java +++ b/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/bytecodes/StoreBytecodes.java @@ -23,18 +23,18 @@ public final class StoreBytecodes { private abstract static class AbstractStoreIntoAssociationNode extends AbstractStoreIntoNode { - protected final long variableIndex; + protected final Object literalVariable; private AbstractStoreIntoAssociationNode(final CompiledCodeObject code, final int index, final int numBytecodes, final long variableIndex) { super(code, index, numBytecodes); - this.variableIndex = variableIndex; + literalVariable = code.getLiteral(variableIndex); storeNode = SqueakObjectAtPutAndMarkContextsNode.create(ASSOCIATION.VALUE); } @Override public final String toString() { CompilerAsserts.neverPartOfCompilation(); - return getTypeName() + "IntoLit: " + SqueakObjectAt0Node.getUncached().execute(code.getLiteral(variableIndex), ASSOCIATION.KEY); + return getTypeName() + "IntoLit: " + SqueakObjectAt0Node.getUncached().execute(literalVariable, ASSOCIATION.KEY); } } @@ -115,7 +115,7 @@ public PopIntoLiteralVariableNode(final CompiledCodeObject code, final int index @Override public void executeVoid(final VirtualFrame frame) { - storeNode.executeWrite(code.getLiteral(variableIndex), popNode.execute(frame)); + storeNode.executeWrite(literalVariable, popNode.execute(frame)); } @Override @@ -187,7 +187,7 @@ public StoreIntoLiteralVariableNode(final CompiledCodeObject code, final int ind @Override public void executeVoid(final VirtualFrame frame) { - storeNode.executeWrite(code.getLiteral(variableIndex), topNode.execute(frame)); + storeNode.executeWrite(literalVariable, topNode.execute(frame)); } @Override