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.
18 package gov.nasa.jpf.jvm.bytecode;
20 import gov.nasa.jpf.vm.Instruction;
21 import gov.nasa.jpf.vm.LoadOnJPFRequired;
22 import gov.nasa.jpf.vm.MJIEnv;
23 import gov.nasa.jpf.vm.StackFrame;
24 import gov.nasa.jpf.vm.ThreadInfo;
25 import gov.nasa.jpf.vm.Types;
29 * Determine if object is of given type
30 * ..., objectref => ..., result
32 public class INSTANCEOF extends Instruction implements JVMInstruction {
37 * typeName is of a/b/C notation
39 public INSTANCEOF (String typeName){
40 type = Types.getTypeSignature(typeName, false);
44 public Instruction execute (ThreadInfo ti) {
45 if(Types.isReferenceSignature(type)) {
47 if(Types.isArray(type)) {
48 // retrieve the component terminal
49 t = Types.getComponentTerminal(type);
54 // resolve the referenced class
56 ti.resolveReferencedClass(t);
57 } catch(LoadOnJPFRequired lre) {
62 StackFrame frame = ti.getModifiableTopFrame();
63 int objref = frame.pop();
65 if (objref == MJIEnv.NULL) {
67 } else if (ti.getElementInfo(objref).instanceOf(type)) {
76 public String getType() {
81 public int getLength() {
82 return 3; // opcode, index1, index2
86 public int getByteCode () {
91 public void accept(JVMInstructionVisitor insVisitor) {
92 insVisitor.visit(this);