RFR: JDK-8152690: main thread does not have native thread name
Yasumasa Suenaga
yasuenag at gmail.com
Wed Mar 30 13:47:35 UTC 2016
Hi,
I uploaded new webrev.
Could you review it?
http://cr.openjdk.java.net/~ysuenaga/JDK-8152690/webrev.01/
Thanks,
Yasumasa
On 2016/03/30 19:10, Robbin Ehn wrote:
> Hi,
>
> On 03/30/2016 11:41 AM, Yasumasa Suenaga wrote:
>> Hi Robbin,
>>
>> 2016/03/30 18:22 "Robbin Ehn" <robbin.ehn at oracle.com
>> <mailto:robbin.ehn at oracle.com>>:
>> >
>> > Hi Yasumasa,
>> >
>> >
>> > On 03/25/2016 12:48 AM, Yasumasa Suenaga wrote:
>> >>
>> >> Hi Robbin,
>> >> 2016/03/25 1:51 "Robbin Ehn" <robbin.ehn at oracle.com
>> <mailto:robbin.ehn at oracle.com>
>> >> <mailto:robbin.ehn at oracle.com <mailto:robbin.ehn at oracle.com>>>:
>> >>
>> >> >
>> >> > Hi Yasumasa,
>> >> >
>> >> > I'm not sure why you don't set it:
>> >> >
>> >> > diff -r ded6ef79c770 src/share/vm/runtime/thread.cpp
>> >> > --- a/src/share/vm/runtime/thread.cpp Thu Mar 24 13:09:16 2016
>> +0000
>> >> > +++ b/src/share/vm/runtime/thread.cpp Thu Mar 24 17:40:09 2016
>> +0100
>> >> > @@ -3584,6 +3584,7 @@
>> >> > JavaThread* main_thread = new JavaThread();
>> >> > main_thread->set_thread_state(_thread_in_vm);
>> >> > main_thread->initialize_thread_current();
>> >> > + main_thread->set_native_thread_name("main");
>> >> > // must do this before set_active_handles
>> >> > main_thread->record_stack_base_and_size();
>> >> > main_thread->set_active_handles(JNIHandleBlock::allocate_block());
>> >> >
>> >> > here instead? Am I missing something?
>> >>
>> >> Native thread name is the same to thread name in Thread class.
>> >> It is set in c'tor in Thread or setName().
>> >> If you create new thread in Java app, native thread name will be set at
>> >> startup. However, main thread is already starte in VM.
>> >> Thread name for "main" is set in create_initial_thread().
>> >> I think that the place of setting thrrad name should be the same.
>> >
>> >
>> > Yes, I see your point. But then something like this is nicer, no?
>> >
>> > --- a/src/share/vm/runtime/thread.cpp Tue Mar 29 09:43:05 2016 +0200
>> > +++ b/src/share/vm/runtime/thread.cpp Wed Mar 30 10:51:12 2016 +0200
>> > @@ -981,6 +981,7 @@
>> > // Creates the initial Thread
>> > static oop create_initial_thread(Handle thread_group, JavaThread*
>> thread,
>> > TRAPS) {
>> > + static const char* initial_thread_name = "main";
>> > Klass* k =
>> SystemDictionary::resolve_or_fail(vmSymbols::java_lang_Thread(), true,
>> CHECK_NULL);
>> > instanceKlassHandle klass (THREAD, k);
>> > instanceHandle thread_oop =
>> klass->allocate_instance_handle(CHECK_NULL);
>> > @@ -988,8 +989,10 @@
>> > java_lang_Thread::set_thread(thread_oop(), thread);
>> > java_lang_Thread::set_priority(thread_oop(), NormPriority);
>> > thread->set_threadObj(thread_oop());
>> > -
>> > - Handle string = java_lang_String::create_from_str("main", CHECK_NULL);
>> > +
>> > + thread->set_native_thread_name(initial_thread_name);
>> > +
>> > + Handle string =
>> java_lang_String::create_from_str(initial_thread_name, CHECK_NULL);
>> >
>> > JavaValue result(T_VOID);
>> > JavaCalls::call_special(&result, thread_oop,
>>
>> Okay, I will upload new webrev later.
>
> Thanks!
>
>>
>> >> > The launcher seem to name itself 'java' and naming this thread just
>> >> > 'main' is confusing to me.
>> >> >
>> >> > E.g. so main thread of the process (and thus the process) is
>> 'java' but
>> >> > first JavaThread is 'main'.
>> >>
>> >> The native main thread in the process is not JavaThread. It is waiting
>> >> for ending of Java main thread with pthread_join().
>> >> set_native_thread_name() is for JavaThread. So I think that we do not
>> >> need to call it for native main thread.
>> >
>> >
>> > Not sure if we can change it anyhow, since we want java and native
>> name to be the same and java thread name might have some dependents.
>> >
>> > The name is visible in e.g. /proc.
>> >
>> > $ ps H -C java -o 'pid tid comm' | head -4
>> > PID TID COMMAND
>> > 6423 6423 java
>> > 6423 6424 main
>> > 6423 6425 GC Thread#0
>> >
>> > It would be nice with something like 'Java Main Thread'.
>>
>> I do not think so.
>> Native main thread might not be a Java launcher - e.g. Apache
>> commons-daemon, JNI application, etc.
>>
>> If you want to change native main thread name, I think that we have to
>> change Java launcher code.
>> Should I include it in new webrev?
>
> No
>
> Thanks again!
>
> /Robbin
>
>>
>> Thanks,
>>
>> Yasumasa
>>
>> > Thanks
>> >
>> > /Robbin
>> >
>> >
>> >>
>> >> Thanks,
>> >>
>> >> Yasumasa
>> >>
>> >> > Thanks!
>> >> >
>> >> > /Robbin
>> >> >
>> >> > On 03/24/2016 03:26 PM, Yasumasa Suenaga wrote:
>> >> > > Hi all,
>> >> > >
>> >> > > HotSpot for Linux will set thread name via pthread_setname_np().
>> >> > > However, main thread does not have it.
>> >> > >
>> >> > > All JavaThread have native name, and main thread is JavaThread.
>> >> > > For consistency, main thread should have native thread name.
>> >> > >
>> >> > > I uploaded a webrev. Could you review it?
>> >> > >
>> >> > > http://cr.openjdk.java.net/~ysuenaga/JDK-8152690/webrev.00/
>> >> > >
>> >> > > I cannot access JPRT.
>> >> > > So I need a sponsor.
>> >> > >
>> >> > >
>> >> > > Thanks,
>> >> > >
>> >> > > Yasumasa
>> >> > >
>> >>
>>
More information about the hotspot-runtime-dev
mailing list