1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.nabla.forward.trimming;
18
19 import org.objectweb.asm.Opcodes;
20 import org.objectweb.asm.tree.AbstractInsnNode;
21 import org.objectweb.asm.tree.InsnList;
22 import org.objectweb.asm.tree.VarInsnNode;
23
24
25
26
27 public class SwappedDstoreTrimmer extends BytecodeTrimmer {
28
29
30
31 public SwappedDstoreTrimmer() {
32 super(4);
33 }
34
35
36 @Override
37 protected boolean trimWindow(final InsnList instructions,
38 final AbstractInsnNode[] window) {
39
40 if ((window[0].getOpcode() == Opcodes.DUP2_X2) &&
41 (window[1].getOpcode() == Opcodes.POP2) &&
42 (window[2].getOpcode() == Opcodes.DSTORE) &&
43 (window[3].getOpcode() == Opcodes.DSTORE)) {
44
45
46 final int tmp = ((VarInsnNode) window[2]).var;
47 ((VarInsnNode) window[2]).var = ((VarInsnNode) window[3]).var;
48 ((VarInsnNode) window[3]).var = tmp;
49
50
51 instructions.remove(window[0]);
52 instructions.remove(window[1]);
53
54
55 window[0] = window[2];
56 window[1] = window[3];
57 window[2] = window[1].getNext();
58 window[3] = (window[2] == null) ? null : window[2].getNext();
59 return true;
60
61 }
62
63
64 return false;
65
66 }
67
68 }