@@ -477,33 +477,40 @@ internal object DebugProbesImpl {
477
477
478
478
/*
479
479
* Trim intervals of internal methods from the stacktrace (bounds are excluded from trimming)
480
- * E.g. for sequence [e, i1, i2, i3, e, i4, e, i5, i6, e7 ]
480
+ * E.g. for sequence [e, i1, i2, i3, e, i4, e, i5, i6, i7 ]
481
481
* output will be [e, i1, i3, e, i4, e, i5, i7]
482
+ *
483
+ * If an interval of internal methods ends in a synthetic method, the last non-synthetic method in that interval
484
+ * will also be included.
482
485
*/
483
486
val result = ArrayList <StackTraceElement >(size - probeIndex + 1 )
484
487
result + = createArtificialFrame(ARTIFICIAL_FRAME_MESSAGE )
485
- var includeInternalFrame = true
486
- for (i in (probeIndex + 1 ) until size - 1 ) {
487
- val element = stackTrace[i]
488
- if (! element.isInternalMethod) {
489
- includeInternalFrame = true
490
- result + = element
491
- continue
492
- }
493
-
494
- if (includeInternalFrame) {
495
- result + = element
496
- includeInternalFrame = false
497
- } else if (stackTrace[i + 1 ].isInternalMethod) {
498
- continue
488
+ var i = probeIndex + 1
489
+ while (i < size) {
490
+ if (stackTrace[i].isInternalMethod) {
491
+ result + = stackTrace[i] // we include the boundary of the span in any case
492
+ // first index past the end of the span of internal methods that starts from `i`
493
+ var j = i + 1
494
+ while (j < size && stackTrace[j].isInternalMethod) {
495
+ j + = 1
496
+ }
497
+ // index of the last non-synthetic internal methods in this span, or `i` if there are no such methods
498
+ var k = j - 1
499
+ while (k > i && stackTrace[k].fileName == null ) {
500
+ k - = 1
501
+ }
502
+ if (k > i && k < j - 1 ) {
503
+ /* there are synthetic internal methods at the end of this span, but there is a non-synthetic method
504
+ ofter `i`, so we include it. */
505
+ result + = stackTrace[k]
506
+ }
507
+ result + = stackTrace[j - 1 ] // we include the other boundary of this span in any case, too
508
+ i = j
499
509
} else {
500
- result + = element
501
- includeInternalFrame = true
510
+ result + = stackTrace[i]
511
+ i + = 1
502
512
}
503
-
504
513
}
505
-
506
- result + = stackTrace[size - 1 ]
507
514
return result
508
515
}
509
516
0 commit comments