News for hackers. Stuff that matters.
Re:String.intern() by relics443 on Monday May 15, 2017 @08:25PM (#14346432)
"The performance is at the mercy of the native HashTable implementation, which may lag behind what is available in high-performance Java world, especially under concurrent access."

What native HashTable is used? Shouldn't the JVM be using an optimized one?

Re:String.intern() by QuercusMax on Monday May 15, 2017 @09:05PM (#14346626)
I think by "native" they mean "implemented-in-c++-by-the-JVM", which potentially vary; not java.util.HashTable, which should be pretty standard across JVM implementations.
Re:String.intern() by electrum on Tuesday May 16, 2017 @01:05AM (#14347488)
Yes, although Hashtable is legacy from JDK 1.0. New code should use HashMap or ConcurrentHashMap.
Re:String.intern() by Tharkun on Tuesday May 16, 2017 @02:20AM (#14347733)
Please be careful with blanket statements like this. HashMap, Hashtable and ConcurrentHashMap behave differently in certain (subtle?) ways. ConcurrentHashMap doesn't like NULL but is thread-safe. Hashtable is synchronized, slow and thread-safe, but doesn't mind NULL. HashMap is not thread safe and doesn't mind NULL.

Edit: pardon the dupes, on unreliable mobile link :-(

Re:String.intern() by josefx on Tuesday May 16, 2017 @09:04AM (#14349191)
> Hashtable is synchronized, slow and thread-safe, but doesn't mind NULL.

The issue with Hashtable or rather all legacy collection classes is that the API is rarely useful without additional synchronization. So you might as well use a HashMap wrapped by Collections.synchronizedMap or use a ConcurrentHashMap with a placeholder object instead of null.

Re:String.intern() by jakewins on Monday May 15, 2017 @10:10PM (#14346872)
It's using a custom c++ hashtable:

https://github.com/JetBrains/jdk8u_hotspot/blob/master/src/s...

Interestingly, the hash table implementation it's subclassing has changed from `HashTable` to `RehashableHashtable` between JDK7 and JDK8, so I guess there's at least been work to try and improve the performance there.

The hashmap header is here, code lives in the matching cpp file in the same directory:

https://github.com/JetBrains/jdk8u_hotspot/blob/master/src/s...

Re:String.intern() by pjmlp on Tuesday May 16, 2017 @07:02AM (#14348686)
That is an implementation detail, there are many JVMs to choose from.
Re:String.intern() by jakewins on Tuesday May 16, 2017 @07:41AM (#14348811)
Absolutely - that's what the blog post is about, how OpenJDK's particular implementation behaves. When Aleksey is talking about the hashtables not being resizeable, he's talking about the project he works on, which is the code above.
Re:String.intern() by pjmlp on Tuesday May 16, 2017 @07:54AM (#14348857)
I missed that.
Re:String.intern() by pjmlp on Tuesday May 16, 2017 @07:02AM (#14348689)
That is an implementation detail, there are many JVMs implementations to choose from.