Package alt.jiapi.instrumentor

Source Code of alt.jiapi.instrumentor.TailInstrumentor

/*
* Copyright (C) 2001 Mika Riekkinen, Joni Suominen
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/

package alt.jiapi.instrumentor;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.apache.log4j.Category;

import alt.jiapi.Instrumentor;
import alt.jiapi.Runtime;
import alt.jiapi.reflect.InstructionList;

/**
* This Instrumentor gets in an InstructionList and
* selects zero or more instructions from end of the instruction list
* given.
*
* @author Mika Riekkinen
* @author Joni Suominen
* @version $Revision: 1.9 $ $Date: 2004/03/15 14:47:53 $
*/
public class TailInstrumentor extends AbstractInstrumentor {
    private static Category log = Runtime.getLogCategory(TailInstrumentor.class);
    /**
     * Number of instructions this Instrumentor applies to.
     */
    protected int instructionCount = 0;

    /**
     * Constructor. Selects zero instructions from the enf of the list.
     * Selecting zero instructions acts as a marker to end of the list.
     */
    public TailInstrumentor() {
        this(0);
    }

    /**
     * This constructor selects zero or more instructions from the end of the
     * list.
     *
     * @param instructionCount number of instructions to select
     */
    public TailInstrumentor(int instructionCount) {
        log.info("Instruction count " + instructionCount);

        if (instructionCount < 0) {
            throw new IllegalArgumentException(instructionCount + " < 0");
        }

        this.instructionCount = instructionCount;
    }

    /**
     * Selects instructionCount instructions from the end of the
     * InstructionList given.
     *
     * @param il InstructionList to consider
     * @see #instructionCount
     */
    public void instrument(InstructionList il) {
        log.info("Instrumenting " + getCurrentClass().getName() + "." +
                 il.getDeclaringMethod().getName());

        InstructionList view;

        if (instructionCount > il.size()) {
            log.warn("List size exceeded: instructions needed : " +
                     instructionCount + ", available " + il.size() +
                     ". Using all that is available.");

             view = il.createView(0, il.size());
        }
        else {
             view = il.createView(il.size() - instructionCount, il.size());
        }

        forward(view);
    }
}
TOP

Related Classes of alt.jiapi.instrumentor.TailInstrumentor

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.