JDK-4972961 : Use SourceDebugExtension in stack traces
  • Type: Enhancement
  • Component: hotspot
  • Sub-Component: runtime
  • Affected Version: 5.0
  • Priority: P4
  • Status: Closed
  • Resolution: Won't Fix
  • Submitted: 2003-12-26
  • Updated: 2021-12-20
  • Resolved: 2021-12-20
Related Reports
Duplicate :  
Description

Name: tb29552			Date: 12/26/2003


It would be useful if java.lang.Throwable printStackTrace() and fillInStackTrace()
used the extra information provided by SourceDebugExtension [NOTE 1] if that
information is available.

A user writes:

  I'm investigating using SourceDebugExtension for compiling a non-java language,
  Nice: http://nice.sf.net. So far the results are promising, in that jdb reports
  files and line numbers as encoded in the SMAP my compiler generates. So far, so
  good.

  However, if a stack trace is generated, I think the jvm should also try to use
  the info in SourceDebugExtension for the default stratum if available, to report
  the line numbers of the stack locations. I found that it does not. Is there a
  plan to implement this in a future version of the JDK? Should I open a bug
  report in the bug database about this?


[NOTE 1] as implemented in JSR 45 "Debugging Support for Other Languages"
    http://jcp.org/en/jsr/detail?id=45



======================================================================

Comments
The JVMS defines the SDE attribute but not the value of the debug_extension array (it doesn't know about the source map/SMAP). So the VM just skips this attribute, except when the JVM TI capability to read this attribute is enabled, in which case the UTF-8 string is made available to the debugger that is able to parse it. Expanding the scope of the attribute for use with stack traces produced by the VM would likely be a significant exploration effort, I assume pulling on the string would require changes to all APIs that deal with stack traces, e.g. StackWalker.
17-12-2021

This could affect Kotlin users. See JDK-8272568 and additional information and an example there. I compiled the example using the Kotlin/JVM compiler 1.5.20 and apparently the Kotlin compiler does emit the JSR-45 extended debugging information. At least, some very suggestive output is emitted by javap: $ cat a.kt inline fun a() { error("") } $ cat b.kt fun main() { a() } // line 5 // line 6 // line 7 $ /usr/local/kotlinc-1.5.20/kotlinc/bin/kotlinc a.kt b.kt $ javap -v BKt.class ... SourceFile: "b.kt" SourceDebugExtension: SMAP b.kt Kotlin *S Kotlin *F + 1 b.kt BKt + 2 a.kt AKt *L 1#1,8:1 2#2:9 *S KotlinDebug *F + 1 b.kt BKt *L 2#1:9 *E ... Moving to hotspot/runtime to see if the JVM folks are interested in implementing this.
18-08-2021

WORK AROUND Name: tb29552 Date: 12/26/2003 Call java.lang.throwable.getStackTrace() and post-process the results to reflect SourceDebugExtension ======================================================================
22-09-2004

PUBLIC COMMENTS Name: tb29552 Date: 12/26/2003 . ======================================================================
22-09-2004

EVALUATION This would require a VM change; in fact, it's solely a VM change. It is not clear whether it's worth doing. ###@###.### 2004-01-07
07-01-2004