1818package net .raphimc .javadowngrader .transformer .j8 .methodcallreplacer ;
1919
2020import net .raphimc .javadowngrader .transformer .MethodCallReplacer ;
21- import net .raphimc .javadowngrader .util .ASMUtil ;
2221import org .objectweb .asm .Opcodes ;
2322import org .objectweb .asm .Type ;
2423import org .objectweb .asm .tree .*;
@@ -54,8 +53,6 @@ public InsnList getReplacement(ClassNode classNode, MethodNode methodNode, Strin
5453 return replacement ;
5554 }
5655
57- final int arrayListIndex = ASMUtil .getFreeVarIndex (methodNode ); // ArrayList
58-
5956 // Object...
6057 replacement .add (new TypeInsnNode (Opcodes .NEW , "java/util/ArrayList" ));
6158 // Object... ArrayList?
@@ -65,28 +62,26 @@ public InsnList getReplacement(ClassNode classNode, MethodNode methodNode, Strin
6562 // Object... ArrayList? ArrayList? int
6663 replacement .add (new MethodInsnNode (Opcodes .INVOKESPECIAL , "java/util/ArrayList" , "<init>" , "(I)V" ));
6764 // Object... ArrayList
68- replacement .add (new VarInsnNode (Opcodes .ASTORE , arrayListIndex ));
69- // Object...
7065 for (int i = 0 ; i < argCount ; i ++) {
71- // Object... Object
66+ // Object... Object ArrayList
67+ replacement .add (new InsnNode (Opcodes .DUP_X1 ));
68+ // Object... ArrayList Object ArrayList
69+ replacement .add (new InsnNode (Opcodes .DUP_X1 ));
70+ // Object... ArrayList ArrayList Object ArrayList
71+ replacement .add (new InsnNode (Opcodes .POP ));
72+ // Object... ArrayList ArrayList Object
7273 replacement .add (new MethodInsnNode (
7374 Opcodes .INVOKESTATIC ,
7475 "java/util/Objects" ,
7576 "requireNonNull" ,
7677 "(Ljava/lang/Object;)Ljava/lang/Object;"
7778 ));
78- // Object... Object
79- replacement .add (new VarInsnNode (Opcodes .ALOAD , arrayListIndex ));
80- // Object... Object ArrayList
81- replacement .add (new InsnNode (Opcodes .SWAP ));
82- // Object... ArrayList Object
79+ // Object... ArrayList ArrayList Object
8380 replacement .add (new MethodInsnNode (Opcodes .INVOKEINTERFACE , "java/util/List" , "add" , "(Ljava/lang/Object;)Z" ));
84- // Object... boolean
81+ // Object... ArrayList boolean
8582 replacement .add (new InsnNode (Opcodes .POP ));
86- // Object...
83+ // Object... ArrayList
8784 }
88- //
89- replacement .add (new VarInsnNode (Opcodes .ALOAD , arrayListIndex ));
9085 // ArrayList
9186 replacement .add (new InsnNode (Opcodes .DUP ));
9287 // ArrayList ArrayList
@@ -95,43 +90,44 @@ public InsnList getReplacement(ClassNode classNode, MethodNode methodNode, Strin
9590 } else {
9691 final LabelNode forStart = new LabelNode ();
9792 final LabelNode forEnd = new LabelNode ();
98- final int iIndex = ASMUtil .getFreeVarIndex (methodNode ); // int
9993
10094 // Object[]
10195 replacement .add (new InsnNode (Opcodes .ICONST_0 ));
102- // Object[] int
103- replacement .add (new VarInsnNode (Opcodes .ISTORE , iIndex ));
104- // Object[]
96+ // Object[] int(i)
10597 replacement .add (forStart );
106- // Object[]
107- replacement .add (new InsnNode (Opcodes .DUP ));
108- // Object[] Object[]
98+ // Object[] int(i)
99+ replacement .add (new InsnNode (Opcodes .DUP_X1 ));
100+ // int(i) Object[] int(i)
101+ replacement .add (new InsnNode (Opcodes .SWAP ));
102+ // int(i) int(i) Object[]
103+ replacement .add (new InsnNode (Opcodes .DUP_X2 ));
104+ // Object[] int(i) int(i) Object[]
109105 replacement .add (new InsnNode (Opcodes .ARRAYLENGTH ));
110- // Object[] int
111- replacement .add (new VarInsnNode (Opcodes .ILOAD , iIndex ));
112- // Object[] int int
113- replacement .add (new JumpInsnNode (Opcodes .IF_ICMPLE , forEnd ));
114- // Object[]
115- replacement .add (new InsnNode (Opcodes .DUP ));
116- // Object[] Object[]
117- replacement .add (new VarInsnNode (Opcodes .ILOAD , iIndex ));
118- // Object[] Object[] int
119- replacement .add (new IincInsnNode (iIndex , 1 ));
120- // Object[] Object[]
106+ // Object[] int(i) int(i) int(length)
107+ replacement .add (new JumpInsnNode (Opcodes .IF_ICMPGE , forEnd ));
108+ // Object[] int(i)
109+ replacement .add (new InsnNode (Opcodes .DUP2 ));
110+ // Object[] int(i) Object[] int(i)
121111 replacement .add (new InsnNode (Opcodes .AALOAD ));
122- // Object[] Object
112+ // Object[] int(i) Object
123113 replacement .add (new MethodInsnNode (
124114 Opcodes .INVOKESTATIC ,
125115 "java/util/Objects" ,
126116 "requireNonNull" ,
127117 "(Ljava/lang/Object;)Ljava/lang/Object;"
128118 ));
129- // Object[] Object
119+ // Object[] int(i) Object
130120 replacement .add (new InsnNode (Opcodes .POP ));
131- // Object[]
121+ // Object[] int(i)
122+ replacement .add (new InsnNode (Opcodes .ICONST_1 ));
123+ // Object[] int(i) int
124+ replacement .add (new InsnNode (Opcodes .IADD ));
125+ // Object[] int(i)
132126 replacement .add (new JumpInsnNode (Opcodes .GOTO , forStart ));
133127
134128 replacement .add (forEnd );
129+ // Object[] int(i)
130+ replacement .add (new InsnNode (Opcodes .POP ));
135131 // Object[]
136132 replacement .add (new MethodInsnNode (Opcodes .INVOKESTATIC , "java/util/Arrays" , "asList" , "([Ljava/lang/Object;)Ljava/util/List;" ));
137133 // List
0 commit comments