JDK-8368816 : Convert jio_snprintf chains to stringStream
  • Type: Enhancement
  • Component: hotspot
  • Sub-Component: runtime
  • Priority: P4
  • Status: New
  • Resolution: Unresolved
  • Submitted: 2025-09-28
  • Updated: 2025-09-28
Related Reports
Blocks :  
Relates :  
Relates :  
Relates :  
Description
As suggested in JDK-8364103, code that builds up strings manually, using a chaing of snprintf-like calls and manually counting the character offsets should be transformed to use stringStream instead. And the reason to do so is that the snprintf-chains a difficult to read and maintain, and are error-prone.

JDK-8364103 addressed the remaining uses of that kind that were using os::snprintf. But there are many more that are using jio_snprintf. Those should be similarly fixed.

The only thing jio_snprintf does differently from os::snprintf and os::snprintf_checked is treat a buffer size > INT_MAX as an error, returning -1 in that case. And NOT ensuring the buffer is null terminated! The idea is that such a value is really an underflow, probably from not properly handling an jio_snprintf-chain. But as suggested here, those shouldn't exist.  Also, stringStream has its own internal notion of what a "reasonable" maximum string size might be. So we shouldn't be losing anything by moving away from jio_snprintf.

As there are a fair number of jio_snprintf chains, scattered across HotSpot, it may be desirable to break the work down into multiple changes.