search
HomeJavaJavagetting StartedHow does java code run

How does java code run

Nov 13, 2019 am 09:24 AM
java

How does java code run

#How does the Java virtual machine run Java bytecode?

From the perspective of the virtual machine, executing java code first requires loading the compiled class file into the java virtual machine. The loaded java class will be stored in the method area. When actually running, the virtual machine executes the code in the method area. (Recommended learning: java course)

How does java code run

During the running process, whenever a java method is called, the java virtual opportunity Generate a stack frame in the java method stack of the current thread to store local variables and bytecode operands. The size of this stack frame is calculated in advance, and the Java virtual machine does not require stack frames to be continuously distributed in the memory space.

How does java code run

In hotspot, the above translation process has two forms: the first is interpretation and execution, that is, translating bytecode into machine code one by one and executing it; The second is just-in-time compilation (JIT), which compiles all the bytecode contained in a method into machine code before executing it.

The advantage of the former is that there is no need to wait for compilation, while the advantage of the latter is that it actually runs faster. HotSpot adopts hybrid mode by default, which combines the advantages of interpreted execution and just-in-time compilation. He will first interpret and execute the bytecode, and then compile the hotspot codes that are repeatedly executed in method units on the fly.

How efficient is the Java virtual machine?

Just-in-time compilation is based on the assumption that the program complies with the 80/20 rule, that is, 20% of the code occupies 80% of the computing resources.

For the uncommon code that occupies the majority, we do not need to spend time compiling it into machine code, but run it through interpretation and execution; on the other hand, for the hot code that occupies only a small part, We can compile it into machine code to achieve the desired running speed.

Theoretically speaking, the execution efficiency of a just-in-time compiled java program may exceed that of c. This is because compared with static compilation, just-in-time compilation has the runtime information of the program and can make corresponding optimizations based on this information.

For example: for a virtual method call, although there are many target methods, it may only call one of them during actual operation. This information can be exploited by the just-in-time compiler to avoid the overhead of virtual method calls.

The above is the detailed content of How does java code run. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools