Write Advanced Applications 3

zhaozj2021-02-08  294

The JIT compiler is provided as a local library that relies on the platform. If the JIT compiler inventory is in, the Java virtual machine will initialize the local code branch of the Java local interface (JNI) to call the JIT function available in the library instead of calling the corresponding function in the interpreter.

The Java.lang.Compiler class is used to load the local library and launch initialization within the JIT compiler. When the Java virtual machine calls a Java method, it uses the invoker method specified in the method block of the loaded class object. The Java virtual machine has several caller methods, for example, if the method is synchronized, or it is a local method, a different caller will be used. JIT compiler uses its own caller. Sun's product can be a value ACC_MACHINE_COMPILED to check the method to tell the interpretation The code's code has been compiled and stored in the load class.

When does the code become a JIT compiled code?

When a method is first called, the JIT compiler compiles the method block into a local code and stores it in the block of the method.

Once the code is compiled, the bit of the ACC_MACHINE_COMPILED used on the Sun platform is set.

How do I know what JIT compiler is doing?

Environment Variable JIT_ARGS allows you to simply control the Sun Solaris JIT compiler. Trace and Exclude (List) are two useful values. To eliminate the Exclude method from the sample inlineme and display the Track Record (Trace), JIT_ARGS should be set as follows:

UNIX:

Export Jit_args = "Trace Exclude (InlineMe.addcount InlineMe.Method1)"

$ java inlineme

Initializing the Jit Library ...

Dynamically Compiling Java / Lang / System.getProperty MB = 0x63E74

Dynamically Compiling Java / Util / Properties.getProperty MB = 0x6DE74

Dynamically Compiling Java / Util / Hashtable.get MB = 0x714ec

Dynamically Compiling Java / Lang / String.hashcode MB = 0x44aec

Dynamically Compiling Java / Lang / String.Equals MB = 0x447F8

Dynamically Compiling Java / Lang / String.Valueof MB = 0x454C4

Dynamically Compiling Java / Lang / String.toString MB = 0x451D0

Dynamically Compiling Java / Lang / StringBuffer. MB = 0x7d690

>>>> Inlined Java / Lang / String.Length (4)

Note that inline methods (such as string.length) are exempt from. String.Length is also a special method, which is generally compiled into an internal shortcut by Java interpretation. When using the JIT compiler, these optimization fails provided by the Java interpreter, so that the JIT compiler can understand which method is being called.

How to use JIT to play your strengths

The first thing to remember is that the JIT compiler will improve most of the speed when calling a method for the second time. The JIT compiler is indeed compiled through the entire method, not the progressive explanation, and the progressive interpret is also a way to improve performance when running an executable JIT-enabled application. This means that if the code is only called once, you will not see too much performance improvement. The JIT compiler will also ignore the constructor, so if possible, the constructor code should be retained. If some Java boundary conditions are not pre-examined, the JIT compiler can also achieve maximum performance improvement, which includes an exception such as a null pointer or a boundary of the border. The JIT compiler can know that the only way to appear zero pointer is to pass the signal provided by the operating system. Since this signal comes from an operating system, instead of from a Java virtual machine, your program will appear performance interference. To ensure that you can get the best performance when you run an application with JIT, you should make sure your code is completely unusual as the zero pointer or a borderport.

If you want to run a Java virtual machine in a remote debug state, or you want to see the source code line rather than see the label in your Java stack track, you may need to make the JIT compiler to fail. To make the JIT compiler fail, provide a blank or invalid name for the JIT compiler when you call the interpreter command. The following example demonstrates the process of compiling the source code as a bytecode with a javac command, and the process of calling the interpretation without the JIT compiler with two forms.

Javac myclass.java

Java -djava.compiler = none myclass

oral

Javac myclass.java

Java -djava.compiler = "" "Myclass

Third-party tool

Other available tools include tools available to reduce general Java class file size. The Java class file includes a region called constant pool. Constant pools maintain a list of strings and other information in a certain place for a list of other information for reference. One of the many information that can be obtained in the constant pool is the name of the method and field.

Class file references a field in the class as a reference to an entry in the constant pool. This means that as long as the reference remains the same, it doesn't matter what value stores in the constant pool. Some tools use this to rewrite the field names and method names in the constant pool into shortened names. With this technology, it can greatly reduce the size of the class file, so that the downloaded file on the Internet is simple.

转载请注明原文地址:https://www.9cbs.com/read-908.html

New Post(0)