当前位置:网站首页>day1-jvm+leetcode
day1-jvm+leetcode
2022-07-24 06:06:00 【lonelyMangoo】
First, let's talk about why we wrote the article , I'm going to study second , No matter what the teacher said, I didn't study hard , I can't find internships now , What are you doing
no way , In order not to do five, Decided to start writing articles to record learning , By the way, review the content learned every day in the evening , I hope I can do better every day .
Simply talk about your current goal ,jvm+ Find out all kinds of other aspects , Brush problem top100, Write a web version of fighting landlord , Optimize
Previous projects , Deploy . First of all. , I hope I can stick to .
Today's summary
See the dark horse jvm 1-34
leetcode Did top 3 Tao simple
Look at a little websocket
JVM
jvm The benefits of
java Of ( Binary bytecode ) Running environment
- Write once , Run anywhere
- Automatic memory management , Garbage collection function
- Array subscript out of bounds check
- The bottom layer uses virtual methods to realize polymorphism

Memory structure
1 Program counter
Program Counter Register
Java Code flow :
Code - Interpreter - Machine code -cpu
- effect : Remember the address of the next instruction
- characteristic
- Thread private
- There will be no memory overflow
2 Virtual machine stack
Stack - The memory space required for thread operation
Stack frame - Memory required for each method to run ( Save parameters 、 local variable 、 The return address )
Each thread has only one active stack frame , Corresponding to the currently executing method
Relevant interview questions
- Does garbage collection design stack memory ?
- Unwanted , Will pop up the stack by itself
- The larger the stack memory allocation, the better ?
- No , Physical memory is certain , The larger the stack memory , The number of threads will be less .
- Whether the local variables in the method are thread safe ?
- Local variables are thread private thread safe .
- There will be thread safety problems when passing as method parameters ( Will be shared ).
- As a method return value, there are also problems .( Will be shared )
- Conclusion : There is no escape method. The access scope is safe , Local variables reference objects and escape scope , There are thread safety issues .
Stack memory overflow
Wrong name :java.lang.StackOverflowError
reason :
- There are too many stacks ( Recursion has no end condition , Circular reference one with another )
- The stack frame is too large
Thread running diagnostics
- Case study 1 : cpu Take up too much
- Positioning how to occupy
(1): linux Next
top: Check the system occupation , See which process is taking up too much
ps : It depends on which thread takes up too much
ps H -eo pid,tid,%cpu | grep process id
(2): use jdk Methods
according to jstack Find the problematic thread , Further locate the number of rows of the problem
- Case study 2 : The program runs for a long time without results
jstack+ process id You can see the deadlock
3 Native Method Stack
native method stacks: use c/c++ Compiling api
such as : Object Of clone()
wait()、hashcode()、wait()、notify()、notifyAll()
4 Pile up
heap Pile up : use new The created object uses heap memory
characteristic :
- Thread sharing , Thread safety needs to be considered
- There's a garbage collection mechanism
Heap memory overflow
java.lang.OutOfMemoryError:Java heap space
Heap memory diagnostics
- jps Tools
- See what's in the system java process
- jmap Tools
- Check heap memory usage
- jconsole Tools
- Continuous monitoring
Use jmap When something goes wrong ,
After searching, it may be jdk Version of the problem , So I changed it to jdk11


A mistake … Come again , Change the environment mac edition , Because it uses the command line
mac Next operation : Enter the first /Library/Java/JavaVirtualMachines Find the version number name
vim ~/.bash_profile
modify JAVA_HOME Version number of
source /etc/profile Save it
Reference resources https://www.jianshu.com/p/4fd5f6bc6dfb
And then OK 了 
But the problem remains unsolved …
So use the prompt 
…?? There is another problem at the beginning , People are numb
Permission problems 
Not yet. …
https://zhuanlan.zhihu.com/p/399352540
Brush to a post … Or last year , Also didn't succeed , Forget it, give up , Numb or use jconsole
- Case study : Memory usage is still high after garbage collection
First loading jvisualVM
https://blog.csdn.net/Tanganling/article/details/119790892
Method area
Definition : It's all java A zone shared by virtual machine threads ( Now in local memory ), It stores some information related to the structure of the class : Runtime constant pool 、 Member variables , Method data , Member method , Constructor method and some special methods . Created when the virtual machine starts , Logically, it is a part of the heap . The permanent generation and meta space is an implementation of the method area . The method area will also overflow 
out of memory
- 1.8 Before the permanent generation
- 1.8 And then the meta space
scene :spring and mybatis use cjlib Agents dynamically generate classes to generate many runtime classes , Permanent generation garbage collection ratio Poor .
Constant pool
It's actually a table , Find the class name to be executed according to this table 、 Method name 、 Parameter type 、 Literal quantity and other information .
Binary bytecode includes : Class basic information , Constant pool , Class method definition , Virtual machine instructions
getstatic: Get static variables
ldc: Load a parameter
invokevirtual: Execute a virtual method call
Runtime constant pool
When a class runs, it should be put in memory , The location in memory is the runtime constant pool
StringTable String pool
The information in the constant pool will be loaded into the runtime constant pool , It hasn't become java String object .
ldc When , Will get to StringTable Go inside , If not, the symbol will be changed into a string object and put into the string pool . The zone is created only when it is used ( Lazy loading ).
StringTable It's a hashtable Structure , It can't be expanded .
- Splicing
String s3 = s1+s2 ;
Create a new StringBuilder And call the constructor .

s3 It's in the string pool ,s4 yes new Of , therefore false
s5 It depends on the value after splicing ( Spliced in the compiler , Because they're all constants , Previous s1,s2 They're all constants ) Whether there is , So it is true.
Dynamically spliced elements will not exist in the string pool , Like this ,”a“ and "b" Will appear in the string pool ,"ab" It will not exist in the string pool ( Dynamic splicing ), Will be put in the pile , Only constants can be put in 
call s.intern() Method will try to put it into the string pool , And return the objects in the string pool 
All two are true, Because they are all the same 
On ture: Because they are all taken from the constant pool
Next false:s That's new Coming out
Leetcode
461 Hamming distance
Directly use the loop , Every time and 1 And it's ok
338 Bit count
- Use the cycle , It's too complicated
- Dynamic programming , Only the last one is different , So look Moves to the right one ( Already exist )+ Whether the last one has changed
215 The... In the array K The biggest element
It's a sort question , Read the article by yourself and prepare to realize manual , It turned out to be quite difficult , I forgot everything I learned before , And theory and practice are two different things , Only now 5 A simple one. , Let's sum up tomorrow .
Finally, I want to say
I learned for a long time today , Maybe it's about the same time as the postgraduate entrance examination , Because I suddenly feel helpless , I hope I can stick to it !!
边栏推荐
- bat批处理脚本、同时运行多个文件、按照顺序执行的批处理命令及xshell脚本。
- Draw contour cv2.findcontours function and parameter interpretation
- HAL_ Delay() delay error about 1ms
- Paper reading endmember guided unmixing network (EGU net)
- In GCC__ attribute__ ((constructor) and__ attribute__ ((destructor)).
- Watermelon book / Pumpkin book -- Chapter 1 and 2 Summary
- MySql下载,及安装环境设置
- "Statistical learning methods (2nd Edition)" Li Hang Chapter 13 introduction to unsupervised learning mind map notes
- [MYCAT] Introduction to MYCAT
- Qt char型转QString型 16进制与char型 转 16进制整型
猜你喜欢

Accessing a two-dimensional array with a pointer

Sequential stack C language stack entry and exit traversal

Machine learning (zhouzhihua) Chapter 2 model selection and evaluation notes learning experience
![[activiti] Introduction to activiti](/img/99/e973279d661960853b3af69a7e8ef2.png)
[activiti] Introduction to activiti

‘Results do not correspond to current coco set‘
![[deep learning] handwritten neural network model preservation](/img/4a/27031f29598564cf585b3af20fe27b.png)
[deep learning] handwritten neural network model preservation
![[MYCAT] MYCAT sub database and sub table](/img/a8/ebaedfa084754ef3c96f42ed78eb81.png)
[MYCAT] MYCAT sub database and sub table

【FatFs】手动移植FatFs,将SRAM虚拟U盘

Learning rate optimization strategy

Signals and systems: Hilbert transform
随机推荐
树莓派大用处,利用校园网搭建一个校园局域网站
JUC并发编程基础(1)--相关基础概念
bat批处理脚本、同时运行多个文件、按照顺序执行的批处理命令及xshell脚本。
STM32 DSP库MDK VC5\VC6编译错误: 256, (const float64_t *)twiddleCoefF64_256, armBitRevIndexTableF64_256,
QT drawing exception using pure code
Vscode multiline comments always expand automatically
STM32 standard peripheral Library (Standard Library) official website download method, with 2021 latest standard firmware library download link
对ArrayList<ArrayList<Double>>排序
【FatFs】手动移植FatFs,将SRAM虚拟U盘
【数据库系统原理】第五章 代数和逻辑查询语言:包、扩展操作符、关系逻辑、关系代数与Datalog
"Statistical learning methods (2nd Edition)" Li Hang Chapter 17 latent semantic analysis LSA LSI mind mapping notes and after-school exercise answers (detailed steps) Chapter 17
Numpy cheatsheet
Write the list to txt and directly remove the comma in the middle
jupyter notebook一直自动重启(The kernel appears to have died. It will restart automatically.)
"Statistical learning methods (2nd Edition)" Li Hang Chapter 13 introduction to unsupervised learning mind map notes
How to solve the problem of large distribution gap between training set and test set
Target detection tagged data enhancement code
Commands for quickly opening management tools
QT char to qstring hexadecimal and char to hexadecimal integer
Jupyter notebook select CONDA environment