java memory deeply - amresh087/newronaRepos GitHub Wiki

Compiler flag

-XX:+PrintCompilation

image

image

  1. In output console first column is showing since the virtual machine is started in mile second.
  2. In output console second column is showing order the method is compiled in Mili second.
  3. 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
  4. 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. image

Remote machine compiler flag

-XX:+UnlockDiagnosticVMOptions -XX:+LogCompilation

image

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

image

Now if you want to increase code cache size then there are three parameters.

  1. InitialCodeCacheSize
  2. ReservedCodeCacheSize
  3. CodeCacheExpansionSize

-XX:ReservedCodeCacheSize=28 -XX:ReservedCodeCacheSize=28k -XX:ReservedCodeCacheSize=28m -XX:ReservedCodeCacheSize=28g

Mean you can pass size in byte, kilobyte, megabyte, gigabyte.

image

image

image

image

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

image

Mean Every thread having separate Stack.

image

image

image

image

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

image

image

image

image

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

image

Now we can check same code is taking less time Now heap flag

image

image

We can set heap size

image

image

image

We can also short sentences

image

image

image

image

Static variable never participates in garbage collection

image

Above program run in java1.8

Now running in java11

image