Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the JVM interview questions?

2025-04-09 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article is to share with you what are the contents of the JVM interview questions. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

(1) basic concepts:

JVM is an imaginary computer that can run Java code, including a set of bytecode instructions, a set of registers, a stack,

A garbage collection, heap, and a storage method domain. JVM runs on the operating system and is not directly related to the hardware.

The interaction.

(2) running process:

We all know that Java source files, through the compiler, can produce the corresponding. Class files, that is, bytecode files

The bytecode file is compiled into machine code on a specific machine through the interpreter in the Java virtual machine.

That is, as follows:

① Java source file-- > compiler-- > bytecode file

② bytecode file-- > JVM-- > machine code

The interpreter for each platform is different, but the virtual machine implemented is the same, which is why Java can

For cross-platform reasons, when a program starts to run, the virtual machine begins to instantiate, and multiple programs start.

There are multiple virtual machine instances. If the program exits or closes, the virtual machine instance dies and the data between multiple virtual machine instances does not exist.

Can be shared.

2.1. Thread

The thread here refers to a threaded entity in the process of program execution. JVM allows an application to execute multiple threads concurrently.

There is a direct mapping relationship between Java threads in Hotspot JVM and native operating system threads. When threads are stored locally, buffered

Once the buffer allocation, synchronization objects, stacks, program counters, and so on are ready, an operating system native thread is created.

The Java thread ends and the native thread is recycled. The operating system is responsible for scheduling all threads and assigning them to any

On the CPU. When the native thread is initialized, the run () method of the Java thread is called. When the thread ends

All resources of native and Java threads are freed.

The main system threads running in the background of Hotspot JVM are as follows:

2.2.JVM memory area

JVM memory area is mainly divided into thread private area [program counter, virtual machine stack, local method area], thread sharing area [JAVA heap, method area], and direct memory.

The life cycle of the thread private data area is the same as that of the thread, depending on the start / end of the user thread to create / destroy (within Hotspot VM, each thread is mapped directly to the local thread of the operating system, so the memory / death of this part of the memory area corresponds to the birth / death of the local thread).

The thread sharing area is created / destroyed with the startup / shutdown of the virtual machine.

Direct memory is not part of the JVM runtime data area, but it is also frequently used: NIO feeds introduced in JDK 1.4

Provides IO based on Channel and Buffer, which can use the Native function library to directly allocate out-of-heap memory, and then use the

The DirectByteBuffer object operates as a reference to this piece of memory (for details, see the Java I _ hand O extension), which avoids the Java

Data is replicated back and forth in the heap and Native heap, so performance can be significantly improved in some scenarios.

2.2.1. Program counter (thread private)

A small piece of memory is the line number indicator of the bytecode executed by the current thread, and each thread must have a separate

Program counter, this type of memory is also known as "thread private" memory.

If the java method is being executed, the counter records the address of the virtual machine bytecode instruction (the address of the current instruction). Such as

If it is still the Native method, it is empty.

This memory area is the only one that does not specify any OutOfMemoryError conditions in the virtual machine.

2.2.2. Virtual machine stack (thread private)

Is a memory model that describes the execution of java methods. Each method creates a stack frame (Stack Frame) when it is executed.

It is used to store local variable table, Operand stack, dynamic link, method exit and other information. Each method from the call to the completion of the execution

The process corresponds to the process of a stack frame in the virtual machine stack from stack to stack.

Frame is a data structure used to store data and partial process results, and is also used to handle dynamic links.

(Dynamic Linking), method return value, and exception dispatch (Dispatch Exception). Stack frames are created with method calls

Build and destroy as the method ends-- whether the method completes normally or an exception is completed (exceptions that are not caught within the method are thrown) are counted as the end of the method.

2.2.3. Local method area (thread private)

The local method area works similarly to Java Stack, except that the virtual machine stack serves to execute Java methods, while the local method stack is

Native method service, if a VM implementation uses the C-linkage model to support Native calls, then the stack will be a

C stack, but HotSpot VM directly combines the local method stack with the virtual machine stack.

2.2.4. Heap (Heap- thread sharing)-runtime datazone

Is a memory area shared by threads. The created objects and arrays are stored in Java heap memory, which is also performed by the garbage collector.

The most important area of memory for garbage collection. Because modern VM adopts generation-by-generation collection algorithm, Java heap can be subdivided into Cenozoic (Eden, From Survivor and To Survivor) and old age from the point of view of GC.

2.2.5. Method area / permanent generation (thread sharing)

That is, what we often call Permanent Generation, which is used to store class information, constants, static variables, code compiled by just-in-time compiler and other data loaded by JVM. HotSpot VM extends GC generational collection to the method zone, even if the permanent generation of the Java heap is used to implement the method area, so that HotSpot's garbage collector can manage this part of memory just like managing the Java heap without having to develop a special memory manager for the method area. (the main goal of memory collection with permanent belt is for constant pool recycling and type unloading, so the benefits are generally small). The runtime constant pool (Runtime Constant Pool) is part of the method area. In addition to the description of the version, field, method, interface and other information of the class in the Class file, another piece of information is constant pool Constant Pool Table), which is used to store various literals and symbol references generated during compilation. This part of the content will be stored in the runtime pool of the method area after the class is loaded. The Java virtual machine has strict rules on the format of every part of the Class file (including the constant pool, of course). Every byte used to store which kind of data must meet the specification requirements, so that it can be recognized, loaded and executed by the virtual machine.

Thank you for reading! This is the end of this article on "what are the JVM interview questions?". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report