Skip to content

Commit

Permalink
Revert "fix: try fix for TeaVM"
Browse files Browse the repository at this point in the history
This reverts commit 385cff1.
  • Loading branch information
zlataovce committed Aug 20, 2024
1 parent 385cff1 commit 1502dfa
Showing 1 changed file with 25 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public class InstructionSequenceReplacer implements InstructionVisitor, Constant
private final InstructionVisitor extraInstructionVisitor;

private final MyReplacementInstructionFactory replacementInstructionFactory =
new MyReplacementInstructionFactory(this);
new MyReplacementInstructionFactory();

/**
* Creates a new InstructionSequenceReplacer.
Expand Down Expand Up @@ -382,26 +382,21 @@ private boolean matchedInstructionsUnmodified() {
* This class creates replacement instructions for matched sequences, with any matched arguments
* filled out.
*/
private static class MyReplacementInstructionFactory implements InstructionVisitor {
private final InstructionSequenceReplacer replacer;
private class MyReplacementInstructionFactory implements InstructionVisitor {
private Instruction replacementInstruction;

private MyReplacementInstructionFactory(InstructionSequenceReplacer replacer) {
this.replacer = replacer;
}

/** Creates the replacement instruction for the given index in the instruction sequence. */
public Instruction create(Clazz clazz, CodeAttribute codeAttribute, int index) {
int matchedInstructionIndex =
index < replacer.instructionSequenceMatcher.instructionCount()
index < instructionSequenceMatcher.instructionCount()
? index
: replacer.instructionSequenceMatcher.instructionCount() - 1;
: instructionSequenceMatcher.instructionCount() - 1;

int matchedInstructionOffset =
replacer.instructionSequenceMatcher.matchedInstructionOffset(matchedInstructionIndex);
instructionSequenceMatcher.matchedInstructionOffset(matchedInstructionIndex);

// Create the instruction.
replacer.replacementInstructions[index].accept(
replacementInstructions[index].accept(
clazz, null, codeAttribute, matchedInstructionOffset, this);

// Return it.
Expand All @@ -420,8 +415,7 @@ public void visitSimpleInstruction(
replacementInstruction =
new SimpleInstruction(
simpleInstruction.opcode,
replacer.matchedArgument(
clazz, method, codeAttribute, offset, simpleInstruction.constant));
matchedArgument(clazz, method, codeAttribute, offset, simpleInstruction.constant));
}

@Override
Expand All @@ -434,9 +428,9 @@ public void visitVariableInstruction(
replacementInstruction =
new VariableInstruction(
variableInstruction.opcode,
replacer.matchedArgument(
matchedArgument(
clazz, method, codeAttribute, offset, variableInstruction.variableIndex),
replacer.instructionSequenceMatcher.matchedArgument(variableInstruction.constant));
instructionSequenceMatcher.matchedArgument(variableInstruction.constant));
}

@Override
Expand All @@ -449,9 +443,8 @@ public void visitConstantInstruction(
replacementInstruction =
new ConstantInstruction(
constantInstruction.opcode,
replacer.matchedConstantIndex(
(ProgramClass) clazz, constantInstruction.constantIndex),
replacer.instructionSequenceMatcher.matchedArgument(constantInstruction.constant));
matchedConstantIndex((ProgramClass) clazz, constantInstruction.constantIndex),
instructionSequenceMatcher.matchedArgument(constantInstruction.constant));
}

@Override
Expand All @@ -464,7 +457,7 @@ public void visitBranchInstruction(
replacementInstruction =
new BranchInstruction(
branchInstruction.opcode,
replacer.matchedBranchOffset(offset, branchInstruction.branchOffset));
matchedBranchOffset(offset, branchInstruction.branchOffset));
}

@Override
Expand All @@ -477,10 +470,10 @@ public void visitTableSwitchInstruction(
replacementInstruction =
new TableSwitchInstruction(
tableSwitchInstruction.opcode,
replacer.matchedBranchOffset(offset, tableSwitchInstruction.defaultOffset),
replacer.instructionSequenceMatcher.matchedArgument(tableSwitchInstruction.lowCase),
replacer.instructionSequenceMatcher.matchedArgument(tableSwitchInstruction.highCase),
replacer.matchedJumpOffsets(offset, tableSwitchInstruction.jumpOffsets));
matchedBranchOffset(offset, tableSwitchInstruction.defaultOffset),
instructionSequenceMatcher.matchedArgument(tableSwitchInstruction.lowCase),
instructionSequenceMatcher.matchedArgument(tableSwitchInstruction.highCase),
matchedJumpOffsets(offset, tableSwitchInstruction.jumpOffsets));
}

@Override
Expand All @@ -493,9 +486,9 @@ public void visitLookUpSwitchInstruction(
replacementInstruction =
new LookUpSwitchInstruction(
lookUpSwitchInstruction.opcode,
replacer.matchedBranchOffset(offset, lookUpSwitchInstruction.defaultOffset),
replacer.instructionSequenceMatcher.matchedArguments(lookUpSwitchInstruction.cases),
replacer.matchedJumpOffsets(offset, lookUpSwitchInstruction.jumpOffsets));
matchedBranchOffset(offset, lookUpSwitchInstruction.defaultOffset),
instructionSequenceMatcher.matchedArguments(lookUpSwitchInstruction.cases),
matchedJumpOffsets(offset, lookUpSwitchInstruction.jumpOffsets));
}

// Similar methods for pseudo-instructions.
Expand All @@ -506,8 +499,7 @@ public void visitLabelInstruction(
// pseudo-instruction for the code attribute editor.
// Then make sure we create a unique label, because
// there may be other matching sequences.
replacementInstruction =
replacer.codeAttributeEditor.label(replacer.uniqueLabel(label.identifier));
replacementInstruction = codeAttributeEditor.label(uniqueLabel(label.identifier));
}

public void visitCatchInstruction(
Expand All @@ -517,11 +509,11 @@ public void visitCatchInstruction(
// Then make sure we create and reference unique labels,
// because there may be other matching sequences.
replacementInstruction =
replacer.codeAttributeEditor.catch_(
replacer.uniqueLabel(catch_.identifier),
replacer.uniqueLabel(catch_.startOffset),
replacer.uniqueLabel(catch_.endOffset),
replacer.matchedConstantIndex((ProgramClass) clazz, catch_.catchType));
codeAttributeEditor.catch_(
uniqueLabel(catch_.identifier),
uniqueLabel(catch_.startOffset),
uniqueLabel(catch_.endOffset),
matchedConstantIndex((ProgramClass) clazz, catch_.catchType));
}
}

Expand Down

0 comments on commit 1502dfa

Please sign in to comment.