01: //
02: // Copyright (C) 2005 United States Government as represented by the
03: // Administrator of the National Aeronautics and Space Administration
04: // (NASA). All Rights Reserved.
05: //
06: // This software is distributed under the NASA Open Source Agreement
07: // (NOSA), version 1.3. The NOSA has been approved by the Open Source
08: // Initiative. See the file NOSA-1.3-JPF at the top of the distribution
09: // 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.JVM;
22: import gov.nasa.jpf.jvm.MethodInfo;
23: import gov.nasa.jpf.jvm.ThreadInfo;
24:
25: import org.apache.bcel.classfile.ConstantPool;
26: import org.apache.bcel.generic.InstructionHandle;
27:
28: /**
29: * abstraction for the various return instructions
30: */
31: public abstract class ReturnInstruction extends Instruction {
32: protected void init(InstructionHandle h, int o, MethodInfo m,
33: ConstantPool cp) {
34: super .init(h, o, m, cp);
35: isObservable |= JVM.observableReturns.contains(mi
36: .getCompleteName());
37: }
38:
39: abstract int storeReturnValue(ThreadInfo th);
40:
41: abstract void pushReturnValue(ThreadInfo th);
42:
43: protected Instruction cleanUpAndAdvance(ThreadInfo th) {
44:
45: storeReturnValue(th);
46:
47: // always check if we have to unlock
48: mi.leave(th);
49:
50: if (th.wasDirectCall()) {
51: // return from something we called ourselves implicitly (i.e. there is
52: // no corresponding invoke BC in the code)
53:
54: // there always has to be something on the stack, so we always have to remove
55: // the args and return the pc that implicitly cause the direct call
56: th.popFrame();
57: th.removeArguments(mi);
58:
59: // we don't push any return value, since it wouldn't be used in the code
60: return th.getPC();
61: } else {
62: if (!th.popFrame()) {
63: // no more frames, done with this thread (hence no need for a return value push)
64: return null;
65: } else {
66: th.removeArguments(mi);
67: pushReturnValue(th);
68:
69: return getNext(th);
70: }
71: }
72: }
73: }
|