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

Yumin Qi minqi at openjdk.java.net
Tue Dec 1 16:50:02 UTC 2020


On Tue, 1 Dec 2020 15:34:54 GMT, Thomas Stuefe <stuefe at openjdk.org> wrote:

>> 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 :)

Thanks, it is using ::vnsprintf in os::vnsprintf, tested on linux, using NULL is OK but Windows counterpart is quite complex --- should avoid using 0 as length. I will be careful to use args and saved_args, they should only be used once --- it could be altered by call to ::vnsprintf. The patch already used it twice, now with David's suggestion, that usage will be eliminated.

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

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


More information about the hotspot-runtime-dev mailing list