UL question: combining output flags with or at code site?

Stefan Karlsson stefan.karlsson at oracle.com
Thu Apr 23 07:33:20 UTC 2020


Hi Thomas,

On 2020-04-23 06:45, Thomas Stüfe wrote:
> Hi,
> 
> with UL, is there a way at the logging site to specify that a logging has
> to happen if one of the flags is set (so, *or* combined)?
> 
> E.g. if I wanted to print something when either "cds" or "metaspace" is
> active? Without forcing the user to specify an asterix at the -Xlog
> command, because that would activate too many other output sites.
> 
> If I use it like this:
> 
> LogTarget(Info, cds, metaspace) lt;
> 
> both flags must be active to print the output, right?

You can use the type-erasure feature of the LogTargetHandle.

   LogTarget(Info, cds) log_cds;
   LogTarget(Info, metaspace) log_metaspace;

   LogTargetHandle log_handle_cds(log_cds);
   LogTargetHandle log_handle_metaspace(log_metaspace);

   LogTargetHandle log(log_cds.is_enabled() ? log_handle_cds : 
log_handle_metaspace);

   log.print("Either cds or metaspace");

With the above you get:

$ java -Xlog:cds -XX:+UseZGC -version
[0.015s][info][cds] Either cds or metaspace

$ java -Xlog:metaspace -XX:+UseZGC -version
[0.015s][info][metaspace] Either cds or metaspace

$ java -Xlog:metaspace,cds -XX:+UseZGC -version
[0.015s][info][cds] Either cds or metaspace

And nothing if you don't specify either:
$ java -XX:+UseZGC -version

You could also use a third LogTarget/LogTargetHandle to specify the 
combination of cds+metaspace and use that as a combination above.

Maybe there's a way to shrink this down. It would have been nice to be 
able to write:

LogTargetHandle log(log_cds.is_enabled() ? log_cds.handle() : 
log_metaspace.handle());

Or you could create a helper function to hide it:
LogTargetHandle log = cds_or_metaspace_logger();

HTH,
StefanK

> 
> Thanks, Thomas
> 


More information about the hotspot-dev mailing list