2

I have been reading https://www.alibabacloud.com/blog/the-clever-design-of-java-map_597979 for the internal implementation of the HashMap and CHM.

There is an interesting line for which I could not find more explanation for :

enter image description here

Can someone point me to the bug this refers to?

I could only find the bug related to HashMap improvement with RB-Trees, but nothing about the dead loop.

https://github.com/openjdk/jdk/commit/0fb014c2b3cff00c15e9e7cb6653818d061216e9

https://bugs.openjdk.org/browse/JDK-8023463

Sergey Tsypanov
  • 3,265
  • 3
  • 8
  • 34
ng.newbie
  • 2,807
  • 3
  • 23
  • 57
  • 1
    I think this question was answered here: https://stackoverflow.com/questions/35534906/java-hashmap-getobject-infinite-loop – Sergey Tsypanov Aug 22 '23 at 09:29
  • 2
    Technically it is not really a bug. A `HashMap` is not threadsafe, so trying to use it concurrently without proper external synchronization can exhibit any number of incorrect behaviours. The bug is attempting to use a `HashMap` in that way. – Mark Rotteveel Aug 22 '23 at 09:32
  • @MarkRotteveel What's impressive is that they managed to tackle somewhat of it using the lo high bits. – ng.newbie Aug 22 '23 at 09:38
  • 1
    @MarkRotteveel not only “technically”. There is no bug in `HashMap` and never was (in this context). And the article’s conclusion “that HashMap is not suitable for high concurrency scenarios” is totally wrong. As you already said, `HashMap ` is not suitable for concurrency scenarios at all when not using correct external synchronization. There’s also no evidence that the changes made to `HashMap` were “to fix the bug”. All I can see, are performance optimizations. – Holger Aug 23 '23 at 11:19

1 Answers1

1

Here is the bug in JDK tracker: https://bugs.openjdk.org/browse/JDK-7027300

And the similar question was answered in Java HashMap.get(Object) infinite loop. Here is the link to exact place in the code causing the issue: https://stackoverflow.com/a/44180452/12473843

P.S. This one is for CHM: https://bugs.openjdk.org/browse/JDK-8142175

Sergey Tsypanov
  • 3,265
  • 3
  • 8
  • 34
  • Thanks so much, I am still learning how to navigate the JDK bug tracker – ng.newbie Aug 22 '23 at 09:39
  • 2
    You are welcome. I've found the issue with the following Yandex/Google query: `site:bugs.openjdk.org dead loop HashMap.get`. The very first link brought me there – Sergey Tsypanov Aug 22 '23 at 09:40
  • 1
    To be clear: the first linked bug is about a bug in `SunLayoutEngine` (to use `HashMap` without synchronization, which has been fixed by not using `HashMap` anymore), not a bug in `HashMap`. Whereas the last linked bug is totally unrelated to the topic, it just happens to be about an infinite loop. It’s about a different class, a different operation, and a different kind of wrong usage. In fact, it’s not even about multi-threading. – Holger Aug 23 '23 at 11:24