Bug 223589 - [PATCH] java/openjdk8: support setting thread name in OpenJDK8
Summary: [PATCH] java/openjdk8: support setting thread name in OpenJDK8
Status: Closed FIXED
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: Any Any
: --- Affects Many People
Assignee: Greg Lewis
URL:
Keywords: patch
Depends on:
Blocks:
 
Reported: 2017-11-10 08:35 UTC by nagy.attila
Modified: 2018-03-27 07:11 UTC (History)
4 users (show)

See Also:
bugzilla: maintainer-feedback? (java)


Attachments
openjdk8 thread name patch (1.71 KB, patch)
2017-11-10 08:35 UTC, nagy.attila
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description nagy.attila 2017-11-10 08:35:14 UTC
Created attachment 187902 [details]
openjdk8 thread name patch

The following patch makes OpenJDK8 able to set threads' native name, which is quite useful for debugging which thread uses resources.
Before the patch you can see this in top:
43720 tomcat         20    0 11563M  9233M kqread  7   1:12   0.45% java{java}
43720 tomcat         20    0 11563M  9233M kqread  8   1:17   0.45% java{java}
43720 tomcat         20    0 11563M  9233M kqread  5   1:09   0.44% java{java}
43720 tomcat         20    0 11563M  9233M kqread 15   1:19   0.44% java{java}
43720 tomcat         20    0 11563M  9233M kqread 16   0:58   0.44% java{java}
43720 tomcat         20    0 11563M  9233M kqread  6   1:15   0.44% java{java}
43720 tomcat         20    0 11563M  9233M kqread  3   1:16   0.43% java{java}
43720 tomcat         20    0 11563M  9233M kqread 12   1:15   0.43% java{java}
43720 tomcat         20    0 11563M  9233M kqread 18   1:24   0.40% java{java}
after the patch:
46396 tomcat          21    0  7228M  1004M uwait   3   0:46   7.80% java{C2 CompilerThread1}
46396 tomcat          20    0  7228M  1004M uwait   2   0:49   2.73% java{C2 CompilerThread0}
46396 tomcat          20    0  7228M  1004M uwait   0   0:42   1.83% java{qtp927744186-64}
46396 tomcat          20    0  7228M  1004M select  1   0:03   0.01% java{AMQP Connection 0:0}
46349 tomcat          20    0  7005M   816M kqread  1   0:02   0.00% java{pool-7-thread-1}
46396 tomcat          20    0  7228M  1004M kqread  0   0:09   0.10% java{lettuce-nioEventLoo}

According to thr_set_name(2), the thread's name can be maximum 19 characters (MAXCOMLEN + 1 bytes), we'll give a buffer of that size just to be sure.
The MacOS code prefixes everthing with "Java", but it's totally useless (as can be seen above, just eats valuable space), so use only the name which is given by the caller.
Comment 1 Greg Lewis freebsd_committer freebsd_triage 2018-03-04 17:34:27 UTC
I'd like to push this change back upstream.  Are you able/willing to fill out an Oracle Contributor Agreement?
Comment 2 commit-hook freebsd_committer freebsd_triage 2018-03-04 17:35:33 UTC
A commit references this bug:

Author: glewis
Date: Sun Mar  4 17:35:30 UTC 2018
New revision: 463588
URL: https://svnweb.freebsd.org/changeset/ports/463588

Log:
  . Allow thread names to be set on FreeBSD.

  PR:		223589
  Submitted by:	bra@fsn.hu

Changes:
  head/java/openjdk8/files/patch-hotspot_src_os_bsd_vm_os__bsd.cpp
Comment 3 Greg Lewis freebsd_committer freebsd_triage 2018-03-04 17:36:18 UTC
I've committed a variant of this.  Please let me know if it works for you.
Comment 4 Steve Wills freebsd_committer freebsd_triage 2018-03-21 17:10:15 UTC
(In reply to Greg Lewis from comment #3)
Thanks for committing this, I happened to test it and it seems to be working and is really useful. I did notice the thread name seems to be limited to 19 characters, which seems both odd and too short to fit all the threads that I'm seeing in my java processes. Is there a way to increase that limit or is that some system limit?
Comment 5 Michael Osipov 2018-03-21 18:53:29 UTC
(In reply to Steve Wills from comment #4)
This is defined in https://github.com/freebsd/freebsd/blob/ef58aa56fe105ceb708d376ff01798fc3162de88/sys/sys/param.h#L107. Seems like it is used in other places as well. At most increased in CURRENT?
Comment 6 Steve Wills freebsd_committer freebsd_triage 2018-03-22 17:27:32 UTC
(In reply to Michael Osipov from comment #5)
I see, thanks for the pointer.
Comment 7 Ronald Klop 2018-03-24 09:06:03 UTC
(In reply to Steve Wills from comment #6)
Maybe already known to you, but there are java specific tool like jstack which can give you the full names. Just saying.

Regards,
Ronald.
Comment 8 Greg Lewis freebsd_committer freebsd_triage 2018-03-27 07:11:12 UTC
Limitations on thread names appear to be OS limitations, so I'm closing this.