RFR: 8355636: Speed up Throwable::printStackTrace by reducing object allocation
Shaojin Wen
swen at openjdk.org
Sat Apr 26 04:04:30 UTC 2025
In the Throwable::printStackTrace method, StringBuilder is created multiple times to build String. By sharing StringBuilder to build String, object allocation and copying are reduced.
In the scenario without suppressed and ourCause, unused IdentityHashMap is not created.
Through these optimizations, the performance of `new Exception().printStackTrace()` can be improved by about 10%.
-------------
Commit messages:
- lineBuffer, from @liach
- bug fix
- bug fix
- from @liach
- Update src/java.base/share/classes/java/lang/Throwable.java
- from @liach
- Remove redundant toString
- from @liach
- from @liach
- from @liach
- ... and 2 more: https://git.openjdk.org/jdk/compare/82c24944...a68c6932
Changes: https://git.openjdk.org/jdk/pull/24864/files
Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=24864&range=00
Issue: https://bugs.openjdk.org/browse/JDK-8355636
Stats: 252 lines in 3 files changed: 223 ins; 8 del; 21 mod
Patch: https://git.openjdk.org/jdk/pull/24864.diff
Fetch: git fetch https://git.openjdk.org/jdk.git pull/24864/head:pull/24864
PR: https://git.openjdk.org/jdk/pull/24864
More information about the core-libs-dev
mailing list