RFR: JDK-8319307: DCmds should not assert on truncation and should report truncation

Thomas Stuefe stuefe at openjdk.org
Fri Nov 3 12:23:31 UTC 2023


`bufferedStream` was originally intended to provide intermediate output buffering; the buffer was supposed to drain upon flushing. However, in many cases, `flush()` is a no-op, so the buffer never gets drained.

To prevent infinitely raising buffer sizes for non-flushing `bufferedStream`, [JDK-8220394](https://bugs.openjdk.org/browse/JDK-8220394) introduced the notion of a "maximum reasonable cap". Upon reaching this threshold, we assert in debug VMs since we assumed this to be a condition worth analyzing. In release VMs, we silently truncate.

But DCmds - one of the primary users of `bufferedStream` - can reach the maximum cap under normal conditions; one example would be printing the list of dynamic libraries on Linux (just prints the process memory map) - this can get very large. Similarly, NMT detail reports and VM.info output can get just as large.

Therefore, neither asserting nor silent truncation is optimal. Instead, we should truncate the output, print a visible truncation marker, and - if possible - interrupt the printing.

---

The patch is minimally invasive to simplify review. Like most stream classes, `bufferedStream` would benefit from an overhaul, but I'd like to leave that to a future RFE.

Testing: Tested manually with a number of commands with artificially increased output size. GHAs (Windows test errors unrelated).

-------------

Commit messages:
 - fix mac builds
 - JDK-8319307-DCmds-should-not-assert-on-truncation-and-should-report-truncation

Changes: https://git.openjdk.org/jdk/pull/16474/files
 Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=16474&range=00
  Issue: https://bugs.openjdk.org/browse/JDK-8319307
  Stats: 36 lines in 9 files changed: 20 ins; 6 del; 10 mod
  Patch: https://git.openjdk.org/jdk/pull/16474.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/16474/head:pull/16474

PR: https://git.openjdk.org/jdk/pull/16474


More information about the hotspot-dev mailing list