2 * Copyright (C) 2014, United States Government, as represented by the
3 * Administrator of the National Aeronautics and Space Administration.
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
10 * http://www.apache.org/licenses/LICENSE-2.0.
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.
19 package gov.nasa.jpf.jvm;
21 import gov.nasa.jpf.vm.NativeMethodInfo;
22 import gov.nasa.jpf.vm.NativeStackFrame;
23 import gov.nasa.jpf.vm.StackFrame;
24 import gov.nasa.jpf.vm.ThreadInfo;
25 import gov.nasa.jpf.vm.Types;
28 * a NativeStackFrame used for calling NativeMethods from Java bytecode
30 public class JVMNativeStackFrame extends NativeStackFrame {
32 public JVMNativeStackFrame (NativeMethodInfo callee){
36 public void setArguments (ThreadInfo ti){
37 StackFrame callerFrame = ti.getTopFrame(); // we are not going to modify it
38 NativeMethodInfo nmi = (NativeMethodInfo) mi;
39 int nArgs = nmi.getNumberOfArguments();
40 byte[] argTypes = nmi.getArgumentTypes();
42 Object[] a = new Object[nArgs+2];
49 for (i = 0, stackOffset = 0, j = nArgs + 1, k = nArgs - 1;
52 switch (argTypes[k]) {
54 ival = callerFrame.peek(stackOffset);
55 a[j] = Boolean.valueOf(Types.intToBoolean(ival));
60 ival = callerFrame.peek(stackOffset);
61 a[j] = Byte.valueOf((byte) ival);
66 ival = callerFrame.peek(stackOffset);
67 a[j] = Character.valueOf((char) ival);
72 ival = callerFrame.peek(stackOffset);
73 a[j] = new Short((short) ival);
78 ival = callerFrame.peek(stackOffset);
79 a[j] = new Integer(ival);
84 lval = callerFrame.peekLong(stackOffset);
85 stackOffset++; // 2 stack words
86 a[j] = new Long(lval);
91 ival = callerFrame.peek(stackOffset);
92 a[j] = new Float(Types.intToFloat(ival));
97 lval = callerFrame.peekLong(stackOffset);
98 stackOffset++; // 2 stack words
99 a[j] = new Double(Types.longToDouble(lval));
104 // NOTE - we have to store T_REFERENCE as an Integer, because
105 // it shows up in our native method as an 'int'
106 ival = callerFrame.peek(stackOffset);
107 a[j] = new Integer(ival);
113 //--- set our standard MJI header arguments
114 a[0] = ti.getMJIEnv();
116 if (nmi.isStatic()) {
117 a[1] = new Integer( nmi.getClassInfo().getClassObjectRef());
119 int thisRef = callerFrame.getCalleeThis(nmi);
120 a[1] = new Integer( thisRef);