KickJava   Java API By Example, From Geeks To Geeks.

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


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.KernelState;
23 import gov.nasa.jpf.jvm.MethodInfo;
24 import gov.nasa.jpf.jvm.SystemState;
25 import gov.nasa.jpf.jvm.ThreadInfo;
26
27 import org.apache.bcel.classfile.ConstantPool;
28
29
30 /**
31  * Return void from method
32  * ... [empty]
33  */

34 public class RETURN extends ReturnInstruction {
35   public RETURN () {}
36   
37   public RETURN (MethodInfo mi, int offset, int position) {
38     this.mi = mi;
39     this.offset = offset;
40     this.position = position;
41   }
42   
43   public void setPeer (org.apache.bcel.generic.Instruction i, ConstantPool cp) {
44   }
45
46   public boolean isExecutable (SystemState ss, KernelState ks, ThreadInfo th) {
47     boolean isExec = true;
48     MethodInfo mi = th.getMethod();
49
50     if (mi.isThreadEntry(th)){
51       int objref = th.getObjectReference();
52       isExec = ks.da.get(objref).canLock(th);
53     }
54     
55     return isExec;
56   }
57   
58   public boolean isSchedulingRelevant (SystemState ss, KernelState ks, ThreadInfo ti) {
59     // if it's synchronized, we will release a lock
60
MethodInfo mi = ti.getMethod();
61     if (mi.isSynchronized()) {
62       return ti.hasOtherRunnables();
63     }
64     
65     return false;
66   }
67   
68   int storeReturnValue (ThreadInfo th) {
69     return 0; // we don't have any
70
}
71   
72   void pushReturnValue (ThreadInfo th) {
73     // nothing to do
74
}
75   
76   public Instruction execute (SystemState ss, KernelState ks, ThreadInfo th) {
77     int objref = -1;
78     ClassInfo ci = null;
79     MethodInfo mi = th.getMethod();
80     
81     // return from a constructor
82
if (mi.isCtor()) {
83       objref = th.getThis();
84
85       ci = ks.da.get(objref).getClassInfo();
86
87       if (mi.getClassInfo() != ci) {
88         ci = null;
89       }
90     }
91
92     // no return value to push here
93
return cleanUpAndAdvance(th);
94   }
95   
96   public String JavaDoc toString() {
97     return "return";
98   }
99   
100
101   public int getByteCode () {
102     return 0xB1;
103   }
104 }
105
Popular Tags