[JVM] Use HashSet instead of SmartSet in MaxStackFrameSizeAndLocalsCalculator

This change speeds up backend by approximately 0.25%.
This commit is contained in:
Ivan Kylchik
2023-08-23 16:43:46 +02:00
committed by Space Team
parent 05b364a5f1
commit 67460962c3
@@ -337,7 +337,7 @@ public class MaxStackFrameSizeAndLocalsCalculator extends MaxLocalsCalculator {
*/ */
int max = 0; int max = 0;
Stack<LabelWrapper> stack = new Stack<>(); Stack<LabelWrapper> stack = new Stack<>();
Set<LabelWrapper> pushed = SmartSet.create(); Set<LabelWrapper> pushed = new HashSet<>();
stack.push(firstLabel); stack.push(firstLabel);
pushed.add(firstLabel); pushed.add(firstLabel);
@@ -418,16 +418,31 @@ public class MaxStackFrameSizeAndLocalsCalculator extends MaxLocalsCalculator {
private LabelWrapper nextLabel = null; private LabelWrapper nextLabel = null;
private final Collection<ControlFlowEdge> successors = new LinkedList<>(); private final Collection<ControlFlowEdge> successors = new LinkedList<>();
private final int index;
private int outputStackMax = 0; private int outputStackMax = 0;
private int inputStackSize = 0; private int inputStackSize = 0;
public LabelWrapper(Label label) { public LabelWrapper(Label label, int index) {
this.label = label; this.label = label;
this.index = index;
} }
private void addSuccessor(LabelWrapper successor, int outputStackSize, boolean isExceptional) { private void addSuccessor(LabelWrapper successor, int outputStackSize, boolean isExceptional) {
successors.add(new ControlFlowEdge(successor, outputStackSize, isExceptional)); successors.add(new ControlFlowEdge(successor, outputStackSize, isExceptional));
} }
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
LabelWrapper wrapper = (LabelWrapper) o;
return index == wrapper.index;
}
@Override
public int hashCode() {
return index;
}
} }
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
@@ -435,7 +450,7 @@ public class MaxStackFrameSizeAndLocalsCalculator extends MaxLocalsCalculator {
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
private LabelWrapper getLabelWrapper(Label label) { private LabelWrapper getLabelWrapper(Label label) {
return labelWrappersTable.getOrCreate(label, () -> new LabelWrapper(label)); return labelWrappersTable.getOrCreate(label, () -> new LabelWrapper(label, labelWrappersTable.getSize()));
} }
private void increaseStackSize(int variation) { private void increaseStackSize(int variation) {