UL question: combining output flags with or at code site?
Robbin Ehn
robbin.ehn at oracle.com
Mon Apr 27 11:44:05 UTC 2020
On 2020-04-23 12:21, Thomas Stüfe wrote:
> Thank you, Stefan. For the moment a helper function may be the simplest
> solution.
>
> Maybe long-term we could have a LogTarget variant OR-combining the flags
> instead of AND-ing them...
>
> Sometimes I think I would have prepared ORing the flags by default, I would
> have found that less surprising and easier to use (e.g. if I find a
> particular "gc" log output useful, I could have added a "metaspace" tag and
> thus selected it for -Xlog=metaspace too. As it is now, this would just
> effectively mute the output by requiring both flags to be set).
>
> Alas, it is now what it is, and its a matter of taste anyway...
I agree that we should change something, as it is now I always add
asterisk. E.g. -Xlog:thread gives nothing with -version, but you most
likely wanted the os+thread output.
/Robbin
>
> Thanks, Thomas
>
>
>
> On Thu, Apr 23, 2020 at 9:33 AM Stefan Karlsson <stefan.karlsson at oracle.com>
> wrote:
>
>> 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