Package alt.jiapi.instrumentor

Source Code of alt.jiapi.instrumentor.MethodCallStrategy

/*
* 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.List;

import alt.jiapi.JiapiException;
import alt.jiapi.Rule;
import alt.jiapi.Runtime;
import alt.jiapi.reflect.Instruction;
import alt.jiapi.reflect.InstructionList;

import alt.jiapi.reflect.instruction.Invocation;
import alt.jiapi.reflect.instruction.OpcodeGroups;

/**
* This Strategy finds invocations made to methods.
* Each part in a List returned, points to a method invocation
* instruction.
*
* @author Mika Riekkinen
* @author Joni Suominen
* @version $Revision: 1.6 $ $Date: 2004/03/15 14:47:53 $
*/
public class MethodCallStrategy extends AbstractStrategy {
    public MethodCallStrategy() {
        this("*");
    }

    /**
     * Constructor.
     * @param matcher A matcher that is used
     */
    public MethodCallStrategy(String matcher) {
        super(matcher);
    }

    /**
     * Constructor.
     * @param matchers An array of matchers
     * @param reverse if true, matching is reversed.
     */
    public MethodCallStrategy(String [] matchers, boolean reverse) {
        super(matchers, reverse);
    }

    /**
     * Scans InstructionList for method invocations made. Each known spot
     * returned is of length 1, pointing to the method invocation being
     * made.
     *
     * @param il InstructionList to scan for method invocation instructions.
     * @return A List of known spots, each of which points to method
     *        invocation instruction.
     */
    public List findHotSpots(InstructionList il) {
        List hotSpots = new ArrayList();
        int index = 0;
       
        // Find invokeXXX instructions
        while ((index = il.indexOf(OpcodeGroups.INVOKE_INSTRUCTIONS,
                                   index)) != -1) {
//              Instruction ins = il.get(index);
//              Operand o = ins.getOperand();
            Invocation ins = (Invocation)il.get(index);
            String targetName = ins.getClassName() + "." + ins.getMethodName();
            // Grep
            //if (match(o.toString())) {
            if (match(targetName)) {
                Instrumentation i = getInstrumentation();
                //i.setTargetName(o.toString());
                i.setTargetName(targetName);
                HotSpot h = new HotSpot(index, index + 1);
                hotSpots.add(h);
            }

            index++;
        }

        return hotSpots;
    }
}
TOP

Related Classes of alt.jiapi.instrumentor.MethodCallStrategy

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.