Throwable stack trace printing again
Mark Wielaard
mark@klomp.org
Fri Jul 26 14:34:00 GMT 2002
Hi,
I rewrote Throwable stack trace (printing) support. With this patch the
Junk example mentioned in the Throwable javadoc gives (when compiled
with -g):
HighLevelException: MidLevelException: LowLevelException
at Junk.a() (/tmp/Junk.java:21)
at Junk.main(java.lang.String[]) (/tmp/Junk.java:7)
Caused by: MidLevelException: LowLevelException
at Junk.c() (/tmp/Junk.java:36)
at Junk.b() (/tmp/Junk.java:29)
at Junk.a() (/tmp/Junk.java:19)
...1 more
Caused by: LowLevelException
at Junk.e() (/tmp/Junk.java:46)
at Junk.d() (/tmp/Junk.java:44)
at Junk.c() (/tmp/Junk.java:34)
...3 more
The patch tries to accomplish a couple of things:
- Simplify and optimize the stack trace printing algorithm which is done
by refactoring the code and using a StringBuffer. This also solves the
bug I mentioned a couple of days ago which was caused by forgetting to
flush the PrintWriter. Now no temporary PrintWriter is created at all.
- Separating the VM dependent part from the VM independent part by
moving fillInStackTrace() and getStackTrace() into a new package final
class VMThrowable. This should make Throwable easier to share with other
VMs based on GNU Classpath.
- Do as much as possible in java which makes manipulating the
StackTraceElement[] that much easier. I followed the advise of Bryce and
store the raw stack trace as an long[] so only two short native methods
are needed. The resulting stack traces look much more like traditional
java stack traces now.
2002-07-26 Mark Wielaard <mark@klomp.org>
* Makefile.am (libgcj_la_SOURCES): Remove name-finder.cc.
(core_java_source_files): Add VMThrowable.java and NameFinder.java
(nat_source_files): Add natNameFinder.cc.
* Makefile.in: Regenerate.
* prims.cc: Use trace_enabled from VMThrowable.
* name-finder.cc: Removed.
* gcj/javaprims.h: Add class VMThrowable.
* gnu/gcj/runtime/NameFinder.java: New file.
* gnu/gcj/runtime/natNameFinder.cc: Likewise.
* include/name-finder.h: Removed.
* java/lang/Throwable.java (printStackTrace (PrintStream)): Use new
method stackTraceString().
(printStackTrace (PrintWriter)): Likewise.
(stackTraceString): Complete rewrite of old printStackTrace using
StringBuffer.
(stackTraceStringBuffer): New helper method for stackTraceString().
(fillInStackTrace): Delegate to VMTrowable.
(getStackTrace): Likewise.
(getStackTrace0): Removed.
(trace_enabled, stackTraceBytes): Moved to new VMThrowable.java.
* java/lang/VMThrowable.java: New class.
* java/lang/natThrowable.cc (fillInStackTrace): Now part of
VMThrowable. Put the result of backtrace() in a long[].
(getStackTrace0): Removed.
Questions:
- Is the separation of Throwable and VMThrowable OK? I had hoped that
gcj would inline calls to a final package local class but it currently
doesn't.
- Is the conversion to/from void*/jlong correct? It works on my
i686-pc-linux-gnu and I will try it out on a powerpc-unknown-linux-gnu
machine soon, but my C knowledge is not good enough to know if this will
always work on any architecture.
- Is doing most things in java a good idea? I personally think nicer
stack traces are much more important than having working stack traces
when the runtime breaks down. And you probably have much bigger problems
then having a working printStackTrace(). But I guess not everybody loves
using gdb ;)
- OK to commit?
Cheers,
Mark
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Throwable.diff
Type: text/x-patch
Size: 40385 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/java-patches/attachments/20020726/7e14d0d3/attachment.bin>
More information about the Java-patches
mailing list