KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > alt > jiapi > instrumentor > MethodReturnStrategy


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

18
19 package alt.jiapi.instrumentor;
20
21 import java.util.ArrayList JavaDoc;
22 import java.util.List JavaDoc;
23
24 import alt.jiapi.reflect.Instruction;
25 import alt.jiapi.reflect.InstructionList;
26 import alt.jiapi.reflect.instruction.OpcodeGroups;
27
28 /**
29  * This class implements Strategy so, that return instructions
30  * in InstructionList are used as split boundaries.
31  *
32  * @author Mika Riekkinen
33  * @author Joni Suominen
34  * @version $Revision: 1.7 $ $Date: 2004/03/15 14:47:53 $
35  */

36 public class MethodReturnStrategy extends AbstractStrategy {
37     /**
38      * Empty constructor.
39      */

40     public MethodReturnStrategy() {
41     }
42
43
44     /**
45      * Scans InstructionList for return statements. Each known spot
46      * returned is of length 1, pointing to the return instruction.
47      *
48      * @param il InstructionList to scan for return instructions.
49      * @return A List of known spots, each of which points to return
50      * instruction.
51      */

52     public List JavaDoc findHotSpots(InstructionList il) {
53         String JavaDoc name = il.getDeclaringMethod().getName();
54         Instrumentation i = getInstrumentation();
55         i.setTargetName(name);
56
57         List JavaDoc hotSpots = new ArrayList JavaDoc();
58         int index = 0;
59         
60         // Find return instructions
61
while ((index = il.indexOf(OpcodeGroups.RETURN_INSTRUCTIONS,
62                                    index)) != -1) {
63             // Grep
64
if (match(name)) {
65                 HotSpot h = new HotSpot(index, index + 1);
66                 hotSpots.add(h);
67             }
68
69             index++;
70         }
71
72         return hotSpots;
73     }
74
75     /**
76      * Converts this Instrumentor to String.
77      */

78     public String JavaDoc toString() {
79         return this.getClass().getName();
80     }
81 }
82
Popular Tags