Detailed knowledge of core Java: JVM + + + distributed micro-service design patterns + Data Structures and Algorithms

JVM

(1) basic concepts:

JVM is a virtual computer executable Java code comprises a bytecode instruction set, a set of registers, a stack,

A garbage collection, and heap storage method for a domain. JVM running on top of the operating system, it does not directly with the hardware

Interactions.

(2) running process:

We all know that Java source file by the compiler, capable of producing the appropriate .Class file, which is byte code file,

The bytecode files and the Java virtual machine interpreter, compiled into machine code on a particular machine.

It is as follows:

① Java source files -> compiler -> bytecode files

② bytecode files -> JVM -> machine code

Each platform interpreter is different, but the implementation of the virtual machine is the same, which is why Java can

The reason of the cross-platform, when a program from running, then start the virtual machine is instantiated, the multiple programs will start

There are multiple virtual machine instances. Or close the program exits, the virtual machine instance die data between a plurality of virtual machine instances not

Can be shared.

2.1 Thread

Here's a thread refers to a thread entity during program execution. JVM allows an application concurrently executing threads.

Hotspot JVM in Java threads and native operating system thread has a direct mappings. When the thread local storage, slow

Red area allocation, synchronization objects, stack, program counter, etc. When ready, it will create an operating system native threads.

Java thread end, native threads will be recycled. Operating system is responsible for scheduling all the threads, and assign them to any

The use of the CPU. When the original thread initialization is complete, it will call run Java thread () method. At the end of the thread, 13/04/2018 Page 21 of 283

We will release all resources and native threads Java threads.

Hotspot JVM thread systems running in the background there are a few below:

2.2.JVM memory area

 

JVM thread private memory area is divided into regions [program counter, stack virtual machines, local area] method, thread shared area

Domain [JAVA heap, the method area], direct memory.

Thread private data area of ​​the life cycle of the same thread, dependent on the user thread start / end and create / destroy (at Hotspot

VM 内, 每个线程都与操作系统的本地线程直接映射, 因此这部分内存区域的存/否跟随本地线程的

生/死对应)。线程共享区域随虚拟机的启动/关闭而创建/销毁。

直接内存并不是 JVM 运行时数据区的一部分, 但也会被频繁的使用: 在 JDK 1.4 引入的 NIO 提

供了基于 Channel 与 Buffer 的 IO 方式, 它可以使用 Native 函数库直接分配堆外内存, 然后使用

DirectByteBuffer 对象作为这块内存的引用进行操作(详见: Java I/O 扩展), 这样就避免了在 Java

堆和 Native 堆中来回复制数据, 因此在一些场景中可以显著提高性能。

2.2.1. 程序计数器(线程私有)

一块较小的内存空间, 是当前线程所执行的字节码的行号指示器,每条线程都要有一个独立的

程序计数器,这类内存也称为“线程私有”的内存。

正在执行 java 方法的话,计数器记录的是虚拟机字节码指令的地址(当前指令的地址)。如

果还是 Native 方法,则为空。

这个内存区域是唯一一个在虚拟机中没有规定任何 OutOfMemoryError 情况的区域。

2.2.2. 虚拟机栈(线程私有)

是描述java方法执行的内存模型,每个方法在执行的同时都会创建一个栈帧(Stack Frame)

用于存储局部变量表、操作数栈、动态链接、方法出口等信息。每一个方法从调用直至执行完成

的过程,就对应着一个栈帧在虚拟机栈中入栈到出栈的过程。

栈帧( Frame)是用来存储数据和部分过程结果的数据结构,同时也被用来处理动态链接

(Dynamic Linking)、 方法返回值和异常分派( Dispatch Exception)。栈帧随着方法调用而创13/04/2018 Page 23 of 283

建,随着方法结束而销毁——无论方法是正常完成还是异常完成(抛出了在方法内未被捕获的异

常)都算作方法结束。

 

 

由于篇幅过大,小编已经整理成一份PDF格式的文档资料,详细讲解,详细看完后你可以收获很多。

 

Spring原理

 

微服务

 

还有其他的就不一一发出来了。这份资料是小编的一位架构师朋友整理了将近一个月才完成的,整理不易,有需要的朋友可以点个赞,转发下后台私信回复“微服务”‘JVM’获取整理出来的Java架构师核心资料。

资料获取方式:关注+转发后+后台私信回复“微服务”‘JVM’获取资料传送门,通过后将有专人免费发放资料。

Guess you like

Origin blog.csdn.net/weixin_45136579/article/details/91049677