-
Notifications
You must be signed in to change notification settings - Fork 5.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
8338139: {ClassLoading,Memory}MXBean::isVerbose methods are inconsistent with their setVerbose methods #20628
Conversation
Co-authored-by: David Holmes <david.holmes@oracle.com>
👋 Welcome back stefank! A progress list of the required criteria for merging this PR into |
@stefank This change now passes all automated pre-integration checks. ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details. After integration, the commit message for the final commit will be:
You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed. At the time when this comment was updated there had been 126 new commits pushed to the
As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details. ➡️ To integrate this PR with the above commit message to the |
@stefank The following labels will be automatically applied to this pull request:
When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing lists. If you would like to change these labels, use the /label pull request command. |
Webrevs
|
/contributor add @dholmes-ora |
@stefank |
/label remove core-libs |
@AlanBateman |
* @summary Basic unit test of TestVerboseMemory.set/isVerbose() when | ||
* related unified logging is enabled. | ||
* | ||
* @run main/othervm -Xlog:gc=trace:file=vm.log TestVerboseMemory false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it makes sense to add case where not only 'gc' logging is set from CLI with file output? It would be the exact copy of failed case.
@run main/othervm -Xlog:all=trace:file=vm.log TestVerboseMemory false
(Same for ClassLoading Bean)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that's a good suggestion. I've updated the tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thumbs up.
bool MemoryService::get_verbose() { | ||
for (LogTagSet* ts = LogTagSet::first(); ts != nullptr; ts = ts->next()) { | ||
// set_verbose only sets gc and not gc*, so check for an exact match | ||
const bool is_gc_exact_match = ts->contains(LogTag::_gc) && ts->ntags() == 1; | ||
if (is_gc_exact_match) { | ||
LogLevelType l = ts->level_for(LogConfiguration::StdoutLog); | ||
if (l == LogLevel::Info || l == LogLevel::Debug || l == LogLevel::Trace) { | ||
return true; | ||
} | ||
} | ||
} | ||
|
||
return false; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we have -Xlog:gc
and -Xlog:gc+foo
set I think this version of
MemoryService::get_verbose()
will return false
. Is that really
what we want?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update: Looks like the CSR says that's exactly what we want.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wait. This is not what the implementation does. If you specify -Xlog:gc and -Xlog:gc+init (using a real tag instead of foo), get_verbose
will return true. It only cares about the tag set that is exactly 'gc' and ignores the 'gc+init' tag set.
I'm adding a test line to show that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So in this test case:
-Xlog:gc,gc+init
you have it so that true
is returned.
With this line of code:
const bool is_gc_exact_match = ts->contains(LogTag::_gc) && ts->ntags() == 1;
I would think that this part is false
: ts->ntags() == 1
for the -Xlog:gc,gc+init
test case so we'll be returning false
.
What am I missing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The important part is that ts
contains one single tag set and that gc,gc+init
is a string that specifies the two tag sets gc
and gc+init
. Also, note that -Xlog:gc,gc+init
and -Xlog:gc -Xlog:gc+init
is effectively the same.
It is also important to understand that the for loop iterates over all tag sets that have been used in the HotSpot code. It is not iterating over the tag sets specified by -Xlog lines.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, I get it now. The loop cycles thru the tag set and finds one that is
a singleton and an exact match, i.e., -Xlog:gc
. With -Xlog:gc+init
,
the ts->ntags() == 1
would be false
because that one is not an
exact match.
I misunderstood the algorithm a bit. Sorry for the noise.
* @run main/othervm -Xlog:class+load=trace TestVerboseClassLoading false | ||
* @run main/othervm -Xlog:class+load=debug TestVerboseClassLoading false | ||
* @run main/othervm -Xlog:class+load=info TestVerboseClassLoading false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm... I was expecting these to be true
. What am I missing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update: The CSR makes it clear that it is -Xlog:class+load*
so all have to be set.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is one of those places where we changed the behavior. Previously, 'isVerbose` would return true here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup. We're in agreement here.
* @run main/othervm -Xlog:class+load*=info,class+load+cause=off TestVerboseClassLoading false | ||
*/ | ||
|
||
import java.lang.management.*; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought we tried to avoid wild-card imports.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also tend to avoid wild-card imports, so I've updated the tests. (FWIW, the management package is full of wild-card imports, so it's unclear if we actually do try to avoid it for this part of the source code)
* @run main/othervm -Xlog:gc=off,gc+init=info TestVerboseMemory false | ||
*/ | ||
|
||
import java.lang.management.*; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought we tried to avoid wild-card imports.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought we tried to avoid wild-card imports.
Contrary to common opinion, there is no ban on wild-card imports.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tests looks good.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Thanks for taking this over @stefank !
* @run main/othervm -Xlog:class+load=trace TestVerboseClassLoading false | ||
* @run main/othervm -Xlog:class+load=debug TestVerboseClassLoading false | ||
* @run main/othervm -Xlog:class+load=info TestVerboseClassLoading false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup. We're in agreement here.
bool MemoryService::get_verbose() { | ||
for (LogTagSet* ts = LogTagSet::first(); ts != nullptr; ts = ts->next()) { | ||
// set_verbose only sets gc and not gc*, so check for an exact match | ||
const bool is_gc_exact_match = ts->contains(LogTag::_gc) && ts->ntags() == 1; | ||
if (is_gc_exact_match) { | ||
LogLevelType l = ts->level_for(LogConfiguration::StdoutLog); | ||
if (l == LogLevel::Info || l == LogLevel::Debug || l == LogLevel::Trace) { | ||
return true; | ||
} | ||
} | ||
} | ||
|
||
return false; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So in this test case:
-Xlog:gc,gc+init
you have it so that true
is returned.
With this line of code:
const bool is_gc_exact_match = ts->contains(LogTag::_gc) && ts->ntags() == 1;
I would think that this part is false
: ts->ntags() == 1
for the -Xlog:gc,gc+init
test case so we'll be returning false
.
What am I missing?
Thanks all for reviewing. This passed tier1-7 and my local runs of JCK. |
Going to push as commit 9775d57.
Your commit was automatically rebased without conflicts. |
/backport :jdk23 |
@stefank the backport was successfully created on the branch backport-stefank-9775d571-jdk23 in my personal fork of openjdk/jdk. To create a pull request with this backport targeting openjdk/jdk:jdk23, just click the following link: The title of the pull request is automatically filled in correctly and below you find a suggestion for the pull request body:
If you need to update the source branch of the pull then run the following commands in a local clone of your personal fork of openjdk/jdk:
|
The
ClassLoadingMXBean
andMemoryMXBean
APIs havesetVerbose
methods to control verbose mode andisVerbose
methods to query it. Some JCK tests expectsetVerbose(false)
to disable verbose mode and, subsequently,isVerbose()
to return false. However, if logging to a file is enabled by using -Xlog on the java launcher command line thenisVerbose()
returns true even after callingsetVerbose(false)
.The proposed patch solves this by introducing two changes:
The previous implementation used the
log_is_enabled
functionality to check if logging was enabled for the given tag set. This returns true if logging has been turned on for any output. The patch changes this so thatisVerbose
only checks what has been configured for stdout, which is the output thatsetVerbose
configures.The previous implementation of
setVerbose
turned onclass+load*
(notice the star) but thenisVerbose
only checkedclass+load
(without the star). The patch changes this so that theisVerbose
in-effect checksclass+load*
. (Thegc
part of the patch did not have this problem)The main focus on this patch is to fix the JCK failure, with an implementation that follows the API documentation. While looking at this area of the code it is clear that there are other problems that we might want to addressed in the future, but we're intentionally keeping this patch limited in scope so that it can be backported to JDK 23.
A CSR for this change has been created.
Testing:
The patch is co-authored by me and David Holmes
Progress
Issues
Reviewers
Contributors
<dholmes@openjdk.org>
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/20628/head:pull/20628
$ git checkout pull/20628
Update a local copy of the PR:
$ git checkout pull/20628
$ git pull https://git.openjdk.org/jdk.git pull/20628/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 20628
View PR using the GUI difftool:
$ git pr show -t 20628
Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/20628.diff
Webrev
Link to Webrev Comment