001: //
002: // Copyright (C) 2005 United States Government as represented by the
003: // Administrator of the National Aeronautics and Space Administration
004: // (NASA). All Rights Reserved.
005: //
006: // This software is distributed under the NASA Open Source Agreement
007: // (NOSA), version 1.3. The NOSA has been approved by the Open Source
008: // Initiative. See the file NOSA-1.3-JPF at the top of the distribution
009: // directory tree for the complete NOSA document.
010: //
011: // THE SUBJECT SOFTWARE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY OF ANY
012: // KIND, EITHER EXPRESSED, IMPLIED, OR STATUTORY, INCLUDING, BUT NOT
013: // LIMITED TO, ANY WARRANTY THAT THE SUBJECT SOFTWARE WILL CONFORM TO
014: // SPECIFICATIONS, ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR
015: // A PARTICULAR PURPOSE, OR FREEDOM FROM INFRINGEMENT, ANY WARRANTY THAT
016: // THE SUBJECT SOFTWARE WILL BE ERROR FREE, OR ANY WARRANTY THAT
017: // DOCUMENTATION, IF PROVIDED, WILL CONFORM TO THE SUBJECT SOFTWARE.
018: //
019: package gov.nasa.jpf.jvm.bytecode;
020:
021: import gov.nasa.jpf.jvm.ClassInfo;
022: import gov.nasa.jpf.jvm.JVM;
023: import gov.nasa.jpf.jvm.MethodInfo;
024: import gov.nasa.jpf.jvm.Types;
025:
026: import org.apache.bcel.classfile.ConstantPool;
027: import org.apache.bcel.generic.ConstantPoolGen;
028: import org.apache.bcel.generic.InstructionHandle;
029:
030: /**
031: * abstraction for all invoke instructions
032: */
033: public abstract class InvokeInstruction extends Instruction {
034: /* Those are all from the BCEL class, i.e. straight from the class file.
035: * Note that we can't directly resolve to MethodInfo objects because
036: * the corresponding class might not be loaded yet (has to be done
037: * on execution)
038: */
039: public String cname;
040: public String mname;
041: public String signature;
042:
043: int argSize = -1;
044:
045: /** to cache the last callee object */
046: int lastObj = Integer.MIN_VALUE;
047:
048: /**
049: * watch out - this is only const for static and special invocation
050: * all virtuals will use it only as a cache
051: */
052: MethodInfo invokedMethod;
053:
054: protected InvokeInstruction() {
055: }
056:
057: public void setPeer(org.apache.bcel.generic.Instruction i,
058: ConstantPool cp) {
059: org.apache.bcel.generic.InvokeInstruction ii;
060: ConstantPoolGen cpg;
061:
062: cpg = ClassInfo.getConstantPoolGen(cp);
063: ii = (org.apache.bcel.generic.InvokeInstruction) i;
064:
065: cname = ii.getClassName(cpg);
066: signature = ii.getSignature(cpg);
067: mname = MethodInfo.getUniqueName(ii.getMethodName(cpg),
068: signature);
069: }
070:
071: /**
072: * return the last invoked MethodInfo (cached). Note this is only
073: * valid AFTER the insn got checked/executed, since it has to be set by
074: * the concrete InvokeInstruction subclasses (and only statics and specials
075: * give us const MehodInfos)
076: */
077: public MethodInfo getInvokedMethod() {
078: return invokedMethod;
079: }
080:
081: protected InvokeInstruction(MethodInfo mi, String cname,
082: String mname, String signature, int offset, int position) {
083: this .mi = mi;
084: this .cname = cname;
085: this .mname = mname + signature;
086: this .signature = signature;
087: this .offset = offset;
088: this .position = position;
089: }
090:
091: protected void init(InstructionHandle h, int o, MethodInfo m,
092: ConstantPool cp) {
093: super .init(h, o, m, cp);
094: isObservable |= JVM.observableInvokes.contains(cname + "."
095: + mname);
096: }
097:
098: protected int getArgSize() {
099: if (argSize < 0) {
100: argSize = Types.getArgumentsSize(signature) + 1; // 'this'
101: }
102:
103: return argSize;
104: }
105:
106: }
|