Skip to content

Preserve thread name after attaching it to JVM#838

Merged
bradh352 merged 3 commits intoc-ares:mainfrom
Hsilgos:khnykin/preserve_android_name
Aug 1, 2024
Merged

Preserve thread name after attaching it to JVM#838
bradh352 merged 3 commits intoc-ares:mainfrom
Hsilgos:khnykin/preserve_android_name

Conversation

@Hsilgos
Copy link
Contributor

@Hsilgos Hsilgos commented Jul 29, 2024

When native thread is attached to JVM, then it's name is taken from JavaVMAttachArgs. When no JavaVMAttachArgs, or no JavaVMAttachArgs::name passed, then JVM on its own decides on taming thread. Those names are not descriptive. To preserve thread name, pass the currently set thread name in JavaVMAttachArgs::name. pthread_getname_np was introduced in API 26, hence use more generic approach.

Fixes: #837

When native thread is attached to JVM, then it's name is taken from JavaVMAttachArgs.
When no JavaVMAttachArgs, or no JavaVMAttachArgs::name passed,
then JVM on its own decides on taming thread. Those names are not descriptive.
To preserve thread name, pass the currently set thread name in JavaVMAttachArgs::name.
pthread_getname_np was introduced in API 26, hence use more generic approach.

Signed-off-by: Yauheni Khnykin <yauheni.khnykin@here.com>
@bradh352
Copy link
Member

also, not sure if you'd be interested in maybe helping out with creating a github action for building the Android library. Currently our CI system isn't building android to validate PRs like this. :)

@Hsilgos
Copy link
Contributor Author

Hsilgos commented Jul 29, 2024

also, not sure if you'd be interested in maybe helping out with creating a github action for building the Android library. Currently our CI system isn't building android to validate PRs like this. :)

I may have a look at weekend

@Hsilgos Hsilgos requested a review from bradh352 July 30, 2024 15:51
@Hsilgos Hsilgos requested a review from bradh352 July 31, 2024 09:49
@bradh352
Copy link
Member

looks good to me. If you think you can add a GitHub Action to do a test build for android, I'll wait on that and accept it as one PR ...

@bradh352
Copy link
Member

bradh352 commented Aug 1, 2024

I ended up adding a GitHub action, so I'll go ahead and merge this. Thanks!

@bradh352 bradh352 merged commit 9377126 into c-ares:main Aug 1, 2024
bradh352 pushed a commit that referenced this pull request Aug 2, 2024
When native thread is attached to JVM, then it's name is taken from
JavaVMAttachArgs. When no JavaVMAttachArgs, or no JavaVMAttachArgs::name
passed, then JVM on its own decides on taming thread. Those names are
not descriptive. To preserve thread name, pass the currently set thread
name in JavaVMAttachArgs::name. pthread_getname_np was introduced in API
26, hence use more generic approach.

Fixes #837
Authored By: Yauheni Khnykin (@Hsilgos)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AttachCurrentThread spoils current thread mame

2 participants