| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| SwappedDstoreTrimmer |
|
| 0.0;0 | ||||
| SwappedDstoreTrimmer$1 |
|
| 0.0;0 | ||||
| SwappedDstoreTrimmer$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 (DUP2_X2, POP2, DSTORE i, DSTORE j) with (DSTORE j, DSTORE i). | |
| 25 | */ | |
| 26 | 1 | public class SwappedDstoreTrimmer 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 SwappedDstoreTrimmer(); |
| 32 | } | |
| 33 | ||
| 34 | /** Hidden constructor. | |
| 35 | */ | |
| 36 | private SwappedDstoreTrimmer() { | |
| 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 | 1693 | if ((window[0].getOpcode() == Opcodes.DUP2_X2) && |
| 54 | (window[1].getOpcode() == Opcodes.POP2) && | |
| 55 | (window[2].getOpcode() == Opcodes.DSTORE) && | |
| 56 | (window[3].getOpcode() == Opcodes.DSTORE)) { | |
| 57 | ||
| 58 | // reverse the DSTORE orders | |
| 59 | 23 | final int tmp = ((VarInsnNode) window[2]).var; |
| 60 | 23 | ((VarInsnNode) window[2]).var = ((VarInsnNode) window[3]).var; |
| 61 | 23 | ((VarInsnNode) window[3]).var = tmp; |
| 62 | ||
| 63 | // remove the operand stack swap instructions | |
| 64 | 23 | instructions.remove(window[0]); |
| 65 | 23 | instructions.remove(window[1]); |
| 66 | ||
| 67 | // update lookahead instructions | |
| 68 | 23 | window[0] = window[2]; |
| 69 | 23 | window[1] = window[3]; |
| 70 | 23 | window[2] = window[1].getNext(); |
| 71 | 23 | window[3] = (window[2] == null) ? null : window[2].getNext(); |
| 72 | 23 | return true; |
| 73 | ||
| 74 | } | |
| 75 | ||
| 76 | // nothing have been done | |
| 77 | 1670 | return false; |
| 78 | ||
| 79 | } | |
| 80 | ||
| 81 | } |