Details
-
Enhancement
-
Resolution: Fixed
-
P4
-
7-pool
-
b86
-
generic
-
generic
-
Verified
Backports
Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-8025623 | 7u80 | Dmeetry Degrave | P4 | Resolved | Fixed | b01 |
JDK-8060967 | 7u79 | Dmeetry Degrave | P4 | Resolved | Fixed | b01 |
JDK-8057438 | 7u76 | Dmeetry Degrave | P4 | Resolved | Fixed | b01 |
JDK-8047614 | 7u72 | Dmeetry Degrave | P4 | Resolved | Fixed | b01 |
JDK-8040861 | 7u71 | Dmeetry Degrave | P4 | Resolved | Fixed | b01 |
JDK-8058442 | 7u67 | Dmeetry Degrave | P4 | Resolved | Fixed | b31 |
JDK-8040341 | 7u66 | Dmeetry Degrave | P4 | Resolved | Fixed | b01 |
JDK-8044573 | 7u60 | Dmeetry Degrave | P4 | Resolved | Fixed | b33 |
JDK-8025622 | 6u81 | Dmeetry Degrave | P4 | Resolved | Fixed | b01 |
JDK-8024980 | 5.0u61 | Dmeetry Degrave | P4 | Closed | Fixed | b01 |
Description
Object histogram for top memory consumers
#instances Shallow size Impl-inclusive size Class name
---------------------------------------------------------------
.............
84,223 11,843K (1.0%) 11,843K (1.0%) java.lang.reflect.Method
31,900 3,738K (0.3%) 3,738K (0.3%) java.lang.reflect.Field
29,987 3,279K (0.3%) 3,279K (0.3%) java.lang.reflect.Constructor
47,526 1,485K (0.1%) 1,485K (0.1%) sun.reflect.annotation.AnnotationInvocationHandler
.............
These classes store information about annotations for the corresponding members in LinkedHashMaps. There are typically just a few annotations for a given member. However, for a LinkedHashMap the default size of the 'buckets' array is 16, and it looks like these maps are allocated with the default size in the relevant JDK code. As a result, a noticeable amount of memory gets wasted due to the null pointers in 'bucket' arrays of LinkedHashMaps. Here is what JOverflow reports:
sun.reflect.annotation.AnnotationInvocationHandler.memberValues -->
10,438K (0.9%): LinkedHashMap: 31207 of SMALL 7,615K (0.6%), 46052 of SPARSE_SMALL 2,342K (0.2%), 1084 of BOXED 255K (0.0%), 1440 of EMPTY 225K (0.0%)
java.lang.reflect.Field.declaredAnnotations -->
4,300K (0.4%): LinkedHashMap: 17380 of SMALL 3,296K (0.3%), 17380 of SPARSE_SMALL 1,003K (0.1%)
java.lang.reflect.Method.declaredAnnotations -->
2,031K (0.2%): LinkedHashMap: 6791 of SMALL 1,605K (0.1%), 8191 of SPARSE_SMALL 426K (0.0%)
The amount of memory being wasted under SPARSE_SMALL category (which means that less than half of the default 16 slots are used in the map) can be very easily reduced if the respective LinkedHashMaps are allocated with non-default initial size of say 4.
Even more memory (see the SMALL category, which means that the respective map contains 4 elements or fewer) can be saved if LinkedHashMaps are replaced with small ArrayLists or just arrays. Since in most cases the number of annotations is small, simple sequential lookup in lists will likely result in no noticeable performance difference compared to hash map lookup.
Attachments
Issue Links
- backported by
-
JDK-8025622 (ann) Optimize Annotation handling in java/sun.reflect.* code for small number of annotationsC
- Resolved
-
JDK-8025623 (ann) Optimize Annotation handling in java/sun.reflect.* code for small number of annotationsC
- Resolved
-
JDK-8040341 (ann) Optimize Annotation handling in java/sun.reflect.* code for small number of annotationsC
- Resolved
-
JDK-8040861 (ann) Optimize Annotation handling in java/sun.reflect.* code for small number of annotationsC
- Resolved
-
JDK-8044573 (ann) Optimize Annotation handling in java/sun.reflect.* code for small number of annotationsC
- Resolved
-
JDK-8047614 (ann) Optimize Annotation handling in java/sun.reflect.* code for small number of annotationsC
- Resolved
-
JDK-8057438 (ann) Optimize Annotation handling in java/sun.reflect.* code for small number of annotationsC
- Resolved
-
JDK-8058442 (ann) Optimize Annotation handling in java/sun.reflect.* code for small number of annotationsC
- Resolved
-
JDK-8060967 (ann) Optimize Annotation handling in java/sun.reflect.* code for small number of annotationsC
- Resolved
-
JDK-8024980 (ann) Optimize Annotation handling in java/sun.reflect.* code for small number of annotationsC
- Closed