RFR: 8256256: UL should not use heap allocation for output string [v4]

Thomas Stuefe stuefe at openjdk.java.net
Tue Dec 1 15:39:00 UTC 2020


On Tue, 1 Dec 2020 06:22:55 GMT, David Holmes <dholmes at openjdk.org> wrote:

>> line 124:  When buf is small, buf is filled with whatever truncated string with format to get the length needed for new buffer, it does not include prefix. The new version keeps prefix and the buf ends with "..(truncated), native OOM" even if prefix already overflows buf.
>
> Ah I missed that.  But do we need to do that? If we introduce:
> `char buf2[1];`
> at line 123 and use that to determine the necessary additional length, then we don't need to re-start the whole process from scratch.

I agree, that would be easier:
- at line 124, print into a dummy buffer of len 1. That gives you the length of the expanded string, but leaves the (truncated) prefix in buf intact. According to C99 a one should even be able to use a `NULL, 0` for the buffer but I am not sure where we are with os::vnsprintf.
- Then, at line 140ff, buf contains either just the truncated prefix (line 124) or the truncated prefix + message (122). You then just stamp your truncated message over it. 

Only, make sure (maybe static assert) that the truncation text is smaller than the buffer :)

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

PR: https://git.openjdk.java.net/jdk/pull/1246


More information about the hotspot-runtime-dev mailing list