Java: what is jitc’s reflection on inflation?

I recently came across this interesting word and searched on the Internet to learn more However, the information I found is rough Someone may give me a detailed explanation of what this is and why it is useful?

From the information I found, it seems that this mechanism makes reflection methods execute faster at the expense of creating a large number of dynamic classes and occupying permanent memory areas, but I'm not sure

Solution

There are some source code mining and coding to calculate by themselves, which I found:

The 'method' class of Java has a member variable 'methodaccessor' of type 'methodaccessor', which is an interface of method 'invoke', similar to the call of method Method calls a method to access the methodaccessor

If inflation is enabled (noinflation is false), the accessor points to the implementation that runs this Java method using JNI (I think getobjectclass, getmethodid and call * method using API) It's like duel dispatch. For this and other reasons, JNI execution is slow (What makes JNI calls slow?)

After 15 times of executing the method through reflection ('15 'is the default and can be changed) and noinflation false, the JNI based accessor immediately creates a class (the name is dynamically generated, for example,' generatedmethodaccessor 1 '), which also has calling methods Now, in this' invoke 'method, it transforms the first' obj 'parameter into its corresponding class, and then calls its target method. It then creates an instance of this class and changes the methodaccessor setting so that each execution of the method is delegated to this instance instead of the JNI accessor This is called inflation

Because this instance is a Java class that delegates to Java objects, the subsequent delegate is an ordinary Java delegate It will never go to JNI, so it saves overhead. In addition, jitc can optimize it because it becomes efficient

The disadvantage is that if many methods are filled in this way, their classes take up extra space and may lead to out of memory errors

For details, see:

http://hg.openjdk.java.net/jdk8/jdk8/jdk/file/tip/src/share/classes/sun/reflect/ReflectionFactory.java

http://java.sun.com/docs/books/jni/html/fldmeth.html

http://anshuiitk.blogspot.com/2010/11/excessive-full-garbage-collection.html

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>