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
8268425: Show decimal nid of OSThread instead of hex format one #4449
Conversation
|
@kelthuzadx The following label 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 list. If you would like to change these labels, use the /label pull request command. |
Webrevs
|
/label add hotspot |
@kelthuzadx |
Do you think this would facilitate debugging process? And is it acceptable? Any feedback is appreciated! |
/label add serviceability |
@kelthuzadx |
@@ -38,18 +38,18 @@ OSThread::~OSThread() { | |||
|
|||
// Printing | |||
void OSThread::print_on(outputStream *st) const { | |||
st->print("nid=0x%x ", thread_id()); | |||
st->print("nid=%d ", thread_id()); |
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.
thread_id is of an opaque type (eg pthread_t). I think we can reasonably assume its numeric, but I would print it as an unsigned 64bit int just in case.
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.
Hi Thomas, we can not use other format specifiers (%ld
,%llu
) after my practice, because it can not compile on my mac:
/home/qingfeng.yy/jdktip/src/hotspot/share/runtime/osThread.cpp:41:21: error: format '%llu' expects argument of type 'long long unsigned int', but argument 3 has type 'OSThread::thread_id_t' {aka 'int'} [-Werror=format=]
41 | st->print("nid=%llu ", thread_id());
| ~~~^ ~~~~~~~~~~~
| | |
| | OSThread::thread_id_t {aka int}
| long long unsigned int
| %u
/home/qingfeng.yy/jdktip/src/hotspot/share/runtime/osThread.cpp:41:20: error: format '%ld' expects argument of type 'long int', but argument 3 has type 'OSThread::thread_id_t' {aka 'int'} [-Werror=format=]
41 | st->print("nid=%ld ", thread_id());
| ~~^ ~~~~~~~~~~~
| | |
| long int OSThread::thread_id_t {aka int}
| %d
cc1plus: all warnings being treated as errors
After a quick search, I find many occurrences that using %d
as a format specifier, so it looks ok.
(Conversions looks redundant)
st->print("[%ld] ", (long) Thread::current()->osthread()->thread_id()); |
st->print("[%ld] ", (long) Thread::current()->osthread()->thread_id()); |
tty->print_cr(" Thread = " INTPTR_FORMAT ", thread ID = %d", p2i(thread), thread->osthread()->thread_id()); |
jdk/src/hotspot/share/runtime/safepoint.cpp
Lines 892 to 894 in f45be15
st->print_cr("Thread: " INTPTR_FORMAT | |
" [0x%2x] State: %s _at_poll_safepoint %d", | |
p2i(_thread), _thread->osthread()->thread_id(), s, _at_poll_safepoint); |
jdk/src/hotspot/share/runtime/safepointMechanism.cpp
Lines 102 to 113 in f45be15
uintptr_t SafepointMechanism::compute_poll_word(bool armed, uintptr_t stack_watermark) { | |
if (armed) { | |
log_debug(stackbarrier)("Computed armed for tid %d", Thread::current()->osthread()->thread_id()); | |
return _poll_word_armed_value; | |
} | |
if (stack_watermark == 0) { | |
log_debug(stackbarrier)("Computed disarmed for tid %d", Thread::current()->osthread()->thread_id()); | |
return _poll_word_disarmed_value; | |
} | |
log_debug(stackbarrier)("Computed watermark for tid %d", Thread::current()->osthread()->thread_id()); | |
return stack_watermark; | |
} |
jdk/src/hotspot/share/runtime/stackWatermark.cpp
Lines 114 to 115 in f45be15
log_info(stackbarrier)("Processing whole stack for tid %d", | |
_jt->osthread()->thread_id()); |
jdk/src/hotspot/share/runtime/stackWatermark.cpp
Lines 199 to 200 in f45be15
log_info(stackbarrier)("Starting stack processing for tid %d", | |
_jt->osthread()->thread_id()); |
jdk/src/hotspot/share/runtime/stackWatermark.cpp
Lines 238 to 239 in f45be15
log_info(stackbarrier)("Finished stack processing iteration for tid %d", | |
_jt->osthread()->thread_id()); |
jdk/src/hotspot/share/runtime/thread.cpp
Line 619 in f45be15
st->print(" [id=%d]", osthread()->thread_id()); |
jdk/src/hotspot/share/runtime/thread.cpp
Line 2098 in f45be15
st->print(", id=%d", osthread()->thread_id()); |
jdk/src/hotspot/share/utilities/vmError.cpp
Line 763 in f45be15
st->print_cr("JavaThread " PTR_FORMAT " (nid = %d) was being processed", p2i(jt), jt->osthread()->thread_id()); |
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.
You'd do:
print("nid: " UINT64_FORMAT, (uint64_t) id):;
thread_t is, among other things, pthread_t, which is opaque. Any current code treating that as signed int is incorrect too.
switch (_state) { | ||
case ALLOCATED: st->print("allocated "); break; | ||
case INITIALIZED: st->print("initialized "); break; | ||
case RUNNABLE: st->print("runnable "); break; | ||
case MONITOR_WAIT: st->print("waiting for monitor entry "); break; | ||
case CONDVAR_WAIT: st->print("waiting on condition "); break; | ||
case OBJECT_WAIT: st->print("in Object.wait() "); break; | ||
case BREAKPOINTED: st->print("at breakpoint"); break; |
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.
These cleanups don't seem to have anything to do with this change.
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.
Restored.
Hi, |
Why not do it platform dependent then? This would make sense especially since the type is opaque. Let each platform handling printing. Windows can hex-print its DWORD thread id. Linux can print its kernel LWP. And platforms where the thread id is 64bit, or a structure, can print that. For now default implementations could live in |
Checked Visual Studio, and that goes with decimal for thread IDs. 8-) It's the tools rather than the platform. But yes, hex for thread IDs seems to be in the minority. (I have occasionally found this annoying.) |
Mailing list message from David Holmes on hotspot-dev: On 28/06/2021 6:49 pm, Thomas Stuefe wrote:
If it is opaque then I don't see how signed or unsigned makes any David |
1 similar comment
Mailing list message from David Holmes on hotspot-dev: On 28/06/2021 6:49 pm, Thomas Stuefe wrote:
If it is opaque then I don't see how signed or unsigned makes any David |
My first comments were to say that this makes things better for some people, but a little worse for others. If so (and if we don't discover more tools that prefer hex for thread IDs!), then we want to be consistent, so in addition to the native/built in implementation, we should also update: src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/runtime/JavaThread.java And if changing that, also change: I don't see other tests that parse this information. |
My |
Thanks for the comments! I will change the corresponding SA implementation and tests.
Will it be too heavy to add a platform-dependent implementation for this small function? As Kevin said, maybe this change delights some users and frustrates others. But since POSIX is the vast majority of users, it may be a better choice to adapt to them. Just IMHO.. |
Maybe we can't make everybody happy, but what we have now is a good improvement (for many/most).
I don't think it's a change we should backport, or at least not quickly, out of concern for people/tools who might be parsing this output. |
@@ -38,7 +38,7 @@ OSThread::~OSThread() { | |||
|
|||
// Printing | |||
void OSThread::print_on(outputStream *st) const { | |||
st->print("nid=%d ", thread_id()); |
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.
Just update the (C) year above from 2019 to 2021.
JhsdbThreadInfoTest.java has it already in the latest revision.
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 in both osThread.cpp and test file.
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
out.shouldMatch("\".+\" #\\d+ daemon prio=\\d+ tid=0x[0-9a-f]+ nid=0x[0-9a-f]+ .+ \\[0x[0-9a-f]+]"); | ||
out.shouldMatch("\"main\" #\\d+ prio=\\d+ tid=0x[0-9a-f]+ nid=0x[0-9a-f]+ .+ \\[0x[0-9a-f]+]"); | ||
out.shouldMatch("\".+\" #\\d+ daemon prio=\\d+ tid=0x[0-9a-f]+ nid=[0-9]+ .+ \\[0x[0-9a-f]+]"); | ||
out.shouldMatch("\"main\" #\\d+ prio=\\d+ tid=0x[0-9a-f]+ nid=[0-9]+ .+ \\[0x[0-9a-f]+]"); |
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.
small nit, instead of [0-9]
you could use \d
, and to match a hex number \p{XDigit}
could be used. But since you just follow the existing pattern, I leave it up to you whether you want to change this.
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.
Good catch! \p{XDigit}
seems a standard/better way to match any hexadecimal character than [0-9a-fA-F]+
@kelthuzadx This change now passes all automated pre-integration checks. 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 363 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.
|
@dholmes-ora David, can you please take a look at the latest versions. Thanks! |
@@ -38,7 +38,7 @@ OSThread::~OSThread() { | |||
|
|||
// Printing | |||
void OSThread::print_on(outputStream *st) const { | |||
st->print("nid=0x%x ", thread_id()); | |||
st->print("nid=" UINT64_FORMAT " ", (uint64_t)thread_id()); |
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.
Why are you forcing this to be a 64-bit type?
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.
IMHO, I prefer using %d
since a large portion of existing code using %d
. Thomas suggests using UINT64_FORMAT rather than %d
:
You'd do:
print("nid: " UINT64_FORMAT, (uint64_t) id):;
thread_t is, among other things, pthread_t, which is opaque. Any current code treating that as signed int is incorrect too.
There is no uniform format for the formatted output of thread_id in hotspot. As far as I can see, %ld
%d
and UINTX_FORMAT
are used, so I want to left the decision to reviewers.
/integrate |
Going to push as commit a9e2010.
Your commit was automatically rebased without conflicts. |
@kelthuzadx Pushed as commit a9e2010. |
Mailing list message from David Holmes on hotspot-dev: On 6/07/2021 1:25 pm, Yi Yang wrote:
Okay. This is a mess but that's not your issue. At least a 64-bit If Thomas and Keven are happy with the latest changes then that is fine. Thanks, |
From users' perspective, we can find corresponding os thread via top directly, otherwise, we must convert hex format based nid to an integer, and find that thread via
top -pid <pid>
. This slightly facilitates our debugging process, but would obviously break some existing jstack analysis tool.Jstack Before:
"ParGC Thread#7" os_prio=0 cpu=103260.18ms elapsed=5255043.58s tid=0x00007f967000b000 nid=0x12e67 runnable
"ParGC Thread#8" os_prio=0 cpu=104818.76ms elapsed=5255043.58s tid=0x00007f967000c000 nid=0x12e68 runnable
"ParGC Thread#9" os_prio=0 cpu=102164.69ms elapsed=5255043.58s tid=0x00007f967000e000 nid=0x12e69 runnable
Jstack After:
"G1 Conc#0" os_prio=0 cpu=0.03ms elapsed=1295.27s tid=0x00007f99dc096490 nid=117707 runnable
"G1 Refine#0" os_prio=0 cpu=0.06ms elapsed=1295.22s tid=0x00007f99dc2cad20 nid=117708 runnable
"G1 Service" os_prio=0 cpu=87.05ms elapsed=1295.22s tid=0x00007f99dc2cc140 nid=117709 runnable
Top:
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
49083 tianxia+ 20 0 32.8g 594148 10796 S 103.3 0.1 0:10.05 java
71291 qingfen+ 20 0 39.3g 26.7g 18312 S 100.7 5.3 16861:35 jhsdb
50407 tianxia+ 20 0 32.5g 32796 9768 S 100.3 0.0 0:05.80 java
107429 maolian+ 20 0 11.4g 1.1g 10956 S 100.3 0.2 20173:52 java
99923 root 10 -10 288520 163228 5088 S 5.9 0.0 6463:53 AliYunDun
Progress
Issue
Reviewers
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.java.net/jdk pull/4449/head:pull/4449
$ git checkout pull/4449
Update a local copy of the PR:
$ git checkout pull/4449
$ git pull https://git.openjdk.java.net/jdk pull/4449/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 4449
View PR using the GUI difftool:
$ git pr show -t 4449
Using diff file
Download this PR as a diff file:
https://git.openjdk.java.net/jdk/pull/4449.diff