Initial import
[jpf-core.git] / src / main / gov / nasa / jpf / vm / DirectCallStackFrame.java
1 /*
2  * Copyright (C) 2014, United States Government, as represented by the
3  * Administrator of the National Aeronautics and Space Administration.
4  * All rights reserved.
5  *
6  * The Java Pathfinder core (jpf-core) platform is licensed under the
7  * Apache License, Version 2.0 (the "License"); you may not use this file except
8  * in compliance with the License. You may obtain a copy of the License at
9  * 
10  *        http://www.apache.org/licenses/LICENSE-2.0. 
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and 
16  * limitations under the License.
17  */
18 package gov.nasa.jpf.vm;
19
20 import gov.nasa.jpf.SystemAttribute;
21
22 /**
23  * DirectCallStackFrames are only used for overlay calls (from native code), i.e.
24  * there is no corresponding INVOKE instruction. The associated MethodInfos are
25  * synthetic, their only code is (usually) a INVOKEx and a DIRECTCALLRETURN.
26  * NOTE: such MethodInfos do not belong to any class
27  * 
28  * Arguments for the invoke insn have to be pushed explicitly by the caller
29  * 
30  * direct calls do not return any values themselves, but they do get the return values of the
31  * called method pushed onto their own operand stack. If the DirectCallStackFrame user
32  * needs such return values, it has to do so via ThreadInfo.getReturnedDirectCall()
33  *
34  */
35 public abstract class DirectCallStackFrame extends StackFrame implements SystemAttribute {
36   
37   MethodInfo callee;
38
39   protected DirectCallStackFrame (MethodInfo miDirectCall, MethodInfo callee, int maxLocals, int maxStack){
40     super( miDirectCall, maxLocals, maxStack);    
41     this.callee = callee;
42   }
43   
44   protected DirectCallStackFrame (MethodInfo miDirectCall, MethodInfo callee){
45     super( miDirectCall, miDirectCall.getMaxLocals(), miDirectCall.getMaxStack());
46     this.callee = callee;
47   }
48   
49   public MethodInfo getCallee (){
50     return callee;
51   }
52   
53   @Override
54   public String getStackTraceInfo () {
55     StringBuilder sb = new StringBuilder(128);
56     sb.append('[');
57     sb.append( callee.getUniqueName());
58     sb.append(']');
59     return sb.toString();
60   }
61   
62   public DirectCallStackFrame getPreviousDirectCallStackFrame(){
63     StackFrame f = prev;
64     while (f != null && !(f instanceof DirectCallStackFrame)){
65       f = f.prev;
66     }
67     
68     return (DirectCallStackFrame) f;
69   }
70   
71   public void setFireWall(){
72     mi.setFirewall(true);
73   }
74
75   @Override
76   public boolean isDirectCallFrame () {
77     return true;
78   }
79   
80   @Override
81   public boolean isSynthetic() {
82     return true;
83   }
84   
85   /*
86    * those set the callee arguments for the invoke insn - the returned value is the slot index OFFSET (not the slot index
87    * itself) for the next argument. This has to be used in a pattern like 
88    *   int argOffset = frame.setArgument( 0, firstArg, a0);
89    *   argOffset = frame.setLongArgument( argOffset, secondArg, a1);
90    *   ...
91    */
92   
93   public abstract int setArgument (int argOffset, int value, Object attr);
94   public abstract int setLongArgument (int argOffset, long value, Object attr);
95   public abstract int setReferenceArgument (int argOffset, int ref, Object attr);
96
97   public int setFloatArgument (int argOffset, float value, Object attr){
98     return setArgument( argOffset, Float.floatToIntBits(value), attr);
99   }
100   public int setDoubleArgument (int argOffset, double value, Object attr){
101     return setLongArgument( argOffset, Double.doubleToLongBits(value), attr);
102   }
103   
104 }