Request for review (S): JDK-8011009: Use do-while(0) instead of while(0) in EC_TRACE and RC_TRACE* macros
John Rose
john.r.rose at oracle.com
Thu Mar 28 16:55:27 PDT 2013
On Mar 28, 2013, at 4:22 PM, Krystal Mo <krystal.mo at oracle.com> wrote:
> I'd say it has to do with the way ResourceMark works.
This is a common feature with all sorts of conditional coprocessing facilities. The pattern is:
x = some_value;
if (logging_is_enabled) {
x' = derive_interesting_details_for_logging(x);
print_to_logger(x');
}
One would like to capture it in a subroutine:
x = some_value;
maybe_log(derive_interesting_details_for_logging(x));
But this transfers the expense of digging out the "details" (or the formatted detail string) outside of the guard, adding an expense even when the logging is disabled.
Assertions can also be thought of as a sort of conditional processing. Java works around the expense of computing assertion parameters by making the whole thing a special language feature under a keyword.
In JDK 8 with lambdas, there will be new options for conditional execution of expressions:
x = some_value;
maybe_log(()->derive_interesting_details_for_logging(x));
In C, we get to use macros for this sort of thing.
— John
More information about the hotspot-dev
mailing list