Deep Exploration of how Java works: JVM, Memory recycling, and more

Source: Internet
Author: User
Tags file system garbage collection memory usage new features

The Java language introduces Java virtual machines, which are capable of running across platforms and can be well adapted to various web applications. Also, to improve the performance and robustness of the Java language, new features such as the garbage collection mechanism have been introduced to give Java its unique working principles.

1. Java Virtual machines

The Java Virtual machine (Java MACHINE,JVM) is a software-emulated computer that performs a safe and compatible byte code stored in a. class file on any processor, whether on the computer or in other electronic devices. The Java Virtual machine's "machine code" is stored in the. class file, sometimes referred to as a bytecode file.

The cross-platform nature of Java programs is that bytecode files can be run on any computer or electronic device that has a Java virtual machine, and the Java interpreter in the Java Virtual Machine is responsible for interpreting bytecode files into specific machine code for operation. Therefore, at run time, the Java source program needs to be compiled into a. class file through the compiler.

The establishment of Java Virtual Machine needs to be implemented for different software and hardware platforms, considering the model of the processor and the type of operating system. This allows Java virtual machines to be implemented on UNIX, Linux, Windows, and some real-time operating systems on embedded processing chips such as SPARC architecture, X86 Architecture, MIPS, and PPC.

2. Unwanted memory automatic recovery mechanism

In the process of execution of the program, some of the memory in use after the abandoned state, if not in time for recycling, it is likely to lead to memory leaks, resulting in system crashes. In C + + language is the memory of the programmer to reclaim, programmers need to write the program will not use the object memory freed, this method of management of memory release is often due to the negligence of the programmer caused memory can not be recycled, but also increased the workload of the programmer. In the Java running environment, there is always a system-level thread that specifically tracks memory usage, periodically detects memory that is no longer in use, automatically reclaims it, avoids leaks of memory, and eases the workload of programmers.

3. code security checking mechanism

Security and convenience are always relatively contradictory. The advent of the Java programming language makes it easy for client computers to upload or download Java programs from the network to run on the local computer, but how can you ensure that the Java program does not carry viruses or has no other dangerous purpose? To ensure the security of Java programs, the Java language uses applet programs to control the security of illegal programs, which means that the Java language survives.

Java bytecode execution takes the following 3 steps:

(1) The class loader (loader) is responsible for loading the class file (. class file) into the Java virtual machine. In this process, you need to verify that the class file conforms to the class file specification.

(2) The Bytecode Checker (bytecode verifier) checks the code of the class file for certain illegal operations, such as the operation of the local computer file system written in the applet program.

(3) If the bytecode checker passes, the Java interpreter is responsible for interpreting the class file as machine code for execution.

Attention:

The Java Virtual machine takes the "sandbox" running mode, which restricts the Java program's code and data to a certain memory space, and does not allow the program to access memory outside the memory space. If it is an applet program, access to the client machine's file system is not allowed.

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.