-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Inside the JVM #40
Comments
JVM OptionWhat are JVM options? They allow configuring parameters of JVM and are usually specified at the JVM startup.
Here [options] means single or multiple options. If several options are passed, they should be separated by spaces. Standard optionsStandard options are supported by all JVM implementations, which allow you to launch the application, set up an environment, and use some Java APIs.
-D<property_name>=<property_value>: sets a system property value. Non-standard optionsNon-standard options start with -X, where X stands for extension, which can change the mode of runtime compilation, enable profiling, use CDS, and set heap size. Stack Management
Heap Management
It is preferable to limit the maximum size of the heap. This will help reduce the impact of memory leaks on other processes in the operating system. Otherwise, the OS memory may be overused due to the work of your application and other processes will also lack memory.
|
tmp |
Write, compile and run: javac and java (JVM)
First of all, java code goes through 2 stages: a compilation from source code to bytecode (.java -> .class) and a bytecode interpretation.
write by Intellij IDEA
compile by javac
decompile by javap
run by java
What is JVM?
The Java Virtual Machine (JVM) is a virtual simulation of a physical computer that executes compiled Java programs (.class), according to the JVM specification document. The JVM runs as an application on top of an operating system and provides an environment for Java programs.
Because they use virtual machines, Java programs are platform-independent and can be executed on different hardware and operating systems according to the WORA (Write Once Run Anywhere) principle.
There are a lot of different JVM implementations. HotSpot is the primary reference Java VM implementation. It's used by Oracle Java and OpenJDK.
JVMs (including HotSpot) are implemented according to the Java Virtual Machine Specification.
JVM internals overview
Let's consider every subsystem in more detail.
1. class loader subsystem: .class 文件(字节码) 加载和验证子系统
It loads the bytecode for execution, verifies it and then allocates memory for the bytecode.
There are 3 standard class loaders: bootstrap, platform, and system. A class loading process is performed according to a delegation model. Although dealing with classloading is not a daily job for most programmers, understanding the concept helps to investigate some types of exceptions.
2. runtime data areas (RDA): 运行时数据区
It reporesents JVM memory. The areas are used for different purposes during the program execution.
Figure 1. JVM call stack
Every thread has its own PC register, stack, and native method stack, but all threads share the same heap and method area.
3. execution engine: 字节码执行引擎
It is responsible for executing the bytecode. It also interacts with various data areas of the JVM when executing a bytecode.
The execution engine has the following parts:
bytecode interpreter: interprets the bytecode line by line and executes it (rather slowly);
just-in-time compiler (JIT compiler): translates bytecode into native machine language while executing the program (it executes the program faster than the interpreter);
garbage collector: cleans unused objects from the heap.
Different JVM implementations can contain both a bytecode interpreter and a JIT compiler, or only one of them.
The text was updated successfully, but these errors were encountered: