当前位置:网站首页>JVM memory model and local memory
JVM memory model and local memory
2022-06-12 16:50:00 【Fairy wants carry】
Java Class instances of are generally in JVM Heap allocation , and Java It's through JNI call C Code to implement Socket communication , that C Where is the memory required by the code to be run allocated ?C Whether the code can operate directly Java Pile up ?
To answer these questions , Let me start with JVM Relationship with user processes . If you want to run a Java Class file , You can use the following Java Command to execute
java my.class
This Command line Medium java It is actually an executable program , This program will create JVM To load and run your Java class .
The operating system will create a process to execute this java Executable program , Each process has its own virtual address space ,JVM Use of Memory ( Including heaps 、 Stack and method area ) It is allocated from the virtual address space of the process . Please note that ,JVM Memory is just a part of the process space , In addition, there are code segments in the process space 、 Data segment 、 Memory mapped area 、 Kernel space .JVM From the perspective of ,JVM The part outside of memory is called local memory ,C The memory used by the program code in the running process is allocated in the local memory . Let's use a picture to understand .
There is something wrong with this diagram , The method area is already in Java8 Time is put into local memory , Named meta space ——> Deposit class Class loaded class information


that HeapByteBuffer and DirectByteBuffer What's the difference ?HeapByteBuffer The object itself is JVM Heap allocation , And it holds an array of bytes byte[] Also in JVM Heap allocation .
But if you use HeapByteBuffer To receive network data , You need to copy the data from the kernel to a temporary local memory , Copy from temporary local memory to JVM Pile up , Instead of copying directly from the kernel to JVM Pile it up . Why is that ? This is because the data is copied from the kernel to JVM In the process of stacking ,JVM It could happen GC,GC Objects may be moved during the process , in other words JVM The byte array on the heap may be moved , In this case Buffer The address is invalid . If this is transferred through local memory , From local memory to JVM During the copy of the heap JVM Can guarantee not to do GC.
If you use HeapByteBuffer, You'll find that JVM There is a layer of transition between the heap and the kernel , and DirectByteBuffer To solve this problem ,DirectByteBuffer The object itself is JVM Pile it up , But the byte array it holds is not from JVM Allocated on the heap , It is allocated from local memory .
DirectByteBuffer One of the objects is long The type field address, The local address of the memory is recorded , So when receiving data , Pass this local memory address directly to C Program ,C The program will copy the network data from the kernel to this local memory ,JVM You can read this local memory directly , This way ratio HeapByteBuffer One less copy , So generally speaking, it will be faster than HeapByteBuffer Several times faster . You can deepen your understanding through the above figure .
What then? HeapByteBuffer Performance ratio of DirectByteBuffer The difference is still in use ?
This is because the local memory is difficult to manage , It is difficult to locate a memory leak , In terms of stability ,
HeapByteBuffer Better ;
relevant :
(26 Bar message ) Class loading some understanding (—)_Fairy want carry The blog of -CSDN Blog
边栏推荐
- \Begin{algorithm} notes
- Idea displays services on the console to uniformly manage all jetty services,
- Analysis of Nacos config dynamic refresh source code
- The C programming language (version 2) notes / 8 UNIX system interface / 8.3 open, create, close, unlink
- 叶子分享站PHP源码下载
- canvas 高级功能(下)
- pytorch和torchvision官方文档使用方法
- PostgreSQL source code (53) plpgsql syntax parsing key processes and function analysis
- [fishing artifact] UI library second change lowcode tool -- List part (I) design and Implementation
- Extract the new Chinese cross modal benchmark zero from 5billion pictures and texts, and Qihoo 360's new pre training framework surpasses many SOTAS
猜你喜欢
![[MySQL] Cartesian product - multi table query (detailed explanation)](/img/46/6a9a62b35eaa538232da1d738b3931.jpg)
[MySQL] Cartesian product - multi table query (detailed explanation)

How to base on CCS_ V11 new tms320f28035 project

Joint recruitment notice of ganfei research group of Wuhan University and xuzhenjiang research group of Nanchang University

Anyone who watches "Meng Hua Lu" should try this Tiktok effect

Large scale real-time quantile calculation -- a brief history of quantitative sketches

RMI, JNDI, LDAP introduction +log4j vulnerability analysis

双写一致性问题

Idea how to set the guide package without * sign

WebRTC 的音频网络对抗概述

博士申請 | 新加坡國立大學Xinchao Wang老師招收圖神經網絡方向博士/博後
随机推荐
Swin transformer code explanation
Large scale real-time quantile calculation -- a brief history of quantitative sketches
std::set compare
Double write consistency problem
Uniapp壁纸小程序源码/双端微信抖音小程序源码
Recommend AI intelligent drawing repair software
\Begin{algorithm} notes
std::set compare
The C programming language (version 2) notes / 8 UNIX system interfaces / 8.6 instances (directory list)
Differences between SQL and NoSQL of mongodb series
【研究】英文论文阅读——英语poor的研究人员的福利
h t fad fdads
[MySQL] internal connection, external connection and self connection (detailed explanation)
CAS乐观锁
Exception assertion of assertj
博士申请 | 新加坡国立大学Xinchao Wang老师招收图神经网络方向博士/博后
[raspberry pie]: (IV) camera advanced
Super detailed dry goods! Docker+pxc+haproxy build a MySQL Cluster with high availability and strong consistency
pytorch和torchvision官方文档使用方法
SwinTransformer网络架构