RFR (S) 8059677: Thread.getName() instantiates Strings

Aleksey Shipilev aleksey.shipilev at oracle.com
Sun Nov 9 18:45:35 UTC 2014


Hi,

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/

JDK changes are trivial, but HS changes require some rewiring, since VM
treats Thread.name specially. However, it turns out we can make a
contained change, since the getter is used sparingly, and setter seems
to be not used at all. Any trouble with this change?

Testing: JPRT, manual tests, jdk/test/java/lang/Thread jtreg,
hotspot/test/runtime/ jtreg, vm.quick.testlist, nsk.jvmti.testlist,
svc.quick.testlist

Thanks,
-Aleksey.




More information about the core-libs-dev mailing list