JDK-6862158 : Make sun.nio.cs.* charset objects light-weight
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.nio.charsets
  • Affected Version: 7
  • Priority: P5
  • Status: Closed
  • Resolution: Won't Fix
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2009-07-20
  • Updated: 2018-02-20
  • Resolved: 2018-02-20
- Make constructor of charset classes to only init their names.
- Mapping data should be lazy initialized by method newXcoder().
- Mapping data should only be hold by appropriate Xcoder class.
- If mapping data is huge, it should not be hold in static fields; instead hold 1 instance each of decoder and encoder by soft reference, themselves holding mapping data by final members, and cheaply instantiate new clones on invocation of newXcoder().

- instead of holding canonical names and aliases of charsets in classMap and aliasMap of sun.nio.cs.FastCharsetProvider, all Charset objects could be instantiated from init() of class StandardCharsets and putted directly into it's cache. Additional instatiation of charset object should not be more expensive than filling up additional pre-hashed map.
- in consequence static alias variables could be saved
- in consequence slow reflective instantiation of charsets by class name could be saved.
- in consequence mapping of canonical names to class names could be saved.
- in consequence Charset.forName() should never wait for lazy instantiation of charsets.
- for ExtendedCharsets caching charsets via soft reference would become superfluous.
- solves Bug Id: 6853699.

SUGGESTED FIX See latest webrev attached from OpenJDK bugzilla.