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.
I'd like to push this change back upstream. Are you able/willing to fill out an Oracle Contributor Agreement?
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
I've committed a variant of this. Please let me know if it works for you.
(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?
(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?
(In reply to Michael Osipov from comment #5) I see, thanks for the pointer.
(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.
Limitations on thread names appear to be OS limitations, so I'm closing this.