View Javadoc

1   // x86ReferenceExceptionDeliverer.java, created Mon Feb  5 23:23:21 2001 by joewhaley
2   // Copyright (C) 2001-3 John Whaley <jwhaley@alum.mit.edu>
3   // Licensed under the terms of the GNU LGPL; see COPYING for details.
4   package joeq.Compiler.Reference.x86;
5   
6   import joeq.Class.jq_CompiledCode;
7   import joeq.Class.jq_Method;
8   import joeq.Class.jq_TryCatch;
9   import joeq.Memory.CodeAddress;
10  import joeq.Memory.HeapAddress;
11  import joeq.Memory.StackAddress;
12  import joeq.Runtime.ExceptionDeliverer;
13  import joeq.Runtime.SystemInterface;
14  import joeq.Runtime.Unsafe;
15  import jwutil.util.Assert;
16  
17  /***
18   * @author  John Whaley <jwhaley@alum.mit.edu>
19   * @version $Id: x86ReferenceExceptionDeliverer.java 1941 2004-09-30 03:37:06Z joewhaley $
20   */
21  public class x86ReferenceExceptionDeliverer extends ExceptionDeliverer {
22  
23      public static /*final*/ boolean TRACE = false;
24      
25      public static final x86ReferenceExceptionDeliverer INSTANCE =
26      new x86ReferenceExceptionDeliverer();
27  
28      private x86ReferenceExceptionDeliverer() {}
29  
30      public final void deliverToStackFrame(jq_CompiledCode cc, Throwable x, jq_TryCatch tc, CodeAddress ip, StackAddress fp) {
31          jq_Method m = cc.getMethod();
32          // find new top of stack
33          int n_paramwords = m.getParamWords();
34          int n_localwords = m.getMaxLocals();
35          StackAddress sp = (StackAddress)fp.offset(((n_paramwords-n_localwords)<<2) - 4);
36          if (TRACE) SystemInterface.debugwriteln("poking exception object "+HeapAddress.addressOf(x).stringRep()+" into location "+sp.stringRep());
37          // push exception object there
38          sp.poke(HeapAddress.addressOf(x));
39          // branch!
40          Unsafe.longJump(ip, fp, sp, 0);
41      }
42      
43      public final Object getThisPointer(jq_CompiledCode cc, CodeAddress ip, StackAddress fp) {
44          jq_Method m = cc.getMethod();
45          int n_paramwords = m.getParamWords();
46          Assert._assert(n_paramwords >= 1);
47          return ((HeapAddress)fp.offset((n_paramwords+1)<<2).peek()).asObject();
48      }
49  
50  }