View Javadoc

1   // Throwable.java, created Fri Apr  5 18:36:41 2002 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.ClassLib.sun14_win32.java.lang;
5   
6   import joeq.Allocator.CodeAllocator;
7   import joeq.Class.jq_CompiledCode;
8   import joeq.Class.jq_Method;
9   import joeq.Memory.CodeAddress;
10  import joeq.Runtime.ExceptionDeliverer;
11  import joeq.UTF.Utf8;
12  
13  /*
14   * @author  John Whaley <jwhaley@alum.mit.edu>
15   * @version $Id: Throwable.java 1744 2004-05-07 08:11:01Z joewhaley $
16   */
17  public abstract class Throwable {
18      
19      private java.lang.Object backtrace;
20      
21      // native method implementations
22      private int getStackTraceDepth() {
23          ExceptionDeliverer.StackFrame backtrace = (ExceptionDeliverer.StackFrame)this.backtrace;
24          int i=-1;
25          while (backtrace != null) { backtrace = backtrace.getNext(); ++i; }
26          if (i == -1) i = 0;
27          return i;
28      }
29      
30      private StackTraceElement getStackTraceElement(int i) {
31          ExceptionDeliverer.StackFrame backtrace = (ExceptionDeliverer.StackFrame)this.backtrace;
32          while (--i >= 0) {
33              backtrace = backtrace.getNext();
34          }
35          java.lang.String declaringClass = "";
36          java.lang.String methodName = "";
37          java.lang.String fileName = null;
38          int lineNumber = -2;
39          CodeAddress ip = backtrace.getIP();
40          jq_CompiledCode cc = CodeAllocator.getCodeContaining(ip);
41          if (cc != null) {
42              jq_Method m = cc.getMethod();
43              if (m != null) {
44                  declaringClass = m.getDeclaringClass().getJDKName();
45                  methodName = m.getName().toString();
46                  //int code_offset = ip.difference(cc.getStart());
47                  Utf8 fn = m.getDeclaringClass().getSourceFile();
48                  if (fn != null) fileName = fn.toString();
49                  int bc_index = cc.getBytecodeIndex(ip);
50                  lineNumber = m.getLineNumber(bc_index);
51              }
52          }
53          return new StackTraceElement(declaringClass, methodName, fileName, lineNumber);
54      }
55  
56      public java.lang.Throwable fillInStackTrace() {
57          this.backtrace = ExceptionDeliverer.getStackTrace();
58          java.lang.Object o = this;
59          return (java.lang.Throwable)o;
60      }
61  
62      public java.lang.Object getBacktraceObject() { return this.backtrace; }
63  }