KickJava   Java API By Example, From Geeks To Geeks.

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


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.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 /**
30  * abstraction for the various return instructions
31  */

32 public abstract class ReturnInstruction extends Instruction {
33   protected void init (InstructionHandle h, int o, MethodInfo m,
34                        ConstantPool cp) {
35     super.init(h, o, m, cp);
36     isObservable |= JVM.observableReturns.contains(mi.getCompleteName());
37   }
38   
39   abstract int storeReturnValue (ThreadInfo th);
40   abstract void pushReturnValue (ThreadInfo th);
41   
42   protected Instruction cleanUpAndAdvance (ThreadInfo th) {
43
44     storeReturnValue(th);
45
46     // always check if we have to unlock
47
mi.leave(th);
48     
49     if (th.wasDirectCall()) {
50       // return from something we called ourselves implicitly (i.e. there is
51
// no corresponding invoke BC in the code)
52

53       // there always has to be something on the stack, so we always have to remove
54
// the args and return the pc that implicitly cause the direct call
55
th.popFrame();
56       th.removeArguments(mi);
57       
58       // we don't push any return value, since it wouldn't be used in the code
59
return th.getPC();
60     } else {
61       if (!th.popFrame()) {
62         // no more frames, done with this thread (hence no need for a return value push)
63
return null;
64       } else {
65         th.removeArguments(mi);
66         pushReturnValue(th);
67         
68         return getNext(th);
69       }
70     }
71   }
72 }
Popular Tags