KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > gov > nasa > jpf > jvm > bytecode > InvokeInstruction


1 //
2
// Copyright (C) 2005 United States Government as represented by the
3
// Administrator of the National Aeronautics and Space Administration
4
// (NASA). All Rights Reserved.
5
//
6
// This software is distributed under the NASA Open Source Agreement
7
// (NOSA), version 1.3. The NOSA has been approved by the Open Source
8
// Initiative. See the file NOSA-1.3-JPF at the top of the distribution
9
// directory tree for the complete NOSA document.
10
//
11
// THE SUBJECT SOFTWARE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY OF ANY
12
// KIND, EITHER EXPRESSED, IMPLIED, OR STATUTORY, INCLUDING, BUT NOT
13
// LIMITED TO, ANY WARRANTY THAT THE SUBJECT SOFTWARE WILL CONFORM TO
14
// SPECIFICATIONS, ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR
15
// A PARTICULAR PURPOSE, OR FREEDOM FROM INFRINGEMENT, ANY WARRANTY THAT
16
// THE SUBJECT SOFTWARE WILL BE ERROR FREE, OR ANY WARRANTY THAT
17
// DOCUMENTATION, IF PROVIDED, WILL CONFORM TO THE SUBJECT SOFTWARE.
18
//
19
package gov.nasa.jpf.jvm.bytecode;
20
21 import gov.nasa.jpf.jvm.ClassInfo;
22 import gov.nasa.jpf.jvm.JVM;
23 import gov.nasa.jpf.jvm.MethodInfo;
24 import gov.nasa.jpf.jvm.Types;
25
26 import org.apache.bcel.classfile.ConstantPool;
27 import org.apache.bcel.generic.ConstantPoolGen;
28 import org.apache.bcel.generic.InstructionHandle;
29
30
31 /**
32  * abstraction for all invoke instructions
33  */

34 public abstract class InvokeInstruction extends Instruction {
35   /* Those are all from the BCEL class, i.e. straight from the class file.
36    * Note that we can't directly resolve to MethodInfo objects because
37    * the corresponding class might not be loaded yet (has to be done
38    * on execution)
39    */

40   public String JavaDoc cname;
41   public String JavaDoc mname;
42   public String JavaDoc signature;
43
44   int argSize = -1;
45
46   /** to cache the last callee object */
47   int lastObj = Integer.MIN_VALUE;
48   
49   /**
50    * watch out - this is only const for static and special invocation
51    * all virtuals will use it only as a cache
52    */

53   MethodInfo invokedMethod;
54   
55   protected InvokeInstruction () {}
56   
57   public void setPeer (org.apache.bcel.generic.Instruction i, ConstantPool cp) {
58     org.apache.bcel.generic.InvokeInstruction ii;
59     ConstantPoolGen cpg;
60
61     cpg = ClassInfo.getConstantPoolGen(cp);
62     ii = (org.apache.bcel.generic.InvokeInstruction) i;
63
64     cname = ii.getClassName(cpg);
65     signature = ii.getSignature(cpg);
66     mname = MethodInfo.getUniqueName(ii.getMethodName(cpg), signature);
67   }
68
69   /**
70    * return the last invoked MethodInfo (cached). Note this is only
71    * valid AFTER the insn got checked/executed, since it has to be set by
72    * the concrete InvokeInstruction subclasses (and only statics and specials
73    * give us const MehodInfos)
74    */

75   public MethodInfo getInvokedMethod () {
76     return invokedMethod;
77   }
78   
79   protected InvokeInstruction (MethodInfo mi, String JavaDoc cname, String JavaDoc mname, String JavaDoc signature,
80                        int offset, int position) {
81     this.mi = mi;
82     this.cname = cname;
83     this.mname = mname + signature;
84     this.signature = signature;
85     this.offset = offset;
86     this.position = position;
87   }
88   
89   protected void init (InstructionHandle h, int o, MethodInfo m,
90                        ConstantPool cp) {
91     super.init(h, o, m, cp);
92     isObservable |= JVM.observableInvokes.contains(cname + "." + mname);
93   }
94   
95   protected int getArgSize () {
96     if (argSize < 0) {
97       argSize = Types.getArgumentsSize(signature) + 1; // 'this'
98
}
99
100     return argSize;
101   }
102   
103 }
104
Popular Tags