00001 package gov.nasa.arc.ase.jpf.jvm.bytecode; 00002 00003 import de.fub.bytecode.classfile.ConstantPool; 00004 import gov.nasa.arc.ase.jpf.jvm.SystemState; 00005 import gov.nasa.arc.ase.jpf.jvm.KernelState; 00006 import gov.nasa.arc.ase.jpf.jvm.ThreadInfo; 00007 import gov.nasa.arc.ase.jpf.jvm.ElementInfo; 00008 import gov.nasa.arc.ase.util.Debug; 00009 00010 public class CHECKCAST extends Instruction { 00011 String type; 00012 00013 public Instruction execute(SystemState ss, KernelState ks, ThreadInfo th) { 00014 int objref = th.pop(); 00015 00016 if(objref == -1) 00017 th.push(objref, true); 00018 else { 00019 ElementInfo e = ks.da.get(objref); 00020 00021 if(e.instanceOf(type)) 00022 th.push(objref, true); 00023 else 00024 return th.createAndThrowException("java.lang.ClassCastException"); 00025 } 00026 00027 return th.getPC().getNext(); 00028 } 00029 public void setPeer(de.fub.bytecode.generic.Instruction i, ConstantPool cp) { 00030 type = cp.constantToString(cp.getConstant(((de.fub.bytecode.generic.CHECKCAST)i).getIndex())); 00031 if(!type.startsWith("[")) type = "L" + type + ";"; 00032 } 00033 }