Skip to content

Commit

Permalink
Cache literals in bytecode nodes
Browse files Browse the repository at this point in the history
This is mostly for interpreter performance, literals should not change anyway
  • Loading branch information
fniephaus committed Jan 3, 2021
1 parent 1aade11 commit 3b556e8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -374,46 +374,46 @@ 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;
}
}

@NodeInfo(cost = NodeCost.NONE)
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;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 3b556e8

Please sign in to comment.