当前位置:网站首页>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 !!
边栏推荐
- QT drawing exception using pure code
- 数组常用方法
- [deep learning] teach you to write "handwritten digit recognition neural network" hand in hand, without using any framework, pure numpy
- The problem that the user name and password are automatically filled in when Google / Firefox manages the background new account
- Points for attention in adding spp module to the network
- [MYCAT] MYCAT configuration file
- Raspberry pie is of great use. Use the campus network to build a campus local website
- synergy局域网实现多主机共享键鼠(amd、arm)
- Accessing a one-dimensional array with a pointer
- String methods and instances
猜你喜欢

‘Results do not correspond to current coco set‘

PDF文本合并
![[activiti] Introduction to activiti](/img/99/e973279d661960853b3af69a7e8ef2.png)
[activiti] Introduction to activiti

【数据库系统原理】第四章 高级数据库模型:统一建模语言UML、对象定义语言ODL

Jupyter notebook select CONDA environment

树莓派大用处,利用校园网搭建一个校园局域网站

A small problem in labelme to VOC code

synergy局域网实现多主机共享键鼠(amd、arm)

String methods and instances

STM32 standard peripheral Library (Standard Library) official website download method, with 2021 latest standard firmware library download link
随机推荐
QT char to qstring hexadecimal and char to hexadecimal integer
day3-jvm+排序总结
Add se channel attention module to the network
‘Results do not correspond to current coco set‘
Write the list to txt and directly remove the comma in the middle
Installation of tensorflow and pytorch frames and CUDA pit records
Accessing a one-dimensional array with a pointer
day2-WebSocket+排序
vsual studio 2013环境 Udp组播
JDBC初级学习 ------(师承尚硅谷)
STM32 standard peripheral Library (Standard Library) official website download method, with 2021 latest standard firmware library download link
"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
MySql下载,及安装环境设置
学习率优化策略
论文阅读-Endmember-Guided Unmixing Network (EGU-Net) 端元指导型高光谱解混网络
JUC并发编程基础(7)--多线程锁
Test whether the label and data set correspond after data enhancement
【深度学习】手写神经网络模型保存
The problem that the user name and password are automatically filled in when Google / Firefox manages the background new account
Machine learning (zhouzhihua) Chapter 1 Introduction notes learning experience