Main Page   Packages   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members  

ATHROW.java

00001 package gov.nasa.arc.ase.jpf.jvm.bytecode;
00002 
00003 import de.fub.bytecode.classfile.CodeException;
00004 import de.fub.bytecode.classfile.Utility;
00005 import de.fub.bytecode.generic.CodeExceptionGen;
00006 import de.fub.bytecode.generic.InstructionHandle;
00007 import gov.nasa.arc.ase.jpf.*;
00008 import gov.nasa.arc.ase.jpf.jvm.*;
00009 import gov.nasa.arc.ase.util.Debug;
00010 
00011 public class ATHROW extends AbstractInstruction {
00012   private de.fub.bytecode.generic.ATHROW peer;
00013 
00014   public InstructionHandle execute(SystemState ss, KernelState ks, ThreadInfo th) {
00015     int objref = th.pop();
00016 
00017     ClassInfo ci = ks.dynamic_area.getClass(objref);
00018 
00019     return findExceptionHandler(th, objref, ci, ks);
00020   }  
00021   // tries to find an exception handler so that execution is continued there
00022   private InstructionHandle findExceptionHandler(ThreadInfo th,
00023       int exception, ClassInfo type, KernelState ks) {
00024     JPFVM jpfvm = JPFVM.getJPFVM();
00025 
00026     while (th.depth() != 0) {
00027       // gets the current position in the method code
00028       // that is needed to access the exception table
00029       int pc = th.getPC().getPosition();
00030 
00031       // gets the exception table from the current method
00032       CodeExceptionGen[] exceptions = th.getCurrentMethod().getExceptions();
00033 
00034       // checks the exception catched in order
00035       for(int idx = 0, s = exceptions.length; idx < s; idx++) {
00036     // exception entry
00037     CodeException ce = exceptions[idx].getCodeException(th.getCPG());
00038 
00039     // gets the class of exceptions catched.
00040     String classname;
00041     if (ce.getCatchType() == 0)
00042       // any exception
00043       classname = "java.lang.Exception";
00044     else
00045       // gets the class name (beware of / -> . substitution)
00046       classname =  Utility.replace(
00047           exceptions[idx].getCatchType().getClassName(),"/",".");
00048 
00049     ClassInfo ci;
00050     if (classname.equals("java.lang.Exception"))
00051       //** warning: I am not sure what this is for, so  **//
00052       //**          I just leave it alone for now       **//
00053       // ci = type so it will always be matched
00054       ci = type; // matches all exceptions // but also ERRORS now!
00055     else
00056       // gets the class info
00057       ci = jpfvm.getClass(classname);
00058 
00059     // checks if the program counter follows in the range of the
00060     // exception and if the type catched is the corrent one
00061     //** error: this doesn't work if an exception derived from the  **//
00062     //**        base class is thrown. To be corrected soon.     **//
00063     if (pc >= ce.getStartPC() && pc <= ce.getEndPC() && (ci == type)) {
00064       // clears all the operand stack
00065       th.clearOperandStack();
00066 
00067       // pushes the exception on the stack instead
00068       th.push(exception);
00069 // ifdef MARK_N_SWEEP
00070       th.setOperandRef();
00071 //#endif MARK_N_SWEEP
00072 
00073       // jumps to the exception handler
00074       return exceptions[idx].getHandlerPC();
00075     }
00076       }
00077 
00078       // now we are exiting the method 
00079       // to throw the exception at an higher level
00080       
00081       // check if this method was synchronized
00082       MethodInfo mi = th.getCurrentMethod();
00083       if (mi.getMethodGen().isSynchronized()) {
00084         // releases the lock
00085     if (mi.getMethodGen().isStatic()) {
00086       // static method so it's lock on the class
00087       String className = mi.getClassInfo().getClassData().getClassName();
00088 
00089       ks.static_area.monitorUnlock(className, th);
00090     } else {
00091       // non static method so it's lock on an object
00092       ks.dynamic_area.monitorUnlock(th.getThis(), th);
00093     }
00094       }
00095 
00096       // remove a frame
00097       th.popFrame();
00098     }
00099 
00100     // no handler found
00101     throw new InternalErrorException("No handler found for exception " + type.getClassName());
00102   }  
00103   public void setPeer(de.fub.bytecode.generic.Instruction i) {
00104     peer = (de.fub.bytecode.generic.ATHROW)i;
00105   }  
00106 }

Generated at Thu Feb 7 06:40:10 2002 for Bandera by doxygen1.2.10 written by Dimitri van Heesch, © 1997-2001