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.bytecode;
21 import gov.nasa.jpf.vm.Instruction;
22 import gov.nasa.jpf.jvm.JVMInstructionFactory;
23 import gov.nasa.jpf.util.Invocation;
24 import gov.nasa.jpf.vm.MethodInfo;
25 import gov.nasa.jpf.vm.ObjRef;
26 import gov.nasa.jpf.vm.StackFrame;
27 import gov.nasa.jpf.vm.ThreadInfo;
28 import gov.nasa.jpf.vm.Types;
29 import gov.nasa.jpf.vm.choice.InvocationCG;
31 import java.util.List;
34 * a sytnthetic INVOKE instruction that gets it's parameters from an
35 * InvocationCG. Whoever uses this better makes sure the frame this
36 * executes in has enough operand space (e.g. a DirectCallStackFrame).
39 public class INVOKECG extends Instruction implements JVMInstruction {
41 List<Invocation> invokes;
42 JVMInvokeInstruction realInvoke;
44 public INVOKECG(List<Invocation> invokes){
45 this.invokes = invokes;
49 public void setInvokes(List<Invocation> invokes) {
50 this.invokes = invokes;
54 public Instruction execute (ThreadInfo ti) {
56 if (!ti.isFirstStepInsn()) {
57 InvocationCG cg = new InvocationCG( "INVOKECG", invokes);
58 if (ti.getVM().setNextChoiceGenerator(cg)){
63 InvocationCG cg = ti.getVM().getCurrentChoiceGenerator( "INVOKECG", InvocationCG.class);
64 assert (cg != null) : "no current InvocationCG";
66 Invocation call = cg.getNextChoice();
67 MethodInfo callee = call.getMethodInfo();
68 JVMInstructionFactory insnFactory = JVMInstructionFactory.getFactory();
70 String clsName = callee.getClassInfo().getName();
71 String mthName = callee.getName();
72 String signature = callee.getSignature();
74 Instruction realInvoke;
75 if (callee.isStatic()){
76 realInvoke = insnFactory.invokestatic(clsName, mthName, signature);
78 realInvoke = insnFactory.invokevirtual(clsName, mthName, signature);
81 pushArguments(ti, call.getArguments(), call.getAttrs());
89 void pushArguments (ThreadInfo ti, Object[] args, Object[] attrs){
90 StackFrame frame = ti.getModifiableTopFrame();
93 for (int i=0; i<args.length; i++){
95 boolean isLong = false;
98 if (a instanceof ObjRef){
99 frame.pushRef(((ObjRef)a).getReference());
100 } else if (a instanceof Boolean){
101 frame.push((Boolean)a ? 1 : 0, false);
102 } else if (a instanceof Integer){
103 frame.push((Integer)a, false);
104 } else if (a instanceof Long){
105 frame.pushLong((Long)a);
107 } else if (a instanceof Double){
108 frame.pushLong(Types.doubleToLong((Double)a));
110 } else if (a instanceof Byte){
111 frame.push((Byte)a, false);
112 } else if (a instanceof Short){
113 frame.push((Short)a, false);
114 } else if (a instanceof Float){
115 frame.push(Types.floatToInt((Float)a), false);
119 if (attrs != null && attrs[i] != null){
121 frame.setLongOperandAttr(attrs[i]);
123 frame.setOperandAttr(attrs[i]);
131 public boolean isExtendedInstruction() {
135 public static final int OPCODE = 258;
138 public int getByteCode () {
143 public void accept(JVMInstructionVisitor insVisitor) {
144 insVisitor.visit(this);