From 1502dfa0fb69d201a907f0bc7b420b82ee273c83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matou=C5=A1=20Ku=C4=8Dera?= Date: Tue, 20 Aug 2024 12:12:07 +0200 Subject: [PATCH] Revert "fix: try fix for TeaVM" This reverts commit 385cff1baf3248b23baf1b6cca9a3cf4ac8d2946. --- .../editor/InstructionSequenceReplacer.java | 58 ++++++++----------- 1 file changed, 25 insertions(+), 33 deletions(-) diff --git a/base/src/main/java/proguard/classfile/editor/InstructionSequenceReplacer.java b/base/src/main/java/proguard/classfile/editor/InstructionSequenceReplacer.java index 0342c8aa3..103b6b21e 100644 --- a/base/src/main/java/proguard/classfile/editor/InstructionSequenceReplacer.java +++ b/base/src/main/java/proguard/classfile/editor/InstructionSequenceReplacer.java @@ -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. @@ -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. @@ -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 @@ -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 @@ -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 @@ -464,7 +457,7 @@ public void visitBranchInstruction( replacementInstruction = new BranchInstruction( branchInstruction.opcode, - replacer.matchedBranchOffset(offset, branchInstruction.branchOffset)); + matchedBranchOffset(offset, branchInstruction.branchOffset)); } @Override @@ -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 @@ -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. @@ -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( @@ -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)); } }