java memory deeply - amresh087/newronaRepos GitHub Wiki
Compiler flag
-XX:+PrintCompilation
- In output console first column is showing since the virtual machine is started in mile second.
- In output console second column is showing order the method is compiled in Mili second.
- In output console another column is showing blank but some value like below a. n is denoted native method b. s is denoted synchronous method c. ! is denoted some exceptional handlings happen. d. % is denoted the code is natively complied no it is running special type of memory called code cache
- In output console showing number between 0 to 4. It is showing deep level of compilation. a. 0 is denoted no compilation. The code is just interpreted. b. 1 is denoted deep level of compilation happened. c. 2 is denoted high deep level of compilation. d. 3 is denoted more high level of compilation. e. 4 is denoted more and more high level of compilation in this time special type of memory called code cache.
Note: If you write more complex code then c2 compiler with place in CodeCache Let me comment System.out.print code and pass input 5000 for generate prime number.
Remote machine compiler flag
-XX:+UnlockDiagnosticVMOptions -XX:+LogCompilation
Java compiler is decide if some code is more usage then that is compiled by c2
How can tune cache memory for 4 deep compiler flag
When code cache memory is full then we can get below waring VM waring: CodeCache is full. Compiler has been disabled.
Now we can find out JVM code cache size by using below command. -XX:+PrintCodeCache
Now if you want to increase code cache size then there are three parameters.
- InitialCodeCacheSize
- ReservedCodeCacheSize
- CodeCacheExpansionSize
-XX:ReservedCodeCacheSize=28 -XX:ReservedCodeCacheSize=28k -XX:ReservedCodeCacheSize=28m -XX:ReservedCodeCacheSize=28g
Mean you can pass size in byte, kilobyte, megabyte, gigabyte.
In this example, when first main will called then args variable place in stack then it will place value=7 in stack. Now it is calling calculate method.
Now control will go in calculate method then it will place data=7 after that it will place tempValue=10
After that it will place newValue=20 in stack. When complete the execution of the calculate method then it will remove all variable from stack.
Now value is changing value=20, the code flow is completed then finally stack will be empty
Mean Every thread having separate Stack.
In metaspace storing meta data mean, which method is compile with byte code and which method is compiled with native code All static variables is storing in Meta space. It is working same stack for static variables
In metaspace, all static variables will be live all time garbed collector never clean up
All class and thread having access to meta space
For performance we can increase string pool bucket size. But size number should be prime number The default size is 60013
Now we are going to use next prime number is 120121
Now we can check same code is taking less time Now heap flag
We can set heap size
We can also short sentences
Static variable never participates in garbage collection
Above program run in java1.8
Now running in java11