当前位置:网站首页>[JVM] memory model
[JVM] memory model
2022-06-11 00:11:00 【Xiangge learns big data】
Catalog
1. To illustrate an object from new Start interaction with memory
jvm Memory model
jvm The memory model can be divided into two parts , As shown in the figure below , The heap and method area are common to all thread pools , And virtual machines z Virtual machine stack , Local method stacks and program counters are thread private

1. Pile up (Heap)
Heap memory is common to all threads , It can be divided into two parts : The young and the old . Image below Perm On behalf of the permanent representative , But note that permanent generations are not part of heap memory , meanwhile jdk1.8 Later permanent generations will also be removed .

The pile is java The largest area of memory managed by a virtual machine , It is also the memory area shared by various threads , This memory area stores object instances and arrays ( But not all object instances are in the heap ). Its size passes through -Xms( minimum value ) and -Xmx( Maximum ) Parameter setting ( The maximum and minimum values should be less than 1G), The former is the minimum memory requested at startup , The default is the physical memory of the operating system 1/64, The latter is JVM Maximum memory that can be requested , Default to physical memory 1/4, By default, when the empty heap memory is less than 40% when ,JVM Will increase heap memory to -Xmx Specified size , It can be done by -XX:MinHeapFreeRation= To specify the ratio column ; When the free heap memory is greater than 70% when ,JVM Will reduce the size of heap memory to -Xms Specified size , It can be done by XX:MaxHeapFreeRation= To specify the ratio column , Of course, to avoid frequent adjustments at runtime Heap Size , Usually -Xms And -Xmx Set the value of to the same . Heap memory = The new generation + Old generation + Lasting generation . When we recycle , We tend to divide heap memory into new and old generations ( Size ratio 1:2), In the Cenozoic, there are Eden and Survivor0,Survivor1 form , The ratio of the three is 8:1:1, The recycling mechanism of the new generation adopts replication algorithm ( When a GC In case of occurrence Eden And a survivor The objects that survive in are placed in another piece survivor in ), stay Minor GC When , We all leave a living area for living objects , The real area is Eden+ One of the survival areas , When our object is older than a certain age ( Default 15, It can be set by parameters ), Will put the object into the old generation , Of course, large objects will directly enter the older generation . The recycling algorithm adopted by the older generation is the tag sorting algorithm .
2. Method area
Method area also known as ” Forever “, It is used to store the class information loaded by the virtual machine 、 Constant 、 Static variables 、 Is an area of memory Shared by each thread . The default minimum value is 16MB, The maximum value is 64MB(64 position JVM Because the pointer expands , The default is 85M), Can pass -XX:PermSize and -XX:MaxPermSize Parameters limit the size of the method area . It's a continuous heap space , The permanent generation of garbage collection is with the elderly generation (old generation) Tied together , So no matter who is full , Will trigger permanent generation and old generation garbage collection . however , An obvious problem is , When JVM The loaded class information capacity exceeds the parameter -XX:MaxPermSize When the set value , Application will report OOM Error of . The parameter is passed through -XX:PermSize and -XX:MaxPermSize To set .
3. Virtual machine stack
Describe the java Memory model for method execution : When each method is executed, a ” Stack frame ”, Used to store local variables ( Including the parameters )、 Stack operation 、 Method exit information . Each method is called to the finished procedure , This corresponds to the process of a stack frame in the virtual machine stack from push to push . The declaration cycle is the same as the thread , Threads are private . Stack frame consists of three parts : Local variable region 、 The stack of operands 、 Frame data area . Local variable areas are organized in units of one word length 、 from 0 Array to start counting , Same as the local variable area , The stack of operands is also organized into an array of word lengths . But unlike the former , It's not accessed by index , It's accessed by pushing and pushing , It can be seen as a storage area for temporary data . In addition to the local variable area and operand stack ,java Stack frames also need some data to support constant pool parsing 、 Normal method return and exception dispatch mechanism . These data are stored in java In the frame data area of the stack frame .
Local variable table : It stores all kinds of basic data types known by the compiler 、 Object reference ( Reference pointer , Not the object itself ), among 64 A length of long and double Type of data is occupied 2 Space of local variables , The rest of the data types only account for 1 individual . The memory space required for local variables is allocated during compilation , When entering a method , How many local variables should be allocated in the stack frame is completely determined , The stack frame does not change the size space of the local variable table during runtime .
4. Native Method Stack
Similar to virtual machine stack , The difference is that the virtual machine stack performs java Method service , The local method stack is for Native Method service .( Stack space is much smaller than heap space )
5. Program counter
It's the smallest memory area , Its function is the line number indicator of bytecode executed by the current thread , In the virtual machine model , The bytecode interpreter works by changing the value of this counter to select the next bytecode instruction to execute , Branch 、 loop 、 exception handling 、 Thread recovery and other basic functions need to rely on counters to complete .
Direct memory
Direct memory is not part of virtual machine memory , Neither Java Memory area defined in virtual machine specification .jdk1.4 New to China NIO, Introduced channel and buffer IO The way , It can call Native Method to allocate out of heap memory directly , This out of heap memory is native memory , Does not affect the size of heap memory .
Reproduced in
https://www.cnblogs.com/itsharehome/p/11290907.html
Frequently asked questions
1. To illustrate an object from new Start interaction with memory
边栏推荐
- [pyGame games] in the first month, it broke 100 million to download a masterpiece that is highly integrated with "super casual game features"~
- 集合删除元素技巧 removeIf
- 【Opencv实战】寒冷的冬季,也会迎来漫天彩虹,这特效你爱了嘛?
- [fireworks in the sky] it's beautiful to light up the night sky with gorgeous fireworks. A programmer brought a fireworks show to pay New Year's greetings to everyone~
- Typecho website speed optimization - Xingze V Club
- 【AI出牌器】第一次见这么“刺激”的斗地主,胜率高的关键因素竟是......
- File转为MultipartFile的方法
- 什么是绝对和相对路径,有哪些优缺点?
- Error report of curl import postman
- Quick sort
猜你喜欢

452. 用最少数量的箭引爆气球

USB IP core FPGA debugging (I)
![[opencv practice] in cold winter, there will be a rainbow. Do you love this special effect?](/img/24/40c299b023f5f8d781d11296bcf28a.png)
[opencv practice] in cold winter, there will be a rainbow. Do you love this special effect?

Basic introduction and core components of kubernetes

The website is harmed by XSS hanging horse

【Pygame小游戏】来了来了它来了——这款五子棋小游戏超A的,分享给你的小伙伴儿一起pk吧~
![[pyGame games] here it is. This Gobang game is super A. share it with your friends~](/img/76/faea3558ed6fadff755c517922088b.png)
[pyGame games] here it is. This Gobang game is super A. share it with your friends~

Bluetooth development (4) -- about flow control

【自动回复小脚本】新年快乐,每一个字都是我亲自手打的,不是转发哦~

Go语言Channel理解使用
随机推荐
[appearance detection artifact] come on, please show me your unique skill (is this appearance worthy of the audience?)
【Turtle表白合集】“海底月是天上月,眼前人是心上人。”余生多喜乐,长平安~(附3款源码)
Merge sort
SQL查询,子查询作为结果字段
763. 划分字母区间
【Pygame小游戏】这款经典的炸弹人超能游戏上线,你爱了嘛?(附源码)
MySQL command line import and export data
The same customized right-click menu beautification on this site - Xingze V Club
启牛学堂理财可靠吗,安全吗
【Pygame小游戏】“史上最炫酷贪吃蛇”驾到,FUN开玩(不好玩不要钱)
Method of converting file to multipartfile
curl导入postman报错小记
yum源更新
Njupt South Post collection_ Experiment 1
Things about Bluetooth development (10) -- getting to know ble for the first time
【Pygame小游戏】趣味益智游戏 :打地鼠,看一下能打多少只呢?(附源码)
【Pygame合集】滴~穿越童年游戏指南 请查收:这里面有你玩过的游戏嘛?(附五款源码自取)
【Pygame小遊戲】別找了,休閑遊戲專題來了丨泡泡龍小程序——休閑遊戲研發推薦
都说验证码是爬虫中的一道坎,看我只用五行代码就突破它。
Is the financial management of qiniu school reliable and safe