RFR (S) CR 8016236: Class.getGenericInterfaces performance improvement (original) (raw)

Peter Levart peter.levart at gmail.com
Mon Jun 10 20:57:49 UTC 2013


Hi Aleksey,

When 'sun.reflect.noCaches=true' system property is defined, reflectionData() returns null. In that case, the code should cope without using ReflectionData (no caching). See other uses of reflectionData() (for example: in privateGetDeclaredFields())...

I should note that ReflectionData is invalidated when the class is redefined. I don't know if generic signature is one of those things that can change with class redefinition, but invalidation is just one purpose of ReflectionData and the other is caching (via SoftReference), so generic signature can be added to it for that purpose. If 'genericSignature' is cached on ReflectionData then it would be consistent to also cache the derived 'genericInfo', what do you think?

I don't think 3 fields are needed (genericSignatureResolved, genericSignature & genericInfo). I think one boolean flag (say : genericInfoPresent) and genericInfo is all that is needed. If there was a singleton ClassRepository NONE instance, then event the boolean flag wouldn't be needed.

Regards, Peter

On 06/10/2013 05:53 PM, Aleksey Shipilev wrote:

Hi,

This is the follow-up on the issue Doug identified: http://mail.openjdk.java.net/pipermail/core-libs-dev/2013-June/017798.html I had reworked the patch, webrev is here: http://cr.openjdk.java.net/~shade/8016236/webrev.01/ Notable differences from Doug's version are: - handle non-generic cases as well - reuse ReflectionData to cache the interfaces and generic signatures - code style (chained ternary operators blown up) - fixes the race along the way http://bugs.sun.com/bugdatabase/viewbug.do?bugid=6398355 Testing: - Linux x8664/release: build OK - Linux x8664/release: java/lang/reflect regression tests OK - Microbenchmarks show whooping increase in performance, see below (If there are no stylistic and other comments, I would like to do the JPRT submit and/or additional testing [which?]). The benchmark is here (you need JMH to build and run): http://cr.openjdk.java.net/~shade/8016236/classbench.zip Before: Benchmark Mode Thr Cnt Sec Mean Mean error Units o.b.ClassBench.genericgetGenericInterfaces avgt 1 5 1 326.835 1.220 nsec/op o.b.ClassBench.genericgetGenericSuperclass avgt 1 5 1 308.793 2.828 nsec/op o.b.ClassBench.genericgetTypeParameters avgt 1 5 1 312.627 1.637 nsec/op o.b.ClassBench.rawgetGenericInterfaces avgt 1 5 1 216.983 8.902 nsec/op o.b.ClassBench.rawgetGenericSuperclass avgt 1 5 1 59.933 0.183 nsec/op o.b.ClassBench.rawgetTypeParameters avgt 1 5 1 65.469 0.284 nsec/op Doug's version: Benchmark Mode Thr Cnt Sec Mean Mean error Units o.b.ClassBench.genericgetGenericInterfaces avgt 1 5 1 15.106 0.271 nsec/op o.b.ClassBench.genericgetGenericSuperclass avgt 1 5 1 5.304 0.024 nsec/op o.b.ClassBench.genericgetTypeParameters avgt 1 5 1 16.739 0.045 nsec/op o.b.ClassBench.rawgetGenericInterfaces avgt 1 5 1 213.825 1.346 nsec/op o.b.ClassBench.rawgetGenericSuperclass avgt 1 5 1 61.651 0.394 nsec/op o.b.ClassBench.rawgetTypeParameters avgt 1 5 1 64.340 0.522 nsec/op After: Benchmark Mode Thr Cnt Sec Mean Mean error Units o.b.ClassBench.genericgetGenericInterfaces avgt 1 5 1 14.985 0.104 nsec/op o.b.ClassBench.genericgetGenericSuperclass avgt 1 5 1 5.300 0.008 nsec/op o.b.ClassBench.genericgetTypeParameters avgt 1 5 1 16.874 0.175 nsec/op o.b.ClassBench.rawgetGenericInterfaces avgt 1 5 1 23.941 0.177 nsec/op o.b.ClassBench.rawgetGenericSuperclass avgt 1 5 1 8.583 0.044 nsec/op o.b.ClassBench.rawgetTypeParameters avgt 1 5 1 12.400 0.045 nsec/op Thanks, Aleksey.



More information about the core-libs-dev mailing list