001    /*
002     * Licensed to the Apache Software Foundation (ASF) under one or more
003     * contributor license agreements.  See the NOTICE file distributed with
004     * this work for additional information regarding copyright ownership.
005     * The ASF licenses this file to You under the Apache License, Version 2.0
006     * (the "License"); you may not use this file except in compliance with
007     * the License.  You may obtain a copy of the License at
008     *
009     *      http://www.apache.org/licenses/LICENSE-2.0
010     *
011     * Unless required by applicable law or agreed to in writing, software
012     * distributed under the License is distributed on an "AS IS" BASIS,
013     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014     * See the License for the specific language governing permissions and
015     * limitations under the License.
016     */
017    package org.apache.commons.nabla.forward.trimming;
018    
019    import org.objectweb.asm.Opcodes;
020    import org.objectweb.asm.tree.AbstractInsnNode;
021    import org.objectweb.asm.tree.InsnList;
022    
023    /** Trimmer removing (DLOAD i, POP2).
024     * @version $Id$
025     */
026    public class DLoadPop2Trimmer extends BytecodeTrimmer {
027    
028        /** Simple constructor.
029         */
030        public DLoadPop2Trimmer() {
031            super(2);
032        }
033    
034        /** {@inheritDoc} */
035        @Override
036        protected boolean trimWindow(final InsnList instructions,
037                                     final AbstractInsnNode[] window) {
038    
039            if ((window[0].getOpcode() == Opcodes.DUP2) &&
040                (window[1].getOpcode() == Opcodes.POP2)) {
041    
042                // remove the no-op instructions pair
043                instructions.remove(window[0]);
044                instructions.remove(window[1]);
045    
046                return true;
047    
048            }
049    
050            // nothing have been done
051            return false;
052    
053        }
054    
055    }