Category: Java Application Performance and Memory Management
-
[Java Application Performance and Memory Management] Chapter 21 – Other Coding Choices
Primitive type vs Reference type Primitives are stored on stack while the other is on heap. Primitive types are mostly faster https://www.baeldung.com/java-primitives-vs-objects BigDecimal vs Double BigDecimal requires more precision which consumes more resources StringBuilder vs String literal StringBuilder always shows better performance If the String literals concatenation is in one…
-
[Java Application Performance and Memory Management] Chapter 20 – How Lists Work
ArrayList ArrayList is internally created as an Array As seen from the above screenshot, it is saved in this.elementData array Initially, the size of the ArrayList is 0 and the elementData length is 0 as well. However when the first element is added, the size of the ArrayList is 1…
-
[Java Application Performance and Memory Management] Chapter 15 – Garbage Collection Tuning
Monitoring/Tuning Garbage Collections Flags -verbose:gc Prints the Garbage Collector activities such as whether they performed Minor GC, Full GC, etc. -XX:-UseAdaptiveSizePolicy Young Generation space like Eden, S0 and S1 area is dynamically being resized by the virtual machine in runtime. This flag is to disable that feature. -XX:NewRatio=n The ratio…
-
[Java Application Performance and Memory Management] Chapter 14 – Garbage Collection
Mark and Sweep During the “Mark” process, the garbage collector looks through the memory space and mark the ones that are being referenced by either stack variables or static variables. During this “Mark” process, the application itself is being paused, which is called “Stop the world”. If there’s any other…
-
[Java Application Performance and Memory Management] Chapter 12, 13 – Monitoring the Heap, Analysing a heap dump
JVisualVM Under the installed jdk directory(e.g. /Library/Java/JavaVirtualMachines/jdk1.8.0_271.jdk/Contents/Home/bin) , there is an execution file called jvisualvm which should look like above screenshot when it’s opened. From the left panel of the applications list, you can select the java application running on your local and see the heap usage of that application…
-
[Java Application Performance and Memory Management] Chapter 10 – Tuning JVM Memory Settings
For tuning JVM settings, we can use below flags -XX:+PrintStringTableStatistics, -XX:StringTableSize=n Updating the String Pool, which can affect the performance of using String. https://willtheguruhome.wordpress.com/2022/02/09/difference-between-string-literal-and-string-object/ -XX:MaxHeapSize=n (same as -Xmxng), -XX:InitialHeapSize=n (same as -Xmsng) Updating the heap size with these flags by like java .. -Xmx1g will enable to set up the…
-
[Java Application Performance and Memory Management] Chapter 9 – Metaspace and the PermGen
All the static variables and general metadata lives in Metaspace area. All the objects on the Heap that are referenced by the static variables in Metaspace will never be garbage collected. Because the static variable is never gone. Before Java 7, it was called as the PermGen. Sometimes when the…
-
[Java Application Performance and Memory Management] Chapter 5 – Passing objects between methods
Passing by Value Passing by Reference – NOT Possible in Java Passing by Value with Objects Final keyword final keyword makes the assignment to happen only once. Generally, using final keyword is good because it allows the Java compiler to potentially optimize the code. However, final keyword doesn’t stop an…
-
[Java Application Performance and Memory Management] Chapter 4 – the stack and the heap
Stack First-In-Last-Out structure. Stores local variables, reference variables, as it lives for short lifetime. It only stores simple data types like primitives(e.g. int, double, ..) . It doesn’t save complex data types like objects. Each Thread has its own Stack Data on a stack cannot be accessed from other threads…
-
[Java Application Performance and Memory Management] Chapter 3- Selecting the JVM
32 bit vs 64 bit Differs per Operating System. 32bit The size of memory pointer is small. The size of memory which is supported by OS is small as well. Might be faster if heap is less than 3GB Only C1 compiler(=Client Compiler) is supported. Application like client application which…
