JDK-8187338 : Per anonymous class class loader data is costly
  • Type: Enhancement
  • Component: hotspot
  • Sub-Component: runtime
  • Affected Version: 10
  • Priority: P3
  • Status: Closed
  • Resolution: Won't Fix
  • Submitted: 2017-09-07
  • Updated: 2019-09-12
  • Resolved: 2019-02-19
Related Reports
Relates :  
Relates :  
Relates :  
Relates :  
Description
Each anonymous class has its own class loader data, and it appears to be VERY costly.

The cost does not show up in overall metaspace statistics, because it does not reflect the reality that the free space held by these class loader data can not be used by others.

One statistics (wildfly https://github.com/wildfly-swarm-openshiftio-boosters/wfswarm-rest-http) shows that 60+% of metadata held by them is wasted.

Link to full log: http://cr.openjdk.java.net/~zgu/cld_metaspace/wildfly.txt

The patch for reporting per-class loader data's metaspace info:
http://cr.openjdk.java.net/~zgu/cld_metaspace/webrev.00/

Given Lambda's growing popularity, I can expect the situation to get worse.





Comments
Runtime Triage: This is not on our current list of priorities. We will consider this feature if we receive additional customer requirements.
19-02-2019

This turns out to be somewhat VERY bad chunk allocation sizing strategy, especially for anonymous metadata space. Several applications I studied, showing average size of anonymous metadata space is just a little over 1K (around ~50% size < 1K, and ~50% size between 1K and 2K, with 98+% sizes < 4K) Wildfly: 1.30K SpecJBB: 1.15K Elasticsearch: 1.06K SwingSet2: 1.32K The chunk allocation sizing strategy for anonymous metadata is, initial size = 1K, then + SmallChunk (4K). So, there is significant waste for metadata spaces with size between 1K - 2K. jdk/internal/reflect/DelegatingClassLoader metadata space size usually around 2K to 4K, so use small chunk as its initial chunk size yields better result. Anonymous and DelegatingClassLoader's average class space sizes are in the similar range, just little over 0.5K, which translates to ~40% waste. I experimented to expand anonymous metadata space by SpecializedChunk (instead of SmallChunk), up to 4, that reduced waste from 60+% to ~30%
03-11-2017

jdk/internal/reflect/DelegatingClassLoader class loader has similar characteristics: ClassLoader: jdk/internal/reflect/DelegatingClassLoader Metadata capacity= 5.00KB used= 1.43KB free= 3.57KB waste= 0.05KB Class data capacity= 1.00KB used= 0.56KB free= 0.44KB waste= 0.00KB ClassLoader: jdk/internal/reflect/DelegatingClassLoader Metadata capacity= 5.00KB used= 1.52KB free= 3.48KB waste= 0.05KB Class data capacity= 1.00KB used= 0.56KB free= 0.44KB waste= 0.00KB
02-11-2017