RFR: 8349083: Factor out filename handling code from logging

David Holmes dholmes at openjdk.org
Wed Feb 12 06:29:09 UTC 2025


On Sat, 1 Feb 2025 16:53:13 GMT, Zhengyu Gu <zgu at openjdk.org> wrote:

> Factor out filename substitution code from unified logging, so that it can be used elsewhere:
> 
> 1. Make filename substitution consistent.  Support following substitutions cross JVM
> ```   
>    %p -> pid
>    %t -> timestamp
>    %hn -> hostname
> 
> 
> 2. Reduce redundant code

I'm not sure how best to handle the "%t". My view was that we would standardize "%t" to mean the timestamp of when the VM started, but I guess if there are pre-existing uses of "%t" that mean something different then that would be a problem. Note that share/utilities/ostream.cpp also has similar logic for creating log file names with %p and %t.

My concern is your current code re-stringifies the timestamp on every call, whereas the logging code only created the vm_startup_time_str once.  When the timestamp is being passed in, memoizing it is problematic - whereas if you know it is the VM startup time it is no problem at all. The strings for %p and %hn should also be memoized, though logging does not currently do that.

It might be clearer to take a timestamp-string rather than the timestamp and then have utility methods to get `vm_startup_time_str()` and `current_time_str()`, where the former at least can cache the string for future use. The same could be done for `host_name_str()` and `pid_str()`. The caching for idempotent strings doesn't need to use locking, just a `release_store` with a paired `load_acquire`.

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

PR Review: https://git.openjdk.org/jdk/pull/23410#pullrequestreview-2610936532


More information about the hotspot-dev mailing list