JDK-8156079 : make empty instances singletons
  • Type: Sub-task
  • Component: core-libs
  • Sub-Component: java.util:collections
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2016-05-05
  • Updated: 2017-03-28
  • Resolved: 2016-11-05
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 9
9 b144Fixed
Description
Instead of creating multiple instances of List0, Set0, and Map0, they should be singletons. This would save space in the cases where a lot of them are used.

On the other hand, there may be a code size advantage sharing a single field-based implementation for small collections, say with 0, 1, or 2 elements.

Sharing a singleton seems to make sense, but sometimes creating apparently redundant copies improves locality. The tradeoff isn't obvious.
Comments
Memory savings of sharing the same instance seems unlikely to be offset by locality gains. Having a singleton instance also can reduce GC pressure. Review thread: http://mail.openjdk.java.net/pipermail/core-libs-dev/2016-November/044535.html
04-11-2016