Daily Q: Do you know the Java Virtual Machine architecture it?

For in C / C ++ programmers to develop small partner, it is a headache in the field of memory management, because they always need each newto write the pairing operation delete/freecode. For us as well as Android Java programmers, but always because of automatic memory management in the virtual machine and ignore the importance of memory management.

After a brief few pure Android front, I want to give you one o'clock doping may be too many things you do not usually concern. In fact, when I wrote this very tangled, because for most Android developers, they will pay more attention to substantive skills upgrading, instead I will talk today Java virtual machine architecture.

But after a series of ideological struggle, I was going to say this in the end, in order not to waste too much of the time, I still follow "daily asked" series in mind, we have streamlined the text as much as possible, so that every little knowledge read all time control points in five minutes or less.

Java Virtual Machine architecture interview as a high-frequency test sites, you can as you review the interview knowledge, so perhaps the mentality of your learning will be better.

I still have to go online to take off this chart, I would only use this picture to explain the combination was more easy to understand them.

Java virtual machine memory area is really just made up these parts: method area, a virtual machine stack, native method stacks, stack, program counter.

Program Counter

The program counter is a smaller memory space, thread private, it is the only one not specify any area OOM situation in the Java Virtual Machine Specification.

VM stack

VM stack and program counter, same as for the private thread, and the thread and the same life cycle. . Each data stack are private, does not allow access to other stacks, each time the method is executed at the same time creates a stack frame, each method is invoked until the implementation of the completion of the process, it corresponds to a virtual stack frame Drawing machine from the stack to the process stack. Refer to virtual machine stack compile the main storage of a variety of known basic data types and objects.

Native method stacks

本地方法栈与虚拟机栈发挥的作用非常相似,其主要区别是虚拟机栈为虚拟机执行 Java 方法(也就是字节码)服务,而本地房发展则是为虚拟机用到的 Native 方法服务。

Java 堆

Java 堆是垃圾收集器管理的主要区域,主要用于存放对象的实例,自然而然就成了 Java 虚拟机中管理内存最大的一块,并且它可以处于物理上不连续的内存空间中,Java 堆在虚拟机启动的时候就进行创建,并被所有线程所共享。

方法区

方法区和 Java 堆一样,是各个线程共享的内存区域,主要存储已被虚拟机加载的类信息、常量、静态变量、即时编译器编译后的代码等数据。这个区域的内存回收目标主要是针对常量池的回收和对类型的写在,较少发生垃圾收集行为。

上面对 Java 虚拟机结构进行了非常精简的讲解,大家可还对此清晰了一些?如果还是没有太透彻其实没有关系,多回顾几遍,最好能自己画一个图,在一边进行理解。明天我们再来讲一讲我们另外一个面试非常高频的考点:垃圾回收算法,一起来探究 Java 虚拟机到底是怎么来回收一个无用的对象的。

Guess you like

Origin www.cnblogs.com/liushilin/p/11014168.html