Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
SwappedDloadTrimmer |
|
| 0.0;0 | ||||
SwappedDloadTrimmer$1 |
|
| 0.0;0 | ||||
SwappedDloadTrimmer$LazyHolder |
|
| 0.0;0 |
1 | /* | |
2 | * Licensed to the Apache Software Foundation (ASF) under one or more | |
3 | * contributor license agreements. See the NOTICE file distributed with | |
4 | * this work for additional information regarding copyright ownership. | |
5 | * The ASF licenses this file to You under the Apache License, Version 2.0 | |
6 | * (the "License"); you may not use this file except in compliance with | |
7 | * the License. You may obtain a copy of the License at | |
8 | * | |
9 | * http://www.apache.org/licenses/LICENSE-2.0 | |
10 | * | |
11 | * Unless required by applicable law or agreed to in writing, software | |
12 | * distributed under the License is distributed on an "AS IS" BASIS, | |
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
14 | * See the License for the specific language governing permissions and | |
15 | * limitations under the License. | |
16 | */ | |
17 | package org.apache.commons.nabla.automatic.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 | /** Trimmer replacing (DLOAD i, DLOAD j, DUP2_X2, POP2) with (DLOAD j, DLOAD i). | |
25 | */ | |
26 | 1 | public class SwappedDloadTrimmer extends BytecodeTrimmer { |
27 | ||
28 | /** Holder for the singleton instance.*/ | |
29 | 65 | private static class LazyHolder { |
30 | /** The singleton instance. */ | |
31 | 1 | private static final BytecodeTrimmer INSTANCE = new SwappedDloadTrimmer(); |
32 | } | |
33 | ||
34 | /** Hidden constructor. | |
35 | */ | |
36 | private SwappedDloadTrimmer() { | |
37 | 1 | super(4); |
38 | 1 | } |
39 | ||
40 | /** Get the singleton instance. | |
41 | * <p>We use here the Initialization on Demand Holder idiom.</p> | |
42 | * @return the singleton instance | |
43 | */ | |
44 | public static BytecodeTrimmer getInstance() { | |
45 | 65 | return LazyHolder.INSTANCE; |
46 | } | |
47 | ||
48 | /** {@inheritDoc} */ | |
49 | @Override | |
50 | protected boolean trimWindow(final InsnList instructions, | |
51 | final AbstractInsnNode[] window) { | |
52 | ||
53 | 1747 | if ((window[0].getOpcode() == Opcodes.DLOAD) && |
54 | (window[1].getOpcode() == Opcodes.DLOAD) && | |
55 | (window[2].getOpcode() == Opcodes.DUP2_X2) && | |
56 | (window[3].getOpcode() == Opcodes.POP2)) { | |
57 | ||
58 | // reverse the DLOAD orders | |
59 | 31 | final int tmp = ((VarInsnNode) window[0]).var; |
60 | 31 | ((VarInsnNode) window[0]).var = ((VarInsnNode) window[1]).var; |
61 | 31 | ((VarInsnNode) window[1]).var = tmp; |
62 | ||
63 | // remove the operand stack swap instructions | |
64 | 31 | instructions.remove(window[2]); |
65 | 31 | instructions.remove(window[3]); |
66 | ||
67 | // slide window two instructions forward | |
68 | 31 | window[2] = window[1].getNext(); |
69 | 31 | window[3] = (window[2] == null) ? null : window[2].getNext(); |
70 | 31 | return true; |
71 | ||
72 | } | |
73 | ||
74 | // nothing have been done | |
75 | 1716 | return false; |
76 | ||
77 | } | |
78 | ||
79 | } |