Java-related compilation technology

Source: Internet
Author: User

 


In addition to Java compilers and virtual machines, there are also some related compilation technologies. This article attempts to give a simple description.

JIT Compiler
The traditional Java Virtual Machine is stupid. After translating a bytecode command into a machine code, the machine code will be executed immediately. After the machine code is executed, the machine code will be lost, then translate the next bytecode command and continue .... Even if you run the bytecode command before the next time, you still need to re-translate it into a machine code for execution. As a result, the efficiency is of course not good.

Virtual machines that use the JIT compiler (Just-In-Time compiler) technology are smarter and will translate the frequently executed parts In the memory for the first Time and then execute them here again, the machine code can be directly taken out from the memory without translation. In this way, as long as your memory is large enough, the JIT compiler technology is good enough, and your Java bytecode execution speed can be close to the pure compiled program.

Compilers in other programming languages
Any file can be executed by a Java Virtual Machine as long as it complies with the Java bytecode format. There are many ways to create a Java bytecode. You do not have to write programs in Java to compile them into Java bytecode. Java is a language and platform. You can only use the Java platform (Java Virtual Machine) without using the Java language (that is, the Java compiler ). If a language provides a compiler that can compile the original code of the language into a Java bytecode format, it can be executed on the Java platform.

As far as I know, the following languages have provided compilers compatible with the Java platform (in alphabetical order): mongodappel, Ada, Agora 98, BAMBOO, Basic, Bistro, Bolero, c, C ++, CLIPS, COBOL, Correlate, Dawn, E, EcmaScript, Eiffel, Foo, Forth, Fortran, Funnel, Haskel, Hojo, JavaScript, Jickle, JIF, Jinni, lisp, LL, LLP, Logo, Luck, MINERVA, Mini, ML, Modula-2, NetRexx, Nice, Oberon-2, Pascal, PLAN, Pnuts, Prolog, PS3I, Python, Sather, scheme, SELF, Simkin, Small Talk, Tcl, WebL, Yassl, Yoix, Yoyo.

Native Compiler
If you don't care whether Java programs can be cross-platform, you want Java programs to be compiled into machine code like C/C ++, instead of Java bytecode, then you can use the native compiler ). Currently, many such products are available.

There are two types of Java Native compilers: one can compile Java's original code into machine code, and the other can compile Java bytecode into machine code.

Decompilation and obfuscators
Java bytecode is easily decompiled because of its simple file format, complete information retained, and its commands are the simplest stack-based architecture ). Decompilation refers to the opposite process of compilation. For Java, decompilation refers to the process of converting Java bytecode into Java original code.

To prevent the hard-developed Java bytecode from being decompiled into the original code by others, you can use the obfuscator to convert your Java bytecode into a more chaotic Java bytecode, the execution results are the same, but the obfuscated Java bytecode is not easily decompiled. You usually have to pay a price for this, because obfuscated programs usually run slowly. In addition, obfuscators can only increase the difficulty of decompilation and cannot guarantee that your program will not be decompiled successfully. After all, if someone is willing to spend a lot of time and energy decompiling your Java bytecode, you will not be able to block it.

Group translation and anti-group Translation
Assembly is a language that is very similar to machine code. A tool that converts an assembly language into a machine code is called a group interpreter. In turn, a tool that converts a machine code into an assembly language is called a dissembler)

For Java virtual machines, Java bytecode is like its machine code. Is there a language that is very close to Java bytecode? That is to say, does Java have any assembly language? Basically, Sun does not define the Java standard assembly language, but some people define their own Java assembly language and provide Java group interpreters (or even anti-group interpreters ). For example, Jasmin and javaa are both Java group interpreters.

Preprocessor
A pre-processor is also called a pre-compiler or a pre-translator ), the purpose is to convert a part of the source code that does not conform to the language specification into a form that complies with the language specification. For example, we may use custom syntax in addition to the Java language in the Java source code. These custom syntaxes cannot be processed by the Java compiler. Therefore, we must first convert the part of the custom syntax into the Java language through a Preprocessor, and then it can be processed by the Java compiler.

Currently, many Java processors, such as iContract and SQLJ, are used to expand the Java language.

Optimization Tool Software
In general, there are two types of optimization:
1. Reducing the file size can save storage space and speed up network transmission.
2. Make the execution faster.
There is also a third Optimization for Java:
3. It is difficult to decompile the program structure. That is, the obfuscation mentioned above ).

These three goals are often mutually exclusive: Structural accidents, which usually slow the program and increase the volume; smaller, usually make the speed slow, and the structure become neat; the speed becomes faster, generally, it makes the volume larger and the structure become neat.


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.