source: branches/0.16.x/abcl/src/org/armedbear/lisp/JavaStackFrame.java

Last change on this file was 12105, checked in by Mark Evenson, 16 years ago

Split StackFrame? abstraction into Java and Lisp stack frames.

From the original patch/idea from Tobias Rittweiler this introduces
more information of primary interest to ABCL implemnters such as when
a form like (make-thread #'(lambda ())) is evaluated

All users of EXT:BACKTRACE-AS-LIST should now use SYS:BACKTRACE, the
results of which is a list of the new builtin classes JAVA_STACK_FRAME
or LISP_STACK_FRAME. The methods SYS:FRAME-TO-STRING and
SYS:FRAME-TO-LIST are defined to break these new objects into
inspectable parts. As a convenience, there is a SYS:BACKTRACE-AS-LIST
which calls SYS:FRAME-TO-LIST to each element of the computed
backtrace.

Refactorings have occurred on the Java side: the misnamed
LispThread?.backtrace() is now LispThread?.printBacktrace().
LispThread?.backtraceAsList() is now LispThread?.backtrace() as it is
a shorter name, and more to the point.

Java stack frames only appear after a call through Lisp.error(), which
has only the top level as a restart as an option.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 4.4 KB
Line 
1/*
2 * JavaStackFrame.java
3 *
4 * Copyright (C) 2009 Mark Evenson
5 * $Id: JavaStackFrame.java 12105 2009-08-19 14:51:56Z mevenson $
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
20 *
21 * As a special exception, the copyright holders of this library give you
22 * permission to link this library with independent modules to produce an
23 * executable, regardless of the license terms of these independent
24 * modules, and to copy and distribute the resulting executable under
25 * terms of your choice, provided that you also meet, for each linked
26 * independent module, the terms and conditions of the license of that
27 * module.  An independent module is a module which is not derived from
28 * or based on this library.  If you modify this library, you may extend
29 * this exception to your version of the library, but you are not
30 * obligated to do so.  If you do not wish to do so, delete this
31 * exception statement from your version.
32 */
33
34package org.armedbear.lisp;
35
36public class JavaStackFrame 
37  extends StackFrame
38{
39  public final StackTraceElement javaFrame;
40
41  public JavaStackFrame(StackTraceElement javaFrame)
42  {
43    this.javaFrame = javaFrame;
44  }
45
46  @Override
47  public LispObject typeOf() { 
48    return Symbol.JAVA_STACK_FRAME; 
49  }
50
51  @Override
52  public LispObject classOf()   { return BuiltInClass.JAVA_STACK_FRAME; }
53
54  @Override
55  public String writeToString() { 
56    String result = null;
57    final String JAVA_STACK_FRAME = "JAVA-STACK-FRAME";
58    try {
59      result = unreadableString(JAVA_STACK_FRAME + " " 
60        + toLispString().toString()); 
61    } catch (ConditionThrowable t) {
62      Debug.trace("Implementation error: ");
63      Debug.trace(t);
64      result = unreadableString(JAVA_STACK_FRAME);
65    }
66    return result;
67  }
68
69  @Override
70  public LispObject typep(LispObject typeSpecifier) 
71     throws ConditionThrowable
72  {
73     if (typeSpecifier == Symbol.JAVA_STACK_FRAME)
74       return T;
75     if (typeSpecifier == BuiltInClass.JAVA_STACK_FRAME)
76       return T;
77     return super.typep(typeSpecifier);
78   }
79
80  static final Symbol CLASS = Packages.internKeyword("CLASS");
81  static final Symbol METHOD = Packages.internKeyword("METHOD");
82  static final Symbol FILE = Packages.internKeyword("FILE");
83  static final Symbol LINE = Packages.internKeyword("LINE");
84  static final Symbol NATIVE_METHOD = Packages.internKeyword("NATIVE-METHOD");
85
86  public LispObject toLispList() throws ConditionThrowable
87  {
88    LispObject result = Lisp.NIL;
89   
90    if ( javaFrame == null) 
91      return result;
92
93    result = result.push(CLASS);
94    result = result.push(new SimpleString(javaFrame.getClassName()));
95    result = result.push(METHOD);
96    result = result.push(new SimpleString(javaFrame.getMethodName()));
97    result = result.push(FILE);
98    result = result.push(new SimpleString(javaFrame.getFileName()));
99    result = result.push(LINE);
100    result = result.push(Fixnum.getInstance(javaFrame.getLineNumber()));
101    if (javaFrame.isNativeMethod()) {
102      result = result.push(NATIVE_METHOD);
103      result = result.push(Symbol.T);
104    }
105
106    return result.nreverse();
107  }
108
109  @Override
110  public SimpleString toLispString() 
111    throws ConditionThrowable
112  {
113    return new SimpleString(javaFrame.toString());
114  }
115
116  @Override
117  public LispObject getParts() 
118    throws ConditionThrowable
119  { 
120    LispObject result = NIL;
121    result = result.push(new Cons("CLASS", 
122          new SimpleString(javaFrame.getClassName())));
123    result = result.push(new Cons("METHOD", 
124          new SimpleString(javaFrame.getMethodName())));
125    result = result.push(new Cons("FILE", 
126          new SimpleString(javaFrame.getFileName())));
127    result = result.push(new Cons("LINE",
128          Fixnum.getInstance(javaFrame.getLineNumber())));
129    result = result.push(new Cons("NATIVE-METHOD",
130          LispObject.getInstance(javaFrame.isNativeMethod())));
131    return result.nreverse();
132  }
133}
Note: See TracBrowser for help on using the repository browser.