RFR (S) 8059677: Thread.getName() instantiates Strings
David Holmes
david.holmes at oracle.com
Wed Nov 12 04:48:53 UTC 2014
On 12/11/2014 12:40 AM, Aleksey Shipilev wrote:
> Hi,
>
> On 11/09/2014 09:45 PM, Aleksey Shipilev wrote:
>> Thread.getName() returns String, and does new String instantiation every
>> time, because the thread name is stored in char[]. Even though we use a
>> private String constructor that shares the char[] array without copying
>> it, this still hurts some use cases (think extra-fast logging). To the
>> extent some people actually maintain Map<Thread, String> to avoid it.
>> https://bugs.openjdk.java.net/browse/JDK-8059677
>>
>> Here's the attempt to maintain String instead of char[]:
>> http://cr.openjdk.java.net/~shade/8059677/webrev.01.jdk/
>> http://cr.openjdk.java.net/~shade/8059677/webrev.01.hs/
>
> Updated webrevs:
> http://cr.openjdk.java.net/~shade/8059677/webrev.02.jdk/
> http://cr.openjdk.java.net/~shade/8059677/webrev.02.hs/
>
> This version incorporates feedbacks from Chris, Staffan and David. I
> think it is very close to what we would like to push. Opinions?
All looks good to me.
But I also noticed this strange (to me) assertion in javaClasses.cpp
void java_lang_Thread::set_name(oop java_thread, oop name) {
assert(java_thread->obj_field(_name_offset) == NULL, "name should
be NULL");
java_thread->obj_field_put(_name_offset, name);
}
and on investigation it seems like this is dead code - I couldn't locate
a call to java_lang_Thread::set_name ?? It would only be usable on an
attaching thread (else name can't be null) and we pass the name to the
Thread constructor in that case.
Cheers,
David
> Testing: JPRT, jdk/test/java/lang/Thread jtreg, hotspot/test/runtime/
> jtreg, vm.quick.testlist, nsk.jvmti.testlist, svc.quick.testlist,
> vm.tmtools.testlist
>
> Thanks,
> -Aleksey.
>
>
>
>
More information about the core-libs-dev
mailing list